Design of Hardware-in-the-Loop Simulation System for Quadrotor Flight Control

As a core component of unmanned aerial vehicles, the flight control system plays a pivotal role in precisely managing the attitude of quadrotor drones. In the development process of quadrotor systems, simulation technology serves as a critical tool for addressing complex system challenges. This article presents a real-time simulation platform constructed using a combination of LabVIEW, Simulink, VeriStand, and Mission Planner. The platform employs Simulink for modeling the dynamics and kinematics of the quadrotor, utilizes VeriStand to invoke the simulation model, and leverages LabVIEW for online display and modification of model parameters. Mission Planner, as a real-time operating system, ensures the real-time execution of the simulation model, thereby facilitating rapid simulation design, reducing development cycles, and minimizing human-induced influences. Hardware-in-the-loop simulation experiments for the quadrotor flight control system demonstrate that the platform operates reliably, exhibits excellent real-time performance, and enhances the efficiency and reliability of semi-physical simulation testing.

The flight control system is integral to the quadrotor drone, accounting for a significant portion of both development time and cost. Simulation techniques provide an essential means for researching complex systems. In this context, a quadrotor hardware-in-the-loop simulation system is designed to integrate real flight controllers with virtual flight environments, enabling the verification and optimization of control algorithms. The system comprises both hardware and software components, as detailed in the tables below.

Hardware Components of the Quadrotor Simulation System
Hardware Name Primary Function
Pixhawk 2.4.8 Flight Controller Outputs PWM signals
Remote Controller and Receiver Transmits and receives remote commands
NI cDAQ-9174 Performs PWM signal acquisition
NI 9361 Data Acquisition Card Performs PWM signal acquisition
PC Host Computer Resolves quadrotor model attitude information
Serial Cable (USB) Transmits data
Software Components of the Quadrotor Simulation System
Software Name Primary Function
MATLAB/Simulink Quadrotor modeling
LabVIEW Host computer software
VeriStand MIT tool integration
Mission Planner Ground station sensor data

The overall design of the quadrotor simulation system involves using a real flight controller as the control entity. Commands are sent to the quadrotor flight controller via a remote controller, and the flight controller computes and outputs PWM signals. These control signals are acquired using NI cDAQ data acquisition equipment and used for real-time resolution with the quadrotor simulation model. The model calculates flight parameters such as position, velocity, three-axis Euler angles, three-axis angular velocities, and motor speeds, as well as simulated sensor data including gyroscope and compass readings. The quadrotor model transmits these computed flight parameters and simulated sensor information to the flight controller via a serial cable. Mission Planner, connected to the flight controller via a serial cable, compares the sensor data collected by the flight controller with the model outputs, forming a closed simulation loop. The flight state parameters derived from the quadrotor model serve as critical indicators for assessing the normal operation and control accuracy of the flight control software under test.

To analyze the dynamics of the quadrotor, several assumptions are made to simplify the model: the quadrotor is treated as a rigid body; the ground coordinate system is considered inertial during flight; the geometric center coincides with the center of gravity; the mass and moment of inertia remain constant during flight; and the quadrotor is subject only to gravity, propeller thrust, and aerodynamic drag. The actuator model for the quadrotor, which converts PWM control signals into motor drives, is represented as a first-order inertial system:

$$ \Omega = \frac{C_r \sigma + \Omega_b}{T s + 1} $$

where \( T \) is the time constant, \( \sigma \) is the throttle command between 0 and 1, and \( C_r \), \( \Omega_b \) are constants. For a quadrotor in hover, the thrust provided by a single propeller is given by:

$$ f_i = C_t \Omega_i^2 $$

where \( C_t = \frac{1}{4\pi^2} \rho d^4 C_T \) is the comprehensive thrust coefficient determined experimentally, \( \Omega_i \) is the motor speed, and the thrust direction is negative along the Z-axis. The reactive torque of the propeller under static conditions is:

$$ M_i = C_m \Omega_i^2 $$

