MainController
MainController class for high-level vehicle control and state management.
#include <main_controller.hpp>Classes
class MainController
Provides high-level flight control commands and vehicle state for a single vehicle.
auto Arm(bool arm) -> boolArm or disarm the vehicle. Synchronous/blocking
| Parameter | Type | Description |
|---|---|---|
arm |
bool |
True to arm, false to disarm. |
Returns: true if the command was successfully sent and acknowledged by the vehicle, false otherwise.
auto Takeoff() -> boolCommand the vehicle to take off. Synchronous/blocking.
Returns: true if the command was successfully sent and acknowledged by the vehicle, false otherwise
auto Land() -> boolCommand the vehicle to land. Synchronous/blocking.
Returns: true if the command was successfully sent and acknowledged by the vehicle, false otherwise
auto ArmAsync(bool arm) -> std::future<bool>Arm or disarm the vehicle. Asynchronous.
| Parameter | Type | Description |
|---|---|---|
arm |
bool |
True to arm, false to disarm. |
Returns: A future that resolves to true if the command was successfully sent and acknowledged by the vehicle, false otherwise.
auto TakeoffAsync() -> std::future<bool>Command the vehicle to take off. Asynchronous.
Returns: A future that resolves to true if the command was successfully sent and acknowledged by the vehicle, false otherwise
auto LandAsync() -> std::future<bool>Command the vehicle to land. Asynchronous.
Returns: A future that resolves to true if the command was successfully sent and acknowledged by the vehicle, false otherwise
auto SetVelocity(const VelocitySetpoint& setpoint) -> voidSet a velocity and yaw rate setpoint for the vehicle. Synchronous.
| Parameter | Type | Description |
|---|---|---|
setpoint |
const VelocitySetpoint& |
Desired velocity in m/s (NED convention) and yaw rate in rad/s. |
auto SetVelocityBody(const VelocitySetpoint& setpoint) -> voidSet a body-frame velocity and yaw rate setpoint in SI units. Synchronous.
Prefer this over SetVelocity() for autonomy: it always interprets the setpoint in the vehicle's body frame in m/s. Vehicles without a distinct body-frame channel fall back to SetVelocity().
| Parameter | Type | Description |
|---|---|---|
setpoint |
const VelocitySetpoint& |
Desired body-frame velocity in m/s and yaw rate in rad/s. |
auto EmergencyStop() -> voidTrigger an emergency stop, which may cut motors and disable control. Use with caution; recovery may require manual intervention.
auto StartSimulation(double latitude, double longitude, int satellites = 12) -> boolBegin simulating flight from a starting position. Synchronous.
The vehicle runs its real firmware against a simulated airframe: motors stay off while position, attitude, and GNSS behave as if airborne. Vehicles that cannot simulate return false rather than reporting a simulated state.
| Parameter | Type | Description |
|---|---|---|
latitude |
double |
Starting latitude in WGS84 degrees. |
longitude |
double |
Starting longitude in WGS84 degrees. |
satellites |
int |
Satellite count the simulated GNSS reports. |
Returns: true if simulation started; false if unsupported or refused.
auto StopSimulation() -> voidStop the active simulation.
auto StartCircleMission(float radius) -> voidStarts a circular loiter mission around the current position.
| Parameter | Type | Description |
|---|---|---|
radius |
float |
Loiter radius in metres. |
auto StopCircleMission() -> voidStops the active circular loiter mission.
auto RunHealthCheck() -> voidRefresh the pre-flight health report on demand.
Asks the vehicle to re-run its PreArm checks (so a just-fixed problem clears immediately rather than after the autopilot's ~30 s re-broadcast) and to stream vibration for a short window. Both are request-only: the vibration stream is read by nothing else and the vehicle link is kept to essential traffic when no one is looking at the report.
auto StartExploreMission() -> voidStarts autonomous frontier exploration.
auto StopExploreMission() -> voidStops the active autonomous exploration mission.
auto SetMode(const std::string& mode) -> voidRequests a flight mode change by name (e.g., "STABILIZE", "LOITER", "POSHOLD", "GUIDED", "RTL", "LAND", "ALT_HOLD").
| Parameter | Type | Description |
|---|---|---|
mode |
const std::string& |
Flight mode name string. |
auto GetSupportedModesJson() const -> std::stringReturns the flight modes the operator can switch between via SetMode(), as a JSON array of `{name, description, number}` objects. An empty array indicates the vehicle does not support named flight modes.
Returns: JSON-encoded array of supported flight modes.
auto ModeNumberToName(uint32_t mode) const -> std::stringTranslates the integer mode number reported in Pose::flight_mode to a human-readable name (e.g. 4 → "GUIDED").
| Parameter | Type | Description |
|---|---|---|
mode |
uint32_t |
Autopilot mode number from Pose::flight_mode. |
Returns: Mode name string, or an empty string if the number is not in the catalogue.
auto StartCalibration(int type) -> voidStarts a sensor calibration routine on the flight controller. Progress and completion are reported via OnStatusMessage.
| Parameter | Type | Description |
|---|---|---|
type |
int |
Calibration type: 0 = Gyro, 1 = Accelerometer (6-position), |
auto CancelCalibration() -> voidAbort any in-progress calibration.
auto ConfirmCalibrationPosition(int position) -> voidConfirm the vehicle is held in the prompted accel-cal position (1=LEVEL, 2=LEFT, 3=RIGHT, 4=NOSE DOWN, 5=NOSE UP, 6=BACK). The 6-position calibration samples only after confirmation.
| Parameter | Type | Description |
|---|---|---|
position |
int |
auto MotorTest(int motor, int throttle_pct, int timeout_s) -> voidSpin one motor for a bench motor-order and direction check.
The flight controller refuses while armed. Standard across multirotor vehicles.
| Parameter | Type | Description |
|---|---|---|
motor |
int |
Motor test-order number (1..N). |
throttle_pct |
int |
Throttle as a percentage. |
timeout_s |
int |
Spin duration in seconds. |
auto SetParameter(const std::string& name, float value) -> voidSet a flight-controller parameter by name.
| Parameter | Type | Description |
|---|---|---|
name |
const std::string& |
Parameter name. |
value |
float |
New parameter value. |
auto RequestParameter(const std::string& name) -> voidRequest a flight-controller parameter's current value.
The reply is asynchronous; poll GetParameter() until it returns true.
| Parameter | Type | Description |
|---|---|---|
name |
const std::string& |
Parameter name. |
auto GetParameter(const std::string& name, float& out) const -> boolRead a parameter value cached from a prior RequestParameter().
| Parameter | Type | Description |
|---|---|---|
name |
const std::string& |
Parameter name. |
out |
float& |
Receives the cached value when available. |
Returns: true once the value has been delivered; false until then.
auto RebootFlightController() -> voidReboot the flight controller.
Needed after calibrations that apply only on the next boot (accelerometer, compass). The controller refuses while armed and telemetry drops for a few seconds.
auto AscendTo(float meters, AltitudeReference ref = AltitudeReference::RelativeToCurrentPosition) -> voidCommands the vehicle to ascend to the specified altitude or distance.
Valid for aerial and submarine domains. Ground, marine, and space vehicles ignore this command. For submarines, AboveSeaLevel targets above 0 m are clamped to sea level.
| Parameter | Type | Description |
|---|---|---|
meters |
float |
Distance or target altitude interpreted per @p ref. |
ref |
AltitudeReference |
AltitudeReference::RelativeToCurrentPosition (default) or |
auto SetObstacleAvoidance(bool enable) -> boolEnables or disables the vehicle's onboard obstacle avoidance.
Generic across vehicles that expose an avoidance guard. Vehicles without the capability ignore the command (see IsObstacleAvoidanceSupported()).
| Parameter | Type | Description |
|---|---|---|
enable |
bool |
true to turn avoidance on, false to turn it off. |
Returns: true if the command was accepted; false if unsupported or the link
auto IsObstacleAvoidanceSupported() const -> boolReports whether this vehicle supports obstacle-avoidance toggling. The control app should hide the toggle when this returns false.
Returns: true if SetObstacleAvoidance() is meaningful for this vehicle.
auto IsSpaceVehicle() const -> boolCheck the vehicle's domain.
Returns: true if the vehicle is defined as a space vehicle.
auto IsAerialVehicle() const -> boolCheck the vehicle's domain.
Returns: true if the vehicle is defined as an aerial vehicle.
auto IsGroundVehicle() const -> boolCheck the vehicle's domain.
Returns: true if the vehicle is defined as a ground vehicle.
auto IsMarineVehicle() const -> boolCheck the vehicle's domain.
Returns: true if the vehicle is defined as a marine vehicle.
auto IsSubmarineVehicle() const -> boolCheck the vehicle's domain.
Returns: true if the vehicle is defined as a submarine vehicle.
auto IsConnected() const -> boolCheck if the main controller is currently connected to the vehicle.
Returns: true if connected, false otherwise.
auto GetPose() const -> PoseReturns the latest telemetry snapshot for the vehicle.
Returns: Pose struct containing position, orientation, velocity, battery, and GPS data.
auto OnConnectionChanged(std::function<void(bool)> callback) -> voidRegister a callback for connection status changes.
| Parameter | Type | Description |
|---|---|---|
callback |
std::function<void(bool)> |
Function to call when connection status changes. |
Structs
struct Pose
Telemetry snapshot for a vehicle.
Position (x, y, z) is local odometry in metres from power-on. The `valid` field is false until the first telemetry packet is received.
| Field | Type | Description |
|---|---|---|
x |
float |
odometry east (m) |
y |
float |
odometry north (m) |
z |
float |
odometry up (m) |
vx |
float |
m/s |
vy |
float |
m/s |
vz |
float |
m/s, positive = up |
battery_percent |
int |
0–100, -1 = not available |
battery_voltage |
float |
volts (pack voltage); 0 = unavailable |
battery_current |
float |
amps (pack current); 0 = unavailable / idle |
latitude |
double |
WGS84 degrees, 0 = unavailable |
longitude |
double |
WGS84 degrees, 0 = unavailable |
gps_satellites |
int |
number of GPS satellites in use |
rc_signal |
int |
RC signal quality 0–100 |
flight_time_sec |
int |
seconds since motors started |
flight_mode |
uint32_t |
autopilot-specific mode number |
armed |
bool |
true = motors armed (flying or ready to fly) |
valid |
bool |
false until first telemetry packet is received |
gps_signal_level |
int |
GNSS signal quality 0–5, -1 = unavailable; distinct from gps_satellites (tracking is not the same as solving a fix) |
gps_fix_type |
int |
GPS fix quality: 0=no GPS, 1=no fix, 2=2D, 3=3D, 4=DGPS, 5/6=RTK |
rangefinder_m |
float |
downward rangefinder (m); <=0 = unavailable |
yaw_rate |
float |
body yaw rate (rad/s), + = CW (nose-right) |
sensors_present |
uint32_t |
autopilot-specific bitmask of onboard sensors fitted |
sensors_health |
uint32_t |
same bit layout as sensors_present; 1 = that sensor is healthy |
vibe_x |
float |
accel vibration m/s/s (<15 ok, >30 bad) |
vibe_y |
float |
|
vibe_z |
float |
|
vibe_clipping |
uint32_t |
cumulative clipping events; must be 0 |
ekf_flags |
uint16_t |
EKF flags (0x8000 = GPS glitch) |
orientation |
Quaternion |
body orientation as a unit quaternion (x, y, z, w); Euler angles are a derived view (roll()/pitch()/yaw(), set_euler()) |
struct VelocitySetpoint
3D velocity and yaw rate setpoint.
| Field | Type | Description |
|---|---|---|
vx |
float |
forward velocity (m/s, NED convention) |
vy |
float |
lateral velocity (m/s, NED convention) |
vz |
float |
vertical velocity (m/s, NED convention) |
yaw_rate |
float |
yaw rate (rad/s) |