Overview
Read the recording shipped with the example, pick the left- or right-hand file by device handedness, and replay its joint-angle frames at 1 kHz in Position control mode. This is the larger of the two motion examples, meant for observing the hand’s full range. The example does no interpolation, no resampling, no smoothing, and adds no recovery motion. What the recording holds is what goes out. Matching examples:examples/python/wuji_hand_2/6_opposition/opposition.py and examples/c/wuji_hand_2/6_opposition/opposition.c.
For API and field definitions, see JointCommand.
This example drives all 20 joints through large motions, following the joint angles in the selected recording. Before starting, confirm the hand is firmly mounted, clear people, cables, and desk objects from around it, keep someone watching throughout, and stay ready to cut power.
Prerequisites
Hardware
Software
Replay Files
The example directory shipsdata/right.replay and data/left.replay. Copy the entire 6_opposition/ directory, since taking only the source file fails when it can’t find the data.
Data Flow
File Format
A fixed-length container with a 16-byte header followed by 84 bytes per frame.
Handedness ID is 1 for right and 2 for left. File size is
16 + frame_count × 84 bytes. The supplied frame counts are listed below.
Validation completes before enabling. If any of magic, version, handedness, joint count, or file length fails, the example reports an error and exits without enabling the motors.
Integration Steps
1. Connect and Validate the Replay File
Read handedness after connecting, and selectleft.replay or right.replay. After opening the file, validate the magic, version, handedness marker, joint count, and file length. Don’t enable the device if validation fails.
2. Set the Mode and Prepare the Publisher
Before running the example, we recommend disabling the hand to meet the mode-switching requirement. With all 20 joints online and the replay file validated, the example switches to Position mode, then enables the hand. If the mode switch fails, it stops without enabling. After enabling succeeds, the example creates the publisher, captures the current posture, and transitions smoothly to the first replay frame.- Python
- C
3. Publish Replay Frames at 1 kHz
Read 20 position values per frame, createJointCommand(position, 0, 0) entries, and send them at 1 ms intervals. The replay loop must handle stop requests and file-read errors.
_open_replay() validates the complete container, _capture_start_positions() orders joints by nid, and _play_replay() handles the starting transition and frame-by-frame playback.
C uses open_replay_path(), capture_start_positions(), send_ramp(), and play_replay(). They send a fixed 20-joint array through wuji_joint_command_publisher_send().
4. Disable and Release Resources
On normal completion or an error, disable first, close the publisher and replay file, then disconnect. C useswuji_hand_2_disable(device, NULL) and wuji_joint_command_publisher_close(publisher), closes the replay file, disconnects and releases the device, and calls wuji_shutdown().
finally. Collect errors individually, as shown in Python example and C example, so a failure in one cleanup operation doesn’t prevent releasing the remaining resources.
Running It
- Python
- C
Replay Data
The supplied recordings contain:
The durations exclude the starting transition. The program disables the hand when playback finishes or is interrupted.
Notes
On interrupt the hand holds its current posture rather than opening automatically. Stopping mid-motion can leave it clenched, which needs handling by hand.
Adapting It
Name an SN on a Shared Network
As with the MIT joint sweep,auto_connect() refuses to connect when it finds several devices and lists every serial number rather than guessing. Change it to manager.connect(sn="WH2KA00XXXXXXXXX", device_name="hand_2_opposition").
Replay Your Own Recording
Generate a file in the same container format and the whole replay path works unchanged: a 16-byte header plus 84 bytes per frame. The frame index is skipped during replay, and only the 20 joint angles drive control. Make sureside_id matches the target device’s handedness, or container validation fails.
Changing Playback Speed
The interval is hard-coded at 1 ms. Increasing it slows the whole motion, but since nothing is resampled the joint-angle sequence stays the same and each posture holds longer. To change the motion speed, resample the trajectory.Recovering After an Interrupt
Ctrl+C triggers no return motion. After stopping mid-run, the hand holds its posture, and the smooth homing routine in Publishing Control Commands brings it gently back to zero. Don’t send pos=0 directly, since a large error under MIT impedance snaps the hand back hard.
Related
- Publishing Control Commands: general
joint_commandusage and smooth homing - Running an MIT Joint Sweep: the smallest command-path check
- Subscribing With Callbacks: read actual joint state during replay
- Common Data Types: the
JointCommandstructure