Torque Control
Use hand.torque to control and read the torque of the 16 joint motors on the L20 dexterous hand.
- Torque range: 0-100
- Unit: Unitless percentage
Set Torque
from realhand import L20
from realhand.hand.l20 import L20Torque
# Using a list (16 joints)
hand.torque.set_torques([50.0] * 16)
# Using an L20Torque object
torques = L20Torque(
thumb_abd=50.0, # Thumb abduction
thumb_yaw=30.0, # Thumb rotation
thumb_root1=60.0, # Thumb root
thumb_tip=40.0, # Thumb tip
index_abd=50.0, # Index abduction
index_root1=60.0, # Index root
index_tip=40.0, # Index tip
middle_abd=50.0, # Middle abduction
middle_root1=60.0, # Middle root
middle_tip=40.0, # Middle tip
ring_abd=50.0, # Ring abduction
ring_root1=60.0, # Ring root
ring_tip=40.0, # Ring tip
pinky_abd=50.0, # Pinky abduction
pinky_root1=60.0, # Pinky root
pinky_tip=40.0, # Pinky tip
)
hand.torque.set_torques(torques)
Read Torque
Blocking Read
from realhand.exceptions import TimeoutError
try:
data = hand.torque.get_blocking(timeout_ms=500)
print(f"Thumb abduction: {data.torques.thumb_abd}")
print(f"All torque values: {data.torques.to_list()}")
except TimeoutError:
print("Read timed out")
Cached Read
data = hand.torque.get_snapshot()
if data:
print(f"Torque: {data.torques.to_list()}")
print(f"Timestamp: {data.timestamp}")
Streaming Read
Receive all sensor events through the top-level hand.stream() interface:
from realhand.hand.l20 import SensorSource, TorqueEvent
hand.start_polling({SensorSource.TORQUE: 0.1})
try:
for event in hand.stream():
match event:
case TorqueEvent(data=data):
print(f"Torque: {data.torques.to_list()}")
finally:
hand.stop_polling()
hand.stop_stream()
Complete Example
from realhand import L20
with L20(side="left", interface_name="can0") as hand:
# Set torque
hand.torque.set_torques([50.0] * 16)
# Read current torque
data = hand.torque.get_blocking(timeout_ms=500)
print(f"Current torque: {data.torques.to_list()}")
# Set different torque values for each finger
hand.torque.set_torques(
[
80.0,
80.0,
80.0,
80.0, # Thumb
60.0,
60.0,
60.0, # Index
60.0,
60.0,
60.0, # Middle
60.0,
60.0,
60.0, # Ring
60.0,
60.0,
60.0, # Pinky
]
)