Skip to content
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

Add support for Stretch (hello-robot) #409

Merged
merged 45 commits into from
Oct 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
0e4b9e2
Add stretch_body
aliberts Sep 4, 2024
7992d2e
Fix poetry relax
aliberts Sep 4, 2024
bea022f
Fix install
aliberts Sep 6, 2024
90e7895
Add stretch boilerplate
aliberts Sep 6, 2024
bf5b6e1
Fix install
aliberts Sep 6, 2024
e5a4fa3
Add teleop
aliberts Sep 6, 2024
2e36039
Fix '--camera-ids' empty, add init_from_name to IntelRealSenseCamera
aliberts Sep 10, 2024
9a6150c
Add camera rotation
aliberts Sep 10, 2024
38f6be8
Add StretchRobotConfig, cameras obs
aliberts Sep 10, 2024
f2269c1
Add safe_disconnect
aliberts Sep 10, 2024
8b28a3d
Add todo
aliberts Sep 10, 2024
e9682af
Reduce workers
aliberts Sep 10, 2024
4219527
Fixes
aliberts Sep 10, 2024
aaf7fd4
Fix typo
aliberts Sep 10, 2024
2bf4dcb
Invert has_method args
aliberts Sep 10, 2024
f5651a5
Add nav cam, add rotation to opencv cams
aliberts Sep 11, 2024
e755d10
Update lerobot/common/datasets/compute_stats.py
aliberts Sep 11, 2024
a98556b
Fix install
aliberts Sep 11, 2024
6bc1c6b
Fix CI install
aliberts Sep 11, 2024
bd4fdc8
Add copyrights
aliberts Sep 11, 2024
12a2f2c
Remove default robot_type
aliberts Sep 12, 2024
16dd73f
Remove StretchRobot import
aliberts Sep 12, 2024
88526d0
Add capture_observation
aliberts Sep 12, 2024
9e2d98c
Add send_action, type-hints
aliberts Sep 12, 2024
1053845
Add todo
aliberts Sep 12, 2024
652eb01
Merge remote-tracking branch 'origin/main' into user/aliberts/2024_09…
aliberts Sep 24, 2024
3fbd680
Fixes
aliberts Sep 24, 2024
42d9556
Update stretch-body
aliberts Sep 25, 2024
db09ebf
Add pynput
aliberts Sep 25, 2024
ddd8059
Add connection errors
aliberts Sep 25, 2024
d1fc630
Add doc
aliberts Sep 25, 2024
7c87025
Add logging step
aliberts Sep 26, 2024
e0fa5e4
Change stretch log levels
aliberts Sep 26, 2024
d5fbfd4
Add system check
aliberts Sep 26, 2024
78e8435
Update pyproject.toml
aliberts Sep 26, 2024
37572eb
Add todo
aliberts Sep 26, 2024
eb48452
Add suggestion
aliberts Sep 26, 2024
722092a
Cleanup camera utils
aliberts Sep 27, 2024
56d3845
Add nav cam
aliberts Sep 27, 2024
306a1ac
Add more info in markdown
Cadene Oct 4, 2024
c24b137
Add comment
aliberts Oct 4, 2024
2c0feed
fps=20, homogenization intelrealsense opencv
Cadene Oct 4, 2024
d28f556
Merge remote-tracking branch 'origin/main' into user/aliberts/2024_09…
Cadene Oct 4, 2024
d210d2e
fix unit tests
Cadene Oct 4, 2024
d716511
fix unit tests
Cadene Oct 4, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,10 @@ jobs:
lfs: true # Ensure LFS files are pulled

- name: Install apt dependencies
run: sudo apt-get update && sudo apt-get install -y libegl1-mesa-dev ffmpeg
# portaudio19-dev is needed to install pyaudio
run: |
sudo apt-get update && \
sudo apt-get install -y libegl1-mesa-dev ffmpeg portaudio19-dev
Cadene marked this conversation as resolved.
Show resolved Hide resolved

- name: Install poetry
run: |
Expand Down Expand Up @@ -111,7 +114,10 @@ jobs:
lfs: true # Ensure LFS files are pulled

- name: Install apt dependencies
run: sudo apt-get update && sudo apt-get install -y libegl1-mesa-dev
# portaudio19-dev is needed to install pyaudio
run: |
sudo apt-get update && \
sudo apt-get install -y libegl1-mesa-dev portaudio19-dev

- name: Install poetry
run: |
Expand Down
2 changes: 1 addition & 1 deletion examples/7_get_started_with_real_robot.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ poetry install --sync --extras "dynamixel"
```bash
conda install -c conda-forge ffmpeg
pip uninstall opencv-python
conda install -c conda-forge opencv>=4.10.0
conda install -c conda-forge "opencv>=4.10.0"
```

You are now ready to plug the 5V power supply to the motor bus of the leader arm (the smaller one) since all its motors only require 5V.
Expand Down
158 changes: 158 additions & 0 deletions examples/8_use_stretch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
This tutorial explains how to use [Stretch 3](https://hello-robot.com/stretch-3-product) with LeRobot.

## Setup

Familiarize yourself with Stretch by following its [tutorials](https://docs.hello-robot.com/0.3/getting_started/hello_robot/) (recommended).

To use LeRobot on Stretch, 3 options are available:
- [tethered setup](https://docs.hello-robot.com/0.3/getting_started/connecting_to_stretch/#tethered-setup)
- [untethered setup](https://docs.hello-robot.com/0.3/getting_started/connecting_to_stretch/#untethered-setup)
- ssh directly into Stretch (you will first need to install and configure openssh-server on stretch using one of the two above setups)


## Install LeRobot

On Stretch's CLI, follow these steps:

1. [Install Miniconda](https://docs.anaconda.com/miniconda/#quick-command-line-install):
```bash
mkdir -p ~/miniconda3
wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh -O ~/miniconda3/miniconda.sh
bash ~/miniconda3/miniconda.sh -b -u -p ~/miniconda3
rm ~/miniconda3/miniconda.sh
~/miniconda3/bin/conda init bash
```

2. Comment out these lines in `~/.profile` (this can mess up paths used by conda and ~/.local/bin should already be in your PATH)
```
# set PATH so it includes user's private bin if it exists
if [ -d "$HOME/.local/bin" ] ; then
PATH="$HOME/.local/bin:$PATH"
fi
```

3. Restart shell or `source ~/.bashrc`

4. Create and activate a fresh conda environment for lerobot
```bash
conda create -y -n lerobot python=3.10 && conda activate lerobot
```

5. Clone LeRobot:
```bash
git clone https://github.com/huggingface/lerobot.git ~/lerobot
```

6. Install LeRobot with stretch dependencies:
```bash
cd ~/lerobot && pip install -e ".[stretch]"
```

> **Note:** If you get this message, you can ignore it: `ERROR: pip's dependency resolver does not currently take into account all the packages that are installed.`

And install extra dependencies for recording datasets on Linux:
```bash
conda install -y -c conda-forge ffmpeg
pip uninstall -y opencv-python
conda install -y -c conda-forge "opencv>=4.10.0"
```

7. Run a [system check](https://docs.hello-robot.com/0.3/getting_started/stretch_hardware_overview/#system-check) to make sure your robot is ready:
```bash
stretch_system_check.py
```

> **Note:** You may need to free the "robot process" after booting Stretch by running `stretch_free_robot_process.py`. For more info this Stretch's [doc](https://docs.hello-robot.com/0.3/getting_started/stretch_hardware_overview/#turning-off-gamepad-teleoperation).

You should get something like this:
```bash
For use with S T R E T C H (R) from Hello Robot Inc.
---------------------------------------------------------------------

Model = Stretch 3
Tool = DexWrist 3 w/ Gripper
Serial Number = stretch-se3-3054

---- Checking Hardware ----
[Pass] Comms are ready
[Pass] Actuators are ready
[Warn] Sensors not ready (IMU AZ = -10.19 out of range -10.1 to -9.5)
[Pass] Battery voltage is 13.6 V

---- Checking Software ----
[Pass] Ubuntu 22.04 is ready
[Pass] All APT pkgs are setup correctly
[Pass] Firmware is up-to-date
[Pass] Python pkgs are up-to-date
[Pass] ROS2 Humble is ready
```

## Teleoperate, record a dataset and run a policy

**Calibrate (Optional)**
Before operating Stretch, you need to [home](https://docs.hello-robot.com/0.3/getting_started/stretch_hardware_overview/#homing) it first. Be mindful about giving Stretch some space as this procedure will move the robot's arm and gripper. Now run this command:
```bash
python lerobot/scripts/control_robot.py calibrate \
--robot-path lerobot/configs/robot/stretch.yaml
```
This is equivalent to running `stretch_robot_home.py`

Cadene marked this conversation as resolved.
Show resolved Hide resolved
> **Note:** If you run any of the LeRobot scripts below and Stretch is not poperly homed, it will automatically home/calibrate first.

**Teleoperate**
Before trying teleoperation, you need activate the gamepad controller by pressing the middle button. For more info, see Stretch's [doc](https://docs.hello-robot.com/0.3/getting_started/hello_robot/#gamepad-teleoperation).

Now try out teleoperation (see above documentation to learn about the gamepad controls):
```bash
python lerobot/scripts/control_robot.py teleoperate \
--robot-path lerobot/configs/robot/stretch.yaml
```
This is essentially the same as running `stretch_gamepad_teleop.py`

**Record a dataset**
Once you're familiar with the gamepad controls and after a bit of practice, you can try to record your first dataset with Stretch.

If you want to use the Hugging Face hub features for uploading your dataset and you haven't previously done it, make sure you've logged in using a write-access token, which can be generated from the [Hugging Face settings](https://huggingface.co/settings/tokens):
```bash
huggingface-cli login --token ${HUGGINGFACE_TOKEN} --add-to-git-credential
```

Store your Hugging Face repository name in a variable to run these commands:
```bash
HF_USER=$(huggingface-cli whoami | head -n 1)
echo $HF_USER
```

Record one episode:
```bash
python lerobot/scripts/control_robot.py record \
--robot-path lerobot/configs/robot/stretch.yaml \
--fps 20 \
--root data \
--repo-id ${HF_USER}/stretch_test \
Cadene marked this conversation as resolved.
Show resolved Hide resolved
--tags stretch tutorial \
--warmup-time-s 3 \
--episode-time-s 40 \
--reset-time-s 10 \
--num-episodes 1 \
--push-to-hub 0
```

> **Note:** If you're using ssh to connect to Stretch and run this script, you won't be able to visualize its cameras feed (though they will still be recording). To see the cameras stream, use [tethered](https://docs.hello-robot.com/0.3/getting_started/connecting_to_stretch/#tethered-setup) or [untethered setup](https://docs.hello-robot.com/0.3/getting_started/connecting_to_stretch/#untethered-setup).

**Replay an episode**
Now try to replay this episode (make sure the robot's initial position is the same):
```bash
python lerobot/scripts/control_robot.py replay \
--robot-path lerobot/configs/robot/stretch.yaml \
--fps 20 \
--root data \
--repo-id ${HF_USER}/stretch_test \
--episode 0
```

Follow [previous tutorial](https://github.com/huggingface/lerobot/blob/main/examples/7_get_started_with_real_robot.md#4-train-a-policy-on-your-data) to train a policy on your data and run inference on your robot. You will need to adapt the code for Stretch.

> TODO(rcadene, aliberts): Add already setup environment and policy yaml configuration files

If you need help, please reach out on Discord in the channel `#stretch3-mobile-arm`.
Loading
Loading