Temperature Reading
Use hand.temperature to read the temperature of the 16 L20 joint motors in °C.
Temperature fields
| Field | Description |
|---|---|
thumb_abd | Thumb abduction motor |
thumb_yaw | Thumb rotation motor |
thumb_root1 | Thumb root motor |
thumb_tip | Thumb tip motor |
index_abd | Index abduction motor |
index_root1 | Index root motor |
index_tip | Index tip motor |
middle_abd | Middle abduction motor |
middle_root1 | Middle root motor |
middle_tip | Middle tip motor |
ring_abd | Ring abduction motor |
ring_root1 | Ring root motor |
ring_tip | Ring tip motor |
pinky_abd | Pinky abduction motor |
pinky_root1 | Pinky root motor |
pinky_tip | Pinky tip motor |
Read Temperature
Blocking Read
from realhand.exceptions import TimeoutError
try:
data = hand.temperature.get_blocking(timeout_ms=500)
print(f"Thumb abduction temperature: {data.temperatures.thumb_abd}°C")
except TimeoutError:
print("Read timed out")
Parameter
timeout_ms: Timeout in milliseconds, default100
Return value
TemperatureData: Containstemperatures(L20Temperature) andtimestamp
Exception
TimeoutError: No response before timeout
Cached Read
Read the most recent cached temperature data without blocking.
data = hand.temperature.get_snapshot()
if data:
print(f"Temperature: {data.temperatures.to_list()}")
Return value
TemperatureDataorNoneif no cached data is available
Streaming Read
Receive all sensor events through the top-level hand.stream() interface:
from realhand.hand.l20 import SensorSource, TemperatureEvent
hand.start_polling({SensorSource.TEMPERATURE: 0.1})
try:
for event in hand.stream():
match event:
case TemperatureEvent(data=data):
print(f"Temperature: {data.temperatures.to_list()}")
finally:
hand.stop_polling()
hand.stop_stream()
Examples
Read All Joint Temperatures
from realhand import L20
with L20(side="left", interface_name="can0") as hand:
data = hand.temperature.get_blocking(timeout_ms=500)
# Access by field
print(f"Thumb abduction: {data.temperatures.thumb_abd}°C")
print(f"Index abduction: {data.temperatures.index_abd}°C")
# Convert to list
temps = data.temperatures.to_list()
print(f"All temperatures: {temps}")
# Index access
print(f"First joint motor: {data.temperatures[0]}°C")
Temperature Monitoring
from realhand import L20
from realhand.hand.l20 import SensorSource, TemperatureEvent
with L20(side="left", interface_name="can0") as hand:
hand.start_polling({SensorSource.TEMPERATURE: 0.1})
try:
for event in hand.stream():
match event:
case TemperatureEvent(data=data):
for i, temp in enumerate(data.temperatures.to_list()):
if temp > 60.0:
print(f"Warning: joint motor {i} is overheating ({temp}°C)")
except KeyboardInterrupt:
pass
finally:
hand.stop_polling()
hand.stop_stream()