This project contains a Python script (controller.py) for controlling the RH56 dexterous hand via a serial port. The script encapsulates the low-level communication protocol and provides a high-level RH56Hand Python class, making it easier for developers to implement complex control logic.
Currently, the project features a Adaptive Force Control function that can adjust force thresholds while dynamically changing finger positions to achieve a preset contact force.
- Basic Control:
- Set/read the angle for all six degrees of freedom (five fingers + thumb rotation).
- Set/read the movement speed for each finger.
- Set/read the force control threshold for each finger (unit: grams).
- Sensor Reading:
- Real-time reading of the pressure sensor for each finger (unit: grams).
- Force Sensor Calibration:
- Provides an interactive calibration routine to calibrate the force sensors before precise control operations.
- Advanced Control Logic:
- Adaptive Force Control (
adaptive_force_control): This is an advanced control mode with the following characteristics:- Position-Force Coordinated Control: Can simultaneously move fingers to a target angle and have them reach a target contact force.
- Step-wise Adjustment: Gradually moves fingers to the target position instead of all at once, making the control process smoother and more stable.
- Intelligent Force Adjustment: During movement, it dynamically adjusts the force control threshold based on the difference between the current force reading and the original target.
- Adaptive Force Control (
- RH56 Dexterous Hand
- USB-to-Serial adapter to connect the hand to the computer
- Python 3
pyseriallibrarynumpylibrary
Before running the script, you need to modify two key parameters at the bottom of the controller.py file, inside the if __name__ == "__main__": block, according to your setup:
-
Serial Port (
port):- Find the line
hand = RH56Hand(...). - Change the
portparameter to the actual serial port recognized by your computer.- Windows: e.g.,
COM3,COM4 - macOS/Linux: e.g.,
/dev/tty.usbserial-xxxxor/dev/ttyUSB0
- Windows: e.g.,
- Find the line
-
Hand ID (
hand_id):- In the same line, modify the
hand_idparameter.- 1: Right Hand
- 2: Left Hand
- In the same line, modify the
Example:
if __name__ == "__main__":
# Modify the parameters here based on your hardware connection
hand = RH56Hand(port="/dev/tty.usbserial-1130", hand_id=1)
...The script can be run directly to start the pre-configured Adaptive Force Control demonstration.
- Connect Hardware: Ensure the dexterous hand is correctly connected to the computer and powered on.
- Modify Configuration: Correctly configure the serial port and hand ID as described in the previous section.
- Execute Script: Run the following command in your terminal:
python controller.py
- Start Calibration (Optional):
- By default, the script first runs
demonstrate_force_calibration. - You will see the prompt
Press Enter to start calibration.... Press Enter to begin. The calibration process takes about 15 seconds. - If you do not need to calibrate, you can comment out the
demonstrate_force_calibration(...)line in the__main__block.
- By default, the script first runs
- Observe Adaptive Force Control:
- After calibration, the script will automatically start the
adaptive_force_controlroutine. - You will see real-time output in the terminal showing each finger's current angle, current force reading, original target force, and the action taken for each iteration.
- The program will finish after reaching the targets or the maximum number of iterations and will print a final summary report.
- After calibration, the script will automatically start the
force_set(thresholds: List[int])
- Function: Directly sets the force control thresholds for the 6 fingers.
- Parameters:
thresholds- A list of 6 integers, with each value ranging from 0-1000g.
angle_set(angles: List[int])
- Function: Sets the target angles for the 6 fingers.
- Parameters:
angles- A list of 6 integers, with each value ranging from 0-1000.
force_act() -> Optional[List[int]]
- Function: Reads and returns the current force sensor readings for the 6 fingers (unit: grams).
- Returns: A list of 6 integers, or
Noneif the read fails.
angle_read() -> Optional[List[int]]
- Function: Reads and returns the current angle positions for the 6 fingers.
- Returns: A list of 6 integers, or
Noneif the read fails.
adaptive_force_control(target_forces: List[int], target_angles: List[int], step_size: int = 50, max_iterations: int = 20)
- Function: Executes the advanced adaptive force control routine.
- Parameters:
target_forces: List of target contact forces (unit: grams).target_angles: List of target angles.step_size: The angle step for each iteration.max_iterations: The maximum number of iterations.
- Returns: A dictionary containing detailed results and history.
demonstrate_force_calibration(port: str, hand_id: int)
- Function: Starts an interactive force sensor calibration routine. It is recommended to run this before performing precision tasks.
- Controller Precision and Response: The precision and response speed of the finger controllers are currently limited.
- Force Control Overshoot: Even at the slowest movement speeds, the force control can overshoot the preset target values by 50-100 grams.
- High-Speed Behavior: When moving at high speeds, the fingers tend to "ignore" the preset maximum force thresholds and move directly to their peak force.
- Testing Status: All features have currently only undergone light and informal testing.