Based on roh_firmware
pip install unienv-rohandFirst install CH340 driver for your platform.
I found the official driver on Linux to not work at all, I used this intead.
Then add your user to the dialout group (if on Linux) to allow access to the serial port without root privileges. This is typically done with the following command:
sudo usermod -a -G dialout $USERUsually you need to log out and log back in for the group change to take effect. Sometimes it may also be necessary to restart your computer.
Then find the serial port of your OYMotion hand. On Linux, you can use ls /dev/ttyUSB* to list all serial devices. The OYMotion hand is usually listed as /dev/ttyUSB0 or similar.
Then you can use the RohandActor class to control the OYMotion hand:
from unienv_interface.backends.numpy import NumpyComputeBackend
from unienv_interface.world import RealWorld
from unienv_rohand import RohandActor
import numpy as np
import time
world = RealWorld(
NumpyComputeBackend,
world_timestep=0.04, # Usualy we should set this to exactly the same as the control timestep
batch_size=None # None means single instance
)
actor = RohandActor(
world,
port="/dev/ttyUSB0",
node_id=2,
baudrate=115200,
control_mode='position', # Use "position" or "angle" control mode
control_timestep=0.04,
update_timestep=0.04,
)
rng = np.random.default_rng(42)
actor.reset()
time_s = time.monotonic()
while True:
dt = time.monotonic() - time_s
actor.update(dt)
obs = actor.get_observation()
print(obs)
rng, action = actor.action_space.sample(rng)
actor.set_next_action(action)
actor.pre_environment_step(dt)
time_s += dt| Key | Units | Notes |
|---|---|---|
joint_angles |
rad | |
joint_positions |
normalized | -1 fully open, 1 fully closed; raw_range=[0, 65535] register ticks |
joint_currents |
A | |
joint_forces |
N | shape (5,): the 5 fingers (ROH_FINGER_FORCE0..4), no force sensor on the thumb rotation |
The action is an absolute joint target: radians with control_mode='angle',
normalized [-1, 1] positions with control_mode='position'.
Every space carries UniEnv space metadata (unienv>=0.0.1b16): the units
above, the joint names, source (the node name), the serial port and
Modbus node_id, and fps (1 / control_timestep) on the observations, and
kind="action", control="joint_position", mode="absolute" with units /
normalized on the action. RohandActor.build_spaces(control_mode, ...)
builds both spaces without connecting to a hand:
from unienv_rohand import RohandActor
obs_space, action_space = RohandActor.build_spaces("position", name="rohand", control_timestep=0.04)
print(obs_space["joint_positions"].metadata)