Skip to main content

(Ⅶ) 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.

图 1-打开数据广播视图

Figure 1 - Open Data Broadcast View

图 2-动捕中vrpn配置

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.

图 3-打开设备视图

Figure 3 - Open Device View

图 4-修改动捕帧率

Figure 4 - Modify Motion Capture Frame Rate

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
  1. First extract the flightmaster2 matlab suite, open the suite with matlab, and make sure flightmaster2.slx is in the current folder.
图 5-打开flightmaster2的matlab套件

Figure 5 - Open Flightmaster2 Matlab Suite

  1. Run the following code in the matlab terminal to select the compiler and compilation language.
mex -setup C++
图 6-选择编译语言

Figure 6 - Select Compilation Language

  1. Run the following command to compile custom messages.
ros2genmsg('custom_msgs');
图 7-编译自定义消息类型

Figure 7 - Compile Custom Message Types

  1. Double-click flightmaster2.slx to enter the simulink model.
图 8-打开flightmaster2的simulink程序

Figure 8 - Open Flightmaster2 Simulink Program

  1. 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.
图 9-配置ROS2网络

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.

  1. 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.
图 10-建立刚体

Figure 10 - Create Rigid Bodies

  1. Double-click flightmaster2.slx to open the simulink model.
图 11-双击该文件打开模型

Figure 11 - Double-Click This File to Open Model

图 12-simulink模型页面

Figure 12 - Simulink Model Page

  1. Open ubuntu and enable three crazyflies in flightmasters.yaml in flightmaster2.
图 13-启动三架crazyflie

Figure 13 - Start Three Crazyflies

  1. Open a terminal and use the following command to open the flightmaster2 graphical control interface.

    cd ~/FlightMaster2/

    python fmclient.py

图 14-运行flightmaster2图形化界面

Figure 14 - Run Flightmaster2 Graphical Interface

  1. 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.
图 15-flightmaster2图形化界面

Figure 15 - Flightmaster2 Graphical Interface

  1. 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.
图 16-将轮盘拨至No

Figure 16 - Set Dial to No

图 17-运行simulink

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.

图 18-轮盘拨至takeoff

Figure 18 - Set Dial to Takeoff

图 19-无人机起飞

Figure 19 - Drone Takeoff

图 20-rviz显示

Figure 20 - rviz Display

(Ⅱ) Crazyflie Single Aircraft Square Flight

  1. 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.
图 21-创建刚体

Figure 21 - Create Rigid Body

  1. Open ubuntu, enable one crazyflie in flightmasters.yaml, and start FlightSwarm on the flightmaster2 graphical control interface.
图 22-启用一架crazyflie

Figure 22 - Enable One Crazyflie

图 23-启动FlightSwarm

Figure 23 - Start FlightSwarm

  1. 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.
图 24-将轮盘拨至No

Figure 24 - Set Dial to No

图 25-运行simulink

Figure 25 - Run Simulink

  1. 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.
图 26-启用设备

Figure 26 - Enable Device

  1. Set the demo control dial to crazyflie. At this time, vehicle3 will first take off and then fly around a square.
图 27-轮盘拨至crazyflie

Figure 27 - Set Dial to Crazyflie

图 28-crazyflie绕方形

Figure 28 - Crazyflie Flying Around Square

图 29-rviz显示

Figure 29 - rviz Display