|
Auterion App SDK
Auterion SDK is a library that can be used by AuterionOS apps to communicate with the system.
|
Defines a mode to control the vehicle using a (set) of setpoint types. More...
#include <auterion_sdk/control/mode.hpp>
Public Member Functions | |
| Mode (SDK &sdk, const std::string &mode_name, const std::vector< ModalityConfig > &controls, ModeConfiguration config=ModeConfiguration{}) | |
| Constructor to initialize a mode. | |
| void | onActivate (const std::function< void()> &callback) |
| Sets a callback function to be called when the mode is activated. | |
| void | onDeactivate (const std::function< void()> &callback) |
| Sets a callback function to be called when the mode is deactivated. | |
| void | onUpdateSetpoint (const std::function< Setpoint(float)> &callback) |
| Sets a callback function to be called at periodically at the update frequency of the mode. | |
| void | canRun (const std::function< void(FailureReporter &)> &callback) |
| Sets a callback that checks whether the mode is allowed to arm and run, reporting the reasons to the ground station when it is not. | |
| void | onFailsafeDeferred (const std::function< void()> &callback) |
| Sets a callback that is called when the flight controller wants to trigger a failsafe while failsafes are being deferred. | |
| void | deferFailsafes (bool enabled, int timeout_s=0) |
| Enables or disables deferring failsafes while this mode is active. | |
| auterion::ManualControlInput | lastManualControlInput () const |
| ModeConfiguration::PX4Mode::ID | id () const |
| Returns the nav_state ID assigned to this mode after registration with PX4. | |
| void | completed (Result result) |
| Signal that the mode has finished and hand control back to PX4. | |
Defines a mode to control the vehicle using a (set) of setpoint types.
Example usage:
To create your own flight mode:
To register callbacks to specific events in the mode life cycle:
| auterion::Mode::Mode | ( | SDK & | sdk, |
| const std::string & | mode_name, | ||
| const std::vector< ModalityConfig > & | controls, | ||
| ModeConfiguration | config = ModeConfiguration{} |
||
| ) |
Constructor to initialize a mode.
| sdk | Reference to the SDK instance. |
| mode_name | Name of the mode. |
| controls | Vector of ModalityConfig objects specifying which setpoints types the mode will output. |
| config | Optional ModeConfiguration specifying mode requirements and capabilities. |
| void auterion::Mode::canRun | ( | const std::function< void(FailureReporter &)> & | callback | ) |
Sets a callback that checks whether the mode is allowed to arm and run, reporting the reasons to the ground station when it is not.
The callback is evaluated continuously. Report each failing condition through the FailureReporter: while any reason is reported the flight controller will not let the operator switch into this mode, and falls back to another mode if this mode is already active. Report nothing when the mode may arm and run.
| callback | Function reporting the reasons the mode may not arm and run. |
| void auterion::Mode::completed | ( | Result | result | ) |
Signal that the mode has finished and hand control back to PX4.
| result | Outcome of the mode |
| void auterion::Mode::deferFailsafes | ( | bool | enabled, |
| int | timeout_s = 0 |
||
| ) |
Enables or disables deferring failsafes while this mode is active.
While enabled, most failsafe actions are held off instead of taking the vehicle out of this mode. These still trigger:
A single one of those being active also disables the deferral for all other failsafes.
Deferring cannot be enabled while a failsafe action is already running, so call this from the onActivate() callback. The flight controller stores the setting per mode and does not clear it on deactivation, so disable it again from onDeactivate().
Use onFailsafeDeferred() to be notified when a failsafe is being held off.
| enabled | True to defer failsafes, false to stop deferring. |
| timeout_s | How long a failsafe may be deferred, counted from the point the failsafe would have triggered. 0 = flight controller default (30s), -1 = no timeout. Once exceeded, the failsafe triggers. |
| ModeConfiguration::PX4Mode::ID auterion::Mode::id | ( | ) | const |
Returns the nav_state ID assigned to this mode after registration with PX4.
Returns ModeConfiguration::PX4Mode::kModeIDInvalid (0xff) if the mode has not yet been registered.
| void auterion::Mode::onActivate | ( | const std::function< void()> & | callback | ) |
Sets a callback function to be called when the mode is activated.
| callback | Function to call on mode activation. |
| void auterion::Mode::onDeactivate | ( | const std::function< void()> & | callback | ) |
Sets a callback function to be called when the mode is deactivated.
| callback | Function to call on mode deactivation. |
| void auterion::Mode::onFailsafeDeferred | ( | const std::function< void()> & | callback | ) |
Sets a callback that is called when the flight controller wants to trigger a failsafe while failsafes are being deferred.
Only called while deferring is enabled through deferFailsafes(). Use it to bring the vehicle to a safe state on the mode's own terms before the deferral times out.
| callback | Function to call when a failsafe was deferred. |
| void auterion::Mode::onUpdateSetpoint | ( | const std::function< Setpoint(float)> & | callback | ) |
Sets a callback function to be called at periodically at the update frequency of the mode.
The ModalityConfig(s) used to instantiate the mode determine the update frequency of the mode, as well as the expected return Setpoint types of the callback function passed to this method.
| callback | Function to call to update setpoints. |