HighLevelMode Module Documentation¶
Toolbox: RflySim Swarm

Introduction¶
One-sentence Description: A high-level flight control mode management module designed for UAV swarm development, providing processed control commands and desired control outputs to the PX4 flight controller, along with flight safety mechanisms.
This module serves as the core preprocessing component within the RflySim Swarm toolchain for high-level UAV control, supporting general usage in both simulation and real-flight scenarios. It provides basic flight control safety guarantees for beginners while meeting the differentiated control needs of advanced users, and is compatible with the three mainstream control modes: position, velocity, and acceleration. The module requires input commands from a mode-switching module and reprocesses PX4-required disarming, arming, Offboard mode switching, and other commands. By default, it repeats command transmission at 1-second intervals to balance command transmission reliability and network stability. Additionally, it restricts the output control quantities based on the drone’s state verification results and current flight mode: no user-defined control quantities are output when the mode is not Flying; all outputs are cleared when state verification fails, thereby avoiding risks such as abnormal takeoff or misoperation.
This module interfaces with the PX4 flight controller, exchanging information with the CopterSim simulation engine or real aircraft flight controllers via the RflyUdpMavlink module, and outputs standardized bus-format control commands and desired control quantities for direct use by subsequent control logic. It supports both single-UAV development and multi-UAV swarm control scenarios, with 16-dimensional control inputs reserved for complex custom control tasks.
Port Descriptions¶
Input Ports (Inputs)¶
| Port Name | Data Type | Dimension | Description |
|---|---|---|---|
cmd |
double |
1×1 |
Flight controller command input, must be generated by the mode-switching module, used to send commands such as arming, disarming, takeoff, and mode switching |
mode |
double |
1×1 |
Control mode selection input: 1 for position control mode, 2 for velocity control mode, 3 for acceleration control mode |
ctrls |
double |
1×16 |
Control quantity input: the first four dimensions correspond to control targets, and the remaining 12 dimensions are reserved for expansion; default to 0 |
takeoff_height |
double |
1×1 |
Automatic takeoff target height, compatible with NED coordinate system (positive downward); for indoor takeoff to 1m height, typically set to -1 |
check_pass |
double |
1×1 |
UAV state verification flag input; if verification fails, all outputs of the module are set to 0 |
Output Ports (Outputs)¶
| Port Name | Data Type | Dimension | Description |
|---|---|---|---|
outBus |
Bus |
Non-standard | Output control bus, containing processed control commands, enable flags, and desired control quantities corresponding to the active control mode |
Parameter Configuration (Parameters)¶
This module has no configurable parameters.
Module Characteristics (Block Characteristics)¶
| Characteristic | Value |
|---|---|
| Supported Data Types | double, single |
| Direct Feedthrough | Yes |
| Sample Time | Inherited |
| Code Generation Support | No |
Data Communication Protocol¶
This module does not involve network communication.
Related Modules¶
| Module Name | Description |
|---|---|
ModeSwitch |
Generates the mode control command input required by the HighLevelMode module |
RflyUdpMavlink |
Outputs UAV state verification flags, which can be connected to the check_pass input port of this module |
Notes and Common Issues¶
- Initialization and Input Source: The
cmdcommand input of this module must be generated by theModeSwitchmodule in the RflySim Swarm library; direct custom input of commands is not supported, otherwise the module cannot correctly implement timed command retransmission and mode logic processing. - Coordinate System and Height Sign Convention: This module is compatible with the NED coordinate system, where downward is the positive direction for altitude. To take off to a height of 1m, the takeoff height parameter should be set to -1. Incorrect sign settings may cause abnormal takeoff height, resulting in crashes or excessive takeoff altitude.
- Control Mode Matching Input: Only
mode=1(position control),mode=2(velocity control), andmode=3(acceleration control) are supported. Thectrlscontrol input only requires the first four dimensions to be filled; the remaining 12 dimensions must be set to 0. Only the expected control quantities corresponding to the active mode are valid; outputs for non-active modes remain at 0 and must not be used as control inputs. - State Verification Logic: The
check_passstate verification signal output by the RflyUdpMavlink module must be connected. If verification fails, all outputs of this module are set to 0, and no control commands are output—this is normal safety logic, not a module fault. In multi-UAV swarm scenarios, if any UAV fails verification, that UAV will not execute control commands, ensuring flight safety. - Command Transmission Rules: By default, this module retransmits flight controller commands at 1-second intervals. Upon mode switching, it sends the command immediately once, then repeats every 1 second. Do not repeatedly send the same command at high frequency in external logic, to avoid triggering flight controller faults or network congestion.
- Safe Usage Recommendations: Position control mode (
mode=1) is recommended for beginners. Velocity (mode=2) and acceleration (mode=3) control require users to have corresponding control algorithm knowledge; manual control scenarios should avoid direct use of velocity/acceleration modes to prevent flight anomalies. - Non-Flying Mode Safety Logic: When not switched to Flying mode, this module suppresses all externally input control quantities, keeping all control outputs at 0. This is a preset safety mechanism and does not require additional adjustment.
Changelog¶
v4.20(2024-12-09): Initial release, supporting position/velocity/acceleration control mode outputs, integrating flight controller command retransmission and state verification functionality, and outputting standardized control buses for swarm simulation development.