(Ⅶ) Crazyflie Supports Matlab/Simulink Control
Ⅰ. Motion Capture Software VRPN Configuration
Taking motion capture software version XINGYING 4.2.0.5495 as an example, other versions are similar. Open the motion capture software and connect the cameras. Click View -> Data Broadcast in the menu bar. Under the VRPN stream in Data Broadcast, select meters from the unit dropdown, check Rigid Body for type, and enable VRPN.
.png)
Figure 1 - Open Data Broadcast View
.png)
Figure 2 - VRPN Configuration in Motion Capture
Click View -> Devices in the menu bar to open the device view. First click the stop playback button, and modify the motion capture frame rate to 120 in the Advanced box.
.png)
Figure 3 - Open Device View
.png)
Figure 4 - Modify Motion Capture Frame Rate
Ⅱ. MATLAB/Simulink Platform Configuration
Requires ROS version: galactic, Ubuntu version: 20.04. Crazyflie firmware version 2024.10 or above. If the version is too low, update it yourself (cfclient usage). On the Windows host, Matlab version 2020a or above is recommended. This experiment uses 2022a. Install python, cmake, and Microsoft Visual C++ yourself, and make sure they correspond to the matlab version.
(Ⅰ) Ubuntu Environment Configuration
Open a terminal and use the following commands to write the environment configuration to .bashrc. The value range of ROS_DOMAIN_ID is 0~255.
echo "export RMW_IMPLEMENTATION=rmw_fastrtps_cpp" >> ~/.bashrc
echo "export ROS_DOMAIN_ID=26" >> ~/.bashrc
(Ⅱ) Matlab/Simulink Environment Configuration
- First extract the flightmaster2 matlab suite, open the suite with matlab, and make sure flightmaster2.slx is in the current folder.
.png)
Figure 5 - Open Flightmaster2 Matlab Suite
- Run the following code in the matlab terminal to select the compiler and compilation language.
mex -setup C++
.png)
Figure 6 - Select Compilation Language
- Run the following command to compile custom messages.
ros2genmsg('custom_msgs');
.png)
Figure 7 - Compile Custom Message Types
- Double-click flightmaster2.slx to enter the simulink model.
.png)
Figure 8 - Open Flightmaster2 Simulink Program
- Click Simulation at the top, then click ROS Network. Modify Domain ID to be consistent with ubuntu, and modify RMW Implementation to rmw_fastrtps_cpp.
.png)
Figure 9 - Configure ROS2 Network
Ⅲ. Basic Flight Operation Demonstration
(Ⅰ) Basic Control
The basic control dial implements basic control of drones, including unlock, takeoff, hover, land, and emergency stop services, which can operate on single or multiple drones.
- Place three crazyflies with the nose facing the positive x-axis direction in the site. Create rigid bodies nokov1, nokov2, and nokov3 in the motion capture system, with skeleton orientation toward the x-axis, as shown below.
.png)
Figure 10 - Create Rigid Bodies
- Double-click flightmaster2.slx to open the simulink model.
.png)
Figure 11 - Double-Click This File to Open Model
.png)
Figure 12 - Simulink Model Page
- Open ubuntu and enable three crazyflies in flightmasters.yaml in flightmaster2.
.png)
Figure 13 - Start Three Crazyflies
-
Open a terminal and use the following command to open the flightmaster2 graphical control interface.
cd ~/FlightMaster2/
python fmclient.py
.png)
Figure 14 - Run Flightmaster2 Graphical Interface
- Select RealMode on the graphical interface and check RViz, then click Start FlightSwarm. At this time, the flightmaster2 service node will run, and rviz will also start.
.png)
Figure 15 - Flightmaster2 Graphical Interface
- On the matlab simulink interface, first set the swarm demo dial and basic service dial to NO. Then select Simulation at the top and click the Run button.
.png)
Figure 16 - Set Dial to No
.png)
Figure 17 - Run Simulink
First set the basic service dial to Takeoff. At this time, the three drones will take off to 1 meter. Then set the dial to Hold, and the drones will maintain hover at the current position. Then set the dial to Land, and the three drones will land. Finally, set the dial to No.
.png)
Figure 18 - Set Dial to Takeoff
.png)
Figure 19 - Drone Takeoff
.png)
Figure 20 - rviz Display
(Ⅱ) Crazyflie Single Aircraft Square Flight
- Place one crazyflie in the motion capture site with the nose facing the x-axis. Create a rigid body in the motion capture software with the name vehicle3, and skeleton orientation toward the x-axis.
.png)
Figure 21 - Create Rigid Body
- Open ubuntu, enable one crazyflie in flightmasters.yaml, and start FlightSwarm on the flightmaster2 graphical control interface.
.png)
Figure 22 - Enable One Crazyflie
.png)
Figure 23 - Start FlightSwarm
- On the matlab simulink interface, first set the demo control dial and basic service dial to NO. Then select Simulation at the top and click the Run button.
.png)
Figure 24 - Set Dial to No
.png)
Figure 25 - Run Simulink
- Under the demo control dial, set the VEHICLE3 switch to on to enable the device. At this time, the device enabled light will turn green.
.png)
Figure 26 - Enable Device
- Set the demo control dial to crazyflie. At this time, vehicle3 will first take off and then fly around a square.
.png)
Figure 27 - Set Dial to Crazyflie
.png)
Figure 28 - Crazyflie Flying Around Square
.png)
Figure 29 - rviz Display