Skip to content

Commit 7f0498d

Browse files
pablogs9ralph-lange
authored andcommitted
Crazyflie tutorial initial commit
1 parent 5484ee9 commit 7f0498d

1 file changed

Lines changed: 283 additions & 1 deletion

File tree

  • _docs/tutorials/demos/crazyflie_demo

‎_docs/tutorials/demos/crazyflie_demo/index.md‎

Lines changed: 283 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,286 @@ redirect_from:
55
- /crazyflie_demo/
66
---
77

8-
WIP
8+
# Crazyflie + Turtlebot demo
9+
10+
This demo aims to expose an use case of **Micro ROS** running on a pair or embedded devices: a [**Crazyflie 2.1**](https://www.bitcraze.io/crazyflie-2-1/) drone, used as an user controller and a [**Kobuki Turtlebot 2**](https://www.turtlebot.com/turtlebot2/) as a mobile and controlled device.
11+
12+
Both of them rely on **Micro ROS** publication and subscription mechanisms and use an underlaying [**MicroXRCEDSS client**](https://micro-xrce-dds.readthedocs.io/en/latest/).
13+
14+
In order to show the integration with **ROS2**, this demo also includes common ROS2 tooling such as Gazebo, RVIZ and simple ROS2 nodes (aka **external nodes**) acting as data converters.
15+
16+
## Index
17+
18+
- [Crazyflie + Turtlebot demo](#crazyflie--turtlebot-demo)
19+
- [Index](#index)
20+
- [Setup](#setup)
21+
- [Required Hardware](#required-hardware)
22+
- [Installation](#installation)
23+
- [Install external ROS2 nodes](#install-external-ros2-nodes)
24+
- [Compile and flash Crazyflie 2.1 firmware](#compile-and-flash-crazyflie-21-firmware)
25+
- [Install Crazyflie Client + Bridge](#install-crazyflie-client--bridge)
26+
- [Compile and flash Kobuki Turtlebot 2 firmware](#compile-and-flash-kobuki-turtlebot-2-firmware)
27+
- [Usage](#usage)
28+
- [Run Kobuki Turtlebot 2 Node](#run-kobuki-turtlebot-2-node)
29+
- [Run Crazyflie 2.1 Node](#run-crazyflie-21-node)
30+
- [Run external ROS2 nodes](#run-external-ros2-nodes)
31+
- [Run RVIZ visualizers](#run-rviz-visualizers)
32+
33+
## Setup
34+
35+
The proposed demo is composed by different kind of messages and topics.
36+
37+
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 is able to run a node that publish:
38+
- its own relative position as a 3D vector (X, Y and Z) using a *geometry_msg/Point32* message type on */drone/odometry* topic.
39+
- its own attitude as a 3D vector (pitch, roll and yaw) using a *geometry_msg/Point32* message type on */drone/attitude* topic.
40+
41+
The **Kobuki Turtlebot 2** robot is controlled using a UART protocol through a custom DB25 connector. The Micro ROS node runs on a 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 is able to communicate with the robot (UART) and with the ROS2 world (integrated Ethernet). Its used topics are:
42+
- a subscription on */cmd_vel* topic (*geometry_msg/Twist* message type) to receive the controlling angular and linear velocity.
43+
- a publication on */robot_pose* topic (*geometry_msg/Vector3* message type) which includes X position, Y position and robot yaw.
44+
45+
The **external ROS2 nodes** are rclpy tools with some different functionalities:
46+
- *attitude_to_vel.py*
47+
- 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.
48+
- Converts Crazyflie publications on */drone/attitude* and */drone/attitude* topics to *tf2_msgs/TFMessage* messages (required by RVIZ visualizer)
49+
- *odom_to_tf.py*
50+
- Converts Kobuki Turtlebot 2 publications on */robot_pose* topic to *tf2_msgs/TFMessage* messages (required by RVIZ visualizer).
51+
52+
The following image shows the described setup.
53+
54+
![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)
55+
56+
## Required Hardware
57+
58+
This setup uses the following hardware:
59+
60+
| Item | |
61+
|---------------|----------------------------------------------------------|
62+
| Kobuki Turtlebot 2 | [Link](https://www.turtlebot.com/turtlebot2/) |
63+
| Olimex STM32-E407 | [Link](https://www.olimex.com/Products/ARM/ST/STM32-E407/open-source-hardware) |
64+
| Olimex ARM-USB-TINY-H | [Link](https://www.olimex.com/Products/ARM/JTAG/ARM-USB-TINY-H/) |
65+
| Crazyflie 2.1 | [Link](https://store.bitcraze.io/products/crazyflie-2-1) |
66+
| Flow Desk v2 | [Link](https://store.bitcraze.io/collections/decks/products/flow-deck-v2) |
67+
| Debug adapter | [Link](https://store.bitcraze.io/collections/accessories/products/debug-adapter) |
68+
| Crazyradio PA 2.4 GHz USB dongle | [Link](https://store.bitcraze.io/collections/accessories/products/crazyradio-pa) |
69+
| Additional battery + charger (optional) | [Link](https://store.bitcraze.io/collections/accessories/products/240mah-lipo-battery-including-500ma-usb-charger) |
70+
71+
72+
# Installation
73+
74+
## Install external ROS2 nodes
75+
76+
[Install MicroXCRE-DDS](https://micro-xrce-dds.readthedocs.io/en/latest/installation.html). Recommended procedure:
77+
78+
```bash
79+
git clone https://github.com/eProsima/Micro-XRCE-DDS.git
80+
cd Micro-XRCE-DDS
81+
mkdir build && cd build
82+
cmake ..
83+
make
84+
sudo make install
85+
```
86+
87+
Create a workspace folder for this demo:
88+
```bash
89+
mkdir -p crazyflie_demo/src
90+
cd crazyflie_demo
91+
```
92+
93+
Clone this repo:
94+
```bash
95+
git clone --single-branch --branch crazyflie_demo https://github.com/micro-ROS/micro-ROS_kobuki_demo src
96+
```
97+
98+
[Install Gazebo](http://gazebosim.org/tutorials?tut=install_ubuntu&cat=install#InstallGazebousingUbuntupackages). Recommended procedure:
99+
```bash
100+
curl -sSL http://get.gazebosim.org | sh
101+
```
102+
103+
[Install gazebo_ros_pkgs (ROS 2)](http://gazebosim.org/tutorials?tut=ros2_installing&cat=connect_ros). Recommended procedure:
104+
```bash
105+
source /opt/ros/dashing/setup.bash
106+
wget https://bitbucket.org/api/2.0/snippets/chapulina/geRKyA/f02dcd15c2c3b83b2d6aac00afe281162800da74/files/ros2.yaml
107+
vcs import src < ros2.yaml
108+
rosdep update && rosdep install --from-paths src --ignore-src -r -y
109+
rm ros2.yaml
110+
```
111+
112+
Compile the project:
113+
```bash
114+
source /opt/ros/dashing/setup.bash
115+
rosdep update && rosdep install --from-paths src --ignore-src -r -y
116+
colcon build --symlink-install
117+
```
118+
119+
## Compile and flash Crazyflie 2.1 firmware
120+
121+
Install the toolchain:
122+
```bash
123+
sudo add-apt-repository ppa:team-gcc-arm-embedded/ppa
124+
sudo apt-get update
125+
sudo apt install gcc-arm-embedded dfu-util
126+
```
127+
128+
Download and copile the **Crazyflie 2.1** firmware repository:
129+
```bash
130+
mkdir crazyflie_firmware
131+
git clone https://github.com/eProsima/crazyflie-firmware -b cf_micro-xrce-dds
132+
cd crazyflie_firmware
133+
git submodule init
134+
git submodule update
135+
make PLATFORM=cf2
136+
```
137+
138+
Unplug the **Crazyflie 2.1** battery
139+
140+
Push the reset button while connecting the USB power supply.
141+
142+
The top-left blue LED will blink, first slowly and after 4 seconds sightly faster, now it is in DFU programming mode. Check it with `lsusb`:
143+
```bash
144+
Bus 001 Device 051: ID 0483:df11 STMicroelectronics STM Device in DFU Mode
145+
```
146+
147+
Flash the device:
148+
```bash
149+
sudo dfu-util -d 0483:df11 -a 0 -s 0x08000000 -D cf2.bin
150+
```
151+
152+
Unplug and plug the **Crazyflie 2.1** power to exit DFU mode.
153+
154+
155+
## Install Crazyflie Client + Bridge
156+
157+
Install dependencies:
158+
```
159+
sudo apt-get install libusb-1.0-0-dev
160+
sudo apt-get install python3 python3-pip python3-pyqt5 python3-pyqt5.qtsvg
161+
```
162+
163+
Fix permissions for the Crazyradio PA 2.4 GHz USB dongle (restart required for apply changes):
164+
```
165+
sudo groupadd plugdev
166+
sudo usermod -a -G plugdev $USER
167+
sudo echo SUBSYSTEM==\"usb\", ATTRS{idVendor}==\"1915\", ATTRS{idProduct}==\"7777\", \
168+
MODE=\"0664\", GROUP=\"plugdev\" > /etc/udev/rules.d/99-crazyradio.rules
169+
sudo echo SUBSYSTEM==\"usb\", ATTRS{idVendor}==\"0483\", ATTRS{idProduct}==\"5740\", \
170+
MODE=\"0664\", GROUP=\"plugdev\" > /etc/udev/rules.d/99-crazyflie.rules
171+
```
172+
173+
Clone the repo dependencies:
174+
```
175+
git clone -b Micro-XRCE-DDS_Bridge https://github.com/eProsima/crazyflie-clients-python
176+
```
177+
178+
## Compile and flash Kobuki Turtlebot 2 firmware
179+
180+
Create a workspace for compiling **Micro ROS**:
181+
```
182+
source /opt/ros/crystal/setup.bash
183+
sudo apt install python-rosdep
184+
mkdir -p kobuki-firmware/src
185+
cd kobuki-firmware
186+
git clone --recursive -b crazyflie_demo https://github.com/micro-ROS/micro-ros-build.git src/micro-ros-build
187+
colcon build --packages-select micro_ros_setup
188+
source install/local_setup.bash
189+
```
190+
191+
Build **Micro ROS Agent**:
192+
```
193+
colcon build --packages-select micro_ros_setup
194+
source install/local_setup.bash
195+
```
196+
197+
Build Olimex STM32-E407 firmware:
198+
```
199+
ros2 run micro_ros_setup create_firmware_ws.sh
200+
cd firmware/NuttX
201+
tools/configure.sh configs/olimex-stm32-e407/drive_base # FOR EXAMPLE!
202+
cd ../..
203+
ros2 run micro_ros_setup build_firmware.sh
204+
```
205+
206+
Connect Olimex ARM-USB-TINY-H JTAG debugger to Olimex STM32-E407 and flash the board:
207+
```
208+
cd firmware/NuttX
209+
scripts/flash.sh olimex-stm32-e407
210+
```
211+
212+
# Usage
213+
214+
After installation, the following packages should be installed:
215+
216+
```
217+
.
218+
+-- Micro-XRCE-DDS # used for installing Micro-XRCE-DDS
219+
+-- crazyflie_demo
220+
+-- crazyflie-firmware # used for compiling and flashing Crazyflie 2.1 firmware
221+
+-- kobuki-firmware # used for compiling and flashing Kobuki Turtlebot 2 firmware
222+
+-- crazyflie-clients-python
223+
```
224+
225+
Make sure that all ROS2 or MicroROS nodes created along the following steps **can reach each other using its network interfaces**.
226+
227+
## Run Kobuki Turtlebot 2 Node
228+
229+
TODO: Explain data and power connections between Kobuki Turtlebot 2, Olimex STM32-E407 and MiniRouter.
230+
231+
Run the **Micro ROS Agent**:
232+
```
233+
cd kobuki-firmware
234+
source /opt/ros/crystal/setup.bash && source install/local_setup.bash
235+
ros2 run micro_ros_agent micro_ros_agent udp 9999
236+
```
237+
238+
**Micro ROS Agent** should receive an incoming client connection and */robot_pose* topic should be published. Check it with `ros2 topic echo /robot_pose`
239+
240+
## Run Crazyflie 2.1 Node
241+
242+
Connect Crazyradio PA 2.4 GHz USB dongle and turn on Crazyflie 2.1 drone.
243+
244+
Run the Crazyflie Client + Bridge:
245+
```
246+
cd crazyflie-clients-python
247+
python3 bin/cfclient
248+
```
249+
250+
This command should open the Crazyflie Client and print a serial device path in the terminal (something like /dev/pts/0).
251+
252+
Run (in another prompt) a **MicroXRCE Agent**:
253+
```
254+
MicroXRCEAgent serial --dev [serial device]
255+
```
256+
257+
**MicroXRCE 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`
258+
259+
260+
## Run external ROS2 nodes
261+
262+
Run commands:
263+
```
264+
cd crazyflie_demo
265+
source /opt/ros/crystal/setup.bash && source install/local_setup.bash
266+
ros2 run micro-ros_crazyflie_demo_remote attitude_to_vel
267+
```
268+
269+
Topic */cmd_vel* should be published and the **Kobuki Turtlebot 2** should start moving. Check it with `ros2 topic echo /cmd_vel`
270+
271+
## Run RVIZ visualizers
272+
Run complete visualizer:
273+
```
274+
cd crazyflie_demo
275+
source /opt/ros/crystal/setup.bash && source install/local_setup.bash
276+
ros2 launch micro-ros_crazyflie_demo_remote launch_drone_position.launch.py
277+
```
278+
279+
An RVIZ windows should be open and a Crazyflie 2.1 drone model should represent the drone attitude and position along with a historic path.
280+
281+
Run attitude visualizer:
282+
```
283+
cd crazyflie_demo
284+
source /opt/ros/crystal/setup.bash && source install/local_setup.bash
285+
ros2 launch micro-ros_crazyflie_demo_remote launch_drone_attitude.launch.py
286+
```
287+
288+
An RVIZ windows should be open and a Crazyflie 2.1 drone model should represent **only** the drone attitude.
289+
290+

0 commit comments

Comments
 (0)