where \( C_m = \frac{1}{4\pi^2} \rho d^5 C_M \) is determined experimentally. The moment of inertia \( I \) for the quadrotor is a diagonal matrix:

$$ I = \begin{bmatrix} I_x & 0 & 0 \\ 0 & I_y & 0 \\ 0 & 0 & I_z \end{bmatrix} $$

The total thrust \( F \) and moments \( T \) for an X-configuration quadrotor are derived from the motor speeds \( \Omega_i \) (for \( i = 1, 2, 3, 4 \)):

$$ F = \sum_{i=1}^{4} f_i = C_t (\Omega_1^2 + \Omega_2^2 + \Omega_3^2 + \Omega_4^2) $$

$$ \begin{aligned} T_x &= r C_t \left( -\frac{\sqrt{2}}{2} \Omega_1^2 + \frac{\sqrt{2}}{2} \Omega_2^2 + \frac{\sqrt{2}}{2} \Omega_3^2 – \frac{\sqrt{2}}{2} \Omega_4^2 \right) \\ T_y &= r C_t \left( \frac{\sqrt{2}}{2} \Omega_1^2 – \frac{\sqrt{2}}{2} \Omega_2^2 + \frac{\sqrt{2}}{2} \Omega_3^2 – \frac{\sqrt{2}}{2} \Omega_4^2 \right) \\ T_z &= C_m (\Omega_1^2 + \Omega_2^2 – \Omega_3^2 – \Omega_4^2) \end{aligned} $$

where \( r \) is the distance from the center to any motor, and \( C_m \) is the torque coefficient. The thrust and moments can be expressed in matrix form:

$$ \begin{bmatrix} F \\ T_x \\ T_y \\ T_z \end{bmatrix} = \begin{bmatrix} C_t & C_t & C_t & C_t \\ -\frac{\sqrt{2}}{2} r C_t & \frac{\sqrt{2}}{2} r C_t & \frac{\sqrt{2}}{2} r C_t & -\frac{\sqrt{2}}{2} r C_t \\ \frac{\sqrt{2}}{2} r C_t & -\frac{\sqrt{2}}{2} r C_t & \frac{\sqrt{2}}{2} r C_t & -\frac{\sqrt{2}}{2} r C_t \\ C_m & C_m & -C_m & -C_m \end{bmatrix} \begin{bmatrix} \Omega_1^2 \\ \Omega_2^2 \\ \Omega_3^2 \\ \Omega_4^2 \end{bmatrix} $$

In the ground coordinate system, the linear position is denoted by \( P_e = [x, y, z]^T \), and the attitude angles by \( [\phi, \theta, \psi]^T \). The velocity \( V_e = [V_x, V_y, V_z] \) relates to position as:

$$ \dot{P_e} = V_e $$

The body angular rate \( \omega_b = [\omega_x, \omega_y, \omega_z]^T \) relates to the attitude rates through:

$$ \begin{bmatrix} \omega_x \\ \omega_y \\ \omega_z \end{bmatrix} = \begin{bmatrix} 1 & 0 & -\sin\theta \\ 0 & \cos\phi & \cos\theta \sin\phi \\ 0 & -\sin\phi & \cos\theta \cos\phi \end{bmatrix} \begin{bmatrix} \dot{\phi} \\ \dot{\theta} \\ \dot{\psi} \end{bmatrix} $$

Solving for the attitude rates yields:

$$ \begin{bmatrix} \dot{\phi} \\ \dot{\theta} \\ \dot{\psi} \end{bmatrix} = \begin{bmatrix} \omega_x + \tan\theta \sin\phi \omega_y + \tan\theta \cos\phi \omega_z \\ \cos\phi \omega_y – \sin\phi \omega_z \\ \frac{\sin\phi}{\cos\theta} \omega_y + \frac{\cos\phi}{\cos\theta} \omega_z \end{bmatrix} $$

The gyroscopic moments due to propeller rotation are given by:

