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 L20Lite 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 L20lite

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

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

from realhand.exceptions import TimeoutError

try:
    data = hand.force_sensor.get_blocking(timeout_ms=1000)
    print(data.thumb.values)  # Thumb data
    print(data.index.values)  # Index data
except TimeoutError:
    print("Read timed out")
ParameterTypeDefaultDescription
timeout_msfloat1000Timeout in milliseconds for the whole operation

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

Read a Single Finger

Use get_finger() to access the force sensor manager for one finger:

# Get the thumb sensor
thumb_sensor = hand.force_sensor.get_finger("thumb")
thumb_data = thumb_sensor.get_blocking(timeout_ms=1000)
print(thumb_data.values.shape)  # (12, 6)

Available finger names: "thumb", "index", "middle", "ring", "pinky"

Streaming Read

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

from realhand.hand.l20lite import SensorSource, ForceSensorEvent

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

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

Examples

Blocking Read for All Fingers

from realhand import L20lite

with L20lite(side="left", interface_name="can0") as hand:
    data = hand.force_sensor.get_blocking(timeout_ms=1000)
    print(f"Thumb: {data.thumb.values.shape}")
    print(f"Index: {data.index.values.shape}")
    print(f"Middle: {data.middle.values.shape}")
    print(f"Ring: {data.ring.values.shape}")
    print(f"Pinky: {data.pinky.values.shape}")

Stream for a Fixed Duration

import time
from realhand import L20lite
from realhand.hand.l20lite import SensorSource, ForceSensorEvent

with L20lite(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()