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 "QGCApplication.h"
3
4using namespace ActuatorActions;
5
6QString Config::typeToLabel() const
7{
8 switch (type) {
9 case Type::beep: return QCoreApplication::translate("ActuatorAction", "Beep");
10 case Type::set3DModeOn: return QCoreApplication::translate("ActuatorAction", "3D mode: On");
11 case Type::set3DModeOff: return QCoreApplication::translate("ActuatorAction", "3D mode: Off");
12 case Type::setSpinDirection1: return QCoreApplication::translate("ActuatorAction", "Set Spin Direction 1");
13 case Type::setSpinDirection2: return QCoreApplication::translate("ActuatorAction", "Set Spin Direction 2");
14 }
15 return "";
16}
17
18Action::Action([[maybe_unused]] QObject *parent,
19 const Config &action,
20 const QString &label,
21 int outputFunction,
22 Vehicle *vehicle)
23 : _label(label), _outputFunction(outputFunction), _type(action.type), _vehicle(vehicle)
24{
25}
26
28{
29 if (_commandInProgress) {
30 return;
31 }
32 sendMavlinkRequest();
33}
34
35void Action::ackHandlerEntry(void* resultHandlerData, int /*compId*/, const mavlink_command_ack_t& ack, Vehicle::MavCmdResultFailureCode_t failureCode)
36{
37 Action* action = (Action*)resultHandlerData;
38 action->ackHandler(static_cast<MAV_RESULT>(ack.result), failureCode);
39}
40
41void Action::ackHandler(MAV_RESULT commandResult, Vehicle::MavCmdResultFailureCode_t failureCode)
42{
43 _commandInProgress = false;
44 if (failureCode != Vehicle::MavCmdResultFailureNoResponseToCommand && commandResult != MAV_RESULT_ACCEPTED) {
45 qgcApp()->showAppMessage(tr("Actuator action command failed"));
46 }
47}
48
49void Action::sendMavlinkRequest()
50{
51 qCDebug(ActuatorsConfigLog) << "Sending actuator action, function:" << _outputFunction << "type:" << (int)_type;
52
53 Vehicle::MavCmdAckHandlerInfo_t handlerInfo = {};
54 handlerInfo.resultHandler = ackHandlerEntry;
55 handlerInfo.resultHandlerData = this;
56
58 &handlerInfo,
59 MAV_COMP_ID_AUTOPILOT1, // the ID of the autopilot
60 MAV_CMD_CONFIGURE_ACTUATOR, // the mavlink command
61 (int)_type, // action type
62 0, // unused parameter
63 0, // unused parameter
64 0, // unused parameter
65 1000+_outputFunction, // function
66 0, // unused parameter
67 0);
68 _commandInProgress = true;
69}
70
71ActionGroup::ActionGroup([[maybe_unused]] QObject *parent, const QString &label, Config::Type type)
72 : _label(label), _type(type)
73{
74}
#define qgcApp()
ActionGroup(QObject *parent, const QString &label, Config::Type type)
Action(QObject *parent, const Config &action, const QString &label, int outputFunction, Vehicle *vehicle)
MavCmdResultFailureCode_t
Definition Vehicle.h:618
@ MavCmdResultFailureNoResponseToCommand
No response from vehicle to command.
Definition Vehicle.h:620
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:2339
@ set3DModeOn
motors: enable 3D mode (reversible)
@ setSpinDirection2
motors: set spin direction 2
@ set3DModeOff
motors: disable 3D mode (reversible)
@ setSpinDirection1
motors: set spin direction 1
QString typeToLabel() const
MavCmdResultHandler resultHandler
Definition Vehicle.h:639