新文件: src/lerobot/move_motor_test.py
一些检查失败了
Quality / Style (push) Failing after -27s
Quality / Typos (push) Failing after -28s
Tests / Pytest (push) Failing after -28s
Tests / Pytest (minimal install) (push) Failing after -28s
Tests / End-to-end (push) Failing after -28s
Secret Leaks / trufflehog (push) Failing after -28s
Builds / CPU (push) Has been cancelled
Builds / GPU (push) Has been cancelled
Builds / GPU Dev (push) Has been cancelled
Nightly / CPU (push) Has been cancelled
Nightly / GPU (push) Has been cancelled
一些检查失败了
Quality / Style (push) Failing after -27s
Quality / Typos (push) Failing after -28s
Tests / Pytest (push) Failing after -28s
Tests / Pytest (minimal install) (push) Failing after -28s
Tests / End-to-end (push) Failing after -28s
Secret Leaks / trufflehog (push) Failing after -28s
Builds / CPU (push) Has been cancelled
Builds / GPU (push) Has been cancelled
Builds / GPU Dev (push) Has been cancelled
Nightly / CPU (push) Has been cancelled
Nightly / GPU (push) Has been cancelled
新文件: src/lerobot/setup_motor_by_id.py 新文件: st/T1.ipynb 新文件: st/test.ipynb
这个提交包含在:
128
src/lerobot/move_motor_test.py
普通文件
128
src/lerobot/move_motor_test.py
普通文件
@ -0,0 +1,128 @@
|
||||
"""Simple script to move a motor for quick hardware sanity checks.
|
||||
|
||||
Example:
|
||||
|
||||
python -m lerobot.move_motor_test \
|
||||
--robot.type=so100_follower --robot.port=/dev/ttyUSB0 \
|
||||
--motor=wrist_roll --position=2048 --duration=2
|
||||
|
||||
Or move relatively:
|
||||
|
||||
python -m lerobot.move_motor_test --teleop.type=so100_leader --teleop.port=/dev/ttyUSB0 \
|
||||
--motor=wrist_roll --relative=100 --duration=1 --move_back=true
|
||||
|
||||
This script connects to the selected device, sends a `Goal_Position` write
|
||||
for the requested motor and optionally moves it back after `duration` seconds.
|
||||
|
||||
By default this script uses *raw motor units* (i.e. it sets `normalize=False` on
|
||||
bus read/write calls). For many servo motors this corresponds to the controller
|
||||
units (often in the ~0..4095 range).
|
||||
|
||||
Set `--raw=false` if you prefer LeRobot normalized units (e.g. -100..100 or
|
||||
degrees depending on the device configuration).
|
||||
"""
|
||||
|
||||
from dataclasses import dataclass
|
||||
import time
|
||||
from typing import Any
|
||||
|
||||
import draccus
|
||||
|
||||
from lerobot.robots import ( # noqa: F401
|
||||
RobotConfig,
|
||||
koch_follower,
|
||||
lekiwi,
|
||||
make_robot_from_config,
|
||||
so100_follower,
|
||||
so101_follower,
|
||||
)
|
||||
from lerobot.teleoperators import ( # noqa: F401
|
||||
TeleoperatorConfig,
|
||||
koch_leader,
|
||||
make_teleoperator_from_config,
|
||||
so100_leader,
|
||||
so101_leader,
|
||||
)
|
||||
|
||||
|
||||
@dataclass
|
||||
class MoveConfig:
|
||||
teleop: TeleoperatorConfig | None = None
|
||||
robot: RobotConfig | None = None
|
||||
motor: str = ""
|
||||
position: float | None = None
|
||||
relative: float | None = None
|
||||
duration: float = 1.0
|
||||
move_back: bool = False
|
||||
raw: bool = True
|
||||
|
||||
def __post_init__(self):
|
||||
if bool(self.teleop) == bool(self.robot):
|
||||
raise ValueError("Choose either a teleop or a robot.")
|
||||
|
||||
if not self.motor:
|
||||
raise ValueError("Please provide --motor with the target motor name.")
|
||||
|
||||
if self.position is None and self.relative is None:
|
||||
raise ValueError("Provide either --position or --relative to move the motor.")
|
||||
|
||||
|
||||
@draccus.wrap() # type: ignore[attr-defined]
|
||||
def move_motor(cfg: MoveConfig):
|
||||
device_cfg = cfg.robot if cfg.robot is not None else cfg.teleop
|
||||
if device_cfg is None:
|
||||
raise ValueError("Choose either a teleop or a robot.")
|
||||
|
||||
if isinstance(device_cfg, RobotConfig):
|
||||
device = make_robot_from_config(device_cfg)
|
||||
else:
|
||||
device = make_teleoperator_from_config(device_cfg)
|
||||
|
||||
bus: Any = getattr(device, "bus", None)
|
||||
if bus is None:
|
||||
raise AttributeError(f"{device.__class__.__name__} does not expose a motors bus.")
|
||||
|
||||
# Connect without auto-calibration to be quick
|
||||
if hasattr(device, "connect"):
|
||||
try:
|
||||
device.connect(calibrate=False)
|
||||
except Exception:
|
||||
# Some devices' connect may require additional steps; ignore to let low-level bus handle it
|
||||
pass
|
||||
|
||||
if cfg.motor not in bus.motors:
|
||||
raise ValueError(f"Unknown motor '{cfg.motor}'. Available: {', '.join(bus.motors)}")
|
||||
|
||||
normalize = not cfg.raw
|
||||
|
||||
# Read present position if needed
|
||||
present_pos = None
|
||||
if cfg.relative is not None or cfg.move_back:
|
||||
try:
|
||||
present = bus.sync_read("Present_Position", normalize=normalize)
|
||||
present_pos = present[cfg.motor]
|
||||
except Exception:
|
||||
present_pos = None
|
||||
|
||||
if cfg.position is not None:
|
||||
target: float = float(cfg.position)
|
||||
else:
|
||||
if present_pos is None:
|
||||
raise RuntimeError("Could not read present position to apply a relative move.")
|
||||
target = float(present_pos) + float(cfg.relative) # type: ignore[arg-type]
|
||||
|
||||
target_to_send = int(target) if cfg.raw else target
|
||||
|
||||
print(f"Moving '{cfg.motor}' to {target_to_send} (duration {cfg.duration}s)")
|
||||
bus.sync_write("Goal_Position", {cfg.motor: target_to_send}, normalize=normalize)
|
||||
|
||||
time.sleep(cfg.duration)
|
||||
|
||||
if cfg.move_back and present_pos is not None:
|
||||
print(f"Moving '{cfg.motor}' back to {present_pos}")
|
||||
back_to_send = int(present_pos) if cfg.raw else float(present_pos)
|
||||
bus.sync_write("Goal_Position", {cfg.motor: back_to_send}, normalize=normalize)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
move_motor() # type: ignore[call-arg]
|
||||
124
src/lerobot/setup_motor_by_id.py
普通文件
124
src/lerobot/setup_motor_by_id.py
普通文件
@ -0,0 +1,124 @@
|
||||
# Copyright 2024 The HuggingFace Inc. team. All rights reserved.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
"""
|
||||
Helper to set a single motor ID/baudrate from a known current motor ID.
|
||||
|
||||
This is an extended variant of `lerobot.setup_motors` for the case where
|
||||
you already know the ID currently assigned to the plugged motor and want
|
||||
to remap it directly to the target ID expected by a robot/teleoperator
|
||||
configuration.
|
||||
|
||||
Example:
|
||||
|
||||
```shell
|
||||
python -m lerobot.setup_motor_by_id \
|
||||
--teleop.type=so100_leader \
|
||||
--teleop.port=/dev/tty.usbmodem575E0031751 \
|
||||
--motor=wrist_roll \
|
||||
--initial_id=7
|
||||
|
||||
python -m lerobot.setup_motor_by_id \
|
||||
--teleop.type=so100_leader \
|
||||
--teleop.port=/dev/tty.usbmodem575E0031751 \
|
||||
--list_motors=true
|
||||
```
|
||||
"""
|
||||
|
||||
from dataclasses import dataclass
|
||||
from typing import Any
|
||||
|
||||
import draccus
|
||||
|
||||
from lerobot.robots import ( # noqa: F401
|
||||
RobotConfig,
|
||||
koch_follower,
|
||||
lekiwi,
|
||||
make_robot_from_config,
|
||||
so100_follower,
|
||||
so101_follower,
|
||||
)
|
||||
from lerobot.setup_motors import COMPATIBLE_DEVICES
|
||||
from lerobot.teleoperators import ( # noqa: F401
|
||||
TeleoperatorConfig,
|
||||
koch_leader,
|
||||
make_teleoperator_from_config,
|
||||
so100_leader,
|
||||
so101_leader,
|
||||
)
|
||||
|
||||
|
||||
@dataclass
|
||||
class SetupSingleMotorConfig:
|
||||
teleop: TeleoperatorConfig | None = None
|
||||
robot: RobotConfig | None = None
|
||||
list_motors: bool = False
|
||||
motor: str = ""
|
||||
initial_id: int = -1
|
||||
initial_baudrate: int | None = None
|
||||
|
||||
def __post_init__(self):
|
||||
if bool(self.teleop) == bool(self.robot):
|
||||
raise ValueError("Choose either a teleop or a robot.")
|
||||
|
||||
if self.list_motors:
|
||||
return
|
||||
|
||||
if not self.motor:
|
||||
raise ValueError("Please provide --motor with the target motor name.")
|
||||
|
||||
if self.initial_id < 0:
|
||||
raise ValueError("Please provide --initial_id with the currently plugged motor id.")
|
||||
|
||||
|
||||
@draccus.wrap() # type: ignore[attr-defined]
|
||||
def setup_motor_by_id(cfg: SetupSingleMotorConfig):
|
||||
device_cfg = cfg.robot if cfg.robot is not None else cfg.teleop
|
||||
if device_cfg is None:
|
||||
raise ValueError("Choose either a teleop or a robot.")
|
||||
|
||||
if device_cfg.type not in COMPATIBLE_DEVICES:
|
||||
raise NotImplementedError
|
||||
|
||||
if isinstance(device_cfg, RobotConfig):
|
||||
device = make_robot_from_config(device_cfg)
|
||||
else:
|
||||
device = make_teleoperator_from_config(device_cfg)
|
||||
|
||||
bus: Any = getattr(device, "bus", None)
|
||||
if bus is None:
|
||||
raise AttributeError(f"{device.__class__.__name__} does not expose a motors bus.")
|
||||
|
||||
if cfg.list_motors:
|
||||
print(f"Motors for device type '{device_cfg.type}':")
|
||||
for motor_name, motor in bus.motors.items():
|
||||
print(f"- {motor_name}: id={motor.id}")
|
||||
return
|
||||
|
||||
if cfg.motor not in bus.motors:
|
||||
available_motors = ", ".join(bus.motors)
|
||||
raise ValueError(
|
||||
f"Unknown motor '{cfg.motor}'. Available motors are: {available_motors}."
|
||||
)
|
||||
|
||||
bus.setup_motor(
|
||||
cfg.motor,
|
||||
initial_baudrate=cfg.initial_baudrate,
|
||||
initial_id=cfg.initial_id,
|
||||
)
|
||||
print(f"'{cfg.motor}' motor id set to {bus.motors[cfg.motor].id}")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
setup_motor_by_id() # type: ignore[call-arg]
|
||||
23
st/T1.ipynb
普通文件
23
st/T1.ipynb
普通文件
@ -0,0 +1,23 @@
|
||||
{
|
||||
"cells": [
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "4d1268d4-a3cc-4564-ad5f-0b9acc62cebe",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": []
|
||||
}
|
||||
],
|
||||
"metadata": {
|
||||
"kernelspec": {
|
||||
"display_name": "",
|
||||
"name": ""
|
||||
},
|
||||
"language_info": {
|
||||
"name": ""
|
||||
}
|
||||
},
|
||||
"nbformat": 4,
|
||||
"nbformat_minor": 5
|
||||
}
|
||||
0
st/test.ipynb
普通文件
0
st/test.ipynb
普通文件
在新工单中引用
屏蔽一个用户