Overview
Subscribe to the WUJI Hand 2joint_states stream with async/await. Compared with callbacks, frames come out sequentially inside a coroutine with no cross-thread handoff.
When your application already runs on asyncio, this fits more naturally. Concurrency across devices falls out of asyncio.gather() rather than thread management.
Matching example: examples/python/wuji_hand_2/1.subscribe_async.py.
For API and field definitions, see JointStateFrame and JointStateEntry.
The C API has no async form. C subscriptions all go through callbacks, described in Subscribing With Callbacks.
Prerequisites
Hardware
Software
Data Flow
The handle fromsubscribe() supports both retrieval styles: await recv_async() asynchronously and recv() synchronously. Frame structure is identical to the callback form.
Integration Steps
See Python example for the complete implementation.1. Discover and Connect to the Device
Get the manager withSdkManager.instance(), filter scan() for WUJI Hand 2 devices, and confirm that matches exist before connecting. Python example connects to all discovered WUJI Hand 2 devices. The excerpt shows the key calls for one device.
2. Read State Frames in a Coroutine
subscribe() creates the subscription, and recv_async() waits for the next frame. Read the current frame’s joint list and identify joints by nid. Close the subscription in finally so coroutine cancellation also releases it.
3. Run the Consumer and Disconnect
Await the consumer inmain(). For several devices, create one task per device and pass them to asyncio.gather(). Disconnect after the tasks finish, and use asyncio.run(main()) as the entry point. This path only reads state and doesn’t require enabling the motors.
Running It
Measurements
On a right-hand WUJI Hand 2 with all 20 joints online:
Both retrieval styles reach the same throughput and both keep up with the device’s roughly 1 kHz broadcast. Choose based on how your application is structured, not on performance.
Notes
Adapting It
Async or Callback
Concurrency Across Devices
One coroutine per device withasyncio.gather() is enough. Devices don’t block each other.
Lower the Rate
About 1 kHz is higher than most applications need. Useset_rate() on the same handle, noting the firmware version requirement described in Adjusting Stream Rate.
Related
- Subscribing With Callbacks: the callback form, and the only form the C API offers
- Adjusting Stream Rate: lower the firmware push rate
- Data Subscription: subscription model and lifecycle