Skip to content

Commit d7bb5d4

Browse files
committed
Initial commit
1 parent 996e3e8 commit d7bb5d4

21 files changed

+2834
-0
lines changed

.github/workflows/test_solution.yml

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
name: Online Competition
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
- main
8+
9+
10+
jobs:
11+
online-competition:
12+
13+
runs-on: ubuntu-latest
14+
env: # Or as an environment variable
15+
KAGGLE_USERNAME: ${{ secrets.KaggleUsername }}
16+
KAGGLE_KEY: ${{ secrets.KaggleKey }}
17+
18+
steps:
19+
- uses: actions/checkout@v4
20+
- uses: mamba-org/setup-micromamba@v1
21+
with:
22+
micromamba-version: '1.5.6-0' # any version from https://github.com/mamba-org/micromamba-releases
23+
environment-file: environment.yaml
24+
init-shell: >-
25+
bash
26+
cache-environment: true
27+
post-cleanup: 'all'
28+
# - run: |
29+
# pip install setuptools==65.5.0 pip==21
30+
# pip install wheel==0.38.0
31+
- name: Install safe-control-gym
32+
run: |
33+
git clone -b beta-iros-competition https://github.com/utiasDSL/safe-control-gym.git
34+
cd safe-control-gym
35+
pip install . --no-deps
36+
cd ..
37+
shell: bash -el {0}
38+
- name: Install cffirmware
39+
run: |
40+
git clone https://github.com/utiasDSL/pycffirmware.git
41+
cd pycffirmware
42+
git submodule update --init --recursive
43+
./wrapper/build_linux.sh
44+
shell: bash -el {0}
45+
- run: pip install .
46+
shell: bash -el {0}
47+
- name: Run simulation tests
48+
run: python scripts/kaggle.py
49+
shell: bash -el {0}
50+
- name: Export with kaggle
51+
run: kaggle competitions submit lsy-drone-racing-ss24 -f submission.csv -m "Automated submission"
52+
shell: bash -el {0}
53+
54+

.gitignore

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
.vscode/
2+
**.egg-info/
3+
**/__pycache__/
4+
submission.csv

README.md