$$ \begin{aligned} G_\phi &= \sum_{i=1}^{4} I_m \omega_y (-1)^{i+1} \Omega_i \\ G_\theta &= \sum_{i=1}^{4} I_m \omega_x (-1)^i \Omega_i \\ G_\psi &= 0 \end{aligned} $$

where \( I_m \) is the total moment of inertia of the motor rotor and propeller about the axis. Assuming the total force on the quadrotor is \( F_e \), the force analysis leads to:

$$ \dot{V_e} = \frac{F_e}{m} $$

$$ F_e = m G + R_e^b (F + F_d) $$

where \( G = [0, 0, g]^T \) is gravity, \( F = [0, 0, -F]^T \) is thrust, and \( R_e^b \) is the rotation matrix from body to earth frame. The velocity in the earth frame relates to the body frame as \( V_e = R_e^b V_b \), leading to the positional dynamics equation:

$$ \dot{V_b} = -[\omega_b]_\times V_b + g R_e^{-1} e_3 – \frac{F}{m} e $$

where \( e_3 = [0, 0, 1]^T \) is a unit vector, and \( [\omega_b]_\times \) is the skew-symmetric matrix of \( \omega_b \). The attitude dynamics in the body frame are described by:

$$ I \dot{\omega_b} = -\omega_b \times (I \cdot \omega_b) + G + T $$

The software design for the quadrotor hardware-in-the-loop simulation platform utilizes LabVIEW for overall system implementation. The LabVIEW program is divided into four main parts: command information acquisition, data communication, fault simulation, and attitude display. The command acquisition module collects PWM signals from the flight controller and displays them as waveforms. Data communication involves serial port communication for data exchange between the flight controller, ground station, and host computer. Fault simulation injects predefined fault modes into the quadrotor model. Attitude display calls the model to resolve attitude information based on input parameters and displays relevant data.

To establish the joint simulation environment between LabVIEW and Simulink, the Model Interface Toolkit (MIT) integrated into NI VeriStand is used. The setup involves installing software in a specific order: LabVIEW 2015, MATLAB R2015b, Microsoft Visual C++ 2010, and NI VeriStand 2015. The quadrotor model is built in Simulink with NI VeriStand In and Out blocks replacing the input and output ports. The model configuration parameters are set to use a fixed-step solver with a step size of 0.001 seconds and an infinite stop time. The system target file is set to NI VeriStand.tlc for compilation.

Mission Planner, which employs the MAVLink open-source communication protocol, is selected as the ground station for monitoring quadrotor status, controlling flight, and acquiring real-time telemetry data. It provides a user-friendly interface for visualizing sensor data and flight parameters.

Experimental validation involves initiating the simulation on the host computer and sending commands to the quadrotor flight controller via a remote controller. The NI cDAQ device acquires PWM signals, which are displayed on the software interface. During the takeoff phase, the remote controller issues commands, and waveforms for velocity, position, and angular acceleration are observed. In fault simulation, data modifications are applied to channels 0, 1, 2, and 3 to emulate faults. The ground station records sensor data such as accelerometer, gyroscope, compass, and barometer readings, which are compared with values computed by the host computer model. The results indicate that the quadrotor model’s flight state data align with expected behaviors based on input signals, and although slight discrepancies exist between model outputs and ground station measurements, the overall flight dynamics meet requirements.

In conclusion, the quadrotor hardware-in-the-loop simulation platform, built on VeriStand, LabVIEW, Simulink, and Mission Planner, effectively addresses real-time testing challenges. By modeling quadrotor dynamics and kinematics in Simulink, invoking models via VeriStand, and enabling parameter manipulation through LabVIEW, the platform ensures real-time execution with Mission Planner. This approach accelerates simulation design, shortens development cycles, and enhances the reliability of quadrotor flight control systems. Future work could focus on refining model accuracy and expanding fault simulation scenarios for broader quadrotor applications.

Scroll to Top