HerkuleXLib  1.1
Arduino library to drive HerkuleX DRS-0101 and DRS-0201
Public Member Functions | Private Member Functions | Private Attributes | List of all members
HkxContRotation Class Reference

Class to drive one servo in continuous rotation mode. More...

#include <HkxContRotation.h>

Public Member Functions

 HkxContRotation (uint8_t ID, HkxCommunication &herkXCom, HkxPrint &print)
 Constructor. More...
 
boolean tryConnect ()
 Try connect servo. More...
 
uint8_t getID () const
 Get the ID. More...
 
hkxTorqueControl getTorqueControl () const
 Get torque control. More...
 
hkxLEDControl getLEDControl () const
 Get LED control. More...
 
HkxCommunicationgetCommunication () const
 Get servo communication. More...
 
boolean isConnected () const
 Is the servo connected. More...
 
void setLEDControlVariable (hkxLEDControl newLEDControl)
 Set the LED variable. More...
 
boolean isStopped ()
 Check if the servo stopped. More...
 
uint8_t getStatus (HkxStatus &statusED, boolean update)
 Get the status. More...
 
uint8_t clearStatus ()
 Clear the status. More...
 
uint8_t setTorqueLEDControl (HkxMaybe< hkxTorqueControl > newTorqueControl, HkxMaybe< hkxLEDControl > newLEDControl)
 Set torque actuation and LED colour. More...
 
uint8_t moveRotation (int16_t pwm, HkxMaybe< uint16_t > playTime, HkxMaybe< hkxLEDControl > LEDControl)
 Move continuous rotation. More...
 
uint8_t getBehaviour (HkxMaybe< uint16_t > inputVoltage, HkxMaybe< uint16_t > temperature, HkxMaybe< int16_t > velocity, HkxMaybe< int16_t > PWM)
 Get the servo behaviour. More...
 
uint8_t reboot ()
 Reboot servo. More...
 

Private Member Functions

uint8_t updateStatus ()
 Update the status. More...
 
void errorPrint (const String &message)
 Print error. More...
 
void warningPrint (const String &message)
 Print warning. More...
 
void infoPrint (const String &message)
 Print info. More...
 

Private Attributes

HkxCommunication_herkXCom
 
HkxPrint_print
 
boolean _connected
 
const String _className
 
uint8_t _id
 
hkxTorqueControl _torqueControl
 
hkxLEDControl _ledControl
 
HkxStatus _statusED
 

Detailed Description

Class to drive one servo in continuous rotation mode.

This class allows to drive one servo in continuous rotation mode.

Constructor & Destructor Documentation

HkxContRotation::HkxContRotation ( uint8_t  ID,
HkxCommunication herkXCom,
HkxPrint print 
)

Constructor.

The constructor of HkxContRotation.

Parameters
[in]ID: id of the servo to drive. The value shall be [0 ; 253].
[in]herkXCom: Communication with the servos.
[in]print: Communication to print messages.

Example:

HkxPrint print = HkxPrint(Serial, 9600);
HkxCommunication communication = HkxCommunication(HKX_115200, Serial1, print);
HkxContRotation servo = HkxContRotation(10, communication, print); // ID=10, print can be different to communication

Member Function Documentation

uint8_t HkxContRotation::clearStatus ( )

Clear the status.

Clear the status of the servo to leave the "error state" and stop the LED blink and torque deactivation (see p.33 of the user manual for more details about LED and torque policies).

Warning
If the problem still present (e.g. low input voltage), the servo will switch again to error just after clearing.
Returns
0 = OK
1 = Input not correct
2 = Servo not connected

Example:

...
HkxContRotation servo = HkxContRotation(10, communication, print);
HkxStatus currentStatus;
byte error = servo.getStatus(currentStatus, true);
if(error==0 && currentStatus.isError(HKX_STAT_ALL)){ // check if any error
servo.clearStatus();
}
void HkxContRotation::errorPrint ( const String &  message)
inlineprivate

Print error.

Print an error message if setup.

Parameters
[in]message: content to print as an error.
uint8_t HkxContRotation::getBehaviour ( HkxMaybe< uint16_t >  inputVoltage,
HkxMaybe< uint16_t >  temperature,
HkxMaybe< int16_t >  velocity,
HkxMaybe< int16_t >  PWM 
)

Get the servo behaviour.

Get the current servo behaviour. See the user manual for more details about the parameters.

