Python API Reference
This section documents the full Python API.
- class HandExo(name='NMLHandExo', port=None, baudrate=57600, command_delimiter='\\n', send_delay=0.01, verbose=False)[source]
Bases:
object
Class to control the NML Hand Exoskeleton via serial communication.
- Features:
Enable/disable motors
Move motors to specific angles
Query status (angle, torque, current)
Configure velocity and acceleration
Retrieve device information
Send low-level serial commands
- Parameters:
port (str)
baudrate (int)
command_delimiter (str)
send_delay (float)
verbose (bool)
- __init__(name='NMLHandExo', port=None, baudrate=57600, command_delimiter='\\n', send_delay=0.01, verbose=False)[source]
Initializes the HandExo interface.
- Args:
name (str): Name of the exoskeleton instance. port (str): Serial port to connect to (e.g., ‘COM3’ or ‘/dev/ttyUSB0’). baudrate (int): Baud rate for the serial connection (default is 57600). command_delimiter (str): Delimiter used to separate commands (default is ‘
- ‘).
send_delay (float): Delay in seconds after sending a command to allow processing (default is 0.01). verbose (bool): If True, enables verbose logging of commands and responses (default is False).
- Parameters:
port (str | None)
baudrate (int)
command_delimiter (str)
send_delay (float)
verbose (bool)
- logger(*argv, warning=False)[source]
Robust debugging print function
- Parameters:
*argv – (str) Messages to log.
warning (
bool
) – (bool) If True, prints the message in yellow.
- connect(port, baudrate)[source]
Establishes a serial connection to the exoskeleton.
- Parameters:
port (str) – Serial port to connect to.
baudrate (int) – Baud rate for the serial connection.
- send_command(cmd)[source]
Sends a command to the exoskeleton over the serial connection.
- Parameters:
cmd (str) – Command to send to the exoskeleton.
- home(motor_id)[source]
Sends a home command to all motors, unless a specific motor ID is provided.
- Parameters:
motor_id (int or str) – ID of the motor to home, or ‘all’ to home all motors.”
- Returns:
None
- info()[source]
Retrieves information about the exoskeleton, including version and motor details.
- Returns:
A dictionary containing version and motor information.
- Return type:
dict
- enable_motor(motor_id)[source]
Enables the torque output for the specified motor.
- Parameters:
motor_id (int or str) – ID of the motor to enable.
- Returns:
None
- disable_motor(motor_id)[source]
Disables the torque output for the specified motor.
- Parameters:
motor_id (int or str) – ID of the motor to disable.
- Returns:
None
- get_motor_angle(motor_id)[source]
Retrieves the current relative angle of the specified motor.
- Parameters:
motor_id (int or str) – ID of the motor to query.
- Returns:
Current angle of the motor in degrees.
- Return type:
float
- set_motor_angle(motor_id, angle)[source]
Sets the angle for the specified motor.
- Parameters:
motor_id (int or str) – ID of the motor to set the angle for.
angle (float) – Desired angle in degrees.
- Returns:
None
- get_absolute_motor_angle(motor_id)[source]
Retrieves the absolute angle of the specified motor.
- Parameters:
motor_id (int or str) – ID of the motor to query.
- Returns:
Absolute angle of the motor in degrees.
- Return type:
float
- set_absolute_motor_angle(motor_id, angle)[source]
Sets the absolute angle for the specified motor.
- Parameters:
motor_id (int or str) – ID of the motor to set the absolute angle for.
angle (float) – Desired absolute angle in degrees.
- Returns:
None
- get_motor_velocity(motor_id)[source]
Retrieves the current velocity of the specified motor.
- Parameters:
motor_id (int or str) – ID of the motor to query.
- Returns:
Current velocity of the motor in degrees per second.
- Return type:
float
- set_motor_velocity(motor_id, velocity)[source]
Sets the velocity for the specified motor.
- Parameters:
motor_id (int or str) – ID of the motor to set the velocity for.
velocity (float) – Desired velocity in degrees per second.
- Returns:
None
- get_motor_acceleration(motor_id)[source]
Retrieves the current acceleration of the specified motor.
- Parameters:
motor_id (int or str) – ID of the motor to query.
- Returns:
Current acceleration of the motor in degrees per second squared.
- Return type:
float
- set_motor_acceleration(motor_id, acceleration)[source]
Sets the acceleration for the specified motor.
- Parameters:
motor_id (int or str) – ID of the motor to set the acceleration for.
acceleration (float) – Desired acceleration in degrees per second squared.
- Returns:
None
- get_motor_torque(motor_id)[source]
Retrieves the current torque of the specified motor.
- Parameters:
motor_id (int or str) – ID of the motor to query.
- Returns:
Current torque of the motor in Newton-meters.
- Return type:
float
- get_motor_current(motor_id)[source]
Retrieves the current draw of the specified motor.
- Parameters:
motor_id (int or str) – ID of the motor to query.
- Returns:
Current draw of the motor in Amperes.
- Return type:
float
- get_motor_status(motor_id)[source]
Retrieves the status of the specified motor, including angle, torque, current, velocity, and acceleration.
- Parameters:
motor_id (int or str) – ID of the motor to query.
- Returns:
A dictionary containing the motor’s status.
- Return type:
dict
- get_motor_limits(motor_id)[source]
Retrieves the limits for the specified motor, including minimum and maximum angles.
- Parameters:
motor_id (int or str) – ID of the motor to query.
- Returns:
A tuple containing the minimum and maximum angles of the motor.
- Return type:
tuple
- set_motor_upper_limit(motor_id, upper_limit)[source]
Sets the upper limit for the specified motor.
- Parameters:
motor_id (int or str) – ID of the motor to set the upper limit for.
upper_limit (float) – Desired upper limit in degrees.
- Returns:
None
- set_motor_lower_limit(motor_id, lower_limit)[source]
Sets the lower limit for the specified motor.
- Parameters:
motor_id (int or str) – ID of the motor to set the lower limit for.
lower_limit (float) – Desired lower limit in degrees.
- Returns:
None
- set_motor_limits(motor_id, lower_limit, upper_limit)[source]
Sets both the lower and upper limits for the specified motor.
- Parameters:
motor_id (int or str) – ID of the motor to set the limits for.
lower_limit (float) – Desired lower limit in degrees.
upper_limit (float) – Desired upper limit in degrees.
- Returns:
None
- reboot_motor(motor_id)[source]
Reboots the specified motor.
- Parameters:
motor_id (int or str) – ID of the motor to reboot.
- Returns:
None
- enable_led(motor_id)[source]
Enables the LED for the specified motor.
- Parameters:
motor_id (int or str) – ID of the motor to enable the LED for.
- Returns:
None
- disable_led(motor_id)[source]
Disables the LED for the specified motor.
- Parameters:
motor_id (int or str) – ID of the motor to disable the LED for.
- Returns:
None