Record初步实现

This commit is contained in:
2025-12-08 17:43:12 +08:00
parent 2b523acc52
commit 1d09062f79
6 changed files with 140 additions and 69 deletions

View File

@@ -20,6 +20,7 @@ class RealmanRobot(Robot):
port=self.config.port,
motors=config.motors,
joint=config.joint,
mock=self.config.mock,
gripper_range=config.gripper_range,
calibration=self.calibration,
)
@@ -40,7 +41,10 @@ class RealmanRobot(Robot):
@cached_property
def action_features(self) -> dict[str, type]:
return self._motors_ft
if self.config.mode==0:
return self._motors_ft
else:
return {"x.vel":float,"y.vel":float,"z.vel":float,"rx.vel":float,"ry.vel":float,"rz.vel":float,"gripper.vel":float}
@property
def is_connected(self) -> bool:
@@ -120,19 +124,26 @@ class RealmanRobot(Robot):
"""
if not self.is_connected:
raise DeviceNotConnectedError(f"{self} is not connected.")
if self.config.mode==0:
goal_pos = {key.removesuffix(".pos"): val for key, val in action.items() if key.endswith(".pos")}
goal_pos = {key.removesuffix(".pos"): val for key, val in action.items() if key.endswith(".pos")}
# Cap goal position when too far away from present position.
# /!\ Slower fps expected due to reading from the follower.
if self.config.max_relative_target is not None:
present_pos = self.bus.sync_read("Present_Position")
goal_present_pos = {key: (g_pos, present_pos[key]) for key, g_pos in goal_pos.items()}
goal_pos = ensure_safe_goal_position(goal_present_pos, self.config.max_relative_target)
if len(goal_pos)>0:
# Cap goal position when too far away from present position.
# /!\ Slower fps expected due to reading from the follower.
if self.config.max_relative_target is not None:
present_pos = self.bus.sync_read("Present_Position")
goal_present_pos = {key: (g_pos, present_pos[key]) for key, g_pos in goal_pos.items()}
goal_pos = ensure_safe_goal_position(goal_present_pos, self.config.max_relative_target)
# Send goal position to the arm
self.bus.sync_write("Goal_Position", goal_pos)
return {f"{motor}.pos": val for motor, val in goal_pos.items()}
# Send goal position to the arm
self.bus.sync_write("Goal_Position", goal_pos)
return {f"{motor}.pos": val for motor, val in goal_pos.items()}
else:
valAction = {key.removesuffix(".vel"): val for key, val in action.items() if key.endswith(".vel")}
#笛卡尔速度透传
self.bus.sync_write("Goal_Velocity", valAction)
return action
def disconnect(self):
if not self.is_connected: