|
| 1 | +This tutorial explains how to use [Trossen AI Bimanual](https://www.trossenrobotics.com/stationary-ai) with LeRobot. |
| 2 | + |
| 3 | +## Setup |
| 4 | + |
| 5 | +Follow the [documentation from Trossen Robotics](https://docs.trossenrobotics.com/trossen_arm/main/getting_started/hardware_setup.html) for setting up the hardware. |
| 6 | + |
| 7 | + |
| 8 | +## Install LeRobot |
| 9 | + |
| 10 | +On your computer: |
| 11 | + |
| 12 | +1. [Install Miniconda](https://docs.anaconda.com/miniconda/#quick-command-line-install): |
| 13 | +```bash |
| 14 | +mkdir -p ~/miniconda3 |
| 15 | +wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh -O ~/miniconda3/miniconda.sh |
| 16 | +bash ~/miniconda3/miniconda.sh -b -u -p ~/miniconda3 |
| 17 | +rm ~/miniconda3/miniconda.sh |
| 18 | +~/miniconda3/bin/conda init bash |
| 19 | +``` |
| 20 | + |
| 21 | +2. Restart shell or `source ~/.bashrc` |
| 22 | + |
| 23 | +3. Create and activate a fresh conda environment for lerobot |
| 24 | +```bash |
| 25 | +conda create -y -n lerobot python=3.10 && conda activate lerobot |
| 26 | +``` |
| 27 | + |
| 28 | +4. Clone LeRobot: |
| 29 | +```bash |
| 30 | +git clone https://github.com/Interbotix/lerobot.git ~/lerobot |
| 31 | +``` |
| 32 | + |
| 33 | +5. Install LeRobot with dependencies for the Trossen AI arms (trossen-arm) and cameras (intelrealsense): |
| 34 | + |
| 35 | +```bash |
| 36 | +cd ~/lerobot && pip install -e ".[trossen_ai]" |
| 37 | +``` |
| 38 | + |
| 39 | +For Linux only (not Mac), install extra dependencies for recording datasets: |
| 40 | + |
| 41 | +```bash |
| 42 | +conda install -y -c conda-forge ffmpeg |
| 43 | +pip uninstall -y opencv-python |
| 44 | +conda install -y -c conda-forge "opencv>=4.10.0" |
| 45 | +``` |
| 46 | + |
| 47 | +## Troubleshooting |
| 48 | + |
| 49 | +If you encounter the following error. |
| 50 | + |
| 51 | +```bash |
| 52 | +ImportError: /xxx/xxx/xxx/envs/lerobot/lib/python3.10/site-packages/cv2/python-3.10/../../../.././libtiff.so.6: undefined symbol: jpeg12_write_raw_data, version LIBJPEG_8.0 |
| 53 | +``` |
| 54 | + |
| 55 | +The below are the 2 known system specific solutions |
| 56 | + |
| 57 | +### System 76 Serval Workstation (serw13) & Dell Precision 7670 |
| 58 | + |
| 59 | +```bash |
| 60 | + conda install pytorch==2.5.1=cpu_openblas_py310ha613aac_2 -y |
| 61 | + conda install torchvision==0.21.0 -y |
| 62 | +``` |
| 63 | + |
| 64 | +### HP |
| 65 | + |
| 66 | +```bash |
| 67 | + pip install torch==2.5.1+cu121 torchvision==0.20.1+cu121 torchaudio==2.5.1+cu121 --index-url https://download.pytorch.org/whl/cu121 |
| 68 | +``` |
| 69 | + |
| 70 | + |
| 71 | +## Teleoperate |
| 72 | + |
| 73 | +By running the following code, you can start your first **SAFE** teleoperation: |
| 74 | +```bash |
| 75 | +python lerobot/scripts/control_robot.py \ |
| 76 | + --robot.type=trossen_ai_bimanual \ |
| 77 | + --robot.max_relative_target=5 \ |
| 78 | + --control.type=teleoperate |
| 79 | +``` |
| 80 | + |
| 81 | +By adding `--robot.max_relative_target=5`, we override the default value for `max_relative_target` defined in [`TrossenAIBimanualRobot`](lerobot/common/robot_devices/robots/configs.py). It is expected to be `5` to limit the magnitude of the movement for more safety, but the teleoperation won't be smooth. When you feel confident, you can disable this limit by adding `--robot.max_relative_target=null` to the command line: |
| 82 | + |
| 83 | +```bash |
| 84 | +python lerobot/scripts/control_robot.py \ |
| 85 | + --robot.type=trossen_ai \ |
| 86 | + --robot.max_relative_target=null \ |
| 87 | + --control.type=teleoperate |
| 88 | +``` |
| 89 | + |
| 90 | +## Record a dataset |
| 91 | + |
| 92 | +Once you're familiar with teleoperation, you can record your first dataset with Trossen AI. |
| 93 | + |
| 94 | +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): |
| 95 | + |
| 96 | +```bash |
| 97 | +huggingface-cli login --token ${HUGGINGFACE_TOKEN} --add-to-git-credential |
| 98 | +``` |
| 99 | + |
| 100 | +Store your Hugging Face repository name in a variable to run these commands: |
| 101 | + |
| 102 | +```bash |
| 103 | +HF_USER=$(huggingface-cli whoami | head -n 1) |
| 104 | +echo $HF_USER |
| 105 | +``` |
| 106 | + |
| 107 | +Record 2 episodes and upload your dataset to the hub: |
| 108 | + |
| 109 | +```bash |
| 110 | +python lerobot/scripts/control_robot.py \ |
| 111 | + --robot.type=trossen_ai_bimanual \ |
| 112 | + --robot.max_relative_target=null \ |
| 113 | + --control.type=record \ |
| 114 | + --control.fps=30 \ |
| 115 | + --control.single_task="Grasp a lego block and put it in the bin." \ |
| 116 | + --control.repo_id=${HF_USER}/trossen_ai_bimanual_test \ |
| 117 | + --control.tags='["tutorial"]' \ |
| 118 | + --control.warmup_time_s=5 \ |
| 119 | + --control.episode_time_s=30 \ |
| 120 | + --control.reset_time_s=30 \ |
| 121 | + --control.num_episodes=2 \ |
| 122 | + --control.push_to_hub=true |
| 123 | +``` |
| 124 | + |
| 125 | +Note: If the camera fps is unstable consider increasing the number of image writers per thread. |
| 126 | + |
| 127 | +```bash |
| 128 | +python lerobot/scripts/control_robot.py \ |
| 129 | + --robot.type=trossen_ai_bimanual \ |
| 130 | + --robot.max_relative_target=null \ |
| 131 | + --control.type=record \ |
| 132 | + --control.fps=30 \ |
| 133 | + --control.single_task="Grasp a lego block and put it in the bin." \ |
| 134 | + --control.repo_id=${HF_USER}/trossen_ai_bimanual_test \ |
| 135 | + --control.tags='["tutorial"]' \ |
| 136 | + --control.warmup_time_s=5 \ |
| 137 | + --control.episode_time_s=30 \ |
| 138 | + --control.reset_time_s=30 \ |
| 139 | + --control.num_episodes=2 \ |
| 140 | + --control.push_to_hub=true \ |
| 141 | + --control.num_image_writer_threads_per_camera = 8 |
| 142 | +``` |
| 143 | + |
| 144 | +## Visualize a dataset |
| 145 | + |
| 146 | +If you uploaded your dataset to the hub with `--control.push_to_hub=true`, you can [visualize your dataset online](https://huggingface.co/spaces/lerobot/visualize_dataset) by copy pasting your repo id given by: |
| 147 | +```bash |
| 148 | +echo ${HF_USER}/trossen_ai_bimanual_test |
| 149 | +``` |
| 150 | + |
| 151 | +If you didn't upload with `--control.push_to_hub=false`, you can also visualize it locally with: |
| 152 | +```bash |
| 153 | +python lerobot/scripts/visualize_dataset_html.py \ |
| 154 | + --repo-id ${HF_USER}/trossen_ai_bimanual_test |
| 155 | +``` |
| 156 | + |
| 157 | +## Replay an episode |
| 158 | + |
| 159 | + |
| 160 | +Now try to replay the first episode on your robot: |
| 161 | +```bash |
| 162 | +python lerobot/scripts/control_robot.py \ |
| 163 | + --robot.type=trossen_ai_bimanual \ |
| 164 | + --robot.max_relative_target=null \ |
| 165 | + --control.type=replay \ |
| 166 | + --control.fps=30 \ |
| 167 | + --control.repo_id=${HF_USER}/trossen_ai_bimanual_test \ |
| 168 | + --control.episode=0 |
| 169 | +``` |
| 170 | + |
| 171 | +## Train a policy |
| 172 | + |
| 173 | +To train a policy to control your robot, use the [`python lerobot/scripts/train.py`](../lerobot/scripts/train.py) script. A few arguments are required. Here is an example command: |
| 174 | +```bash |
| 175 | +python lerobot/scripts/train.py \ |
| 176 | + --dataset.repo_id=${HF_USER}/trossen_ai_bimanual_test \ |
| 177 | + --policy.type=act \ |
| 178 | + --output_dir=outputs/train/act_trossen_ai_bimanual_test \ |
| 179 | + --job_name=act_trossen_ai_bimanual_test \ |
| 180 | + --device=cuda \ |
| 181 | + --wandb.enable=true |
| 182 | +``` |
| 183 | + |
| 184 | +Let's explain it: |
| 185 | +1. We provided the dataset as argument with `--dataset.repo_id=${HF_USER}/trossen_ai_bimanual_test`. |
| 186 | +2. We provided the policy with `policy.type=act`. This loads configurations from [`configuration_act.py`](../lerobot/common/policies/act/configuration_act.py). Importantly, this policy will automatically adapt to the number of motor sates, motor actions and cameras of your robot (e.g. `laptop` and `phone`) which have been saved in your dataset. |
| 187 | +4. We provided `device=cuda` since we are training on a Nvidia GPU, but you could use `device=mps` to train on Apple silicon. |
| 188 | +5. We provided `wandb.enable=true` to use [Weights and Biases](https://docs.wandb.ai/quickstart) for visualizing training plots. This is optional but if you use it, make sure you are logged in by running `wandb login`. |
| 189 | + |
| 190 | +For more information on the `train` script see the previous tutorial: [`examples/4_train_policy_with_script.md`](../examples/4_train_policy_with_script.md) |
| 191 | + |
| 192 | +Training should take several hours. You will find checkpoints in `outputs/train/act_trossen_ai_bimanual_test/checkpoints`. |
| 193 | + |
| 194 | +## Evaluate your policy |
| 195 | + |
| 196 | +You can use the `record` function from [`lerobot/scripts/control_robot.py`](../lerobot/scripts/control_robot.py) but with a policy checkpoint as input. For instance, run this command to record 10 evaluation episodes: |
| 197 | +```bash |
| 198 | +python lerobot/scripts/control_robot.py \ |
| 199 | + --robot.type=trossen_ai_bimanual \ |
| 200 | + --control.type=record \ |
| 201 | + --control.fps=30 \ |
| 202 | + --control.single_task="Grasp a lego block and put it in the bin." \ |
| 203 | + --control.repo_id=${HF_USER}/eval_act_trossen_ai_bimanual_test \ |
| 204 | + --control.tags='["tutorial"]' \ |
| 205 | + --control.warmup_time_s=5 \ |
| 206 | + --control.episode_time_s=30 \ |
| 207 | + --control.reset_time_s=30 \ |
| 208 | + --control.num_episodes=10 \ |
| 209 | + --control.push_to_hub=true \ |
| 210 | + --control.policy.path=outputs/train/act_trossen_ai_bimanual_test/checkpoints/last/pretrained_model \ |
| 211 | + --control.num_image_writer_processes=1 |
| 212 | +``` |
| 213 | + |
| 214 | +As you can see, it's almost the same command as previously used to record your training dataset. Two things changed: |
| 215 | +1. There is an additional `--control.policy.path` argument which indicates the path to your policy checkpoint with (e.g. `outputs/train/eval_act_trossen_ai_bimanual_test/checkpoints/last/pretrained_model`). You can also use the model repository if you uploaded a model checkpoint to the hub (e.g. `${HF_USER}/act_trossen_ai_bimanual_test`). |
| 216 | +2. The name of dataset begins by `eval` to reflect that you are running inference (e.g. `${HF_USER}/eval_act_trossen_ai_bimanual_test`). |
| 217 | +3. We use `--control.num_image_writer_processes=1` instead of the default value (`0`). On our computer, using a dedicated process to write images from the 4 cameras on disk allows to reach constent 30 fps during inference. Feel free to explore different values for `--control.num_image_writer_processes`. |
| 218 | + |
| 219 | +## More |
| 220 | + |
| 221 | +Follow this [previous tutorial](https://github.com/huggingface/lerobot/blob/main/examples/7_get_started_with_real_robot.md#4-train-a-policy-on-your-data) for a more in-depth explaination. |
| 222 | + |
0 commit comments