Servo class¶
-
class
Servo
(servoid=None, serial=None)[source]¶ Represent a connected Smart HerkuleX Actuator.
Servo class allows to establish serial connection with servos, access configuration parameters, get sensor feedbacks and send control instructions.
- Parameters
servoid (int) – The ID of the servo. If not provided, the
Servo
instance will broadcast any command to all connected servo.serial (serial.Serial) – port instance of
serial.Serial
. If not provided, the last used serial port will be used. If no serial port were used yet, an auto detection will be attempted.
- Example
#!/usr/bin/env python import pyherkulex as hx import time # Open the serial port (auto detected) with default baud rate 115200 serial0 = hx.serial() # Broadcast reboot command to all servos connected to serial0 # and light their LED in white broadcast_srv = hx.Servo(serial = serial0) broadcast_srv.reboot() broadcast_srv.led = hx.LED_WHITE # Create an instance of servo ID 0x01 # (considering the last used serial port # as no specific port parameter is provided) srv1 = hx.Servo(0x01) # Check first if there is any error status if srv1.status[0]: # Print status and raise an exception srv1.print_status() raise Exception('Please check your HerkuleX servo error status.') # Print initial position (in step) print('Servo 1 initial position: ', srv1.position) # Get initial angular position (in degree) angle0 = srv1.angle # Enable control mode before sending control instructions srv1.mode = hx.MODE_CONTROL # Increase angular position of 10 degree # to be completed in an operating goal time of 2 second # and light LED in blue srv1.control_angle(angle0+10.0, 2.0, hx.LED_BLUE) # Wait for control instruction to be completed time.sleep(2.0) # Print current position (in step) print('Servo 1 current position: ', srv1.position) # Go back to initial position # to be reached in an operating goal time of 1.5 second # and light LED in green srv1.control_angle(angle0, 1.5, hx.LED_GREEN) # Wait for control instruction to be completed time.sleep(1.5) # Switch off LED of servo 1 srv1.led = hx.LED_OFF
Servo class members¶
Class constants¶
-
class
Servo
[source]¶ -
MODEL
¶ HerkuleX servo model value (int) corresponding to the model number (e.g. 201 corresponds to DRS-0201)
-
VERSION
¶ HerkuleX servo firmware version (int)
-
POSITION_RESOLUTION_DEGREE
¶ HerkuleX servo angular position resolution in degree/step (float)
-
POSITION_MAX
¶ HerkuleX servo maximum supported operating position in step (int)
-
SPEED_INPUT_RESOLUTION_STEP
¶ HerkuleX servo absolute speed input resolution in step/second (float)
-
SPEED_OUTPUT_RESOLUTION_STEP
¶ HerkuleX servo absolute speed output resolution in step/second (float)
-
SPEED_INPUT_RESOLUTION_DEGREE
¶ HerkuleX servo angular speed input resolution in degree/second (float)
-
SPEED_OUTPUT_RESOLUTION_DEGREE
¶ HerkuleX servo angular speed output resolution in degree/second (float)
-
GOAL_SPEED_RESOLUTION_STEP
¶ HerkuleX servo absolute goal speed resolution in step/second (float)
-
GOAL_SPEED_RESOLUTION_DEGREE
¶ HerkuleX servo angular goal speed resolution in degree/second (float)
-
Configuration parameters¶
-
class
Servo
[source]¶ -
status
¶ - Getter
Get status
- Setter
Manually set status
- Type
tuple of two int values (error status code, detailed status code)
-
baudrate
¶ - Getter
Get baud rate in bps
- Setter
Set baud rate in bps (save it in EEPROM)
- Type
int among the values supported by the HerkuleX servo model
-
id
¶ - Getter
Get servo ID
- Setter
Set servo ID
- Type
int from 0 to 254 (0xFE), with 254 corresponding to broadcast ID.
-
id_eeprom
¶ - Getter
Get saved ID from EEPROM
- Setter
Save ID in EEPROM
- Type
int
-
led
¶ - Getter
Get LED color
- Setter
Set LED color
- Type
int
Supported values are given as LED color constants.
-
ack_policy
¶ - Getter
Get acknowledgment policy
- Setter
Set acknowledgment policy
- Type
int
-
ack_policy_eeprom
¶ - Getter
Get saved acknowledgment policy from EEPROM
- Setter
Save acknowledgment policy in EEPROM
- Type
int
-
voltage_alarm_led_policy
¶ - Getter
Get voltage alarm led policy
- Setter
Set voltage alarm led policy
- Type
bool
-
voltage_alarm_led_policy_eeprom
¶ - Getter
Get saved voltage alarm led policy from EEPROM
- Setter
Save voltage alarm led policy in EEPROM
- Type
bool
-
position_alarm_led_policy
¶ - Getter
Get position alarm led policy
- Setter
Set position alarm led policy
- Type
bool
-
position_alarm_led_policy_eeprom
¶ - Getter
Get saved position alarm led policy from EEPROM
- Setter
Save position alarm led policy in EEPROM
- Type
bool
-
packet_alarm_led_policy
¶ - Getter
Get packet alarm led policy
- Setter
Set packet alarm led policy
- Type
bool
-
packet_alarm_led_policy_eeprom
¶ - Getter
Get saved packet alarm led policy from EEPROM
- Setter
Save packet alarm led policy in EEPROM
- Type
bool
-
overload_alarm_led_policy
¶ - Getter
Get overload alarm led policy
- Setter
Set overload alarm led policy
- Type
bool
-
overload_alarm_led_policy_eeprom
¶ - Getter
Get saved overload alarm led policy from EEPROM
- Setter
Save overload alarm led policy in EEPROM
- Type
bool
-
driver_alarm_led_policy
¶ - Getter
Get driver alarm led policy
- Setter
Set driver alarm led policy
- Type
bool
-
driver_alarm_led_policy_eeprom
¶ - Getter
Get saved driver alarm led policy from EEPROM
- Setter
Save driver alarm led policy in EEPROM
- Type
bool
-
register_alarm_led_policy
¶ - Getter
Get register alarm led policy
- Setter
Set register alarm led policy
- Type
bool
-
register_alarm_led_policy_eeprom
¶ - Getter
Get saved register alarm led policy from EEPROM
- Setter
Save register alarm led policy in EEPROM
- Type
bool
-
voltage_mode_free_policy
¶ - Getter
Get voltage mode free policy
- Setter
Set voltage mode free policy
- Type
bool
-
voltage_mode_free_policy_eeprom
¶ - Getter
Get saved voltage mode free policy from EEPROM
- Setter
Save voltage mode free policy in EEPROM
- Type
bool
-
position_mode_free_policy
¶ - Getter
Get position mode free policy
- Setter
Set position mode free policy
- Type
bool
-
position_mode_free_policy_eeprom
¶ - Getter
Get saved position mode free policy from EEPROM
- Setter
Save position mode free policy in EEPROM
- Type
bool
-
packet_mode_free_policy
¶ - Getter
Get packet mode free policy
- Setter
Set packet mode free policy
- Type
bool
-
packet_mode_free_policy_eeprom
¶ - Getter
Get saved packet mode free policy from EEPROM
- Setter
Save packet mode free policy in EEPROM
- Type
bool
-
overload_mode_free_policy
¶ - Getter
Get overload mode free policy
- Setter
Set overload mode free policy
- Type
bool
-
overload_mode_free_policy_eeprom
¶ - Getter
Get saved overload mode free policy from EEPROM
- Setter
Save overload mode free policy in EEPROM
- Type
bool
-
driver_mode_free_policy
¶ - Getter
Get driver mode free policy
- Setter
Set driver mode free policy
- Type
bool
-
driver_mode_free_policy_eeprom
¶ - Getter
Get saved driver mode free policy from EEPROM
- Setter
Save driver mode free policy in EEPROM
- Type
bool
-
register_mode_free_policy
¶ - Getter
Get register mode free policy
- Setter
Set register mode free policy
- Type
bool
-
register_mode_free_policy_eeprom
¶ - Getter
Get saved register mode free policy from EEPROM
- Setter
Save register mode free policy in EEPROM
- Type
bool
-
max_temperature
¶ - Getter
Get maximum allowed temperature (in degree Celsius)
- Setter
Set maximum allowed temperature (in degree Celsius)
- Type
float
-
max_temperature_eeprom
¶ - Getter
Get saved maximum allowed temperature (in degree Celsius) from EEPROM
- Setter
Save maximum allowed temperature (in degree Celsius) in EEPROM
- Type
float
-
min_voltage
¶ - Getter
Get minimum operating voltage (in volt)
- Setter
Set minimum operating voltage (in volt)
- Type
float
-
min_voltage_eeprom
¶ - Getter
Get saved minimum operating voltage (in volt) from EEPROM
- Setter
Save minimum operating voltage (in volt) in EEPROM
- Type
float
-
max_voltage
¶ - Getter
Get maximum operating voltage (in volt)
- Setter
Set maximum operating voltage (in volt)
- Type
float
-
max_voltage_eeprom
¶ - Getter
Get saved maximum operating voltage (in volt) from EEPROM
- Setter
Save maximum operating voltage (in volt) in EEPROM
- Type
float
-
alarm_led_period
¶ - Getter
Get blink period of alarm LED
- Setter
Set blink period of alarm LED
- Type
float
-
alarm_led_period_eeprom
¶ - Getter
Get saved blink period of alarm LED from EEPROM
- Setter
Save blink period of alarm LED in EEPROM
- Type
float
-
fault_check_period
¶ - Getter
Get fault check period for temperature and input voltage
- Setter
Set fault check period for temperature and input voltage
- Type
float
-
fault_check_period_eeprom
¶ - Getter
Get saved fault check period for temperature and input voltage from EEPROM
- Setter
Save fault check period for temperature and input voltage in EEPROM
- Type
float
-
packet_garbage_check_period
¶ - Getter
Get packet garbage check period
- Setter
Set packet garbage check period
- Type
float
-
packet_garbage_check_period_eeprom
¶ - Getter
Get saved packet garbage check period from EEPROM
- Setter
Save packet garbage check period in EEPROM
- Type
float
-
Control parameters¶
-
class
Servo
[source]¶ -
acceleration_ratio
¶ - Getter
Get acceleration ratio
- Setter
Set acceleration ratio
- Type
float from 0 (rectangle speed profile) to 0.5 (triangle speed profile)
-
acceleration_ratio_eeprom
¶ - Getter
Get saved acceleration ratio from EEPROM
- Setter
Save acceleration_ratio in EEPROM
- Type
float from 0 (rectangle speed profile) to 0.5 (triangle speed profile)
-
max_acceleration_time
¶ - Getter
Get max acceleration time
- Setter
Set max acceleration time
- Type
float
-
max_acceleration_time_eeprom
¶ - Getter
Get saved max acceleration time from EEPROM
- Setter
Save max acceleration time in EEPROM
- Type
float
-
dead_zone
¶ - Getter
Get dead zone
- Setter
Set dead zone
- Type
int
The dead zone value corresponds to the permitted difference (in step) between goal position and actual position.
If the difference (error) is less than the dead zone value, servo assumes it has reached the goal position and stops.
-
dead_zone_eeprom
¶ - Getter
Get saved dead zone from EEPROM
- Setter
Save dead zone in EEPROM
- Type
int
-
saturator_offset
¶ - Getter
Get saturator offset
- Setter
Set saturator offset
- Type
int
Saturator offset corresponds to the PWM prescribed value when the servo reaches the dead zone boundary.
-
saturator_offset_eeprom
¶ - Getter
Get saved saturator offset from EEPROM
- Setter
Save saturator offset in EEPROM
- Type
int
-
saturator_slope
¶ - Getter
Get saturator slop
- Setter
Set saturator slop
- Type
int
This value corresponds to the slop of the linear transition of the PWM from the saturator offset value to the maximum PWM value versus position.
-
saturator_slope_eeprom
¶ - Getter
Get saved saturator slop from EEPROM
- Setter
Save saturator slop in EEPROM
- Type
int
-
pwm_offset
¶ - Getter
Get PWM offset
- Setter
Set PWM offset
- Type
int
Prescribed PWM will be increased by the amount of the offset. This offset acts similar to a compensator when constant loads are applied on the servo (e.g. from gravity).
-
pwm_offset_eeprom
¶ - Getter
Get saved PWM offset from EEPROM
- Setter
Save PWM offset in EEPROM
- Type
int
-
pwm_min
¶ - Getter
Get minimum PWM
- Setter
Set minimum PWM
- Type
int
Minimum PWM can be used when there is jerky movement due to tight fitting or friction in the servo application system but assigning a minimum PWM value that is too large may lead to unstable system.
-
pwm_min_eeprom
¶ - Getter
Get saved minimum PWM from EEPROM
- Setter
Save minimum PWM in EEPROM
- Type
int
-
pwm_max
¶ - Getter
Get maximum PWM
- Setter
Set maximum PWM
- Type
int
Maximum PWM affects the output maximum torque. Decreasing maximum PWM can also increase battery life.
-
pwm_max_eeprom
¶ - Getter
Get saved maximum PWM from EEPROM
- Setter
Save maximum PWM in EEPROM
- Type
int
-
pwm_overload_threshold
¶ - Getter
Get PWM overload threshold
- Setter
Set PWM overload threshold
- Type
int
Overload activates when external load is greater than PWM overload threshold. Overload never activates when the PWM overload threshold is set to its maximum permitted value.
-
pwm_overload_threshold_eeprom
¶ - Getter
Get saved PWM overload threshold from EEPROM
- Setter
Save PWM overload threshold in EEPROM
- Type
int
-
min_position
¶ - Getter
Get min operating position
- Setter
Set min operating position
- Type
int
-
min_position_eeprom
¶ - Getter
Get saved min operating position from EEPROM
- Setter
Save min operating position in EEPROM
- Type
int
-
max_position
¶ - Getter
Get max operating position
- Setter
Set max operating position
- Type
int
-
max_position_eeprom
¶ - Getter
Get saved max operating position from EEPROM
- Setter
Save max operating position in EEPROM
- Type
int
-
position_gain_p
¶ - Getter
Get proportional gain of the position PID
- Setter
Set proportional gain of the position PID
- Type
float
-
position_gain_p_eeprom
¶ - Getter
Get saved proportional gain of the position PID from EEPROM
- Setter
Save proportional gain of the position PID in EEPROM
- Type
float
-
position_gain_i
¶ - Getter
Get integral gain of the position PID
- Setter
Set integral gain of the position PID
- Type
float
-
position_gain_i_eeprom
¶ - Getter
Get saved integral gain of the position PID from EEPROM
- Setter
Save integral gain of the position PID in EEPROM
- Type
float
-
position_gain_d
¶ - Getter
Get derivative gain of the position PID
- Setter
Set derivative gain of the position PID
- Type
float
-
position_gain_d_eeprom
¶ - Getter
Get saved derivative gain of the position PID from EEPROM
- Setter
Save derivative gain of the position PID in EEPROM
- Type
float
-
feedforward_gain_1
¶ - Getter
Get position feedforward first gain (Kd)
- Setter
Set position feedforward first gain (Kd)
- Type
float
-
feedforward_gain_1_eeprom
¶ - Getter
Get saved position feedforward first gain (Kd) from EEPROM
- Setter
Save position feedforward first gain (Kd) in EEPROM
- Type
float
-
feedforward_gain_2
¶ - Getter
Get position feedforward second gain (Kdd)
- Setter
Set position feedforward second gain (Kdd)
- Type
float
-
feedforward_gain_2_eeprom
¶ - Getter
Get saved position feedforward second gain (Kdd) from EEPROM
- Setter
Save position feedforward second gain (Kdd) in EEPROM
- Type
float
-
velocity_gain_p
¶ - Getter
Get proportional gain of the velocity PID
- Setter
Set proportional gain of the velocity PID
- Type
float
Note
This argument is available only with servo models DRS-0402 and DRS-0602.
-
velocity_gain_p_eeprom
¶ - Getter
Get saved proportional gain of the velocity PID from EEPROM
- Setter
Save proportional gain of the velocity PID in EEPROM
- Type
float
Note
This argument is available only with servo models DRS-0402 and DRS-0602.
-
velocity_gain_i
¶ - Getter
Get integral gain of the velocity PID
- Setter
Set integral gain of the velocity PID
- Type
float
Note
This argument is available only with servo models DRS-0402 and DRS-0602.
-
velocity_gain_i_eeprom
¶ - Getter
Get saved integral gain of the velocity PID from EEPROM
- Setter
Save integral gain of the velocity PID in EEPROM
- Type
float
Note
This argument is available only with servo models DRS-0402 and DRS-0602.
-
stop_detection_period
¶ - Getter
Get stop detection period
- Setter
Set stop detection period
- Type
float
Servo stop is confirmed if stoppage lasts for detection period time.
-
stop_detection_period_eeprom
¶ - Getter
Get saved stop detection period from EEPROM
- Setter
Save stop detection period in EEPROM
- Type
float
-
overload_detection_period
¶ - Getter
Get overload detection period
- Setter
Set overload detection period
- Type
float
-
overload_detection_period_eeprom
¶ - Getter
Get saved overload detection period from EEPROM
- Setter
Save overload detection period in EEPROM
- Type
float
-
stop_threshold
¶ - Getter
Get stop threshold
- Setter
Set stop threshold
- Type
float
The servo is seen as not moving (stopped) when the position movement of the servo is less than the stop threshold value. The servo is determined to be stopped if the stoppage lasts longer than the stop detection period.
-
stop_threshold_eeprom
¶ - Getter
Get saved stop threshold from EEPROM
- Setter
Save stop threshold in EEPROM
- Type
float
-
inposition_margin
¶ - Getter
Get inposition margin
- Setter
Set inposition margin
- Type
float
Standard value to determine if the prescribed position has been reached.
-
inposition_margin_eeprom
¶ - Getter
Get saved inposition margin from EEPROM
- Setter
Save inposition margin in EEPROM
- Type
float
-
calibration_difference
¶ - Getter
Get calibration difference
- Setter
Set calibration difference
- Type
float
Used to calibrate neutral point of the calibrated position (calibrated position = absolute position - calibration difference). It is generally used to make adjustments and compensate assembly variations.
-
calibration_difference_eeprom
¶ - Getter
Get saved calibration difference from EEPROM
- Setter
Save calibration difference in EEPROM
- Type
float
-
mode
¶ - Getter
Get servo control mode
- Setter
Set servo control mode
- Type
int
- Three control mode values are supported:
MODE_FREE: In this mode, the servo shaft is freely movable. Position control and speed control will not work. Set MODE_CONTROL before that.
MODE_BRAKE: In this mode, servo motion is prevented. Position control and speed control will not work. Set MODE_CONTROL before that.
MODE_CONTROL: In this mode, control instructions are permitted.
-
Control actions and outputs¶
-
class
Servo
[source]¶ -
-
speed_mode
¶ - Getter
Get speed control mode state
- Type
bool
Servo.mode value is MODE_CONTROL and continuous rotation is in progress if speed mode is
True
.
-
operating_time
¶ - Getter
Get current operating time (max 2.856 second)
- Type
float
-
position
¶ - Getter
Get current (calibrated) position
- Type
int
-
angle
¶ - Getter
Get current angular (calibrated) position in degree
- Type
float
-
native_speed
¶ - Getter
Get current native speed
- Type
int
-
speed
¶ - Getter
Get current speed in step/sec
- Type
float
-
angular_speed
¶ - Getter
Get current angular speed in degree/second
- Type
int
-
absolute_position
¶ - Getter
Get current absolute position
- Type
int
-
absolute_angle
¶ - Getter
Get current absolute angle
- Type
float
-
absolute_raw_position
¶ - Getter
Get current absolute raw position (from potentiometer)
- Type
int
Note
This argument is available only with servo models DRS-0402 and DRS-0602.
-
Control sensors¶
-
class
Servo
[source]¶ -
absolute_raw_angle
¶ - Getter
Get current absolute raw angle in degree (from potentiometer)
- Type
float
Note
This argument is available only with servo models DRS-0402 and DRS-0602.
-
absolute_goal_position
¶ - Getter
Get current absolute goal position
- Type
int
-
absolute_goal_angle
¶ - Getter
Get current absolute goal angle
- Type
float
-
absolute_intermediate_goal_position
¶ - Getter
Get current absolute intermediate goal position
- Type
int
-
absolute_intermediate_goal_angle
¶ - Getter
Get current absolute intermediate goal angle
- Type
float
-
intermediate_native_goal_speed
¶ - Getter
Get current intermediate native goal speed
- Type
int
-
intermediate_absolute_goal_speed
¶ - Getter
Get current intermediate absolute goal speed in step/second
- Type
float
-
intermediate_angular_goal_speed
¶ - Getter
Get current intermediate angular goal speed in degree/second
- Type
float
-
pwm
¶ - Getter
Get current pulse width modulation value.
- Type
int from -1023 to 1023
Tip
PWM can be considered as a torque like quantity.
-