mirror of
https://github.com/huggingface/lerobot.git
synced 2026-07-30 21:19:40 +00:00
refactor(unitree_g1): revert reset() to simple version
Drop the full-body pause/direct-publish reset special-casing (and the _controller_paused plumbing) so SONIC uses the same reset path as the other controllers. The removed logic is preserved on the better-reset branch. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -151,9 +151,6 @@ class UnitreeG1(Robot):
|
|||||||
self.controller: LocomotionController | None = make_locomotion_controller(config.controller)
|
self.controller: LocomotionController | None = make_locomotion_controller(config.controller)
|
||||||
# Controller thread state
|
# Controller thread state
|
||||||
self._controller_thread = None
|
self._controller_thread = None
|
||||||
# When set, the controller loop stops publishing low commands so reset() can
|
|
||||||
# drive the joints directly without two publishers fighting (single-publisher).
|
|
||||||
self._controller_paused = threading.Event()
|
|
||||||
self._controller_action_lock = threading.Lock()
|
self._controller_action_lock = threading.Lock()
|
||||||
self.controller_input = default_remote_input()
|
self.controller_input = default_remote_input()
|
||||||
self.controller_output = {}
|
self.controller_output = {}
|
||||||
@@ -309,11 +306,6 @@ class UnitreeG1(Robot):
|
|||||||
while not self._shutdown_event.is_set():
|
while not self._shutdown_event.is_set():
|
||||||
start_time = time.time()
|
start_time = time.time()
|
||||||
|
|
||||||
# Paused during reset() so the reset routine is the sole low-cmd publisher.
|
|
||||||
if self._controller_paused.is_set():
|
|
||||||
time.sleep(control_dt)
|
|
||||||
continue
|
|
||||||
|
|
||||||
with self._lowstate_lock:
|
with self._lowstate_lock:
|
||||||
lowstate = self._lowstate
|
lowstate = self._lowstate
|
||||||
|
|
||||||
@@ -635,18 +627,6 @@ class UnitreeG1(Robot):
|
|||||||
if default_positions is None:
|
if default_positions is None:
|
||||||
default_positions = np.array(self.config.default_positions, dtype=np.float32)
|
default_positions = np.array(self.config.default_positions, dtype=np.float32)
|
||||||
|
|
||||||
# Full-body controllers (SONIC) own the whole 29-DoF command and ignore
|
|
||||||
# ``<joint>.q`` in send_action(), so reset() must publish the default pose
|
|
||||||
# directly. Pause the background controller first so the two aren't both writing
|
|
||||||
# low commands while the robot moves to the default pose.
|
|
||||||
full_body = getattr(self.controller, "full_body", False)
|
|
||||||
paused = False
|
|
||||||
if full_body and self._controller_thread is not None:
|
|
||||||
self._controller_paused.set()
|
|
||||||
paused = True
|
|
||||||
time.sleep(control_dt) # let any in-flight controller tick settle
|
|
||||||
|
|
||||||
try:
|
|
||||||
if self.config.is_simulation and self.sim_env is not None:
|
if self.config.is_simulation and self.sim_env is not None:
|
||||||
self.sim_env.reset()
|
self.sim_env.reset()
|
||||||
self.publish_lowcmd(
|
self.publish_lowcmd(
|
||||||
@@ -675,11 +655,6 @@ class UnitreeG1(Robot):
|
|||||||
interp_pos = init_dof_pos[motor.value] * (1 - alpha) + target_pos * alpha
|
interp_pos = init_dof_pos[motor.value] * (1 - alpha) + target_pos * alpha
|
||||||
action_dict[f"{motor.name}.q"] = float(interp_pos)
|
action_dict[f"{motor.name}.q"] = float(interp_pos)
|
||||||
|
|
||||||
# Full-body controllers no-op in send_action(); publish the pose
|
|
||||||
# directly (arm-only controllers keep the send_action() path).
|
|
||||||
if full_body:
|
|
||||||
self.publish_lowcmd(action_dict)
|
|
||||||
else:
|
|
||||||
self.send_action(action_dict)
|
self.send_action(action_dict)
|
||||||
|
|
||||||
# Maintain constant control rate
|
# Maintain constant control rate
|
||||||
@@ -687,12 +662,8 @@ class UnitreeG1(Robot):
|
|||||||
sleep_time = max(0, control_dt - elapsed)
|
sleep_time = max(0, control_dt - elapsed)
|
||||||
time.sleep(sleep_time)
|
time.sleep(sleep_time)
|
||||||
|
|
||||||
# Reset controller internal state (gait phase, obs history, etc.) before
|
# Reset controller internal state (gait phase, obs history, etc.)
|
||||||
# resuming so its buffers reflect the post-reset pose.
|
|
||||||
if self.controller is not None and hasattr(self.controller, "reset"):
|
if self.controller is not None and hasattr(self.controller, "reset"):
|
||||||
self.controller.reset()
|
self.controller.reset()
|
||||||
finally:
|
|
||||||
if paused:
|
|
||||||
self._controller_paused.clear()
|
|
||||||
|
|
||||||
logger.info("Reached default position")
|
logger.info("Reached default position")
|
||||||
|
|||||||
Reference in New Issue
Block a user