Open_Duck_Mini_Runtime/README.md

182 lines
4.8 KiB
Markdown
Raw Permalink Normal View History

2024-09-20 14:02:53 +00:00
# Open Duck Mini Runtime
## Raspberry Pi zero 2W setup
### Install Raspberry Pi OS
Download Raspberry Pi OS Lite (64-bit) from here : https://www.raspberrypi.com/software/operating-systems/
Follow the instructions here to install the OS on the SD card : https://www.raspberrypi.com/documentation/computers/getting-started.html
2025-01-10 17:30:51 +00:00
With the Raspberry Pi Imager, you can pre-configure session, wifi and ssh. Do it like below :
2025-01-10 17:31:34 +00:00
![imager_setup](https://github.com/user-attachments/assets/7a4987b2-de83-41dd-ab7f-585259685f16)
2025-01-10 17:30:51 +00:00
> Tip: I configure the rasp to connect to my phone's hotspot, this way I can connect to it from anywhere.
2025-01-10 18:44:13 +00:00
### Setup SSH (If not setup during the installation)
2024-09-20 14:02:53 +00:00
When first booting on the rasp, you will need to connect a screen and a keyboard. The first thing you should do is connect to a wifi network and enable SSH.
To do so, you can follow this guide : https://www.raspberrypi.com/documentation/computers/configuration.html#setting-up-wifi
Then, you can connect to your rasp using SSH without having to plug a screen and a keyboard.
2025-01-10 19:30:28 +00:00
### Update the system and install necessary stuff
2025-01-10 18:44:13 +00:00
```bash
sudo apt update
sudo apt upgrade
2025-01-10 19:08:38 +00:00
sudo apt install git
2025-01-10 18:44:13 +00:00
sudo apt install python3-pip
2025-01-10 19:08:38 +00:00
sudo apt install python3-virtualenvwrapper
2025-04-08 12:55:22 +00:00
(optional) sudo apt install python3-picamzero
2025-01-10 19:08:38 +00:00
```
Add this to the end of the `.bashrc`:
```bash
export WORKON_HOME=$HOME/.virtualenvs
export PROJECT_HOME=$HOME/Devel
source /usr/share/virtualenvwrapper/virtualenvwrapper.sh
2025-01-10 18:44:13 +00:00
```
2025-01-30 10:38:41 +00:00
### Enable I2C
2024-09-20 14:02:53 +00:00
2025-01-30 10:38:41 +00:00
`sudo raspi-config` -> `Interface Options` -> `I2C`
2025-01-26 15:44:53 +00:00
2025-01-30 10:38:41 +00:00
TODO set 400KHz ?
2024-09-20 14:02:53 +00:00
### Set the usbserial latency timer
```bash
cd /etc/udev/rules.d/
sudo touch 99-usb-serial.rules
sudo nano 99-usb-serial.rules
# copy the following line in the file
SUBSYSTEM=="usb-serial", DRIVER=="ftdi_sio", ATTR{latency_timer}="1"
```
2025-01-11 17:14:59 +00:00
### Set the udev rules for the motor control board
2025-01-10 18:44:13 +00:00
TODO
2024-09-20 14:02:53 +00:00
2025-01-10 19:25:11 +00:00
### Setup xbox one controller over bluetooth
2025-01-11 17:12:31 +00:00
Turn your xbox one controller on and set it in pairing mode by long pressing the sync button on the top of the controller.
Run the following commands on the rasp :
```bash
bluetoothctl
scan on
```
Wait for the controller to appear in the list, then run :
```bash
pair <controller_mac_address>
trust <controller_mac_address>
connect <controller_mac_address>
```
The led on the controller should stop blinking and stay on.
You can test that it's working by running
```bash
python3 mini_bdx_runtime/mini_bdx_runtime/xbox_controller.py
2025-01-11 17:12:31 +00:00
```
2025-01-10 19:25:11 +00:00
2025-03-04 17:27:49 +00:00
## Speaker wiring and configuration
Follow this tutorial
2025-03-24 16:37:46 +00:00
> For now, don't activate `/dev/zero` when they ask
2025-03-04 17:27:49 +00:00
https://learn.adafruit.com/adafruit-max98357-i2s-class-d-mono-amp?view=all
2025-01-10 19:25:11 +00:00
2024-09-20 14:02:53 +00:00
## Install the runtime
2025-01-10 19:30:28 +00:00
### Make a virtual environment and activate it
2025-01-10 18:44:13 +00:00
2025-01-10 19:08:38 +00:00
```bash
mkvirtualenv -p python3 open-duck-mini-runtime
workon open-duck-mini-runtime
```
2025-01-10 18:44:13 +00:00
2024-09-20 14:02:53 +00:00
Clone this repository on your rasp, cd into the repo, then :
```bash
2025-01-10 19:25:11 +00:00
git clone https://github.com/apirrone/Open_Duck_Mini_Runtime
cd Open_Duck_Mini_Runtime
git checkout v2
2024-09-20 14:02:53 +00:00
pip install -e .
```
2025-05-10 13:27:05 +00:00
In Raspberry Pi 5, you need to perform the following operations
```bash
pip uninstall -y RPi.GPIO
pip install lgpio
```
2025-01-10 19:25:11 +00:00
2024-09-20 14:02:53 +00:00
## Test the IMU
```bash
python3 mini_bdx_runtime/mini_bdx_runtime/raw_imu.py
2024-09-20 14:02:53 +00:00
```
2025-02-24 21:41:26 +00:00
You can also run `python3 scripts/imu_server.py` on the robot and `python3 scripts/imu_client.py --ip <robot_ip>` on your computer to check that the frame is oriented correctly.
> To find the ip address of the robot, run `ifconfig` on the robot
2025-04-24 18:43:48 +00:00
## Test motors
This will allow you to verify all your motors are connected and configured.
```bash
python3 scripts/check_motors.py
```
2025-04-19 10:27:13 +00:00
## Make your duck_config.json
Copy `example_config.json` in the home directory of your duck and rename it `duck_config.json`.
`cp example_config.json ~/duck_config.json`
In this file, you can configure some stuff, like registering if you installed the expression features, installed the imu upside down or and other stuff. You also write the joints offsets of your duck here
2025-02-24 21:41:26 +00:00
## Find the joints offsets
2025-04-19 10:27:13 +00:00
This script will guide you through finding the joints offsets of your robot that you can then write in your `duck_config.json`
2025-02-24 21:41:26 +00:00
> This procedure won't be necessary in the future as we will be flashing the offsets directly in each motor's eeprom.
```bash
cd scripts/
python find_soft_offsets.py
```
2025-03-04 17:59:06 +00:00
2025-04-09 09:55:02 +00:00
## Run the walk !
Download the [latest policy checkpoint ](https://github.com/apirrone/Open_Duck_Mini/blob/v2/BEST_WALK_ONNX_2.onnx) and copy it to your duck.
`cd scripts/`
`python v2_rl_walk_mujoco.py --onnx_model_path <path_to>/BEST_WALK_ONNX_2.onnx`
2025-04-09 09:55:02 +00:00
```
- The commands are :
- A to pause/unpause
- X to turn on/off the projector
- B to play a random sound
- Y to turn on/off head control (very experimental, I don't recommend trying that, it can break your duck's head)
- left and right triggers to control the left and right antennas
- LB (new!) press and hold to increase the walking frequency, kind of a sprint mode 🙂
```