fix(piper): enable follower after connect-time calibration

这个提交包含在:
Elvin
2026-03-06 00:52:37 +08:00
父节点 66f21af561
当前提交 271518d52f
共有 2 个文件被更改,包括 39 次插入 和 4 次删除

查看文件

@ -96,14 +96,17 @@ class PiperFollower(Robot):
time.sleep(0.05)
self.configure()
should_auto_calibrate = (
not self.is_calibrated and calibrate and should_require_piper_calibration(self.config.calibration_mode)
)
if should_auto_calibrate:
logger.info("No piper-follower calibration file found for '%s'. Running lerobot-calibrate flow.", self.id)
self.calibrate()
# lerobot-calibrate calls connect(calibrate=False) before running calibrate().
# Keep the arm in drag mode for calibration by skipping auto-enable in this path.
# Keep the arm in drag mode for that path, but re-enable after connect-time calibration.
should_enable = self.config.enable_on_connect and calibrate
if should_enable and not self._wait_enable(self.config.enable_timeout_s):
logger.warning("Piper follower did not report enabled state before timeout.")
if not self.is_calibrated and calibrate and should_require_piper_calibration(self.config.calibration_mode):
logger.info("No piper-follower calibration file found for '%s'. Running lerobot-calibrate flow.", self.id)
self.calibrate()
for cam in self.cameras.values():
cam.connect()

查看文件

@ -35,6 +35,7 @@ class FakePiperInterface:
self.last_gripper = None
self.enable_calls = 0
self.disable_calls = 0
self.is_enabled = False
self._joint_ctrl = SimpleNamespace(
time_stamp=1.0,
@ -86,11 +87,13 @@ class FakePiperInterface:
def EnablePiper(self):
self.enable_calls += 1
self.is_enabled = True
return True
def DisableArm(self, motor_num):
del motor_num
self.disable_calls += 1
self.is_enabled = False
def JointCtrl(self, *args):
self.last_joint = args
@ -286,3 +289,32 @@ def test_piper_calibration_mode_off_allows_uncalibrated_control(monkeypatch):
finally:
teleop.disconnect()
robot.disconnect()
def test_piper_follower_connect_calibrates_then_reenables(monkeypatch, tmp_path):
patch_fake_sdk(monkeypatch)
robot = PiperFollower(
PiperFollowerConfig(
port="can0",
id="connect_reenable_after_calibration",
calibration_dir=tmp_path,
calibration_mode="required",
enable_on_connect=True,
)
)
def fake_calibrate():
# Mirror real calibration's drag-mode behavior.
robot.arm.DisableArm(7)
robot.calibration = make_identity_calibration()
monkeypatch.setattr(robot, "calibrate", fake_calibrate)
robot.connect(calibrate=True)
try:
assert robot.arm.disable_calls == 1
assert robot.arm.enable_calls == 1
assert robot.arm.is_enabled
finally:
robot.disconnect()