mirror of
https://github.com/huggingface/lerobot.git
synced 2026-05-20 19:19:56 +00:00
Add use_present_position to teleoperator
This commit is contained in:
@@ -22,8 +22,14 @@ from ..config import TeleoperatorConfig
|
|||||||
@TeleoperatorConfig.register_subclass("reachy2_teleoperator")
|
@TeleoperatorConfig.register_subclass("reachy2_teleoperator")
|
||||||
@dataclass
|
@dataclass
|
||||||
class Reachy2TeleoperatorConfig(TeleoperatorConfig):
|
class Reachy2TeleoperatorConfig(TeleoperatorConfig):
|
||||||
# Port to connect to the arm
|
# IP address of the Reachy 2 robot used as teleoperator
|
||||||
ip_address: str | None = "localhost"
|
ip_address: str | None = "localhost"
|
||||||
|
|
||||||
|
# Whether to use the present position of the joints as actions
|
||||||
|
# if False, the goal position of the joints will be used
|
||||||
|
use_present_position: bool = False
|
||||||
|
|
||||||
|
# Which parts of the robot to use
|
||||||
with_mobile_base: bool = True
|
with_mobile_base: bool = True
|
||||||
with_l_arm: bool = True
|
with_l_arm: bool = True
|
||||||
with_r_arm: bool = True
|
with_r_arm: bool = True
|
||||||
|
|||||||
@@ -136,7 +136,12 @@ class Reachy2Teleoperator(Teleoperator):
|
|||||||
start = time.perf_counter()
|
start = time.perf_counter()
|
||||||
|
|
||||||
if self.reachy and self.is_connected:
|
if self.reachy and self.is_connected:
|
||||||
joint_action = {k: self.reachy.joints[v].goal_position for k, v in self.joints_dict.items()}
|
if self.config.use_present_position:
|
||||||
|
joint_action = {
|
||||||
|
k: self.reachy.joints[v].present_position for k, v in self.joints_dict.items()
|
||||||
|
}
|
||||||
|
else:
|
||||||
|
joint_action = {k: self.reachy.joints[v].goal_position for k, v in self.joints_dict.items()}
|
||||||
if not self.config.with_mobile_base:
|
if not self.config.with_mobile_base:
|
||||||
dt_ms = (time.perf_counter() - start) * 1e3
|
dt_ms = (time.perf_counter() - start) * 1e3
|
||||||
logger.debug(f"{self} read action: {dt_ms:.1f}ms")
|
logger.debug(f"{self} read action: {dt_ms:.1f}ms")
|
||||||
|
|||||||
@@ -60,6 +60,7 @@ PARAMS = [
|
|||||||
{"with_mobile_base": False, "with_l_arm": False, "with_antennas": False},
|
{"with_mobile_base": False, "with_l_arm": False, "with_antennas": False},
|
||||||
{"with_r_arm": False, "with_neck": False, "with_antennas": False},
|
{"with_r_arm": False, "with_neck": False, "with_antennas": False},
|
||||||
{"with_mobile_base": False, "with_neck": False},
|
{"with_mobile_base": False, "with_neck": False},
|
||||||
|
{"use_present_position": True},
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
@@ -76,7 +77,8 @@ def _make_reachy2_sdk_mock():
|
|||||||
# Mock joints with some dummy positions
|
# Mock joints with some dummy positions
|
||||||
joints = {
|
joints = {
|
||||||
k: MagicMock(
|
k: MagicMock(
|
||||||
goal_position=float(i),
|
present_position=float(i),
|
||||||
|
goal_position=float(i) + 0.5,
|
||||||
)
|
)
|
||||||
for i, k in enumerate(REACHY2_JOINTS.values())
|
for i, k in enumerate(REACHY2_JOINTS.values())
|
||||||
}
|
}
|
||||||
@@ -133,7 +135,10 @@ def test_get_action(reachy2):
|
|||||||
assert set(action.keys()) == expected_keys
|
assert set(action.keys()) == expected_keys
|
||||||
|
|
||||||
for motor in reachy2.joints_dict.keys():
|
for motor in reachy2.joints_dict.keys():
|
||||||
assert action[motor] == reachy2.reachy.joints[REACHY2_JOINTS[motor]].goal_position
|
if reachy2.config.use_present_position:
|
||||||
|
assert action[motor] == reachy2.reachy.joints[REACHY2_JOINTS[motor]].present_position
|
||||||
|
else:
|
||||||
|
assert action[motor] == reachy2.reachy.joints[REACHY2_JOINTS[motor]].goal_position
|
||||||
if reachy2.config.with_mobile_base:
|
if reachy2.config.with_mobile_base:
|
||||||
for vel in REACHY2_VEL.keys():
|
for vel in REACHY2_VEL.keys():
|
||||||
assert action[vel] == reachy2.reachy.mobile_base.last_cmd_vel[REACHY2_VEL[vel]]
|
assert action[vel] == reachy2.reachy.mobile_base.last_cmd_vel[REACHY2_VEL[vel]]
|
||||||
|
|||||||
Reference in New Issue
Block a user