11 _pollTimer.setInterval(1000);
12 _pollTimer.setSingleShot(
false);
23 _autotuneInProgress =
true;
24 _autotuneStatus = tr(
"Autotune: In progress");
34 Q_UNUSED(failureCode);
36 auto * autotune =
static_cast<Autotune *
>(resultHandlerData);
38 if (autotune->_autotuneInProgress) {
40 if ((ack.result == MAV_RESULT_IN_PROGRESS) || (ack.result == MAV_RESULT_ACCEPTED)) {
41 autotune->handleAckStatus(ack.progress);
43 else if (ack.result == MAV_RESULT_FAILED) {
44 autotune->handleAckFailure();
47 autotune->handleAckError(ack.result);
50 autotune->handleAckFailure();
52 emit autotune->autotuneChanged();
54 qWarning() <<
"Ack received for a command different from MAV_CMD_DO_AUTOTUNE_ENABLE ot wrong UI state.";
62 auto * autotune =
static_cast<Autotune *
>(progressHandlerData);
64 if (autotune->_autotuneInProgress) {
65 autotune->handleAckStatus(ack.progress);
66 emit autotune->autotuneChanged();
68 qWarning() <<
"Ack received for a command different from MAV_CMD_DO_AUTOTUNE_ENABLE ot wrong UI state.";
73void Autotune::handleAckStatus(uint8_t ackProgress)
75 _autotuneProgress = ackProgress/100.f;
77 if (ackProgress < 20) {
78 _autotuneStatus = tr(
"Autotune: initializing");
80 else if (ackProgress < 40) {
81 _autotuneStatus = tr(
"Autotune: roll");
83 else if (ackProgress < 60) {
84 _autotuneStatus = tr(
"Autotune: pitch");
86 else if (ackProgress < 80) {
87 _autotuneStatus = tr(
"Autotune: yaw");
89 else if (ackProgress == 95) {
90 _autotuneStatus = tr(
"Wait for disarm");
92 if(!_disarmMessageDisplayed) {
94 _disarmMessageDisplayed =
true;
97 else if (ackProgress < 100) {
98 _autotuneStatus = tr(
"Autotune: in progress");
102 _autotuneInProgress =
false;
104 if (ackProgress == 100) {
105 _autotuneStatus = tr(
"Autotune: Success");
110 _autotuneStatus = tr(
"Autotune: Unknown error");
117void Autotune::handleAckFailure()
120 _autotuneInProgress =
false;
121 _disarmMessageDisplayed =
false;
122 _autotuneStatus = tr(
"Autotune: Failed");
127void Autotune::handleAckError(uint8_t ackError)
130 _autotuneInProgress =
false;
131 _disarmMessageDisplayed =
false;
132 _autotuneStatus = tr(
"Autotune: Ack error %1").arg(ackError);
137void Autotune::startTimers()
144void Autotune::stopTimers()
161 MAV_COMP_ID_AUTOPILOT1,
162 MAV_CMD_DO_AUTOTUNE_ENABLE,
struct __mavlink_command_ack_t mavlink_command_ack_t
static void ackHandler(void *resultHandlerData, int compId, const mavlink_command_ack_t &ack, VehicleTypes::MavCmdResultFailureCode_t failureCode)
static void progressHandler(void *progressHandlerData, int compId, const mavlink_command_ack_t &ack)
Autotune(Vehicle *vehicle)
void sendMavlinkRequest()
Q_INVOKABLE void autotuneRequest()
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.
void showAppMessage(const QString &message, const QString &title)
Modal application message. Queued if the UI isn't ready yet.
Callback info bundle for sendMavCommandWithHandler.
void * progressHandlerData
nullptr for no handler
MavCmdProgressHandler progressHandler
MavCmdResultHandler resultHandler
nullptr for no handler
MavCmdResultFailureCode_t
@ MavCmdResultCommandResultOnly
commandResult specifies full success/fail info