Parameters
[out]inputVoltage: Current servo input voltage. Its value is given in millivolts. This parameter is optional, either set the address of a uint16_t (or unsigned int) variable to return the value, or set HKX_NO_VALUE to ignore it.
[out]temperature: Current temperature of the servo. Its value is given in 10^-2 °C (degree Celsius). This parameter is optional, either set the address of a uint16_t (or unsigned int) variable to return the value, or set HKX_NO_VALUE to ignore it.
[out]velocity: Current angle velocity of the servo. Its value is given in degree / second. This parameter is optional, either set the address of a uint16_t (or unsigned int) variable to return the value, or set HKX_NO_VALUE to ignore it.
[out]PWM: Current PWM (load) of the servo. Its value is given in PWM (raw). This parameter is optional, either set the address of a uint16_t (or unsigned int) variable to return the value, or set HKX_NO_VALUE to ignore it.
Returns
0 = OK
1 = Input not correct
2 = Servo not connected

Example 1: How to get all the values.

...
HkxContRotation servo = HkxContRotation(10, communication, print);
uint16_t inputVoltage, temperature;
int16_t velocity, PWM;
servo->getBehaviour(&inputVoltage, &temperature, &velocity, &PWM);

Example 2: How to get the current velocity only.

int16_t velocity;
servo->getBehaviour(HKX_NO_VALUE, HKX_NO_VALUE, &velocity, HKX_NO_VALUE);
HkxCommunication& HkxContRotation::getCommunication ( ) const
inline

Get servo communication.

Get the communication of the servo.

Returns
Return the communication.
uint8_t HkxContRotation::getID ( ) const
inline

Get the ID.

Get the ID of the driven servo.

Returns
Return the ID.

Example:

...
HkxContRotation servo = HkxContRotation(10, communication, print);
...
byte idOfMyServo = servo.getID();
hkxLEDControl HkxContRotation::getLEDControl ( ) const
inline

Get LED control.

Get the current LED control (colour) of the driven servo (see hkxLEDControl for more details about the options).

Returns
Return the LED control.

Example:

...
HkxContRotation servo = HkxContRotation(10, communication, print);
hkxLEDControl ledControlOfMyServo = servo.getLEDControl();
uint8_t HkxContRotation::getStatus ( HkxStatus statusED,
boolean  update 
)

Get the status.

Get the last received status from the servo.

Parameters
[out]statusED: Last received status of the servo.
[out]update:
  • true to update the status, then to get the current status.
  • false to get the last received status.
Returns
0 = OK
1 = Input not correct
2 = Servo not connected
3 = Data not consistent

Example:

...
HkxContRotation servo = HkxContRotation(10, communication, print);
HkxStatus currentStatus;
byte error = servo.getStatus(currentStatus, true);
if(error==0 && currentStatus.isError(HKX_STAT_VOLTAGE)){ // check voltage error
print.errorPrint(F("Please check input voltage"));
}
hkxTorqueControl HkxContRotation::getTorqueControl ( ) const
inline

Get torque control.

Get the current torque control of the driven servo (see hkxTorqueControl for more details about the options).

Returns
Return the torque control

Example:

...
HkxContRotation servo = HkxContRotation(10, communication, print);
hkxTorqueControl torqueControlOfMyServo = servo.getTorqueControl();
void HkxContRotation::infoPrint ( const String &  message)
inlineprivate

Print info.

Print an info message if setup.

Parameters
[in]message: content to print as an info.
boolean HkxContRotation::isConnected ( ) const
inline

Is the servo connected.

Return if the servo is connected.

Returns
  • true: if the servo is connected (last communication worked),
  • false: if the servo is NOT connected (last communication failed).
boolean HkxContRotation::isStopped ( )
inline

Check if the servo stopped.

Check if the servo is stopped.

Returns
  • true if the servo is stopped.
  • false if the servo is still moving.

Example:

...
HkxPosControl servo = HkxPosControl(10, communication, print);
servo.moveRotation(512, 2000, HKX_NO_VALUE); // move at 512 PWM during 2 seconds
... // different actions done during the movement
while(!servo.isStopped()){} // wait the servo to be stopped
uint8_t HkxContRotation::moveRotation ( int16_t  pwm,
HkxMaybe< uint16_t >  playTime,
HkxMaybe< hkxLEDControl LEDControl 
)

Move continuous rotation.

Move the servo in continuous rotation.

