mavsdk::ModesServer Class Reference ​
#include: modes_server.hpp
Provide the flight modes of an autopilot, the counterpart of the Modes plugin.
The modes are announced using the MAVLink standard modes protocol (AVAILABLE_MODES, AVAILABLE_MODES_MONITOR, CURRENT_MODE).
Once modes are set, this plugin also handles mode change requests (MAV_CMD_DO_SET_STANDARD_MODE, MAV_CMD_DO_SET_MODE and SET_MODE) for those modes, instead of the deprecated flight mode API of the ActionServer plugin.
Data Structures ​
struct Mode
Public Types ​
| Type | Description |
|---|---|
| enum ModeFeedback | Possible answers to a mode change request. |
| enum Result | Possible results returned for mode requests. |
| std::function< void(Result)> ResultCallback | Callback type for asynchronous ModesServer calls. |
| std::function< void(Mode)> ModeRequestedCallback | Callback type for subscribe_mode_requested. |
| Handle< Mode > ModeRequestedHandle | Handle type for subscribe_mode_requested. |
Public Member Functions ​
| Type | Name | Description |
|---|---|---|
| Â | ModesServer (std::shared_ptr< ServerComponent > server_component) | Constructor. Creates the plugin for a ServerComponent instance. |
| Â | ~ModesServer () override | Destructor (internal use only). |
| Â | ModesServer (const ModesServer & other) | Copy constructor. |
| Result | set_available_modes (std::vector< Mode > modes)const | Set the modes the vehicle provides. |
| ModeRequestedHandle | subscribe_mode_requested (const ModeRequestedCallback & callback) | Subscribe to mode change requests. |
| void | unsubscribe_mode_requested (ModeRequestedHandle handle) | Unsubscribe from subscribe_mode_requested. |
| Result | respond_mode_requested (ModeFeedback mode_feedback)const | Respond to the last mode change request. |
| Result | set_current_mode (std::string name)const | Set the mode the vehicle is in. |
| const ModesServer & | operator= (const ModesServer &)=delete | Equality operator (object is not copyable). |
Constructor & Destructor Documentation ​
ModesServer() ​
mavsdk::ModesServer::ModesServer(std::shared_ptr< ServerComponent > server_component)Constructor. Creates the plugin for a ServerComponent instance.
The plugin is typically created as shown below:
auto modes_server = ModesServer(server_component);Parameters
- std::shared_ptr< ServerComponent > server_component - The ServerComponent instance associated with this server plugin.
~ModesServer() ​
mavsdk::ModesServer::~ModesServer() overrideDestructor (internal use only).
ModesServer() ​
mavsdk::ModesServer::ModesServer(const ModesServer &other)Copy constructor.
Parameters
- const ModesServer& other -
Member Typdef Documentation ​
typedef ResultCallback ​
using mavsdk::ModesServer::ResultCallback = std::function<void(Result)>Callback type for asynchronous ModesServer calls.
typedef ModeRequestedCallback ​
using mavsdk::ModesServer::ModeRequestedCallback = std::function<void(Mode)>Callback type for subscribe_mode_requested.
typedef ModeRequestedHandle ​
using mavsdk::ModesServer::ModeRequestedHandle = Handle<Mode>Handle type for subscribe_mode_requested.
Member Enumeration Documentation ​
enum ModeFeedback ​
Possible answers to a mode change request.
| Value | Description |
|---|---|
Unknown | Unknown. |
Accepted | The vehicle switches to the mode. |
Busy | The vehicle can't switch to the mode right now, e.g. it has no GPS. |
Denied | The vehicle doesn't allow switching to the mode. |
Failed | Switching to the mode failed. |
enum Result ​
Possible results returned for mode requests.
| Value | Description |
|---|---|
Unknown | Unknown result. |
Success | Request was successful. |
InvalidModes | Modes are invalid, e.g. none are given, a name or custom mode is used twice, or a standard mode name is unknown. |
ModeNotFound | No available mode with this name. |
NoRequest | There is no mode change request to respond to. |
InvalidFeedback | The feedback is unknown. |
Member Function Documentation ​
set_available_modes() ​
Result mavsdk::ModesServer::set_available_modes(std::vector< Mode > modes) constSet the modes the vehicle provides.
Ground stations are told that the list changed so they download it again. From then on, mode change requests are handled by this plugin.
This function is blocking.
Parameters
- std::vector< Mode > modes -
Returns
 Result - Result of request.
subscribe_mode_requested() ​
ModeRequestedHandle mavsdk::ModesServer::subscribe_mode_requested(const ModeRequestedCallback &callback)Subscribe to mode change requests.
Requests for a mode in the list are reported here and need to be answered with RespondModeRequested. Until then, the ground station is told that the request is in progress.
Parameters
- const ModeRequestedCallback& callback -
Returns
 ModeRequestedHandle -
unsubscribe_mode_requested() ​
void mavsdk::ModesServer::unsubscribe_mode_requested(ModeRequestedHandle handle)Unsubscribe from subscribe_mode_requested.
Parameters
- ModeRequestedHandle handle -
respond_mode_requested() ​
Result mavsdk::ModesServer::respond_mode_requested(ModeFeedback mode_feedback) constRespond to the last mode change request.
If the request is accepted, the requested mode becomes the current mode. Otherwise the vehicle stays in its current mode, e.g. if it can't switch to Position without GPS.
This function is blocking.
Parameters
- ModeFeedback mode_feedback -
Returns
 Result - Result of request.
set_current_mode() ​
Result mavsdk::ModesServer::set_current_mode(std::string name) constSet the mode the vehicle is in.
This function is blocking.
Parameters
- std::string name -
Returns
 Result - Result of request.
operator=() ​
const ModesServer & mavsdk::ModesServer::operator=(const ModesServer &)=deleteEquality operator (object is not copyable).
Parameters
- const ModesServer& -
Returns
 const ModesServer & -

