Skip to content

Commit 5a1db53

Browse files
committed
Add controller setting in config
1 parent f8ffb38 commit 5a1db53

File tree

8 files changed

+89
-71
lines changed

8 files changed

+89
-71
lines changed

README.md

+68-63
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
- [Installation](#installation)
99
- [Fork lsy\_drone\_racing](#fork-lsy_drone_racing)
1010
- [Using conda/mamba](#using-condamamba)
11+
- [Using Docker](#using-docker)
1112
- [Difficulty levels](#difficulty-levels)
1213
- [Switching between configurations](#switching-between-configurations)
1314
- [The online competition](#the-online-competition)
@@ -16,15 +17,18 @@
1617
- [Submitting your latest iteration](#submitting-your-latest-iteration)
1718
- [Creating your own controller](#creating-your-own-controller)
1819
- [Common errors](#common-errors)
19-
- [Deployment (**NOT IMPORTANT FOR STUDENTS FOR NOW**)](#deployment-not-important-for-students-for-now)
20+
- [GLIBCXX](#glibcxx)
21+
- [Deployment](#deployment)
2022
- [Hardware setup](#hardware-setup)
21-
- [Common errors](#common-errors)
23+
- [Common errors](#common-errors-1)
2224
- [libNatNet](#libnatnet)
25+
- [LIBUSB\_ERROR\_ACCESS](#libusb_error_access)
2326
- [Fly with the drones](#fly-with-the-drones)
2427
- [Settings](#settings)
2528
- [Launch](#launch)
2629

2730

31+
2832
## Installation
2933

3034
To run the LSY Autonomous Drone Racing project, you will need 2 repositories:
@@ -46,11 +50,12 @@ First, clone the new fork from your own account and create a new environment wit
4650
```bash
4751
mkdir -p ~/repos && cd repos
4852
git clone https://github.com/<YOUR-USERNAME>/lsy_drone_racing.git
49-
conda create -n drone python=3.8
50-
conda activate drone
53+
conda create -n race python=3.8
54+
conda activate race
5155
```
5256

5357
> **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.
58+
5459
Now you can install the lsy_drone_racing package in editable mode from the repository root
5560

5661
```bash
@@ -67,7 +72,6 @@ cd pycffirmware
6772
git submodule update --init --recursive
6873
sudo apt update
6974
sudo apt install build-essential
70-
conda install swig
7175
./wrapper/build_linux.sh
7276
```
7377

@@ -80,22 +84,47 @@ python scripts/sim.py
8084

8185
If everything is installed correctly, this opens the simulator and simulates a drone flying through four gates.
8286

87+
You can also install the extended dependencies with
88+
```bash
89+
conda activate race
90+
cd ~/repos/lsy_drone_racing
91+
pip install -e .[rl, test]
92+
```
93+
and check if all tests complete with
94+
```bash
95+
cd ~/repos/lsy_drone_racing
96+
pytest tests
97+
```
98+
8399
### Using Docker
84-
TODO: Add docker instructions
100+
You can also run the simulation with Docker, albeit without the GUI at the moment. To test this, install docker with docker compose on your system, and then run
101+
```bash
102+
docker compose build
103+
docker compose up
104+
```
105+
After building, running the container should produce the following output:
106+
107+
```bash
108+
sim-1 | INFO:__main__:Flight time (s): 8.466666666666667
109+
sim-1 | Reason for termination: Task completed
110+
sim-1 | Gates passed: 4
111+
sim-1 |
112+
sim-1 | 8.466666666666667
113+
```
85114

86115
## Difficulty levels
87116
The complete problem is specified by a TOML file, e.g. [`level0.toml`](config/level0.toml)
88117

89118
The config folder contains settings for progressively harder scenarios:
90119

91-
| Evaluation Scenario | Constraints | Rand. Inertial Properties | Randomized Obstacles, Gates | Rand. Between Episodes | Notes |
92-
| :---------------------------------: | :---------: | :-----------------------: | :-------------------------: | :--------------------: | :-------------------: |
93-
| [`level0.toml`](config/level0.toml) | **Yes** | *No* | *No* | *No* | Perfect knowledge |
94-
| [`level1.toml`](config/level1.toml) | **Yes** | **Yes** | *No* | *No* | Adaptive |
95-
| [`level2.toml`](config/level2.toml) | **Yes** | **Yes** | **Yes** | *No* | Learning, re-planning |
96-
| [`level3.toml`](config/level3.toml) | **Yes** | **Yes** | **Yes** | **Yes** | Robustness |
97-
| | | | | | |
98-
| sim2real | **Yes** | Real-life hardware | **Yes** | *No* | Sim2real transfer |
120+
| Evaluation Scenario | Constraints | Rand. Inertial Properties | Randomized Obstacles, Gates | Rand. Between Episodes | Notes |
121+
| :---------------------------: | :---------: | :-----------------------: | :-------------------------: | :--------------------: | :-------------------: |
122+
| [Level 0](config/level0.toml) | **Yes** | *No* | *No* | *No* | Perfect knowledge |
123+
| [Level 1](config/level1.toml) | **Yes** | **Yes** | *No* | *No* | Adaptive |
124+
| [Level 2](config/level2.toml) | **Yes** | **Yes** | **Yes** | *No* | Learning, re-planning |
125+
| [Level 3](config/level3.toml) | **Yes** | **Yes** | **Yes** | **Yes** | Robustness |
126+
| | | | | | |
127+
| sim2real | **Yes** | Real-life hardware | **Yes** | *No* | Sim2real transfer |
99128

100129
> **Note:** "Rand. Between Episodes" (governed by argument `reseed_on_reset`) states whether randomized properties and positions vary or are kept constant (by re-seeding the random number generator on each `env.reset()`) across episodes
101130
@@ -112,7 +141,7 @@ During the semester, you will compete with the other teams on who's the fastest
112141

113142
### Signing up for the online competition
114143

115-
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.
144+
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/487e7e8777364612ba3f9ea3a6a1ea15) to join the competition, go to the [drone racing competition](https://www.kaggle.com/competitions/lsy-drone-racing-ws24/overview), click on "Rules", and accept the competition conditions. This step is necessary to allow submissions from your account.
116145

117146
### Setting up your GitHub repo for the competition
118147

@@ -170,23 +199,18 @@ conda install -c conda-forge gcc=12.1.0
170199

171200
If the program still crashes and complains about not finding `GLIBCXX_3.4.30`, please update your `LD_LIBRARY_PATH` variable to point to your conda environment's lib folder.
172201

173-
## Deployment (**NOT IMPORTANT FOR STUDENTS FOR NOW**)
202+
## Deployment
174203

175204
### Hardware setup
176205

177206
To deploy the controllers on real drones you must install ROS Noetic and the crazyswarm package.
178207

179-
Create a catkin_ws/src folder if it does not exist already, clone the crazywarm package and build the workspace
208+
Clone the [crazyswarm repository](https://github.com/USC-ACTLab/crazyswarm) and follow its [build steps](https://crazyswarm.readthedocs.io/en/latest/installation.html).
180209

181-
**TODO: CREATE WORKING CRAZYSWARM PACKAGE**
182210
```bash
183-
mkdir -p ~/catkin_ws/src
184-
cd ~/catkin_ws/src
185-
git clone https://github.com/utiasDSL/crazyswarm.git
186-
mv crazyswarm/* .
187-
cd ..
188-
catkin_make
189-
source devel/setup.bash
211+
cd ~/repos
212+
git clone https://github.com/USC-ACTLab/crazyswarm
213+
...
190214
```
191215

192216
Next, paste the following block into your terminal
@@ -199,41 +223,30 @@ SUBSYSTEM=="usb", ATTRS{idVendor}=="1915", ATTRS{idProduct}=="0101", MODE="0664"
199223
# Crazyflie (over USB)
200224
SUBSYSTEM=="usb", ATTRS{idVendor}=="0483", ATTRS{idProduct}=="5740", MODE="0664", GROUP="plugdev"
201225
EOF
202-
```
203226

227+
# USB preparation for crazyradio
228+
sudo groupadd plugdev
229+
sudo usermod -a -G plugdev $USER
230+
231+
# Apply changes
232+
sudo udevadm control --reload-rules
233+
sudo udevadm trigger
234+
```
204235

236+
We also need to install the Vicon bridge package to get access to the Vicon positions etc in ROS.
205237
```bash
206238
# Install Vicon bridge nodelet
207239
cd <path/to/catkin_ws>/src/
208-
git clone -b vicon-bridge-nodelet git@github.com:utiasDSL/extras.git
240+
git clone https://github.com/ethz-asl/vicon_bridge
209241
cd ..
210242
catkin_make
211243
source <path/to/catkin_ws>/devel/setup.bash
212-
213-
# Install and make crazyflie-firmware-import
214-
cd ~/GitHub
215-
git clone -b dsl-iros-comp-flight [email protected]:utiasDSL/crazyflie-firmware-import.git # other options are `dsl-sim2real-logging-v1`, etc.
216-
cd crazyflie-firmware-import
217-
git submodule update --init --recursive
218-
sudo apt-get install make gcc-arm-none-eabi
219-
make cf2_defconfig # Make the default config file.
220-
make -j 12
221-
222-
# USB preparation for crazyradio
223-
sudo groupadd plugdev
224-
sudo usermod -a -G plugdev $USER
225244
```
226245

227-
```bash
228-
# Apply changes
229-
sudo udevadm control --reload-rules
230-
sudo udevadm trigger
231-
232-
# Flash crazyflie C10 (cf9 in the Vicon objects list)
233-
# 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.
234-
cd ~/GitHub/crazyflie-firmware-import/
235-
make cload
246+
To start the Vicon bridge by default, you may want to include it in the crazyswarm launchfile.
236247

248+
Optionally, you can also install cfclient to debug issues with the drones and configure IDs etc.
249+
```bash
237250
# (optional) Install cfclient
238251
sudo apt install libxcb-xinerama0
239252
conda create -n cfclient python=3.7
@@ -243,9 +256,6 @@ pip install cfclient
243256
conda deactivate
244257
```
245258

246-
### Vicon bridge
247-
TODO: Expand
248-
249259
### Common errors
250260

251261
#### libNatNet
@@ -263,31 +273,26 @@ Make sure you are familiar with the configuration files. Not all options are rel
263273

264274
The important config files are located in the crazyswarm ROS package:
265275

266-
**TODO:** Insert correct link to files
267-
- Crazyflies types — includes controller properties and marker configurations, etc.
268-
- In-use Crazyflies — includes ID, radio channel, types, etc.
269-
- All Crazyflies
270-
271-
As well as the launch file and Python script:
276+
- [Crazyflies types](https://github.com/USC-ACTLab/crazyswarm/blob/master/ros_ws/src/crazyswarm/launch/crazyflieTypes.yaml) — includes controller properties and marker configurations, etc.
277+
- [In-use Crazyflies](https://github.com/USC-ACTLab/crazyswarm/blob/master/ros_ws/src/crazyswarm/launch/crazyflies.yaml) — includes ID, radio channel, types, etc.
272278

273-
- cf_sim2real.launch
274-
- cmdFullStateCFFirmware.py
279+
As well as the main launch file [hover_swarm.launch](https://github.com/USC-ACTLab/crazyswarm/blob/master/ros_ws/src/crazyswarm/launch/hover_swarm.launch).
275280

276281
#### Launch
277282

278283
>**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.
279284
280285
In a terminal, launch the ROS node for the crazyflies. Change the settings in _<path/to/crazyswarm/package>/launch/crazyflies.yaml_ as necessary.
281286
```bash
282-
roslaunch crazyswarm cf_sim2real.launch
287+
roslaunch crazyswarm hover_swarm.launch
283288
```
284289

285290
In a second terminal:
286291

287292
```bash
288-
python scripts/deploy.py --controller <path/to/your/controller.py> --config config/level3.toml
293+
python scripts/deploy.py --controller <your_controller.py> --config level3.toml
289294
```
290295

291-
where `<path/to/your/controller.py>` implements a controller that inherits from `lsy_drone_racing.controller.BaseController`
296+
where `<your_controller.py>` implements a controller that inherits from `lsy_drone_racing.control.BaseController`
292297

293298

config/level0.toml

+2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
# | Evaluation Scenario | Rand. Inertial Properties | Randomized Obstacles, Gates | Rand. Between Episodes | Notes |
44
# | :-----------------: | :-----------------------: | :-------------------------: | :--------------------: | :---------------: |
55
# | `level0.toml` | *No* | *No* | *No* | Perfect knowledge |
6+
[controller]
7+
file = "trajectory_controller.py" # Put your controller file name here. Specifying a controller as argument to scripts will override this setting. Controllers are located in `lsy_drone_racing/control/`
68

79
[sim]
810
# Physics options:

config/level1.toml

+2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
# | Evaluation Scenario | Rand. Inertial Properties | Randomized Obstacles, Gates | Rand. Between Episodes | Notes |
44
# | :-----------------: | :-----------------------: | :-------------------------: | :--------------------: | :------: |
55
# | `level1.toml` | **Yes** | **Yes** | *No* | Adaptive |
6+
[controller]
7+
file = "trajectory_controller.py" # Put your controller file name here. Specifying a controller as argument to scripts will override this setting. Controllers are located in `lsy_drone_racing/control/`
68

79
[sim]
810
# Physics options:

config/level2.toml

+2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
# | Evaluation Scenario | Rand. Inertial Properties | Randomized Obstacles, Gates | Rand. Between Episodes | Notes |
44
# | :-----------------: | :-----------------------: | :-------------------------: | :--------------------: | :-------------------: |
55
# | `level2.toml` | **Yes** | **Yes** | *No* | Learning, re-planning |
6+
[controller]
7+
file = "trajectory_controller.py" # Put your controller file name here. Specifying a controller as argument to scripts will override this setting. Controllers are located in `lsy_drone_racing/control/`
68

79
[sim]
810
# Physics options:

config/level3.toml

+2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
# | Evaluation Scenario | Rand. Inertial Properties | Randomized Obstacles, Gates | Rand. Between Episodes | Notes |
44
# | :-----------------: | :-----------------------: | :-------------------------: | :--------------------: | :---------------: |
55
# | `level3.toml` | **Yes** | **Yes** | **Yes** | Robustness |
6+
[controller]
7+
file = "trajectory_controller.py" # Put your controller file name here. Specifying a controller as argument to scripts will override this setting. Controllers are located in `lsy_drone_racing/control/`
68

79
[sim]
810
# Physics options:

lsy_drone_racing/envs/drone_racing_deploy_env.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -150,4 +150,5 @@ def info(self) -> dict:
150150
)
151151
return info
152152

153-
def check_gate_progress(self): ...
153+
def check_gate_progress(self):
154+
...

scripts/deploy.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -29,18 +29,20 @@
2929
logger = logging.getLogger("rosout." + __name__)
3030

3131

32-
def main(config: str = "level3.toml", controller: str = "trajectory_controller.py"):
32+
def main(config: str = "level3.toml", controller: str | None = None):
3333
"""Deployment script to run the controller on the real drone.
3434
3535
Args:
3636
config: Path to the competition configuration. Assumes the file is in `config/`.
37-
controller: The name of the controller file in `lsy_drone_racing/control/`.
37+
controller: The name of the controller file in `lsy_drone_racing/control/` or None. If None,
38+
the controller specified in the config file is used.
3839
"""
3940
config = load_config(Path(__file__).parents[1] / "config" / config)
4041
env: DroneRacingDeployEnv = gymnasium.make("DroneRacingDeploy-v0", config=config)
4142
obs, info = env.reset()
4243

43-
controller_path = Path(__file__).parents[1] / "lsy_drone_racing/control" / controller
44+
control_path = Path(__file__).parents[1] / "lsy_drone_racing/control"
45+
controller_path = control_path / (controller or config.controller.file)
4446
controller_cls = load_controller(controller_path)
4547
controller = controller_cls(obs, info)
4648
try:

scripts/sim.py

+6-4
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131

3232
def simulate(
3333
config: str = "level0.toml",
34-
controller: str = "trajectory_controller.py",
34+
controller: str | None = None,
3535
n_runs: int = 1,
3636
gui: bool = True,
3737
env_id: str | None = None,
@@ -40,7 +40,8 @@ def simulate(
4040
4141
Args:
4242
config: The path to the configuration file. Assumes the file is in `config/`.
43-
controller: The name of the controller file in `lsy_drone_racing/control/`.
43+
controller: The name of the controller file in `lsy_drone_racing/control/` or None. If None,
44+
the controller specified in the config file is used.
4445
n_runs: The number of episodes.
4546
gui: Enable/disable the simulation GUI.
4647
@@ -51,8 +52,9 @@ def simulate(
5152
config = load_config(Path(__file__).parents[1] / "config" / config)
5253
config.sim.gui = gui
5354
# Load the controller module
54-
path = Path(__file__).parents[1] / "lsy_drone_racing/control" / controller
55-
controller_cls = load_controller(path) # This returns a class, not an instance
55+
control_path = Path(__file__).parents[1] / "lsy_drone_racing/control"
56+
controller_path = control_path / (controller or config.controller.file)
57+
controller_cls = load_controller(controller_path) # This returns a class, not an instance
5658
# Create the racing environment
5759
env: DroneRacingEnv = gymnasium.make(env_id or config.env.id, config=config)
5860

0 commit comments

Comments
 (0)