Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Current Reading

from realhand import L6

Read the real-time current of the six L6 joint motors in mA.

Overview

Use hand.current to read current values. Three access patterns are supported:

ModeMethodUse case
Blocking readget_blocking()Single query
Streaminghand.stream()Continuous monitoring
Cached readget_snapshot()Read latest cache

Read Current

Blocking Read

Send a request and wait for a response:

data = hand.current.get_blocking(timeout_ms=500)

# Access per-joint current values (mA)
print(data.currents.thumb_flex)  # Thumb flexion
print(data.currents.thumb_abd)  # Thumb abduction
print(data.currents.index)  # Index finger
print(data.currents.middle)  # Middle finger
print(data.currents.ring)  # Ring finger
print(data.currents.pinky)  # Pinky

# Index access
print(data.currents[0])  # thumb_flex

Parameter:

  • timeout_ms: Timeout in milliseconds, default 100

Exception:

  • TimeoutError: No response received before timeout

Cached Read

Get the most recent cached data without sending a request:

data = hand.current.get_snapshot()
if data:
    print(f"Current: {data.currents.to_list()}")

Streaming Read

Receive all sensor events through the top-level hand.stream() interface:

from realhand.hand.l6 import SensorSource, CurrentEvent

hand.start_polling({SensorSource.CURRENT: 0.05})

for event in hand.stream():
    match event:
        case CurrentEvent(data=data):
            print(f"Current: {data.currents.to_list()}")

hand.stop_polling()
hand.stop_stream()

Examples

Detect Overcurrent

from realhand import L6
from realhand.hand.l6 import SensorSource, CurrentEvent

with L6(side="left", interface_name="can0") as hand:
    hand.start_polling({SensorSource.CURRENT: 0.05})

    try:
        for event in hand.stream():
            match event:
                case CurrentEvent(data=data):
                    for i, current in enumerate(data.currents.to_list()):
                        if current > 1000:
                            print(f"Warning: joint {i} current is too high ({current} mA)")
    finally:
        hand.stop_polling()
        hand.stop_stream()

Log Current Data

import time
from realhand import L6
from realhand.hand.l6 import SensorSource, CurrentEvent

with L6(side="left", interface_name="can0") as hand:
    records = []
    start = time.time()
    hand.start_polling({SensorSource.CURRENT: 0.1})

    try:
        for event in hand.stream():
            match event:
                case CurrentEvent(data=data):
                    records.append(
                        {
                            "time": data.timestamp - start,
                            "currents": data.currents.to_list(),
                        }
                    )
            if time.time() - start > 5:  # Record for 5 seconds
                break
    finally:
        hand.stop_polling()
        hand.stop_stream()

    print(f"Collected {len(records)} records")