HerkuleXLib
1.2
Arduino library to drive HerkuleX DRS-0101 and DRS-0201
|
Class to drive one servo in position control mode. More...
#include <HkxPosControl.h>
Public Member Functions | |
HkxPosControl (uint8_t ID, HkxCommunication &herkXCom, HkxPrint &print) | |
Constructor. More... | |
uint8_t | getID () const |
Get the ID. More... | |
hkxTorqueControl | getTorqueControl () const |
Get torque control. More... | |
hkxLEDControl | getLEDControl () const |
Get LED control. More... | |
boolean | isInPosition () |
Check if the servo arrived. More... | |
uint8_t | getStatus (HkxStatus &statusED, boolean update) |
Get the status. More... | |
uint8_t | clearStatus () |
Clear the status. More... | |
uint8_t | setLoad (uint16_t newDeadZone, uint8_t newSaturatorOffset, const uint32_t &newSaturatorSlope, int8_t newPWMOffset, uint8_t newMinPWM, uint16_t newMaxPWM) |
Set load control parameters. More... | |
uint8_t | setTorqueLEDControl (HkxMaybe< hkxTorqueControl > newTorqueControl, HkxMaybe< hkxLEDControl > newLEDControl) |
Set torque actuation and LED colour. More... | |
uint8_t | setCurrentPositionTo (int16_t currentPosition) |
Set current position. More... | |
uint8_t | movePosition (int16_t destinationAngle, uint16_t playTime, HkxMaybe< hkxLEDControl > LEDControl, bool waitStop) |
Move position. More... | |
uint8_t | getBehaviour (HkxMaybe< uint16_t > inputVoltage, HkxMaybe< uint16_t > temperature, HkxMaybe< int16_t > position, HkxMaybe< int16_t > velocity, HkxMaybe< int16_t > PWM, HkxMaybe< int16_t > goalPosition, HkxMaybe< int16_t > trajectoryPosition, HkxMaybe< int16_t > trajectoryVelocity) |
Get the servo behaviour. More... | |
uint8_t | reboot () |
Reboot servo. More... | |
Private Attributes | |
HkxCommunication & | _herkXCom |
HkxPrint & | _print |
boolean | _connected |
int16_t | _zeroPosition |
uint8_t | _id |
uint8_t | _deadZone |
uint8_t | _saturatorOffset |
uint16_t | _saturatorSlope |
int8_t | _pwmOffset |
uint8_t | _minPWM |
uint16_t | _maxPWM |
uint16_t | _minPosition |
uint16_t | _maxPosition |
hkxTorqueControl | _torqueControl |
hkxLEDControl | _ledControl |
HkxStatus | _statusED |
Class to drive one servo in position control mode.
This class allows to drive one servo in position control mode.
HkxPosControl::HkxPosControl | ( | uint8_t | ID, |
HkxCommunication & | herkXCom, | ||
HkxPrint & | |||
) |
Constructor.
The constructor of HkxPosControl.
[in] | ID | : id of the servo to drive. The value shall be [0 ; 253]. |
[in] | herkXCom | : Communication with the servos. |
[in] | : Communication to print messages. |
Example:
uint8_t HkxPosControl::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).
Example:
uint8_t HkxPosControl::getBehaviour | ( | HkxMaybe< uint16_t > | inputVoltage, |
HkxMaybe< uint16_t > | temperature, | ||
HkxMaybe< int16_t > | position, | ||
HkxMaybe< int16_t > | velocity, | ||
HkxMaybe< int16_t > | PWM, | ||
HkxMaybe< int16_t > | goalPosition, | ||
HkxMaybe< int16_t > | trajectoryPosition, | ||
HkxMaybe< int16_t > | trajectoryVelocity | ||
) |
Get the servo behaviour.
Get the current servo behaviour. See the user manual for more details about the 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] | position | : Current relative position of the servo. Its value is given in 10^-1 degrees. 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 int16_t (or int ) variable to return the value, or set HKX_NO_VALUE to ignore it. |
[out] | goalPosition | : Goal position of the current move of the servo. Its value is given in 10^-1 degrees. 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] | trajectoryPosition | : Current trajectory position - desired position at a given time according the trajectory - of the servo. Its value is given in 10^-1 degrees. 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] | trajectoryVelocity | : Current trajectory velocity - desired velocity at a given time according the trajectory - 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. |
Example 1: How to get all the values.
Example 2: How to get the current position only.
|
inline |
Get the ID.
Get the ID of the driven servo.
Example:
|
inline |
Get LED control.
Get the current LED control (colour) of the driven servo (see hkxLEDControl for more details about the options).
Example:
uint8_t HkxPosControl::getStatus | ( | HkxStatus & | statusED, |
boolean | update | ||
) |
Get the status.
Get the last received status from the servo.
[out] | statusED | : Last received status of the servo. |
[out] | update | :
|
Example:
|
inline |
Get torque control.
Get the current torque control of the driven servo (see hkxTorqueControl for more details about the options).
Example:
|
inline |
Check if the servo arrived.
Check if the servo is arrived at its goal position.
true
if the servo reached its goal position.false
if the servo is still moving.Example:
uint8_t HkxPosControl::movePosition | ( | int16_t | destinationAngle, |
uint16_t | playTime, | ||
HkxMaybe< hkxLEDControl > | LEDControl, | ||
bool | waitStop | ||
) |
Move position.
Move the servo.
[in] | destinationAngle | : Relative position to reach. Its value shall be set in 10^-1 degrees. Its range depends on _zeroPosition, _minPosition and _maxPosition. |
[in] | playTime | : Time of the action trajectory for the move. Its value shall be set in milliseconds within the range [0 ; 2845ms]. |
[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.
|
[in] | waitStop | :
|
Example:
uint8_t HkxPosControl::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.
Example:
uint8_t HkxPosControl::setCurrentPositionTo | ( | int16_t | currentPosition | ) |
Set current position.
Set the current position of the servo in order to change its relative position (by modifying the _zeroPosition).
_zeroPosition = absolute
- current
;
[in] | currentPosition | : The current position to calibrate the servo. The value shall be set in 10^-1 degrees within the range [-360° ; 360°]. |
Example:
uint8_t HkxPosControl::setLoad | ( | uint16_t | newDeadZone, |
uint8_t | newSaturatorOffset, | ||
const uint32_t & | newSaturatorSlope, | ||
int8_t | newPWMOffset, | ||
uint8_t | newMinPWM, | ||
uint16_t | newMaxPWM | ||
) |
Set load control parameters.
Set the load control parameters of the servo on the RAM (not kept after servo reboot).
PWM+ | ___________........................................ PWM max | \ | \ Saturator slope | \..................................... Saturator offset | |<dead zone> <dead zone> | |___________ ........................ PWM min | | | --------------------------|------------------------ PWM offset | |__________ Position- |____________________________*__________|_____________ Position+ | goal | | position \ | \__________ | PWM-
[in] | newDeadZone | : The dead zone is the angle error before the servo applies a load compensation to maintain its position (see the above figure). Its value shall be set in 10^-1 degrees within the range [0 ; 82.8°]. |
[in] | newSaturatorOffset | : The saturator offset is the step PWM value of the saturator once dead zone the position goes out of the dead zone (see the above figure). Its value shall be set in PWM within the range [0 ; 254]. |
[in] | newSaturatorSlope | : The saturator slop is a gradient of the saturator, going from the saturator offset and increasing gradually the PWM with the error position to the goal (see the above figure). It provides a flexible and elastic response of the servo to external forces. Its value shall be set in 10^-2 PWM / degree within the range [0 ; 393 PWM/degree]. |
[in] | newPWMOffset | : The PWM offset allows compensating permanent load (e.g. gravity) by shifting the saturator by the same value (see the above figure). Its value shall be set in PWM within the range [-128 ; 127]. |
[in] | newMinPWM | : The min PWM is the minimum PWM that is applied by the servo (see the above figure). As specified in the user manual p.37, this may lead to unstable system. Use 0 as default value. The value shall be set in PWM within the range [0 ; 254]. |
[in] | newMaxPWM | : The max PWM is the maximum PWM that is applied by the servo (see the above figure). It could be used to limit the load of the servo, to avoid damages or injuries or instance. The value shall be set in PWM within the range [0 ; 1023]. |
Example:
uint8_t HkxPosControl::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).
[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.
|
[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.
|
Example:
|
private |
Connexion with the servo to drive
|
private |
Current RAM value of the dead zone (saturator curve) of the servo [raw]
|
private |
Communication with servos
|
private |
ID of the servo
|
private |
Current RAM value of the LED of the servo
|
private |
Max Position the servo is allowed to reach [raw]
|
private |
Current RAM value of the max PWM (saturator curve) of the servo [raw]
|
private |
Min Position the servo is allowed to reach [raw]
|
private |
Current RAM value of the min PWM (saturator curve) of the servo [raw]
|
private |
Communication to print messages
|
private |
Current RAM value of the PWM offset (saturator curve) of the servo [raw]
|
private |
Current RAM value of the saturator offset (saturator curve) of the servo [raw]
|
private |
Current RAM value of the saturator slope (saturator curve) of the servo [raw]
|
private |
Last status received from the servo
|
private |
Current RAM value of the torque control of the servo
|
private |
Shift of the neutral position [in degrees]