• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

mavlink / MAVSDK / 21640460786

03 Feb 2026 05:24PM UTC coverage: 48.976% (-0.1%) from 49.079%
21640460786

Pull #2761

github

web-flow
Merge 7cfecc1f5 into 0bbbe3676
Pull Request #2761: Expanded capabilities for setting flight mode

1 of 91 new or added lines in 2 files covered. (1.1%)

5 existing lines in 3 files now uncovered.

18313 of 37392 relevant lines covered (48.98%)

663.35 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

14.95
/src/mavsdk/plugins/action_server/action_server_impl.cpp
1
#include "action_server_impl.h"
2
#include "unused.h"
3
#include "flight_mode.h"
4
#include "callback_list.tpp"
5
#include "px4_custom_mode.h"
6

7
namespace mavsdk {
8

9
template class CallbackList<ActionServer::Result, ActionServer::ArmDisarm>;
10
template class CallbackList<ActionServer::Result, ActionServer::FlightMode>;
11
template class CallbackList<ActionServer::Result, bool>;
12

13
ActionServer::FlightMode
14
ActionServerImpl::telemetry_flight_mode_from_flight_mode(FlightMode flight_mode)
×
15
{
16
    switch (flight_mode) {
×
17
        case FlightMode::Ready:
×
18
            return ActionServer::FlightMode::Ready;
×
19
        case FlightMode::Takeoff:
×
20
            return ActionServer::FlightMode::Takeoff;
×
21
        case FlightMode::Hold:
×
22
            return ActionServer::FlightMode::Hold;
×
23
        case FlightMode::Mission:
×
24
            return ActionServer::FlightMode::Mission;
×
25
        case FlightMode::ReturnToLaunch:
×
26
            return ActionServer::FlightMode::ReturnToLaunch;
×
27
        case FlightMode::Land:
×
28
            return ActionServer::FlightMode::Land;
×
29
        case FlightMode::Offboard:
×
30
            return ActionServer::FlightMode::Offboard;
×
31
        case FlightMode::FollowMe:
×
32
            return ActionServer::FlightMode::FollowMe;
×
33
        case FlightMode::Manual:
×
34
            return ActionServer::FlightMode::Manual;
×
35
        case FlightMode::Posctl:
×
36
            return ActionServer::FlightMode::Posctl;
×
37
        case FlightMode::Altctl:
×
38
            return ActionServer::FlightMode::Altctl;
×
39
        case FlightMode::Acro:
×
40
            return ActionServer::FlightMode::Acro;
×
41
        case FlightMode::Stabilized:
×
42
            return ActionServer::FlightMode::Stabilized;
×
43
        default:
×
44
            return ActionServer::FlightMode::Unknown;
×
45
    }
46
}
47

48
uint32_t ActionServerImpl::to_px4_mode_from_flight_mode(ActionServer::FlightMode flight_mode)
×
49
{
50
    px4::px4_custom_mode px4_mode;
51
    switch (flight_mode) {
×
52
        case ActionServer::FlightMode::Ready:
×
53
            px4_mode.main_mode = px4::PX4_CUSTOM_MAIN_MODE_AUTO;
×
54
            px4_mode.sub_mode = px4::PX4_CUSTOM_SUB_MODE_AUTO_READY;
×
55
            break;
×
56
        case ActionServer::FlightMode::Takeoff:
×
57
            px4_mode.main_mode = px4::PX4_CUSTOM_MAIN_MODE_AUTO;
×
58
            px4_mode.sub_mode = px4::PX4_CUSTOM_SUB_MODE_AUTO_TAKEOFF;
×
59
            break;
×
60
        case ActionServer::FlightMode::Hold:
×
61
            px4_mode.main_mode = px4::PX4_CUSTOM_MAIN_MODE_AUTO;
×
62
            px4_mode.sub_mode = px4::PX4_CUSTOM_SUB_MODE_AUTO_LOITER;
×
63
            break;
×
64
        case ActionServer::FlightMode::Mission:
×
65
            px4_mode.main_mode = px4::PX4_CUSTOM_MAIN_MODE_AUTO;
×
66
            px4_mode.sub_mode = px4::PX4_CUSTOM_SUB_MODE_AUTO_MISSION;
×
67
            break;
×
68
        case ActionServer::FlightMode::ReturnToLaunch:
×
69
            px4_mode.main_mode = px4::PX4_CUSTOM_MAIN_MODE_AUTO;
×
70
            px4_mode.sub_mode = px4::PX4_CUSTOM_SUB_MODE_AUTO_RTL;
×
71
            break;
×
72
        case ActionServer::FlightMode::Land:
×
73
            px4_mode.main_mode = px4::PX4_CUSTOM_MAIN_MODE_AUTO;
×
74
            px4_mode.sub_mode = px4::PX4_CUSTOM_SUB_MODE_AUTO_LAND;
×
75
            break;
×
76
        case ActionServer::FlightMode::Offboard:
×
77
            px4_mode.main_mode = px4::PX4_CUSTOM_MAIN_MODE_OFFBOARD;
×
78
            px4_mode.sub_mode = 0;
×
79
            break;
×
80
        case ActionServer::FlightMode::FollowMe:
×
81
            px4_mode.main_mode = px4::PX4_CUSTOM_MAIN_MODE_AUTO;
×
82
            px4_mode.sub_mode = px4::PX4_CUSTOM_SUB_MODE_AUTO_FOLLOW_TARGET;
×
83
            break;
×
84
        case ActionServer::FlightMode::Manual:
×
85
            px4_mode.main_mode = px4::PX4_CUSTOM_MAIN_MODE_MANUAL;
×
86
            px4_mode.sub_mode = 0;
×
87
            break;
×
88
        case ActionServer::FlightMode::Posctl:
×
89
            px4_mode.main_mode = px4::PX4_CUSTOM_MAIN_MODE_POSCTL;
×
90
            px4_mode.sub_mode = 0;
×
91
            break;
×
92
        case ActionServer::FlightMode::Altctl:
×
93
            px4_mode.main_mode = px4::PX4_CUSTOM_MAIN_MODE_ALTCTL;
×
94
            px4_mode.sub_mode = 0;
×
95
            break;
×
96
        case ActionServer::FlightMode::Acro:
×
97
            px4_mode.main_mode = px4::PX4_CUSTOM_MAIN_MODE_ACRO;
×
98
            px4_mode.sub_mode = 0;
×
99
            break;
×
100
        case ActionServer::FlightMode::Stabilized:
×
101
            px4_mode.main_mode = px4::PX4_CUSTOM_MAIN_MODE_STABILIZED;
×
102
            px4_mode.sub_mode = 0;
×
103
            break;
×
104
        default:
×
105
            px4_mode.main_mode = 0; // unknown
×
106
            px4_mode.sub_mode = 0;
×
107
            break;
×
108
    }
109
    return px4_mode.data;
×
110
}
111

112
ActionServerImpl::ActionServerImpl(std::shared_ptr<ServerComponent> server_component) :
1✔
113
    ServerPluginImplBase(server_component)
1✔
114
{
115
    _server_component_impl->register_plugin(this);
1✔
116
}
1✔
117

118
ActionServerImpl::~ActionServerImpl()
2✔
119
{
120
    _server_component_impl->unregister_plugin(this);
1✔
121
}
2✔
122

123
void ActionServerImpl::init()
1✔
124
{
125
    _send_version_cookie = _server_component_impl->add_call_every(
1✔
126
        [this]() { _server_component_impl->send_autopilot_version(); }, 1.0);
1✔
127

128
    // Arming / Disarm / Kill
129
    _server_component_impl->register_mavlink_command_handler(
1✔
130
        MAV_CMD_COMPONENT_ARM_DISARM,
131
        [this](const MavlinkCommandReceiver::CommandLong& command) {
18✔
132
            ActionServer::ArmDisarm armDisarm{
133
                command.params.param1 == 1, command.params.param2 == 21196};
4✔
134

135
            std::lock_guard<std::mutex> lock(_callback_mutex);
4✔
136

137
            // Check arm states - Ugly.
138
            auto request_ack = MAV_RESULT_UNSUPPORTED;
4✔
139
            bool force = armDisarm.force;
4✔
140
            if (armDisarm.arm) {
4✔
141
                request_ack = (_armable || (force && _force_armable)) ?
2✔
142
                                  MAV_RESULT::MAV_RESULT_ACCEPTED :
143
                                  MAV_RESULT_TEMPORARILY_REJECTED;
144
            } else {
145
                request_ack = (_disarmable || (force && _force_disarmable)) ?
2✔
146
                                  MAV_RESULT::MAV_RESULT_ACCEPTED :
147
                                  MAV_RESULT_TEMPORARILY_REJECTED;
148
            }
149

150
            if (request_ack == MAV_RESULT::MAV_RESULT_ACCEPTED) {
4✔
151
                set_server_armed(armDisarm.arm);
2✔
152
            }
153

154
            auto result = (request_ack == MAV_RESULT::MAV_RESULT_ACCEPTED) ?
4✔
155
                              ActionServer::Result::Success :
156
                              ActionServer::Result::CommandDenied;
157

158
            _arm_disarm_callbacks.queue(result, armDisarm, [this](const auto& func) {
4✔
159
                _server_component_impl->call_user_callback(func);
×
160
            });
×
161

162
            return _server_component_impl->make_command_ack_message(command, request_ack);
4✔
163
        },
4✔
164
        this);
165

166
    _server_component_impl->register_mavlink_command_handler(
1✔
167
        MAV_CMD_NAV_TAKEOFF,
168
        [this](const MavlinkCommandReceiver::CommandLong& command) {
×
169
            std::lock_guard<std::mutex> lock(_callback_mutex);
×
170

171
            if (_allow_takeoff) {
×
172
                _takeoff_callbacks.queue(
×
173
                    ActionServer::Result::Success, true, [this](const auto& func) {
×
174
                        _server_component_impl->call_user_callback(func);
×
175
                    });
×
176

177
                return _server_component_impl->make_command_ack_message(
×
178
                    command, MAV_RESULT::MAV_RESULT_ACCEPTED);
×
179
            } else {
180
                _takeoff_callbacks.queue(
×
181
                    ActionServer::Result::CommandDenied, false, [this](const auto& func) {
×
182
                        _server_component_impl->call_user_callback(func);
×
183
                    });
×
184

185
                return _server_component_impl->make_command_ack_message(
×
186
                    command, MAV_RESULT::MAV_RESULT_UNSUPPORTED);
×
187
            }
188
        },
×
189
        this);
190

191
    // Flight mode (long)
192
    _server_component_impl->register_mavlink_command_handler(
1✔
193
        MAV_CMD_DO_SET_MODE,
194
        [this](const MavlinkCommandReceiver::CommandLong& command) {
×
195
            auto base_mode = static_cast<uint8_t>(command.params.param1);
×
196
            auto is_custom = (base_mode & MAV_MODE_FLAG_CUSTOM_MODE_ENABLED) ==
×
197
                             MAV_MODE_FLAG_CUSTOM_MODE_ENABLED;
198
            ActionServer::FlightMode request_flight_mode = ActionServer::FlightMode::Unknown;
×
199

200
            auto custom_mode = static_cast<uint8_t>(command.params.param2);
×
201
            auto sub_custom_mode = static_cast<uint8_t>(command.params.param3);
×
202

203
            if (is_custom) {
×
204
                // PX4 uses custom modes
205
                px4::px4_custom_mode px4_mode{};
×
206
                px4_mode.main_mode = custom_mode;
×
207
                px4_mode.sub_mode = sub_custom_mode;
×
208
                auto system_flight_mode = to_flight_mode_from_px4_mode(px4_mode.data);
×
209
                request_flight_mode = telemetry_flight_mode_from_flight_mode(system_flight_mode);
×
210
            } else {
211
                // TO DO: non PX4 flight modes...
212
                // Just bug out now if not using PX4 modes
213
                std::lock_guard<std::mutex> callback_lock(_callback_mutex);
×
214
                _flight_mode_change_callbacks.queue(
×
215
                    ActionServer::Result::ParameterError,
216
                    request_flight_mode,
217
                    [this](const auto& func) { _server_component_impl->call_user_callback(func); });
×
218

219
                return _server_component_impl->make_command_ack_message(
×
220
                    command, MAV_RESULT::MAV_RESULT_UNSUPPORTED);
×
221
            }
×
222

223
            bool allow_mode = false;
×
224
            {
225
                std::lock_guard<std::mutex> flight_mode_lock(_flight_mode_mutex);
×
226
                switch (request_flight_mode) {
×
227
                    case ActionServer::FlightMode::Manual:
×
228
                        allow_mode = true;
×
229
                        break;
×
230
                    case ActionServer::FlightMode::Mission:
×
231
                        allow_mode = _allowed_flight_modes.can_auto_mode;
×
232
                        break;
×
NEW
233
                    case ActionServer::FlightMode::ReturnToLaunch:
×
NEW
234
                        allow_mode = _allowed_flight_modes.can_auto_rtl_mode;
×
NEW
235
                        break;
×
NEW
236
                    case ActionServer::FlightMode::Takeoff:
×
NEW
237
                        allow_mode = _allowed_flight_modes.can_auto_takeoff_mode;
×
NEW
238
                        break;
×
NEW
239
                    case ActionServer::FlightMode::Land:
×
NEW
240
                        allow_mode = _allowed_flight_modes.can_auto_land_mode;
×
NEW
241
                        break;
×
242
                    case ActionServer::FlightMode::Stabilized:
×
243
                        allow_mode = _allowed_flight_modes.can_stabilize_mode;
×
244
                        break;
×
245
                    case ActionServer::FlightMode::Offboard:
×
246
                        allow_mode = _allowed_flight_modes.can_guided_mode;
×
247
                        break;
×
248
                    default:
×
249
                        allow_mode = false;
×
250
                        break;
×
251
                }
252
            }
×
253

254
            // PX4...
255
            px4::px4_custom_mode px4_mode{};
×
256
            px4_mode.data = get_custom_mode();
×
257

258
            if (allow_mode) {
×
259
                px4_mode.main_mode = custom_mode;
×
260
                px4_mode.sub_mode = sub_custom_mode;
×
NEW
261
                uint8_t system_base_mode = get_base_mode();
×
NEW
262
                system_base_mode |= MAV_MODE_FLAG_CUSTOM_MODE_ENABLED;
×
NEW
263
                set_base_mode(system_base_mode);
×
UNCOV
264
                set_custom_mode(px4_mode.data);
×
265
            }
266

267
            {
268
                std::lock_guard<std::mutex> callback_lock(_callback_mutex);
×
269
                _flight_mode_change_callbacks.queue(
×
270
                    allow_mode ? ActionServer::Result::Success :
271
                                 ActionServer::Result::CommandDenied,
272
                    request_flight_mode,
273
                    [this](const auto& func) { _server_component_impl->call_user_callback(func); });
×
274
            }
×
275

276
            return _server_component_impl->make_command_ack_message(
×
277
                command,
278
                allow_mode ? MAV_RESULT::MAV_RESULT_ACCEPTED : MAV_RESULT_TEMPORARILY_REJECTED);
×
279
        },
280
        this);
281

282
    // Flight mode (legacy int, standard for PX4)
283
    _server_component_impl->register_mavlink_message_handler(
1✔
284
        MAVLINK_MSG_ID_SET_MODE,
NEW
285
        [this](const mavlink_message_t& message) {
×
286
            mavlink_set_mode_t set_mode;
NEW
287
            mavlink_msg_set_mode_decode(&message, &set_mode);
×
288

NEW
289
            auto base_mode = set_mode.base_mode;
×
NEW
290
            auto is_custom = (base_mode & MAV_MODE_FLAG_CUSTOM_MODE_ENABLED) ==
×
291
                             MAV_MODE_FLAG_CUSTOM_MODE_ENABLED;
NEW
292
            ActionServer::FlightMode request_flight_mode = ActionServer::FlightMode::Unknown;
×
293

NEW
294
            std::lock_guard<std::mutex> lock(_callback_mutex);
×
295

NEW
296
            if (is_custom) {
×
297
                // for now, custom mode is assumed to be PX4
NEW
298
                auto system_flight_mode = to_flight_mode_from_px4_mode(set_mode.custom_mode);
×
NEW
299
                request_flight_mode = telemetry_flight_mode_from_flight_mode(system_flight_mode);
×
300
            } else {
301
                // TO DO: non PX4 flight modes...
302
                // Just bug out now if not using PX4 modes
NEW
303
                _flight_mode_change_callbacks.queue(
×
304
                    ActionServer::Result::ParameterError,
305
                    request_flight_mode,
NEW
306
                    [this](const auto& func) { _server_component_impl->call_user_callback(func); });
×
307

308
                // make_command_ack_message
NEW
309
                mavlink_command_ack_t command_ack{};
×
NEW
310
                command_ack.command = MAVLINK_MSG_ID_SET_MODE;
×
NEW
311
                command_ack.result = MAV_RESULT::MAV_RESULT_UNSUPPORTED;
×
NEW
312
                command_ack.progress = std::numeric_limits<uint8_t>::max();
×
NEW
313
                command_ack.result_param2 = 0;
×
NEW
314
                command_ack.target_system = message.sysid;
×
NEW
315
                command_ack.target_component = message.compid;
×
NEW
316
                _server_component_impl->send_command_ack(command_ack);
×
317
            }
318

NEW
319
            bool allow_mode = false;
×
NEW
320
            switch (request_flight_mode) {
×
NEW
321
                case ActionServer::FlightMode::Manual:
×
NEW
322
                    allow_mode = true;
×
NEW
323
                    break;
×
NEW
324
                case ActionServer::FlightMode::Mission:
×
NEW
325
                    allow_mode = _allowed_flight_modes.can_auto_mode;
×
NEW
326
                    break;
×
NEW
327
                case ActionServer::FlightMode::ReturnToLaunch:
×
NEW
328
                    allow_mode = _allowed_flight_modes.can_auto_rtl_mode;
×
NEW
329
                    break;
×
NEW
330
                case ActionServer::FlightMode::Takeoff:
×
NEW
331
                    allow_mode = _allowed_flight_modes.can_auto_takeoff_mode;
×
NEW
332
                    break;
×
NEW
333
                case ActionServer::FlightMode::Land:
×
NEW
334
                    allow_mode = _allowed_flight_modes.can_auto_land_mode;
×
NEW
335
                    break;
×
NEW
336
                case ActionServer::FlightMode::Stabilized:
×
NEW
337
                    allow_mode = _allowed_flight_modes.can_stabilize_mode;
×
NEW
338
                    break;
×
NEW
339
                case ActionServer::FlightMode::Offboard:
×
NEW
340
                    allow_mode = _allowed_flight_modes.can_guided_mode;
×
NEW
341
                    break;
×
NEW
342
                default:
×
NEW
343
                    allow_mode = false;
×
NEW
344
                    break;
×
345
            }
346

NEW
347
            if (allow_mode) {
×
NEW
348
                uint8_t system_base_mode = get_base_mode();
×
NEW
349
                system_base_mode |= MAV_MODE_FLAG_CUSTOM_MODE_ENABLED;
×
NEW
350
                set_base_mode(system_base_mode);
×
NEW
351
                set_custom_mode(set_mode.custom_mode);
×
352
            }
353

NEW
354
            _flight_mode_change_callbacks.queue(
×
355
                allow_mode ? ActionServer::Result::Success : ActionServer::Result::CommandDenied,
356
                request_flight_mode,
NEW
357
                [this](const auto& func) { _server_component_impl->call_user_callback(func); });
×
358

359
            // make_command_ack_message
NEW
360
            mavlink_command_ack_t command_ack{};
×
NEW
361
            command_ack.command = MAVLINK_MSG_ID_SET_MODE;
×
NEW
362
            command_ack.result =
×
363
                allow_mode ? MAV_RESULT::MAV_RESULT_ACCEPTED : MAV_RESULT_TEMPORARILY_REJECTED;
NEW
364
            command_ack.progress = std::numeric_limits<uint8_t>::max();
×
NEW
365
            command_ack.result_param2 = 0;
×
NEW
366
            command_ack.target_system = message.sysid;
×
NEW
367
            command_ack.target_component = message.compid;
×
NEW
368
            _server_component_impl->send_command_ack(command_ack);
×
NEW
369
        },
×
370
        this);
371
}
1✔
372

373
void ActionServerImpl::deinit()
1✔
374
{
375
    _server_component_impl->unregister_all_mavlink_command_handlers(this);
1✔
376
    _server_component_impl->remove_call_every(_send_version_cookie);
1✔
377
    _server_component_impl->unregister_all_mavlink_command_handlers(this);
1✔
378
}
1✔
379

380
ActionServer::ArmDisarmHandle
381
ActionServerImpl::subscribe_arm_disarm(const ActionServer::ArmDisarmCallback& callback)
×
382
{
383
    std::lock_guard<std::mutex> lock(_callback_mutex);
×
384
    return _arm_disarm_callbacks.subscribe(callback);
×
385
}
×
386

387
void ActionServerImpl::unsubscribe_arm_disarm(ActionServer::ArmDisarmHandle handle)
×
388
{
389
    std::lock_guard<std::mutex> lock(_callback_mutex);
×
390
    _arm_disarm_callbacks.unsubscribe(handle);
×
391
}
×
392

393
ActionServer::FlightModeChangeHandle ActionServerImpl::subscribe_flight_mode_change(
×
394
    const ActionServer::FlightModeChangeCallback& callback)
395
{
396
    std::lock_guard<std::mutex> lock(_callback_mutex);
×
397
    return _flight_mode_change_callbacks.subscribe(callback);
×
398
}
×
399

400
void ActionServerImpl::unsubscribe_flight_mode_change(ActionServer::FlightModeChangeHandle handle)
×
401
{
402
    std::lock_guard<std::mutex> lock(_callback_mutex);
×
403
    _flight_mode_change_callbacks.unsubscribe(handle);
×
404
}
×
405

406
ActionServer::TakeoffHandle
407
ActionServerImpl::subscribe_takeoff(const ActionServer::TakeoffCallback& callback)
×
408
{
409
    std::lock_guard<std::mutex> lock(_callback_mutex);
×
410
    return _takeoff_callbacks.subscribe(callback);
×
411
}
×
412

413
void ActionServerImpl::unsubscribe_takeoff(ActionServer::TakeoffHandle handle)
×
414
{
415
    std::lock_guard<std::mutex> lock(_callback_mutex);
×
416
    _takeoff_callbacks.unsubscribe(handle);
×
417
}
×
418

419
ActionServer::LandHandle
420
ActionServerImpl::subscribe_land(const ActionServer::LandCallback& callback)
×
421
{
422
    // TODO: implement
423
    std::lock_guard<std::mutex> lock(_callback_mutex);
×
424
    return _land_callbacks.subscribe(callback);
×
425
}
×
426

427
void ActionServerImpl::unsubscribe_land(ActionServer::LandHandle handle)
×
428
{
429
    std::lock_guard<std::mutex> lock(_callback_mutex);
×
430
    _land_callbacks.unsubscribe(handle);
×
431
}
×
432

433
ActionServer::RebootHandle
434
ActionServerImpl::subscribe_reboot(const ActionServer::RebootCallback& callback)
×
435
{
436
    // TODO: implement
437
    std::lock_guard<std::mutex> lock(_callback_mutex);
×
438
    return _reboot_callbacks.subscribe(callback);
×
439
}
×
440

441
void ActionServerImpl::unsubscribe_reboot(ActionServer::RebootHandle handle)
×
442
{
443
    std::lock_guard<std::mutex> lock(_callback_mutex);
×
444
    _reboot_callbacks.unsubscribe(handle);
×
445
}
×
446

447
ActionServer::ShutdownHandle
448
ActionServerImpl::subscribe_shutdown(const ActionServer::ShutdownCallback& callback)
×
449
{
450
    // TODO: implement
451
    std::lock_guard<std::mutex> lock(_callback_mutex);
×
452
    return _shutdown_callbacks.subscribe(callback);
×
453
}
×
454

455
void ActionServerImpl::unsubscribe_shutdown(ActionServer::ShutdownHandle handle)
×
456
{
457
    std::lock_guard<std::mutex> lock(_callback_mutex);
×
458
    _shutdown_callbacks.unsubscribe(handle);
×
459
}
×
460

461
ActionServer::TerminateHandle
462
ActionServerImpl::subscribe_terminate(const ActionServer::TerminateCallback& callback)
×
463
{
464
    // TODO: implement
465
    std::lock_guard<std::mutex> lock(_callback_mutex);
×
466
    return _terminate_callbacks.subscribe(callback);
×
467
}
×
468

469
void ActionServerImpl::unsubscribe_terminate(ActionServer::TerminateHandle handle)
×
470
{
471
    std::lock_guard<std::mutex> lock(_callback_mutex);
×
472
    _terminate_callbacks.unsubscribe(handle);
×
473
}
×
474

475
ActionServer::Result ActionServerImpl::set_allow_takeoff(bool allow_takeoff)
×
476
{
477
    _allow_takeoff = allow_takeoff;
×
478
    return ActionServer::Result::Success;
×
479
}
480

481
ActionServer::Result ActionServerImpl::set_armable(bool armable, bool force_armable)
1✔
482
{
483
    std::lock_guard<std::mutex> lock(_flight_mode_mutex);
1✔
484
    _armable = armable;
1✔
485
    _force_armable = force_armable;
1✔
486
    return ActionServer::Result::Success;
2✔
487
}
1✔
488

489
ActionServer::Result ActionServerImpl::set_disarmable(bool disarmable, bool force_disarmable)
1✔
490
{
491
    std::lock_guard<std::mutex> lock(_flight_mode_mutex);
1✔
492
    _disarmable = disarmable;
1✔
493
    _force_disarmable = force_disarmable;
1✔
494
    return ActionServer::Result::Success;
2✔
495
}
1✔
496

497
ActionServer::Result
498
ActionServerImpl::set_allowable_flight_modes(ActionServer::AllowableFlightModes flight_modes)
×
499
{
500
    std::lock_guard<std::mutex> lock(_flight_mode_mutex);
×
501
    _allowed_flight_modes = flight_modes;
×
502
    return ActionServer::Result::Success;
×
503
}
×
504

505
ActionServer::AllowableFlightModes ActionServerImpl::get_allowable_flight_modes()
×
506
{
507
    std::lock_guard<std::mutex> lock(_flight_mode_mutex);
×
508
    return _allowed_flight_modes;
×
509
}
×
510

511
ActionServer::Result ActionServerImpl::set_armed_state(bool armed)
×
512
{
513
    std::lock_guard<std::mutex> lock(_callback_mutex);
×
514
    ActionServer::ArmDisarm arm_disarm{};
×
515

516
    arm_disarm.arm = armed;
×
517
    arm_disarm.force = true;
×
518
    set_server_armed(armed);
×
519
    _arm_disarm_callbacks.queue(
×
520
        ActionServer::Result::Success, arm_disarm, [this](const auto& func) {
×
521
            _server_component_impl->call_user_callback(func);
×
522
        });
×
523
    return ActionServer::Result::Success;
×
524
}
×
525

526
ActionServer::Result ActionServerImpl::set_flight_mode(ActionServer::FlightMode flight_mode)
×
527
{
NEW
528
    ActionServer::Result res = set_flight_mode_internal(flight_mode);
×
NEW
529
    _flight_mode_change_callbacks.queue(res, flight_mode, [this](const auto& func) {
×
NEW
530
        _server_component_impl->call_user_callback(func);
×
NEW
531
    });
×
532

NEW
533
    return res;
×
534
}
535

536
ActionServer::Result
NEW
537
ActionServerImpl::set_flight_mode_internal(ActionServer::FlightMode flight_mode)
×
538
{
539
    // note: currently on receipt of MAV_CMD_DO_SET_MODE/MAV_CMD_SET_MODE, we error out if the mode
540
    // is *not* PX4 custom. For symmetry we will also convert from FlightMode to
541
    // PX4 custom when set directly.
542
    std::lock_guard<std::mutex> lock(_callback_mutex);
×
543

544
    px4::px4_custom_mode px4_mode{};
×
545
    px4_mode.data = to_px4_mode_from_flight_mode(flight_mode);
×
546

547
    uint8_t base_mode = get_base_mode();
×
548
    base_mode |= MAV_MODE_FLAG_CUSTOM_MODE_ENABLED;
×
549
    set_base_mode(base_mode);
×
550
    set_custom_mode(px4_mode.data);
×
UNCOV
551
    return ActionServer::Result::Success;
×
552
}
×
553

554
void ActionServerImpl::set_base_mode(uint8_t base_mode)
2✔
555
{
556
    _server_component_impl->set_base_mode(base_mode);
2✔
557
}
2✔
558

559
uint8_t ActionServerImpl::get_base_mode() const
2✔
560
{
561
    return _server_component_impl->get_base_mode();
2✔
562
}
563

564
void ActionServerImpl::set_custom_mode(uint32_t custom_mode)
×
565
{
566
    _server_component_impl->set_custom_mode(custom_mode);
×
567
}
×
568

569
uint32_t ActionServerImpl::get_custom_mode() const
×
570
{
571
    return _server_component_impl->get_custom_mode();
×
572
}
573

574
void ActionServerImpl::set_server_armed(bool armed)
2✔
575
{
576
    uint8_t base_mode = get_base_mode();
2✔
577
    if (armed) {
2✔
578
        base_mode |= MAV_MODE_FLAG_SAFETY_ARMED;
1✔
579
    } else {
580
        base_mode &= ~MAV_MODE_FLAG_SAFETY_ARMED;
1✔
581
    }
582
    set_base_mode(base_mode);
2✔
583
}
2✔
584

585
} // namespace mavsdk
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc