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) -> bool

Arm or disarm the vehicle. Synchronous/blocking

ParameterTypeDescription
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() -> bool

Command the vehicle to take off. Synchronous/blocking.

Returns: true if the command was successfully sent and acknowledged by the vehicle, false otherwise

auto Land() -> bool

Command 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.

ParameterTypeDescription
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) -> void

Set a velocity and yaw rate setpoint for the vehicle. Synchronous.

ParameterTypeDescription
setpoint const VelocitySetpoint& Desired velocity in m/s (NED convention) and yaw rate in rad/s.
auto SetVelocityBody(const VelocitySetpoint& setpoint) -> void

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

ParameterTypeDescription
setpoint const VelocitySetpoint& Desired body-frame velocity in m/s and yaw rate in rad/s.
auto EmergencyStop() -> void

Trigger 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) -> bool

Begin 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.

ParameterTypeDescription
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() -> void

Stop the active simulation.

auto StartCircleMission(float radius) -> void

Starts a circular loiter mission around the current position.

ParameterTypeDescription
radius float Loiter radius in metres.
auto StopCircleMission() -> void

Stops the active circular loiter mission.

auto RunHealthCheck() -> void

Refresh 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() -> void

Starts autonomous frontier exploration.

auto StopExploreMission() -> void

Stops the active autonomous exploration mission.

auto SetMode(const std::string& mode) -> void

Requests a flight mode change by name (e.g., "STABILIZE", "LOITER", "POSHOLD", "GUIDED", "RTL", "LAND", "ALT_HOLD").

ParameterTypeDescription
mode const std::string& Flight mode name string.
auto GetSupportedModesJson() const -> std::string

Returns 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::string

Translates the integer mode number reported in Pose::flight_mode to a human-readable name (e.g. 4 → "GUIDED").

ParameterTypeDescription
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) -> void

Starts a sensor calibration routine on the flight controller. Progress and completion are reported via OnStatusMessage.

ParameterTypeDescription
type int Calibration type: 0 = Gyro, 1 = Accelerometer (6-position),
auto CancelCalibration() -> void

Abort any in-progress calibration.

auto ConfirmCalibrationPosition(int position) -> void

Confirm 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.

ParameterTypeDescription
position int
auto MotorTest(int motor, int throttle_pct, int timeout_s) -> void

Spin one motor for a bench motor-order and direction check.

The flight controller refuses while armed. Standard across multirotor vehicles.

ParameterTypeDescription
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) -> void

Set a flight-controller parameter by name.

ParameterTypeDescription
name const std::string& Parameter name.
value float New parameter value.
auto RequestParameter(const std::string& name) -> void

Request a flight-controller parameter's current value.

The reply is asynchronous; poll GetParameter() until it returns true.

ParameterTypeDescription
name const std::string& Parameter name.
auto GetParameter(const std::string& name, float& out) const -> bool

Read a parameter value cached from a prior RequestParameter().

ParameterTypeDescription
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() -> void

Reboot 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) -> void

Commands 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.

ParameterTypeDescription
meters float Distance or target altitude interpreted per @p ref.
ref AltitudeReference AltitudeReference::RelativeToCurrentPosition (default) or
auto SetObstacleAvoidance(bool enable) -> bool

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

ParameterTypeDescription
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 -> bool

Reports 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 -> bool

Check the vehicle's domain.

Returns: true if the vehicle is defined as a space vehicle.

auto IsAerialVehicle() const -> bool

Check the vehicle's domain.

Returns: true if the vehicle is defined as an aerial vehicle.

auto IsGroundVehicle() const -> bool

Check the vehicle's domain.

Returns: true if the vehicle is defined as a ground vehicle.

auto IsMarineVehicle() const -> bool

Check the vehicle's domain.

Returns: true if the vehicle is defined as a marine vehicle.

auto IsSubmarineVehicle() const -> bool

Check the vehicle's domain.

Returns: true if the vehicle is defined as a submarine vehicle.

auto IsConnected() const -> bool

Check if the main controller is currently connected to the vehicle.

Returns: true if connected, false otherwise.

auto GetPose() const -> Pose

Returns 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) -> void

Register a callback for connection status changes.

ParameterTypeDescription
callback std::function<void(bool)> Function to call when connection status changes.

Structs

struct Pose

Telemetry snapshot for a vehicle.

Note:

Position (x, y, z) is local odometry in metres from power-on. The `valid` field is false until the first telemetry packet is received.

FieldTypeDescription
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.

FieldTypeDescription
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)