From 8dee2570abdcdc2eb7e7f5f8ec8f50ddb488c680 Mon Sep 17 00:00:00 2001 From: Julian Oes Date: Thu, 1 Feb 2018 14:12:53 +0100 Subject: [PATCH] PlanManager: use shorter timeout to download items When downloading mission items from the autopilot we need to retry more agressively, so use a shorter timeout. If we don't do this, we might not re-request a mission item in time and the autopilot has already given up the overall mission transfer. This fixes the case where a mission request from QGC to autopilot or a mission item from autopilot to QGC gets lost on the link and needs to be requested again. --- src/MissionManager/PlanManager.cc | 21 +++++++++++++++++++-- src/MissionManager/PlanManager.h | 21 ++++++++++++--------- 2 files changed, 31 insertions(+), 11 deletions(-) diff --git a/src/MissionManager/PlanManager.cc b/src/MissionManager/PlanManager.cc index 284d213d7..b6103ea68 100644 --- a/src/MissionManager/PlanManager.cc +++ b/src/MissionManager/PlanManager.cc @@ -36,8 +36,7 @@ PlanManager::PlanManager(Vehicle* vehicle, MAV_MISSION_TYPE planType) { _ackTimeoutTimer = new QTimer(this); _ackTimeoutTimer->setSingleShot(true); - _ackTimeoutTimer->setInterval(_ackTimeoutMilliseconds); - + connect(_ackTimeoutTimer, &QTimer::timeout, this, &PlanManager::_ackTimeout); } @@ -245,6 +244,24 @@ void PlanManager::_ackTimeout(void) void PlanManager::_startAckTimeout(AckType_t ack) { + switch (ack) { + case AckMissionItem: + // We are actively trying to get the mission item, so we don't want to wait as long. + _ackTimeoutTimer->setInterval(_retryTimeoutMilliseconds); + break; + case AckNone: + // FALLTHROUGH + case AckMissionCount: + // FALLTHROUGH + case AckMissionRequest: + // FALLTHROUGH + case AckMissionClearAll: + // FALLTHROUGH + case AckGuidedItem: + _ackTimeoutTimer->setInterval(_ackTimeoutMilliseconds); + break; + } + _expectedAck = ack; _ackTimeoutTimer->start(); } diff --git a/src/MissionManager/PlanManager.h b/src/MissionManager/PlanManager.h index bb7b60c5c..b5c53b52a 100644 --- a/src/MissionManager/PlanManager.h +++ b/src/MissionManager/PlanManager.h @@ -28,11 +28,11 @@ Q_DECLARE_LOGGING_CATEGORY(PlanManagerLog) class PlanManager : public QObject { Q_OBJECT - + public: PlanManager(Vehicle* vehicle, MAV_MISSION_TYPE planType); ~PlanManager(); - + bool inProgress(void) const; const QList& missionItems(void) { return _missionItems; } @@ -41,11 +41,11 @@ public: /// Last current mission item reported while in Mission flight mode int lastCurrentIndex(void) const { return _lastCurrentIndex; } - + /// Load the mission items from the vehicle /// Signals newMissionItemsAvailable when done void loadFromVehicle(void); - + /// Writes the specified set of mission items to the vehicle /// IMPORTANT NOTE: PlanManager will take control of the MissionItem objects with the missionItems list. It will free them when done. /// @param missionItems Items to send to vehicle @@ -70,9 +70,12 @@ public: } ErrorCode_t; // These values are public so the unit test can set appropriate signal wait times + // When passively waiting for a mission process, use a longer timeout. static const int _ackTimeoutMilliseconds = 1000; + // When actively retrying to request mission items, use a shorter timeout instead. + static const int _retryTimeoutMilliseconds = 250; static const int _maxRetryCount = 5; - + signals: void newMissionItemsAvailable (bool removeAllRequested); void inProgressChanged (bool inProgress); @@ -88,7 +91,7 @@ signals: private slots: void _mavlinkMessageReceived(const mavlink_message_t& message); void _ackTimeout(void); - + protected: typedef enum { AckNone, ///< State machine is idle @@ -134,18 +137,18 @@ protected: Vehicle* _vehicle; MAV_MISSION_TYPE _planType; LinkInterface* _dedicatedLink; - + QTimer* _ackTimeoutTimer; AckType_t _expectedAck; int _retryCount; - + TransactionType_t _transactionInProgress; bool _resumeMission; QList _itemIndicesToWrite; ///< List of mission items which still need to be written to vehicle QList _itemIndicesToRead; ///< List of mission items which still need to be requested from vehicle int _lastMissionRequest; ///< Index of item last requested by MISSION_REQUEST int _missionItemCountToRead;///< Count of all mission items to read - + QList _missionItems; ///< Set of mission items on vehicle QList _writeMissionItems; ///< Set of mission items currently being written to vehicle int _currentMissionIndex; -- 2.22.0