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

Force Sensors

The L6 dexterous hand is equipped with force sensors on 5 fingers (thumb, index, middle, ring, pinky). It supports both blocking and cached reads.

Overview

Use hand.force_sensor to access force sensor data:

from realhand import L6

with L6(side="left", interface_name="can0") as hand:
    data = hand.force_sensor.get_blocking()

Data Structures

ForceSensorData - sensor data for one finger:

  • values: A NumPy array of shape (12, 6) with dtype uint8
  • timestamp: Unix timestamp

AllFingersData - data for all 5 fingers:

  • thumb, index, middle, ring, pinky: the ForceSensorData for each finger

Read Data

Blocking Read

data = hand.force_sensor.get_blocking(timeout_ms=1000)
print(data.thumb.values)  # Thumb data
print(data.index.values)  # Index data
ParameterTypeDefaultDescription
timeout_msfloat1000Timeout in milliseconds

Exceptions: TimeoutError (timeout), ValidationError (invalid parameter)

Cached Read

Get the most recently received data without blocking:

data = hand.force_sensor.get_snapshot()
if data:
    print(f"Thumb: {data.thumb.values[0]}")
    print(f"Index: {data.index.values[0]}")

Return value: AllFingersData or None if any finger is missing data

Streaming Read

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

from realhand.hand.l6 import SensorSource, ForceSensorEvent

hand.start_polling({SensorSource.FORCE_SENSOR: 0.1})

for event in hand.stream():
    match event:
        case ForceSensorEvent(data=data):
            print(data.thumb.values)

hand.stop_polling()
hand.stop_stream()

Examples

Blocking Read for All Fingers

from realhand import L6

with L6(side="left", interface_name="can0") as hand:
    data = hand.force_sensor.get_blocking(timeout_ms=1000)
    print(f"Thumb: {data.thumb.values.shape}")  # (12, 6)
    print(f"Index: {data.index.values.shape}")

Stream for a Fixed Duration

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

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

    try:
        for event in hand.stream():
            match event:
                case ForceSensorEvent(data=data):
                    print(f"Thumb: {data.thumb.values[0]}")
            if time.time() - start > 5:  # Collect for 5 seconds
                break
    finally:
        hand.stop_polling()
        hand.stop_stream()