Parameters
[in]pwm: Torque power to apply. Its value shall be set in PWM within the range [-1023 ; 1023].
[in]playTime: Time of the action. Its value shall be set in milliseconds. This parameter is optional, either set a uint16_t (or unsigned int) variable, or set HKX_NO_VALUE to ignore it.
[in]LEDControl: LED control to apply. This parameter is optional, either set a hkxLEDControl variable, the value (list below), or set HKX_NO_VALUE to ignore it.
  • HKX_LED_OFF,
  • HKX_LED_GREEN,
  • HKX_LED_BLUE,
  • HKX_LED_RED,
  • HKX_LED_CYAN,
  • HKX_LED_YELLOW,
  • HKX_LED_PINK,
  • HKX_LED_WHITE, move.
Returns
0 = OK
1 = Input not correct
2 = Servo not connected

Example:

...
HkxContRotation servo = HkxContRotation(10, communication, print);
servo.move(1200, 1500, HKX_NO_VALUE, true); // move to position 120° in 1.5 seconds and wait arrival
uint8_t HkxContRotation::reboot ( )

Reboot servo.

Reboot the servo. This action will erase the ram, then reinitialize the parameters with the EEP (ROM) values. Wait some time (> 500 ms) before asking any action from the servo.

Returns
0 = OK
2 = Servo not connected

Example:

...
HkxContRotation servo = HkxContRotation(10, communication, print);
servo->reboot();
wait(500); // wait for the servo to restart
...
void HkxContRotation::setLEDControlVariable ( hkxLEDControl  newLEDControl)
inline

Set the LED variable.

Set the LED variable in the class without applying.

Warning
This member is for HkxGroupPosControl use only.
Parameters
[in]newLEDControl: Colour of the led (see hkxLEDControl for more details).
uint8_t HkxContRotation::setTorqueLEDControl ( HkxMaybe< hkxTorqueControl newTorqueControl,
HkxMaybe< hkxLEDControl newLEDControl 
)

Set torque actuation and LED colour.

Set the torque actuation (hkxTorqueControl for more details) and the LED colour (hkxLEDControl for more details).

Parameters
[in]newTorqueControl: Torque control to apply. This parameter is optional, either set a hkxTorqueControl variable, the value (list below), or set HKX_NO_VALUE to ignore it.
  • HKX_TORQUE_FREE: no resistance to the movements (or let say mechanical resistance only)
  • HKX_TORQUE_BREAK: the motor resists but allows the movements
  • HKX_TORQUE_ON: the motor maintain its position (don't allow movements)
[in]newLEDControl: LED control to apply. This parameter is optional, either set a hkxLEDControl variable, the value (list below), or set HKX_NO_VALUE to ignore it.
  • HKX_LED_OFF,
  • HKX_LED_GREEN,
  • HKX_LED_BLUE,
  • HKX_LED_RED,
  • HKX_LED_CYAN,
  • HKX_LED_YELLOW,
  • HKX_LED_PINK,
  • HKX_LED_WHITE,
Returns
0 = OK
1 = Input not correct
2 = Servo not connected

Example:

...
HkxContRotation servo = HkxContRotation(10, communication, print);
servo.setTorqueLEDControl(HKX_LED_GREEN, HKX_NO_VALUE); // set the led to green
servo.setTorqueLEDControl(HKX_LED_WHITE, HKX_TORQUE_BREAK); // set the led to white and the torque to break
boolean HkxContRotation::tryConnect ( )

Try connect servo.

Try to connect to the servo.

Returns
  • true: if the servo is connected,
  • false: if the servo is NOT connected.
uint8_t HkxContRotation::updateStatus ( )
private

Update the status.

Perform a status request to update the stored status _statusED.

Returns
0 = OK
1 = Input not correct
2 = Servo not connected
3 = Data not consistent
void HkxContRotation::warningPrint ( const String &  message)
inlineprivate

Print warning.

Print a warning message if setup.

Parameters
[in]message: content to print as a warning.

Member Data Documentation

const String HkxContRotation::_className
private

Class name to print the messages

boolean HkxContRotation::_connected
private

Connexion with the servo to drive

HkxCommunication& HkxContRotation::_herkXCom
private

Communication with servos

uint8_t HkxContRotation::_id
private

ID of the servo

hkxLEDControl HkxContRotation::_ledControl
private

Current RAM value of the LED of the servo

HkxPrint& HkxContRotation::_print
private

Communication to print messages

HkxStatus HkxContRotation::_statusED
private

Last status received from the servo

hkxTorqueControl HkxContRotation::_torqueControl
private

Current RAM value of the torque control of the servo


The documentation for this class was generated from the following files: