Skip to content

Commit f66d989

Browse files
author
jfm92
committed
Crazyflie demo rework draft
1 parent f1394ef commit f66d989

5 files changed

Lines changed: 402 additions & 242 deletions

File tree

55.2 KB
Loading

_docs/tutorials/demos/crazyflie_demo/micro-ROS_crazyflie.png renamed to _docs/tutorials/demos/crazyflie_demo/images/micro-ROS_crazyflie.png

File renamed without changes.

_docs/tutorials/demos/crazyflie_demo/index.md

Lines changed: 100 additions & 242 deletions
Original file line numberDiff line numberDiff line change
@@ -5,298 +5,156 @@ redirect_from:
55
- /crazyflie_demo/
66
---
77

8-
This demo aims to expose a **micro-ROS** use case. It runs on a pair of embedded devices:
9-
a [**Crazyflie 2.1**](https://www.bitcraze.io/crazyflie-2-1/) drone, used as a user controller,
10-
and a [**Kobuki Turtlebot 2**](https://www.turtlebot.com/turtlebot2/) as a mobile and controlled device.
8+
This demo is a proof concept, which aims to demostrate the versatility of the Micro-ROS project to be adapted to an already exciting product, with constrain memory size and respecting the original firmware. On this demostration we're going to work with the [Crazyflie 2.1 Drone](https://www.bitcraze.io/products/crazyflie-2-1/). This is a tiny and open-source drone which has the next characteristics:
9+
- STM32F405 (Cortex-M4, 168MHz, 192kb SRAM, 1Mb flash)
10+
- Radio and power management by nRF51822 MCU (Up to 1 Km of range)
11+
- BMI088 IMU
12+
- BMP388 barometric sensor
13+
- 100 mAH battery which gives an autonomy of up to 7 minutes.
14+
- Dimensions: 92x92x92 mm
15+
- Takeof weight: 27g
1116

12-
![Illustration of the Crazyflie - DDS interaction](micro-ROS_crazyflie.png)
17+
![](images/crazyflie.jpg)
1318

14-
Both of them rely on **micro-ROS** publication and subscription mechanisms and use an underlying [**Micro XRCE-DSS client**](https://micro-xrce-dds.readthedocs.io/en/latest/).
19+
The main challenge of this demo, was been able to fit Micro-ROS inside of the already existing firmware which with all the features active use around the 60% of the MCU RAM memory and X of the flash memory. Thanks to the modular design of micro-ROS and the versatile configuration system, is possible to fit micro-ROS full stack on this tiny device.
1520

16-
This demo also includes conventional ROS 2 tooling as a demonstration of integration with **ROS 2**. We use Gazebo, RVIZ and simple ROS 2 nodes (aka **external nodes**) acting as data converters.
21+
On the next points we will see the functionalities of this micro-ROS demo and how you can reproduce it.
1722

18-
This demo was developed taking as base the [Kobuki demo](/docs/tutorials/demos/kobuki_demo).
23+
## Required hardware:
1924

20-
## Index
21-
- [Installation](#installation)
22-
- [Install external ROS 2 nodes](#install-external-ros-2-nodes)
23-
- [Build and flash Crazyflie 2.1 firmware](#build-and-flash-crazyflie-21-firmware)
24-
- [Install Crazyflie Client + Bridge](#install-crazyflie-client--bridge)
25-
- [Build and flash Kobuki Turtlebot 2 firmware](#build-and-flash-kobuki-turtlebot-2-firmware)
26-
- [Usage](#usage)
27-
- [Run Kobuki Turtlebot 2 Node](#run-kobuki-turtlebot-2-node)
28-
- [Run Crazyflie 2.1 Node](#run-crazyflie-21-node)
29-
- [Run external ROS 2 nodes](#run-external-ros-2-nodes)
30-
- [Run RVIZ visualizers](#run-rviz-visualizers)
25+
* 1 x [Crazyflie 2.1](https://www.bitcraze.io/crazyflie-2-1/),
26+
* 1 x [Crazyradio PA](https://www.bitcraze.io/crazyradio-pa/),
27+
* 1 x [Flow deck v2](https://www.bitcraze.io/flow-deck-v2/),
28+
* 1 x [Crazyflie-compatible remote controller](https://www.bitcraze.io/docs/crazyflie-clients-python/master/inputdevices/).
3129

32-
## Setup
30+
## Reproduce the demo
31+
On the next points, we will see a set of steps that you need to follow to succeed on the demo reproduction.
32+
(Note: Is necessary to install previously ROS2 Dashing, you can find instructions here: [ROS2 Dashing](https://index.ros.org/doc/ros2/Installation/Dashing/))
33+
### Work Space set-up and configuration
3334

34-
The proposed demo is composed of different kind of messages and topics.
35-
36-
The **Crazyflie 2.1** drone relies on [ST STM32F405](https://www.st.com/en/microcontrollers-microprocessors/stm32f405-415.html) MCU running **[FreeRTOS](https://www.freertos.org/)**. Using the RTOS capabilities and the integrated radio communication device, the drone can run a node that publishes:
37-
- its own relative position as a 3D vector (X, Y and Z) using a *geometry_msg/Point32* message type on */drone/odometry* topic.
38-
- its own attitude as a 3D vector (pitch, roll and yaw) using a *geometry_msg/Point32* message type on */drone/attitude* topic.
39-
40-
The **Kobuki Turtlebot 2** robot is controlled using a UART protocol through a custom DB25 connector. The micro-ROS node runs on an Olimex STM32-E407 board attached to that UART port. This hardware features a [ST STM32F407](https://www.st.com/en/microcontrollers-microprocessors/stm32f407-417.html) MCU running **[Nuttx](https://nuttx.org/)** RTOS. In the same way, this node can communicate with the robot (UART) and with the ROS2 world (integrated Ethernet). Its used topics are:
41-
- a subscription on */cmd_vel* topic (*geometry_msg/Twist* message type) to receive the controlling angular and linear velocity.
42-
- a publication on */robot_pose* topic (*geometry_msg/Vector3* message type) which includes X position, Y position and robot yaw.
43-
44-
The **external ROS 2 nodes** are rclpy tools with some different functionalities:
45-
- *attitude_to_vel.py*
46-
- Converts Crazyflie */drone/attitude* to Kobuki Turtlebot 2 */cmd_vel* so that drone pitch is mapped to robot linear velocity and drone roll to angular valocity.
47-
- Converts Crazyflie publications on */drone/attitude* and */drone/attitude* topics to *tf2_msgs/TFMessage* messages (required by RVIZ visualizer)
48-
- *odom_to_tf.py*
49-
- Converts Kobuki Turtlebot 2 publications on */robot_pose* topic to *tf2_msgs/TFMessage* messages (required by RVIZ visualizer).
50-
51-
The following image shows the described setup.
52-
53-
![Kobuki_drone_demo](http://www.plantuml.com/plantuml/png/XLDHJzim47xlhp3P2wlMP0FniWS40uhGDeegreUXANAJQx18V95zBcBJ_llYIpChfDdwuChVz_axt-VBcILfo5Nbv227ZT8WRYuMjz-MNyGZKMq_9ecHpt6XwD6jdGMJeIRG56TO9UHgcPlZf2wbzXOprR2pJQEOsTee0fjiZ-8FyVl9WT9PwN9mfkpyayQXGXtNN7iFppxo6InMC3j93AwHnjK5Rdrrc-G6DRGw-wHqBOsin5fcJuL1f_CBBD68D_FvV38HpKzf0hEH6OYeFTeMIckq81xkiE6FZtw8wVJAbM34kIvAiDDf9AGL30rSiYfFjr2AXmAm0Z8lQMKBcpHBSl-iB7cp5PIOANhP6J4-C0eNsUUrWepG77ktHSvavzPjH_h37TthxWwj8eLwPz5jsQ8DwdgnIY-NYzkhmqjlyqv4_1-zPVO2gxhPQHAII97B8INqCSJro-IL8hgMFs6DuZEktPEAX2_OGcaB2JumFpz9bujFY_l35cqgxawq9Nana97qRoAYhR9EbifAV_58_6B-TGIq4G_tywzWhInWJ-D_kS7f460jwR49hrdPmC1MeGkPTTFX1UpIxzx7xxEXZOzco4VBrSrtmTcAyrsMxEVnbF5K_kTSTvNNv-hHSssoGT_kMVuxfDswpsQdOVG35eQ6SLQ8E3xTCn4iwEJ_qWnXhXI-bp51UCPHKNWWNjYJxn9w3s1_GBd3FiIElIzl7yv4jsFV_ZWm7w11Eom8MtRelzUG3LCpIeVXu526p1det5Nb7m00)
54-
55-
## Required Hardware
56-
57-
This setup uses the following hardware:
58-
59-
| Item | |
60-
|---------------|----------------------------------------------------------|
61-
| Kobuki Turtlebot 2 | [Link](https://www.turtlebot.com/turtlebot2/) |
62-
| Olimex STM32-E407 | [Link](https://www.olimex.com/Products/ARM/ST/STM32-E407/open-source-hardware) |
63-
| Olimex ARM-USB-TINY-H | [Link](https://www.olimex.com/Products/ARM/JTAG/ARM-USB-TINY-H/) |
64-
| Crazyflie 2.1 | [Link](https://store.bitcraze.io/products/crazyflie-2-1) |
65-
| Flow Desk v2 | [Link](https://store.bitcraze.io/collections/decks/products/flow-deck-v2) |
66-
| Debug adapter | [Link](https://store.bitcraze.io/collections/accessories/products/debug-adapter) |
67-
| Crazyradio PA 2.4 GHz USB dongle | [Link](https://store.bitcraze.io/collections/accessories/products/crazyradio-pa) |
68-
| Additional battery + charger (optional) | [Link](https://store.bitcraze.io/collections/accessories/products/240mah-lipo-battery-including-500ma-usb-charger) |
69-
70-
71-
# Installation
72-
73-
## Install external ROS 2 nodes
74-
75-
[Install Micro XCRE-DDS](https://micro-xrce-dds.readthedocs.io/en/latest/installation.html). Recommended procedure:
35+
To create the work space and set the proper configuration for this demo, you need to execute the next commands:
7636

37+
- Create work space folder and download the micro-ROS build system:
7738
```bash
78-
git clone https://github.com/eProsima/Micro-XRCE-DDS.git -b v1.1.0
79-
cd Micro-XRCE-DDS
80-
mkdir build && cd build
81-
cmake ..
82-
make
83-
sudo make install
84-
```
39+
# Source ROS2 Dashing
40+
source /opt/ros/$ROS_DISTRO/setup.bash
8541

86-
Create a workspace folder for this demo:
87-
```bash
88-
mkdir -p crazyflie_demo/src
89-
cd crazyflie_demo
90-
```
42+
# Create work-space folder
43+
mkdir uros_ws && cd uros_ws
9144

92-
Clone this repo:
93-
```bash
94-
git clone --single-branch --branch crazyflie_demo https://github.com/micro-ROS/micro-ROS_kobuki_demo src
95-
```
45+
# Download the micro-ROS build system
46+
git clone -b $ROS_DISTRO https://github.com/micro-ROS/micro-ros-build.git src/micro-ros-build
9647

97-
[Install Gazebo](http://gazebosim.org/tutorials?tut=install_ubuntu&cat=install#InstallGazebousingUbuntupackages). Recommended procedure:
98-
```bash
99-
curl -sSL http://get.gazebosim.org | sh
100-
```
48+
# Download ros dependencies
49+
rosdep update && rosdep install --from-path src --ignore-src -y
10150

102-
[Install gazebo_ros_pkgs (ROS 2)](http://gazebosim.org/tutorials?tut=ros2_installing&cat=connect_ros). Recommended procedure:
103-
```bash
104-
source /opt/ros/dashing/setup.bash
105-
wget https://bitbucket.org/api/2.0/snippets/chapulina/geRKyA/f02dcd15c2c3b83b2d6aac00afe281162800da74/files/ros2.yaml
106-
vcs import src < ros2.yaml
107-
rosdep update && rosdep install --from-paths src --ignore-src -r -y
108-
rm ros2.yaml
109-
```
51+
# Build and source the micro-ROS build system
52+
colcon build
11053

111-
Build the project:
112-
```bash
113-
source /opt/ros/dashing/setup.bash
114-
rosdep update && rosdep install --from-paths src --ignore-src -r -y
115-
colcon build --symlink-install
54+
source install/local_setup.bash
11655
```
117-
118-
## Build and flash Crazyflie 2.1 firmware
119-
120-
Install the toolchain:
56+
- Set the Crazyflie proper configuration:
12157
```bash
122-
sudo add-apt-repository ppa:team-gcc-arm-embedded/ppa
123-
sudo apt-get update
124-
sudo apt install gcc-arm-embedded dfu-util
125-
```
58+
# Create specific Crazyflie freertos workspace
59+
ros2 run micro_ros_setup create_firmware_ws.sh freertos crazyflie
12660

127-
Download and build the **Crazyflie 2.1** firmware repository:
128-
```bash
129-
mkdir crazyflie_firmware
130-
git clone https://github.com/eProsima/crazyflie-firmware -b crazyflie_demo
131-
cd crazyflie_firmware
132-
git submodule init
133-
git submodule update
134-
make PLATFORM=cf2
61+
# Set the application configuration
62+
ros2 run micro_ros_setup configure_firmware.sh crazyflie_position_publisher
13563
```
13664

137-
Unplug the **Crazyflie 2.1** battery
65+
Now the firmware should be ready to be compile.
13866

139-
Push the reset button while connecting the USB power supply.
67+
### Build the firmware
14068

141-
The top-left blue LED blinks, first slowly and after 4 seconds sightly faster, now it is in DFU programming mode. Check it with `lsusb`:
69+
Type the next command:
14270
```bash
143-
Bus 001 Device 051: ID 0483:df11 STMicroelectronics STM Device in DFU Mode
71+
ros2 run micro_ros_setup build_firmware.sh
14472
```
145-
146-
Flash the device:
73+
If everything goes fine, it should return the next output:
14774
```bash
148-
sudo dfu-util -d 0483:df11 -a 0 -s 0x08000000 -D cf2.bin
149-
```
150-
151-
Unplug and plug the **Crazyflie 2.1** power to exit DFU mode.
152-
75+
Build for the CF2 platform!
76+
Build 120:5142cacdde8b (2019.09 +120) CLEAN
77+
Version extracted from git
78+
text data bss dec hex filename
79+
263996 4972 111996 380964 5d024 cf2.elf
15380

154-
## Install Crazyflie Client + Bridge
155-
156-
Install dependencies:
157-
```
158-
sudo apt-get install libusb-1.0-0-dev
159-
sudo apt-get install python3 python3-pip python3-pyqt5 python3-pyqt5.qtsvg
16081
```
16182

162-
Fix permissions for the Crazyradio PA 2.4 GHz USB dongle (restart required for apply changes):
163-
```
164-
sudo groupadd plugdev
165-
sudo usermod -a -G plugdev $USER
166-
sudo echo SUBSYSTEM==\"usb\", ATTRS{idVendor}==\"1915\", ATTRS{idProduct}==\"7777\", \
167-
MODE=\"0664\", GROUP=\"plugdev\" > /etc/udev/rules.d/99-crazyradio.rules
168-
sudo echo SUBSYSTEM==\"usb\", ATTRS{idVendor}==\"0483\", ATTRS{idProduct}==\"5740\", \
169-
MODE=\"0664\", GROUP=\"plugdev\" > /etc/udev/rules.d/99-crazyflie.rules
170-
```
83+
### Flash the device
17184

172-
Clone the repo dependencies:
173-
```
174-
git clone -b Micro-XRCE-DDS_Bridge https://github.com/eProsima/crazyflie-clients-python
175-
```
176-
177-
## Build and flash Kobuki Turtlebot 2 firmware
178-
179-
Create a workspace for building **micro-ROS**:
180-
```
181-
source /opt/ros/crystal/setup.bash
182-
sudo apt install python-rosdep curl flex ed gperf openocd automake ed bison libncurses5-dev gcc-arm-none-eabi clang clang-tidy usbutils
183-
mkdir -p kobuki-firmware/src
184-
cd kobuki-firmware
185-
git clone --recursive -b crazyflie_demo https://github.com/micro-ROS/micro-ros-build.git src/micro-ros-build
186-
colcon build --packages-select micro_ros_setup
187-
source install/local_setup.bash
188-
```
189-
190-
Build **micro-ROS Agent**:
191-
```
192-
ros2 run micro_ros_setup create_agent_ws.sh
193-
colcon build
194-
source install/local_setup.sh
195-
```
85+
You need to set the device on DFU mode. To active this mode, you need to do next steps:
86+
- Disconnect the battery.
87+
- Push the reset buttom of the drone.
88+
- At the same time that you're pushing the buttom, connect the micro-USB cable to the PC.
89+
- Continue pushing the reset buttom, the blue LED should start blinking.
90+
- Wait on this position until LED blink frequency increase.
19691

197-
Install tools:
198-
```
199-
git clone https://bitbucket.org/nuttx/tools.git ~/tools
200-
pushd ~/tools/kconfig-frontends >/dev/null
201-
./configure --enable-mconf --disable-nconf --disable-gconf --disable-qconf
202-
LD_RUN_PATH=/usr/local/lib && make && make install && ldconfig
203-
popd >/dev/null
204-
```
92+
Now the device is on DFU mode. Now execute the next command to flash the firmware to the device:
20593

206-
Build Olimex STM32-E407 firmware:
94+
```bash
95+
ros2 run micro_ros_setup flash_firmware.sh
20796
```
208-
ros2 run micro_ros_setup create_firmware_ws.sh
209-
cd firmware/NuttX
210-
tools/configure.sh configs/olimex-stm32-e407/uros
211-
cd ../..
97+
Now your drone is flashed and ready with micro-ROS. Disconnect the USB cable and connect again the battery.
21298

213-
#Put here your agent IP and port
214-
find ./firmware/mcu_ws/ -name rmw_microxrcedds.config -exec sed -i "s/CONFIG_IP=127.0.0.1/CONFIG_IP=192.168.8.10/g" {} \;
215-
find ./firmware/mcu_ws/ -name rmw_microxrcedds.config -exec sed -i "s/CONFIG_PORT=8888/CONFIG_PORT=9999/g" {} \;
99+
### Connect the drone to the host PC.
216100

217-
ros2 run micro_ros_setup build_firmware.sh
218-
```
219-
220-
Connect Olimex ARM-USB-TINY-H JTAG debugger to Olimex STM32-E407 and flash the board:
221-
```
222-
cd firmware/NuttX
223-
scripts/flash.sh olimex-stm32-e407
224-
```
101+
The first step is to set-up your PC, to do so, you need to follow the next steps:
102+
```bash
103+
# Download the micro-ROS_crazyflie_demo
104+
git clone https://github.com/micro-ROS/micro-ROS_crazyflie_demo
225105

226-
# Usage
106+
# Install docker compose
107+
sudo apt-get install docker-compose
227108

228-
After installation, the following packages should be present in your system:
109+
# Execute xhost
110+
xhost +
229111

112+
# Execute docker compose to build all the requiered work space
113+
docker-compose up -d
230114
```
231-
.
232-
+-- Micro-XRCE-DDS # used for installing Micro-XRCE-DDS
233-
+-- crazyflie_demo
234-
+-- crazyflie-firmware # used for building and flashing Crazyflie 2.1 firmware
235-
+-- kobuki-firmware # used for building and flashing Kobuki Turtlebot 2 firmware
236-
+-- crazyflie-clients-python
237-
```
238-
239-
Make sure that all ROS 2 or micro-ROS nodes created along with the following steps **can reach each other using its network interfaces**.
115+
This last step could take a while the first time that you execute it, but later on executions, it will execute almost inmediatly.
240116

241-
## Run Kobuki Turtlebot 2 Node
117+
If everything goes fine, it should appear RVIZ and CrazyFlies Client. Each application, has the next utility:
118+
- RVIZ: Shows an animation of the drone, drawing de flight trayectory on screen. This data are obtained from the ROS2 topic published by the drone.
119+
- CrazyFlie Client: Shows the telemetry status of the drone, allows us to modify the configuration of the device and works as communication bridge between the CrazyFlie radio protocol and the micro-ROS network.
242120

243-
TODO: Explain data and power connections between Kobuki Turtlebot 2, Olimex STM32-E407 and MiniRouter.
121+
Once open it should look like this:
122+
<!-- Add image of RVIZ and Crazyflie without connection-->
244123

245-
Run the **micro-ROS Agent**:
246-
```
247-
cd kobuki-firmware
248-
source /opt/ros/crystal/setup.bash && source install/local_setup.bash
249-
ros2 run micro_ros_agent micro_ros_agent udp 9999
250-
```
124+
Push the reset buttom of the drone. The drone will perform an internal check status which if goes fine it should do the next:
125+
- Move the propellers producing a "melody".
126+
- Turning on statically two blue and one red light.
127+
- Blinking the yellow LED.
251128

252-
**micro-ROS Agent** should receive an incoming client connection and */robot_pose* topic should be published. Check it with `ros2 topic echo /robot_pose`
129+
Finally you need to do the next steps:
130+
- Connect the USB radio dongle.
131+
- Push the buttom scan on the Crazyflie Client.
132+
- On the left menu it should appear an interface called ```` select it.
133+
- Finally Push the buttom connect.
253134

254-
## Run Crazyflie 2.1 Node
255-
256-
Connect Crazyradio PA 2.4 GHz USB dongle and turn on Crazyflie 2.1 drone.
257-
258-
Run the Crazyflie Client + Bridge:
259-
```
260-
cd crazyflie-clients-python
261-
python3 bin/cfclient
262-
```
135+
The part of the menu that you need to manipulate is highlited on the next image:
136+
![](images/cfc_connect.png)
263137

264-
This command should open the Crazyflie Client and print a serial device path in the terminal (something like /dev/pts/0).
138+
Now everything is ready and the Crazyflie Client should return the telemetry data and the RVIZ should start to show drone trajectory like on the bottom image:
139+
<!--- Add Image with drone working properly-->
265140

266-
Run (in another prompt) a **Micro XRCE-DDS Agent**:
267-
```
268-
MicroXRCEAgent serial --dev [serial device]
141+
Finally, if you want to close this utilities properly, you need to execute the next command:
142+
```bash
143+
docker-compose down
269144
```
270145

271-
**Micro XRCE-DDS Agent** should receive an incoming client connection and */drone/attitude* and */drone/position* topics should be published. Check it with `ros2 topic echo /drone/attitude` and `ros2 topic echo /drone/position`
146+
## Demo functionality
272147

148+
Once everything is ready you can check on the ROS2 network the telemetry of the drone. On the next image, you see the available topics and how interact it with RVIZ.
273149

274-
## Run external ROS 2 nodes
150+
![](http://www.plantuml.com/plantuml/proxy?cache=no&src=https://raw.githubusercontent.com/micro-ROS/micro-ROS_crazyflie_demo/master/assets/diagrams/architecture.puml)
275151

276-
Run commands:
277-
```
278-
cd crazyflie_demo
279-
source /opt/ros/crystal/setup.bash && source install/local_setup.bash
280-
ros2 run micro-ros_crazyflie_demo_remote attitude_to_vel
281-
```
152+
On the other hand, on the next image you can see a simplify diagram of how is performed the communication path between the drone and the ROS2 network:
282153

283-
Topic */cmd_vel* should be published, and the **Kobuki Turtlebot 2** should start moving. Check it with `ros2 topic echo /cmd_vel`
154+
![](images/micro-ROS_crazyflie.png)
284155

285-
## Run RVIZ visualizers
286-
Run complete visualizer:
287-
```
288-
cd crazyflie_demo
289-
source /opt/ros/crystal/setup.bash && source install/local_setup.bash
290-
ros2 launch micro-ros_crazyflie_demo_remote launch_drone_position.launch.py
291-
```
292-
293-
RVIZ windows should be open, and a Crazyflie 2.1 drone model should represent the drone attitude and position along with a historic path.
156+
## Annex
294157

295-
Run attitude visualizer:
296-
```
297-
cd crazyflie_demo
298-
source /opt/ros/crystal/setup.bash && source install/local_setup.bash
299-
ros2 launch micro-ros_crazyflie_demo_remote launch_drone_attitude.launch.py
300-
```
158+
Is possible to fly the drone at the same time that micro-ROS is running inside of it. To do so, you need to follow the next guide which explains how to connect a compatible controller to the host PC to fligth it.
301159

302-
RVIZ windows should be open and a Crazyflie 2.1 drone model should represent **only** the drone attitude.
160+
[Crazyflies flight Controller](https://www.bitcraze.io/documentation/repository/crazyflie-clients-python/master/inputdevices/)

0 commit comments

Comments
 (0)