-
Notifications
You must be signed in to change notification settings - Fork 3.2k
refactor/lekiwi robot #863
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
aliberts
merged 36 commits into
user/aliberts/2025_02_25_refactor_robots
from
refactor/lekiwi_robot
Apr 29, 2025
Merged
Changes from all commits
Commits
Show all changes
36 commits
Select commit
Hold shift + click to select a range
2df3304
refactor(robots): lewiki v0.1
imstevenpmwork e69dc18
refactor(robots): lekiwi v0.2
imstevenpmwork 84a2852
refactor(robots): lewiki v0.3
imstevenpmwork 130108a
refactor(robots): lekiwi v0.4
imstevenpmwork 9a2aeaa
refactor(robots): lekiwi v0.5
imstevenpmwork 748a534
fix(lekiwi): HW fixes v0.1
pre-commit-ci[bot] 0f590fe
fix(lekiwi): HW fixes v0.2
imstevenpmwork 7f7fa82
fix(lekiwi): HW fixes v0.3
imstevenpmwork 877dc1c
fix(lekiwi): HW fixes v0.4
imstevenpmwork e8283c0
fix(lekiwi): fix calibration issue
imstevenpmwork 1b9a1a2
feat(lekiwi): de-couple classes + make it single-threaded
imstevenpmwork 0167e6c
feat(lekiwi): Make dataset recording work
imstevenpmwork a909190
chore(doc): update todos + license
imstevenpmwork 067209a
refactor(kiwi): update to latest motor API
imstevenpmwork 49a0f96
Update Lekiwi with new MotorsBus
bf8d44f
Rename Lekiwi files & classes
62e6829
Cleanup imports
f8cf826
Group config files
d73ad2d
refactor(robots): update lekiwi for the latest motor bus api
imstevenpmwork 85667c7
refactor(robots): multiple changes from feedback
imstevenpmwork 1627e3e
Apply suggestions from code review
imstevenpmwork 69dc3c9
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] b59c430
Apply suggestions from code review (lekiwi_client.py)
imstevenpmwork 979f0f7
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 1a13eff
Apply suggestions from code review (code changes)
imstevenpmwork 21170d1
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 7274ad0
Apply suggestions from code review
imstevenpmwork e5f0902
chore(robots): apply suggestions from code review
imstevenpmwork efeb15d
chore(robots): apply suggestions from code review
imstevenpmwork 707b5e8
refactor(robots): refactor _get_data in lekiwi for clarity
imstevenpmwork c882875
fix(robots): bootstrap dataset recording again and improve watchdog b…
imstevenpmwork 857de96
chore(robots): update to latest motor bus API
imstevenpmwork 1b23d86
Apply suggestions from code review
imstevenpmwork eeb1d1b
chore(robots): apply suggestions from code review 2
imstevenpmwork 4488273
Apply suggestions from code review
imstevenpmwork e52bfc0
refactor(teleop): remove _is_connected member variable from KeyboardT…
imstevenpmwork File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,98 @@ | ||
| # 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. | ||
|
|
||
| import logging | ||
| import time | ||
|
|
||
| from lerobot.common.datasets.lerobot_dataset import LeRobotDataset | ||
| from lerobot.common.robots.lekiwi.config_lekiwi import LeKiwiClientConfig | ||
| from lerobot.common.robots.lekiwi.lekiwi_client import OBS_STATE, LeKiwiClient | ||
| from lerobot.common.teleoperators.keyboard import KeyboardTeleop, KeyboardTeleopConfig | ||
| from lerobot.common.teleoperators.so100 import SO100Leader, SO100LeaderConfig | ||
|
|
||
| NB_CYCLES_CLIENT_CONNECTION = 250 | ||
|
|
||
|
|
||
| def main(): | ||
| logging.info("Configuring Teleop Devices") | ||
| leader_arm_config = SO100LeaderConfig(port="/dev/tty.usbmodem58760434171") | ||
| leader_arm = SO100Leader(leader_arm_config) | ||
|
|
||
| keyboard_config = KeyboardTeleopConfig() | ||
| keyboard = KeyboardTeleop(keyboard_config) | ||
|
|
||
| logging.info("Configuring LeKiwi Client") | ||
| robot_config = LeKiwiClientConfig(remote_ip="192.0.2.42", id="lekiwi") | ||
| robot = LeKiwiClient(robot_config) | ||
|
|
||
| logging.info("Creating LeRobot Dataset") | ||
|
|
||
| # The observations that we get are expected to be in body frame (x,y,theta) | ||
| obs_dict = {f"{OBS_STATE}." + key: value for key, value in robot.state_feature.items()} | ||
| # The actions that we send are expected to be in wheel frame (motor encoders) | ||
| act_dict = {"action." + key: value for key, value in robot.action_feature.items()} | ||
|
|
||
| features_dict = { | ||
| **act_dict, | ||
| **obs_dict, | ||
| **robot.camera_features, | ||
| } | ||
| dataset = LeRobotDataset.create( | ||
| repo_id="user/lekiwi" + str(int(time.time())), | ||
| fps=10, | ||
| features=features_dict, | ||
| ) | ||
|
|
||
| logging.info("Connecting Teleop Devices") | ||
| leader_arm.connect() | ||
| keyboard.connect() | ||
|
|
||
| logging.info("Connecting remote LeKiwi") | ||
| robot.connect() | ||
|
|
||
| if not robot.is_connected or not leader_arm.is_connected or not keyboard.is_connected: | ||
| logging.error("Failed to connect to all devices") | ||
| return | ||
|
|
||
| logging.info("Starting LeKiwi teleoperation") | ||
| i = 0 | ||
| while i < NB_CYCLES_CLIENT_CONNECTION: | ||
| arm_action = leader_arm.get_action() | ||
| base_action = keyboard.get_action() | ||
| action = {**arm_action, **base_action} if len(base_action) > 0 else arm_action | ||
|
|
||
| action_sent = robot.send_action(action) | ||
| observation = robot.get_observation() | ||
|
|
||
| frame = {**action_sent, **observation} | ||
| frame.update({"task": "Dummy Example Task Dataset"}) | ||
|
|
||
| logging.info("Saved a frame into the dataset") | ||
| dataset.add_frame(frame) | ||
| i += 1 | ||
|
|
||
| logging.info("Disconnecting Teleop Devices and LeKiwi Client") | ||
| robot.disconnect() | ||
| leader_arm.disconnect() | ||
| keyboard.disconnect() | ||
|
|
||
| logging.info("Uploading dataset to the hub") | ||
| dataset.save_episode() | ||
| dataset.push_to_hub() | ||
|
|
||
| logging.info("Finished LeKiwi cleanly") | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| main() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| from .config_lekiwi import LeKiwiClientConfig, LeKiwiConfig | ||
| from .lekiwi import LeKiwi | ||
| from .lekiwi_client import LeKiwiClient |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,89 @@ | ||
| # 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. | ||
|
|
||
| from dataclasses import dataclass, field | ||
|
|
||
| from lerobot.common.cameras.configs import CameraConfig | ||
| from lerobot.common.cameras.opencv.configuration_opencv import OpenCVCameraConfig | ||
|
|
||
| from ..config import RobotConfig | ||
|
|
||
|
|
||
| @RobotConfig.register_subclass("lekiwi") | ||
| @dataclass | ||
| class LeKiwiConfig(RobotConfig): | ||
| port = "/dev/ttyACM0" # port to connect to the bus | ||
|
|
||
| disable_torque_on_disconnect: bool = True | ||
|
|
||
| # `max_relative_target` limits the magnitude of the relative positional target vector for safety purposes. | ||
| # Set this to a positive scalar to have the same value for all motors, or a list that is the same length as | ||
| # the number of motors in your follower arms. | ||
| max_relative_target: int | None = None | ||
|
|
||
| cameras: dict[str, CameraConfig] = field( | ||
| default_factory=lambda: { | ||
| "front": OpenCVCameraConfig( | ||
| camera_index="/dev/video0", fps=30, width=640, height=480, rotation=None | ||
| ), | ||
| "wrist": OpenCVCameraConfig( | ||
| camera_index="/dev/video2", fps=30, width=640, height=480, rotation=180 | ||
| ), | ||
| } | ||
| ) | ||
|
|
||
|
|
||
| @dataclass | ||
| class LeKiwiHostConfig: | ||
| # Network Configuration | ||
| port_zmq_cmd: int = 5555 | ||
| port_zmq_observations: int = 5556 | ||
|
|
||
| # Duration of the application | ||
| connection_time_s: int = 30 | ||
|
|
||
| # Watchdog: stop the robot if no command is received for over 0.5 seconds. | ||
| watchdog_timeout_ms: int = 500 | ||
|
|
||
| # If robot jitters decrease the frequency and monitor cpu load with `top` in cmd | ||
| max_loop_freq_hz: int = 30 | ||
|
|
||
|
|
||
| @RobotConfig.register_subclass("lekiwi_client") | ||
| @dataclass | ||
| class LeKiwiClientConfig(RobotConfig): | ||
| # Network Configuration | ||
| remote_ip: str | ||
| port_zmq_cmd: int = 5555 | ||
| port_zmq_observations: int = 5556 | ||
|
|
||
| teleop_keys: dict[str, str] = field( | ||
| default_factory=lambda: { | ||
| # Movement | ||
| "forward": "w", | ||
| "backward": "s", | ||
| "left": "a", | ||
| "right": "d", | ||
| "rotate_left": "z", | ||
| "rotate_right": "x", | ||
| # Speed control | ||
| "speed_up": "r", | ||
| "speed_down": "f", | ||
| # quit teleop | ||
| "quit": "q", | ||
| } | ||
| ) | ||
|
|
||
| polling_timeout_ms: int = 15 | ||
| connect_timeout_s: int = 5 | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.