QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
ActuatorActions.cc
Go to the documentation of this file.
1#include "ActuatorActions.h"
2#include "MAVLinkLib.h"
3#include "AppMessages.h"
4#include "Vehicle.h"
6
7QGC_LOGGING_CATEGORY(ActuatorActionsLog, "Vehicle.Actuators.ActuatorActions")
8
9using namespace ActuatorActions;
10
11QString Config::typeToLabel() const
12{
13 switch (type) {
14 case Type::beep: return QCoreApplication::translate("ActuatorAction", "Beep");
15 case Type::set3DModeOn: return QCoreApplication::translate("ActuatorAction", "3D mode: On");
16 case Type::set3DModeOff: return QCoreApplication::translate("ActuatorAction", "3D mode: Off");
17 case Type::setSpinDirection1: return QCoreApplication::translate("ActuatorAction", "Set Spin Direction 1");
18 case Type::setSpinDirection2: return QCoreApplication::translate("ActuatorAction", "Set Spin Direction 2");
19 }
20 return "";
21}
22
23Action::Action([[maybe_unused]] QObject *parent,
24 const Config &action,
25 const QString &label,
26 int outputFunction,
27 Vehicle *vehicle)
28 : _label(label), _outputFunction(outputFunction), _type(action.type), _vehicle(vehicle)
29{
30}
31
33{
34 if (_commandInProgress) {
35 return;
36 }
37 sendMavlinkRequest();
38}
39
40void Action::ackHandlerEntry(void* resultHandlerData, int /*compId*/, const mavlink_command_ack_t& ack, VehicleTypes::MavCmdResultFailureCode_t failureCode)
41{
42 Action* action = (Action*)resultHandlerData;
43 action->ackHandler(static_cast<MAV_RESULT>(ack.result), failureCode);
44}
45
46void Action::ackHandler(MAV_RESULT commandResult, VehicleTypes::MavCmdResultFailureCode_t failureCode)
47{
48 _commandInProgress = false;
49 if (failureCode != VehicleTypes::MavCmdResultFailureNoResponseToCommand && commandResult != MAV_RESULT_ACCEPTED) {
50 QGC::showAppMessage(tr("Actuator action command failed"));
51 }
52}
53
54void Action::sendMavlinkRequest()
55{
56 qCDebug(ActuatorActionsLog) << "Sending actuator action, function:" << _outputFunction << "type:" << (int)_type;
57
58 Vehicle::MavCmdAckHandlerInfo_t handlerInfo = {};
59 handlerInfo.resultHandler = ackHandlerEntry;
60 handlerInfo.resultHandlerData = this;
61
63 &handlerInfo,
64 MAV_COMP_ID_AUTOPILOT1, // the ID of the autopilot
65 MAV_CMD_CONFIGURE_ACTUATOR, // the mavlink command
66 (int)_type, // action type
67 0, // unused parameter
68 0, // unused parameter
69 0, // unused parameter
70 1000+_outputFunction, // function
71 0, // unused parameter
72 0);
73 _commandInProgress = true;
74}
75
76ActionGroup::ActionGroup([[maybe_unused]] QObject *parent, const QString &label, Config::Type type)
77 : _label(label), _type(type)
78{
79}
#define QGC_LOGGING_CATEGORY(name, categoryStr)
struct __mavlink_command_ack_t mavlink_command_ack_t
ActionGroup(QObject *parent, const QString &label, Config::Type type)
Action(QObject *parent, const Config &action, const QString &label, int outputFunction, Vehicle *vehicle)
Q_INVOKABLE void trigger()
void sendMavCommandWithHandler(const MavCmdAckHandlerInfo_t *ackHandlerInfo, int compId, MAV_CMD command, float param1=0.0f, float param2=0.0f, float param3=0.0f, float param4=0.0f, float param5=0.0f, float param6=0.0f, float param7=0.0f)
Sends the command and calls the callback with the result.
Definition Vehicle.cc:2170
void showAppMessage(const QString &message, const QString &title)
Modal application message. Queued if the UI isn't ready yet.
Definition AppMessages.cc:9
Callback info bundle for sendMavCommandWithHandler.
MavCmdResultHandler resultHandler
nullptr for no handler
@ MavCmdResultFailureNoResponseToCommand
No response from vehicle to command.