QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
SendMavlinkCommandState.cc
Go to the documentation of this file.
4#include "Vehicle.h"
5
6SendMavlinkCommandState::SendMavlinkCommandState(QState* parent, MAV_CMD command, double param1, double param2, double param3, double param4, double param5, double param6, double param7)
7 : WaitStateBase(QStringLiteral("SendMavlinkCommandState"), parent, 0)
8{
9 setup(command, param1, param2, param3, param4, param5, param6, param7);
10}
11
13 : WaitStateBase(QStringLiteral("SendMavlinkCommandState"), parent, 0)
14{
15}
16
17void SendMavlinkCommandState::setup(MAV_CMD command, double param1, double param2, double param3, double param4, double param5, double param6, double param7)
18{
19 _command = command;
20 _param1 = param1;
21 _param2 = param2;
22 _param3 = param3;
23 _param4 = param4;
24 _param5 = param5;
25 _param6 = param6;
26 _param7 = param7;
27 _configured = true;
28}
29
31{
32 connect(vehicle(), &Vehicle::mavCommandResult, this, &SendMavlinkCommandState::_mavCommandResult);
33}
34
36{
37 if (vehicle()) {
38 disconnect(vehicle(), &Vehicle::mavCommandResult, this, &SendMavlinkCommandState::_mavCommandResult);
39 }
40}
41
43{
44 if (!_configured) {
45 qCCritical(QGCStateMachineLog) << "SendMavlinkCommandState not configured";
46 waitFailed();
47 return;
48 }
49
50 qCDebug(QGCStateMachineLog) << QStringLiteral("Sending %1 command").arg(MissionCommandTree::instance()->friendlyName(_command));
51
52 vehicle()->sendMavCommand(MAV_COMP_ID_AUTOPILOT1,
53 _command,
54 false /* showError */,
55 static_cast<float>(_param1),
56 static_cast<float>(_param2),
57 static_cast<float>(_param3),
58 static_cast<float>(_param4),
59 static_cast<float>(_param5),
60 static_cast<float>(_param6),
61 static_cast<float>(_param7));
62}
63
64void SendMavlinkCommandState::_mavCommandResult(int vehicleId, int targetComponent, int command, int ackResult, int failureCode)
65{
66 Q_UNUSED(vehicleId);
67 Q_UNUSED(targetComponent);
68
69 Vehicle* senderVehicle = qobject_cast<Vehicle*>(sender());
70 if (!senderVehicle) {
71 qWarning() << "Vehicle dynamic cast on sender() failed!";
72 return;
73 }
74 if (senderVehicle != vehicle()) {
75 return; // Not for us
76 }
77 if (command != _command) {
78 return; // Not our command
79 }
80
81 QString commandName = MissionCommandTree::instance()->friendlyName(_command);
82
84 qCDebug(QGCStateMachineLog) << QStringLiteral("%1 Command - No response from vehicle").arg(commandName);
85 waitFailed();
86 } else if (failureCode == Vehicle::MavCmdResultFailureDuplicateCommand) {
87 qCWarning(QGCStateMachineLog) << QStringLiteral("%1 Command - Duplicate command pending").arg(commandName);
88 waitFailed();
89 } else if (ackResult != MAV_RESULT_ACCEPTED) {
90 qCWarning(QGCStateMachineLog) << QStringLiteral("%1 Command failed = ack.result: %2").arg(commandName).arg(ackResult);
91 waitFailed();
92 } else {
93 // MAV_RESULT_ACCEPTED
94 qCDebug(QGCStateMachineLog) << QStringLiteral("%1 Command succeeded").arg(commandName);
95 emit success();
97 }
98}
static MissionCommandTree * instance()
QString friendlyName(MAV_CMD command) const
Returns the friendly name for the specified command.
Vehicle * vehicle() const
SendMavlinkCommandState(QState *parent, MAV_CMD command, double param1=0.0, double param2=0.0, double param3=0.0, double param4=0.0, double param5=0.0, double param6=0.0, double param7=0.0)
void connectWaitSignal() override
Subclasses override to set up their signal connections.
void disconnectWaitSignal() override
Subclasses override to tear down their signal connections.
void onWaitEntered() override
Called when the state is entered - subclasses should call base implementation.
void setup(MAV_CMD command, double param1=0.0, double param2=0.0, double param3=0.0, double param4=0.0, double param5=0.0, double param6=0.0, double param7=0.0)
void sendMavCommand(int compId, MAV_CMD command, bool showError, 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)
Definition Vehicle.cc:2309
@ MavCmdResultFailureNoResponseToCommand
No response from vehicle to command.
Definition Vehicle.h:620
@ MavCmdResultFailureDuplicateCommand
Unable to send command since duplicate is already being waited on for response.
Definition Vehicle.h:621
void mavCommandResult(int vehicleId, int targetComponent, int command, int ackResult, int failureCode)