The process of setting up, uploading, and running code on a Duckiebot is not particularly simple. In this guide we describe the steps we took to successfully run a docker instance on the Duckiebot.
The steps described in this section are taken from the official Duckietown guide (https://docs.duckietown.com/daffy/opmanual-duckiebot/setup/setup_laptop/index.html). We recommend you follow the original guide as they explain in more depth what each command is accomplishing and also contains some troubleshooting tips so you can be sure your installation was successful.
First of all, you will need a machine running Ubuntu version 20.04 or 22.04, as those are the only officially supported ones. Alternatively, a VM can also be used as it is Unofficially Supported. We, however advise against the use of WSL as an alternative since we were unable to perform some steps on it.
Start by ensuring you have the needed development tools pip3, git, git-lfs, curl, and wget, and install open-vm-tools if you are using a VM:
sudo apt update
sudo apt install -y python3-pip git \
git-lfs curl wget
sudo apt install open-vm-tools
You will also need to have a recent Docker version installed and set up the necessary dependencies:
sudo apt-get remove docker docker-engine \
docker.io containerd runc
sudo apt-get update
sudo apt-get install ca-certificates curl \
gnupg
sudo mkdir -m 0755 -p /etc/apt/keyrings
curl -fsSL \
https://download.docker.com/linux/ubuntu/gpg \
| sudo gpg \
--dearmor -o /etc/apt/keyrings/docker.gpg
echo \
"deb [arch="\$(dpkg --print-architecture)" \
signed-by=/etc/apt/keyrings/docker.gpg] \
https://download.docker.com/linux/ubuntu \
"\$(. /etc/os-release && \
echo "\$VERSION\_CODENAME")" stable" | \
sudo tee \
/etc/apt/sources.list.d/docker.list > \
/dev/null
sudo apt-get update
sudo apt-get install docker-ce \
docker-ce-cli containerd.io \
docker-buildx-plugin \
docker-compose-plugin
sudo apt-get install docker-compose
Finally, add docker to your user group
sudo adduser `whoami` docker
The Duckietown Shell is essential to interact with the Duckiebot. Here are the commands to install it and make sure your system can find it:
pip3 install --no-cache-dir \
--user --upgrade duckietown-shell
export PATH=~/.local/bin:\${PATH}
source ~/.bashrc
To configure the correct version of dts:
dts --set-version daffy
You will also need a Duckietown (https://hub.duckietown.com/signup/) and a DockerHub (https://hub.docker.com/) account to generate tokens you'll need.
Use the command dts tok set with your Duckietown token.
And so the Duckiebot can do the needed operations with docker containers and execute the following using your Docker username and the respective token.
dts config docker credentials set \
--username DOCKERHUB\_USERNAME \
--password DOCKERHUB\_ACCESS\_TOKEN
Now, we need to prepare the SD card to be used in the Duckiebot, but before flashing it might need to be formatted as it was in our case.
If, like ours, your SD card raises format and partition errors, you will quite predictably need to solve that issue before flashing it. There are different ways to do so, but here are the steps we followed to do so on a windows machine.
Open the Microsoft DiskPart tool by running diskpart on the command line.
Use the list disk command to find the correct disk corresponding to the SD card.
Now, using select disk DISK_INDEX select the correct disk
Then run the following commands to recreate the correct partitioning
clean
create partition primary
It should now be simple enough to format the SD card using the default settings in the file explorer.
To burn the SD Card, use the following command and follow the instructions given
dts init_sd_card --hostname \
HOSTNAME --type TYPE \
--configuration CONFIGURATION \
--wifi WIFI
where,
--hostname Name of the robot to flash the SD card for.
--type The type of your device. Types are `duckiebot` (default),`watchtower`, `traffic\_light`.
--configuration The model of your robot. This is associated with `--type` option. E.g. `DB21J`, `DB21M`, `DB19`, or `DB18`. Be very careful to use the correct version otherwise, it will not work
--wifi A comma-separated list of WiFi networks, aeach network is passed in the format wifi\_name:wifi\_password; default: duckietown:quackquack
Be careful when choosing the device so as not to flash your main disk, as it may lead to the breaking of the OS. The system will ask you the size of your SD card to try and show you only drives close to that size. If you are using a VM, its size could be similar to that of the SD card, so be extra careful here. You might want to have a recent snapshot ready, just in case. Also, depending on the card reader and machine used, this process may take a long time, so be careful about the steps you take during this phase to avoid repeating them.
Start by inserting the SD card in the correct slot of the Duckiebot and turn it on by pressing the power button of the battery connected to it.
Additionally you may connect the Duckiebot through HDMI to validate if the bot is working correctly if you are suspicious any errors occurred.
Now, to ensure the first boot is successful, ensure that your computer is connected to the same network as the Duckiebot and run dts fleet discover to check the Duckiebots available on your network. In this way, you can monitor the boot.
After the Duckiebot's status has changed to Ready, go to http://![YOUR\_DUCKIEBOT\_NAME].local/ to find its dashboard.
Alternatively, if that link does not work, try http://![YOUR\_DUCKIEBOT\_NAME]/
You can now also shutdown or reboot the robot with the following commands
dts duckiebot shutdown HOSTNAME
dts duckiebot reboot HOSTNAME
To start your development process, you may want to try using the Lane Following Demo (https://docs.duckietown.com/daffy/opmanual-duckiebot/demos/supported/lane_following.html) to get a first feel on the Duckiebot works.
Start by running the command:
dts duckiebot demo --demo_name \
lane_following --duckiebot_name \
![DUCKIEBOT_NAME] --package_name \
duckietown_demos
You may then initiate the keyboard controller with dts duckiebot keyboard_control ![DUCKIEBOT_NAME after which you can control the bot with the arrow keys and start and stop the automatic lane following by pressing the \textit{a} and \textit{s} keys, respectively.
To visualize the image captured by the Duckiebot with the representation of the line detection, it is running the command dts start_gui_tools ![DUCKIEBOT_NAME] and select \_\_/ROBOT\_NAME/line\_detector\_node/debug/segments/compressed\_\_ option on the window launched by the last command.
Writing your own code, generating the container, and pushing it to a Duckiebot to be run is not a simple process, and there are many things that can fail along the way. Many of the problems we ran into were difficult to identify and involved very time-consuming steps that had to be repeated over and over again as they failed at inopportune times. After trial and error, what follows is the process we found that allowed us to run custom-built code on the Duckiebot.
We started by forking the Template ROS Core (https://github.com/duckietown/template-ros-core) repository so that we had the correct starting dependencies and code structure to build an appropriate solution capable of running in a Duckiebot.
Using the docker build command, we generate a docker image and upload it to DockerHub with docker push
To make the Duckiebot pull the new image code, generate a container, and run, use the following command:
dts duckiebot demo \
--demo_name LAUNCH_FILE_NAME --package_name \
PACKAGE --duckiebot_name \
DUCKIEBOT_NAME --image \
DOCKER_HUB_REPO:latest
If the image has already been transferred it will skip the container generation step and will just run.