Various functions¶
simultaneous_control¶
-
simultaneous_control
(time, *instructions)[source]¶ Send control instructions to several servos at the same time. All servos have the same operating goal time to complete their instruction.
- Parameters
time (float) – Operating goal time.
*instructions (tuples) –
Each control instruction is stored in a tuple containing the following items:
servo, an instance of
pyherkulex.Servo
goal value, desired position value or desired speed value, depending on control mode, or
None
for ignoring this control instructioncontrol mode (optional), among the position and speed control constants (default is
pyherkulex.CONTROL_POSITION_DEGREE
)led color (optional), integer among the LED color constants (default is
pyherkulex.LED_OFF
)stop (optional), either
True
to stop servo at current position orFalse
(default) to continue control instructionsvelocity override - VOR (optional), either
True
(default) to enable VOR orFalse
to disable VOR (if the servo model allows to disable VOR)
Note
Each servo must have its control mode enabled before sending control instructions.
- Example
Sending simultaneous instructions to two servos with respective IDs 0x01 and 0x02. The first servo has its position set to -10 degree with its LED switched off. The second servo has its speed set to 3.5 degree/second with its LED lighting green. Both servos have the same operating goal time of 1.5 second.
#!/usr/bin/env python import pyherkulex as hx srv1 = hx.Servo(0x01) srv2 = hx.Servo(0x02) srv1.mode = srv2.mode = hx.MODE_CONTROL hx.simultaneous_control(1.5, (srv1, -10.0), (srv2, 3.5, hx.SPEED_DEGREE, hx.LED_GREEN))
independent_control¶
-
independent_control
(*instructions)[source]¶ Send control instructions to several servos at the same time. Each servo has its own goal time to complete its instruction.
- Parameters
*instructions (tuples) –
Each instruction is stored in a tuple containing the following items:
goal time, the operating time to complete the instruction
servo, an instance of
pyherkulex.Servo
goal value, desired position value or desired speed value, depending on control mode, or
None
for ignoring this control instructioncontrol mode (optional), among the position and speed control constants (default is
pyherkulex.CONTROL_POSITION_DEGREE
)led color (optional), integer among the LED color constants (default is
pyherkulex.LED_OFF
)stop (optional), either
True
to stop servo at current position orFalse
(default) to continue control instructionsvelocity overide - VOR (optional), either
True
(default) to enable VOR orFalse
to disable VOR (if the servo model allows to disable VOR)
Note
Each servo must have its control mode enabled before sending control instructions.
- Example
Sending independent control instructions to two servos with respective IDs 0x01 and 0x02. The first servo has 1.5 second to reach a prescribed position set to -10 degree and its LED switched off. The second servo has 2.0 second to reach a prescribed speed set to 3.5 degree/second and its LED lighting blue.
#!/usr/bin/env python import pyherkulex as hx srv1 = hx.Servo(0x01) srv2 = hx.Servo(0x02) srv1.mode = srv2.mode = hx.MODE_CONTROL hx.independent_instructions((1.5, srv1, -10.0), (2.0, srv2, 3.5, hx.SPEED_DEGREE, hx.LED_BLUE))
find¶
-
find
(number=None, port=None, baudrate=(57600, 115200, 200000, 250000, 400000, 500000, 666666, 1000000), timeout=0.05, fast=False, verbose=True)[source]¶ Scan all possible ID with each supported baud rate and return a dictionary which maps connected servo IDs to tuples containing HerkuleX servo model and baudrate.
- Parameters
number (int) – Number of servos supposed to be connected to serial bus.
port (str) – Serial port name or tuple of several port names to be successively tested. If not specified, each available port will be checked successively,
'COM1'
to'COM256'
if using Windows, any'/dev/ttyUSB*'
and'/dev/ttyS*'
if using Linux or any'/dev/tty.usbserial-'
if using OSx.baudrate (int) – Baud rate, or tuple of several baud rate values to be successively tested.
timeout (float) – Set serial read timeout value.
fast (bool) – For each baud rate, incremental scanning is performed on all possible IDs separately only if any signal is received to a prior call broadcasted to all servo IDs together.
verbose (bool) – Print scanning progression.
- Returns
Dictionary mapping successfully tested ports to dictionaries mapping connected servo IDs to tuples containing two items each (servo model, baudrate).
- Return type
dict
serial¶
-
serial
(port=None, baudrate=115200, timeout=1.0)[source]¶ Open the serial port where HerkuleX servo communication bus is attached.
The output serial port will be considered as default serial port anytime a serial port instance is required but not specified.
- Parameters
port (str) – Serial port name. If not specified, its considered value will be
'COM3'
if using Windows, the first'/dev/ttyUSB*'
or'/dev/ttyS*'
found if using Linux or the first'/dev/tty.usbserial-*'
found if using OSx.baudrate (int) – Set baud rate value among the possible values supported by the servo model.
timeout (float) – Set a read timeout value.
- Returns
Connection instance of
serial.Serial
.- Return type
serial.Serial
- Raises
SerialException – In case the device can not be found or can not be configured.