Chapter 6: External Control and Trajectory Planning¶
After completing the development of the low-level filtering and control system, the unmanned system needs to receive commands from the upper-level decision-making layer to achieve higher-level motion control. External control and trajectory planning serve as the critical bridge connecting low-level control with upper-level intelligent decision-making. This chapter introduces the design and usage of external control interfaces, as well as the development and validation of trajectory planning algorithms.
6.1 Background and Theory¶
As an autonomous flying vehicle, the external control capability of an unmanned aerial vehicle (UAV) is essential for achieving precise flight missions and safe flight operations. Common control methods include: remote controller control, ground station control, semi-autonomous control, and computer interface-based control. Among these, external control theory primarily concerns flight stability in the air, generally understood as position and attitude control of the UAV.
6.1.1 External Control Modes¶
External control (Offboard Control) refers to a mode where control commands are sent to the flight controller from a ground station or onboard computer. In this mode, the flight controller acts as an actuator, receiving position, velocity, or attitude commands generated by external systems and converting them into low-level motor control signals. The MAVLink protocol is the mainstream communication protocol for external control, supporting multiple control modes and message types. Common external control modes supported by remote controllers include:
- Position Mode: Send target positions to the flight controller; the UAV autonomously plans a path to reach the target point.
- Velocity Mode: Send velocity commands to control the UAV’s movement at a specified speed.
- Attitude Mode: Send desired attitude angles to control the UAV to achieve a specified orientation.
6.1.2 Fundamentals of Trajectory Planning¶
Trajectory planning is a critical issue at the decision-making level for multi-rotor UAVs, referring to the process of finding an optimal flight trajectory from a starting point to a target point under specific constraints, while satisfying the UAV’s maneuverability and environmental limitations. It is a key technology for multi-rotor mission planning systems and a technical guarantee for autonomous flight.

The main functions of trajectory planning include: during pre-flight, assisting mission planners in selecting an optimal path for the multi-rotor UAV to execute its mission; and during flight, enabling online path replanning to some extent based on real-time situational data. The planned path serves as a reference trajectory for UAV flight, guiding the multi-rotor to complete its mission under the action of the control law.
6.2 Framework and Interfaces¶
The RflySim toolchain provides rich external control and trajectory planning interfaces, supporting multiple development environments such as Python and MATLAB/Simulink.
6.2.1 MAVLink Control Interface¶
RflySim supports external control via the MAVLink protocol. MAVLink (Micro Air Vehicle Link) is a lightweight UAV communication protocol that has become an industry standard. Through MAVLink, developers can send various types of control commands—including position, velocity, and attitude—to the flight controller, enabling precise UAV control.
The toolchain provides a Python-based MAVLink control interface (RflySimSDK) and a Simulink block library. Users can select the appropriate development tools based on project requirements. Using these interfaces, users can:
- Implement automatic takeoff and landing commands
- Send waypoint mission queues
- Dynamically adjust flight speed and altitude in real time
- Retrieve real-time UAV status information
6.2.2 Trajectory Planning Algorithm Interface¶
For trajectory planning, RflySim provides interfaces to integrate mainstream planning algorithms. Users can implement various planning algorithms in Python or MATLAB environments, including:
- Global Path Planning: Optimal path search based on environmental maps
- Local Obstacle Avoidance Planning: Real-time obstacle avoidance based on sensor data
- Time-Optimal Trajectory Generation: Shortest-time trajectory considering dynamic constraints
- Smooth Trajectory Optimization: Smooth trajectory generation based on differential flatness
6.2.3 External Control Development Workflow¶
A complete external control program includes core steps: communication connection, mode setting and arming, publishing desired commands, state monitoring, and ending with return-to-home.
As illustrated in the flowchart above, when conducting physical hardware-in-the-loop (HITL) or software-in-the-loop (SITL) simulations, the program first establishes a stable communication connection with the flight controller. After confirming successful connection (e.g., by receiving heartbeat packets), it begins continuously sending desired target values—such as position, velocity, angular velocity, or attitude—to the flight controller at a certain frequency (recommended ≥10 Hz). It is crucial to note that only after ensuring stable transmission of target commands can the program, through loop-based judgment, request and successfully switch the flight controller to Offboard control mode. Once the mode switch succeeds, the program issues an arm command to activate the motors and initiate closed-loop control tasks with state monitoring. Finally, after mission completion, it issues landing, return-to-home, and disarm commands to safely recover the vehicle.
6.3 Showcase of Representative Cases¶
Air-Ground Cooperative External Trajectory Planning and Control:
Multi-rotor Virtual Pipe Flight:
6.4 Course-Related Videos¶
Public Lecture Replay for This Chapter (Session 5: External Control and Trajectory Planning):
6.5 Chapter Experiment Cases¶
The verification experiments and guided case studies related to this chapter are located in the [Installation Directory]\RflySimAPIs\6.RflySimExtCtrl folder.
6.5.1 Interface Learning Experiments¶
These are stored in the 6.RflySimExtCtrl\0.ApiExps folder, covering foundational platform interface tutorials and general introductions to various tools.