+203
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,203 @@
1+
# Autonomous Drone Racing Project Course
2+
![ADR Banner](docs/img/banner.jpeg)
3+
4+
## Installation
5+
6+
To run the LSY Autonomous Drone Racing project, you will need 3 main repositories:
7+
- [safe-control-gym](https://github.com/utiasDSL/safe-control-gym/tree/beta-iros-competition) - `beta-iros-competition` branch: The drone simulator and gym environments
8+
- [pycffirmware](https://github.com/utiasDSL/pycffirmware) - `main` branch: A simulator for the on-board controller response of the drones we are using to accurately model their behavior
9+
- [lsy_drone_racing](https://github.com/utiasDSL/lsy_drone_racing) - `master` branch: This repository containing the scripts to simulate and deploy the drones in the racing challenge
10+
11+
### Fork lsy_drone_racing
12+
13+
The first step is to fork the [lsy_drone_racing](https://github.com/utiasDSL/lsy_drone_racing) repository for your own group. This has two purposes: You automatically have your own repository with git version control, and it sets you up for taking part in the online competition and automated testing (see [competition](#the-online-competition)).
14+
15+
If you have never worked with GitHub before, see the [docs](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/working-with-forks/fork-a-repo) on forking.
16+
17+
### Using conda/mamba
18+
19+
The following assumes that you have a functional installation of either [conda](https://conda.io/projects/conda/en/latest/index.html) or [mamba](https://mamba.readthedocs.io/en/latest/).
20+
21+
First, clone the new fork from your own account and create a new environment with Python 3.8 by running
22+
23+
```bash
24+
mkdir -p ~/repos && cd repos
25+
git clone https://github.com/<YOUR-USERNAME>/lsy_drone_racing.git
26+
cd lsy_drone_racing
27+
conda conda env create -f environment.yaml
28+
conda activate drone
29+
```
30+
31+
> **Note:** It is important you stick with **Python 3.8**. Yes, it is outdated. Yes, we'd also like to upgrade. However, there are serious issues beyond our control when deploying the code on the real drones with any other version.
32+
33+
Next, install the lsy_drone_racing package in editable mode from the repository root
34+
35+
```bash
36+
pip install -e .
37+
```
38+
39+
Download the `safe-control-gym` and `pycffirmware` repositories and install them. Make sure you have your conda/mamba environment active!
40+
41+
```bash
42+
cd ~/repos
43+
git clone -b beta-iros-competition https://github.com/utiasDSL/safe-control-gym.git
44+
cd safe-control-gym
45+
pip install . --no-deps
46+
```
47+
```bash
48+
cd ~/repos
49+
git clone https://github.com/utiasDSL/pycffirmware.git
50+
cd pycffirmware
51+
git submodule update --init --recursive
52+
./wrapper/build_linux.sh
53+
```
54+
Finally, you can test if the installation was successful by running
55+
56+
```bash
57+
cd ~/repos/lsy_drone_racing
58+
python scripts/sim.py
59+
```
60+
61+
If everything is installed correctly, this opens the simulator and simulates a drone flying through four gates.
62+
63+
## The online competition
64+
65+
During the semester, you will compete with the other teams on who's the fastest to complete the drone race. You can see the current standings on the competition page in Kaggle, a popular ML competition website. The results of the competition will **NOT** influence your grade directly. However, it gives you a sense of how performant and robust your approach is compared to others. In addition, the competition is an easy way for you to check if your code is running correctly. If there are errors in the automated testing, chances are your project also doesn't run on our systems.
66+
67+
### Signing up for the online competition
68+
69+
To take part in the competition, you first have to create an account on [Kaggle](https://www.kaggle.com/). Next, use this [invite link](https://www.kaggle.com/t/1a37a7de76c745e29a7d7c61e538d581) to join the competition, go to the [drone racing competition](https://www.kaggle.com/competitions/lsy-drone-racing-ss24/overview), click on "Rules", and accept the competition conditions. This step is necessary to allow submissions from your account.
70+
71+
### Setting up your GitHub repo for the competition
72+
73+
The competition submission to Kaggle is fully automated. However, to make the automation works with your Kaggle account, you first have to save your credentials in GitHub. GitHub offers a way to safely store this information without giving anyone else access to it via its [secrets](https://docs.github.com/en/actions/security-guides/using-secrets-in-github-actions). Start by opening your account settings on Kaggle, go to the **API** section and click on **Create New Token**. This will download a json file containing two keys: Your account username and an API key. Next, open your lsy_drone_racing GitHub repository in the browser and go to Settings -> Secrets and variables -> Actions
74+
75+
>**Note:** You have to select the repository settings, not your account settings
76+
77+
Here you add two new repository secrets using the information from the json file you downloaded:
78+
- Name: KaggleUsername Secret: INSERT_YOUR_USERNAME
79+
- Name: KaggleKey Secret: INSERT_YOUR_KEY
80+
81+
### Submitting your latest iteration
82+
83+
The whole point of the steps you just took was to set you up to use the GitHub action defined in your repository's [.github folder](/.github/workflows/test_solution.yml). This workflow runs every time you push changes to your repository's `main` or `master` branch. To prevent submitting every iteration of your code, you can create new branches and only merge them into the main branch once you finished your changes. However, we recommend regularly updating your main branch to see how fast you are and if the code runs without problems.
84+
85+
>**Note:** The competition will count your fastest average lap time. If a submission performed worse than a previous iteration, it won't update your standing.
86+
87+
>**Note:** The first time the test runs on your account, it will take longer than usual because it has to install all dependencies in GitHub. We cache this environment, so subsequent runs should be faster.
88+
89+
>**Warning:** Kaggle only accepts 100 submissions per day. While we really hope you don't make 100 commits in a single day, we do mention it just in case.
90+
91+
Once you have pushed your latest iteration, a GitHub action runner will start testing your implementation. You can check the progress by clicking on the Actions tab of your repository. If the submission fails, you can check the errors. Please let us know if something is not working as intended. If you need additional packages for your project, please make sure to update the [environment.yaml](./environment.yaml) file accordingly. Otherwise, the tests will fail. If you want to get a more detailled summary of your performance, you can have a look at the test output directly:
92+
93+
94+
## Creating your own controller
95+
96+
To implement your own controller, have a look at the [example implementation](./examples/controller.py). We recommend to alter the existing example controller instead of creating your own file to not break the testing pipeline. Please also read through the documentation of the controller. You **must not** alter its function signatures. If you encounter problems implementing something with the given interface, contact one of the lecturers.
97+
98+
## Deployment [TODO: Complete. **NOT IMPORTANT FOR STUDENTS FOR NOW**]
99+
100+
To deploy the controllers on real drones you must install ROS Noetic and the crazyswarm package.
101+
102+
Create a catkin_ws/src folder if it does not exist already, clone the crazywarm package and build the workspace
103+
104+
**TODO: CREATE WORKING CRAZYSWARM PACKAGE**
105+
```bash
106+
mkdir -p ~/catkin_ws/src
107+
cd ~/catkin_ws/src
108+
git clone https://github.com/utiasDSL/crazyswarm.git
109+
mv crazyswarm/* .
110+
cd ..
111+
catkin_make
112+
source devel/setup.bash
113+
```
114+
115+
Next, paste the following block into your terminal
116+
```bash
117+
cat <<EOF | sudo tee /etc/udev/rules.d/99-bitcraze.rules > /dev/null
118+
# Crazyradio (normal operation)
119+
SUBSYSTEM=="usb", ATTRS{idVendor}=="1915", ATTRS{idProduct}=="7777", MODE="0664", GROUP="plugdev"
120+
# Bootloader
121+
SUBSYSTEM=="usb", ATTRS{idVendor}=="1915", ATTRS{idProduct}=="0101", MODE="0664", GROUP="plugdev"
122+
# Crazyflie (over USB)
123+
SUBSYSTEM=="usb", ATTRS{idVendor}=="0483", ATTRS{idProduct}=="5740", MODE="0664", GROUP="plugdev"
124+
EOF
125+
```
126+
127+
128+
```bash
129+
# Install Vicon bridge nodelet
130+
cd <path/to/catkin_ws>/src/
131+
git clone -b vicon-bridge-nodelet [email protected]:utiasDSL/extras.git
132+
cd ..
133+
catkin_make
134+
source <path/to/catkin_ws>/devel/setup.bash
135+
136+
# Install and make crazyflie-firmware-import
137+
cd ~/GitHub
138+
git clone -b dsl-iros-comp-flight [email protected]:utiasDSL/crazyflie-firmware-import.git # other options are `dsl-sim2real-logging-v1`, etc.
139+
cd crazyflie-firmware-import
140+
git submodule update --init --recursive
141+
sudo apt-get install make gcc-arm-none-eabi
142+
make cf2_defconfig # Make the default config file.
143+
make -j 12
144+
145+
# USB preparation for crazyradio
146+
sudo groupadd plugdev
147+
sudo usermod -a -G plugdev $USER
148+
```
149+
150+
```bash
151+
# Apply changes
152+
sudo udevadm control --reload-rules
153+
sudo udevadm trigger
154+
155+
# Flash crazyflie C10 (cf9 in the Vicon objects list)
156+
# Turn the Crazyflie off, then start the Crazyflie in bootloader mode by pressing the power button for 3 seconds. Both the blue LEDs will blink.
157+
cd ~/GitHub/crazyflie-firmware-import/
158+
make cload
159+
160+
# (optional) Install cfclient
161+
sudo apt install libxcb-xinerama0
162+
conda create -n cfclient python=3.7
163+
conda activate cfclient
164+
pip install --upgrade pip # note: we are using a conda python3.7 env
165+
pip install cfclient
166+
conda deactivate
167+
```
168+
169+
## Deploy the drones
170+
171+
### Settings
172+
Make sure you are familiar with the configuration files. Not all options are relevant depending on the motion capture setup. For more info, see the [official documentation](https://crazyswarm.readthedocs.io/en/latest/configuration.html#adjust-configuration-files).
173+
174+
The important config files are located in the crazyswarm ROS package:
175+
176+
**TODO:** Insert correct link to files
177+
- Crazyflies types — includes controller properties and marker configurations, etc.
178+
- In-use Crazyflies — includes ID, radio channel, types, etc.
179+
- All Crazyflies
180+
181+
As well as the launch file and Python script:
182+
183+
- cf_sim2real.launch
184+
- cmdFullStateCFFirmware.py
185+
186+
### Fly
187+
188+
>**Note:** The following is **NOT** within a conda environment, but has to run directly on the system's Python 3.8 installation. ROS has never heard of these best practices you speak of.
189+
190+
In a terminal, launch the ROS node for the crazyflies. Change the settings in _<path/to/crazyswarm/package>/launch/crazyflies.yaml_ as necessary.
191+
```bash
192+
roslaunch crazyswarm cf_sim2real.launch
193+
```
194+
195+
In a second terminal:
196+
197+
```bash
198+
python scripts/deploy.py --controller <path/to/your/controller.py> --config config/level3.yaml
199+
```
200+
201+
where `<path/to/your/controller.py>` implements a controller that inherits from `lsy_drone_racing.controller.BaseController`
202+
203+

0 commit comments

Comments
 (0)