Unverified Commit 52816235 authored by Don Gagne's avatar Don Gagne Committed by GitHub

Merge pull request #6059 from mavlink/fix-mission-upload-download

Robustify mission upload/download
parents c8637237 8dee2570
...@@ -30,13 +30,13 @@ PlanManager::PlanManager(Vehicle* vehicle, MAV_MISSION_TYPE planType) ...@@ -30,13 +30,13 @@ PlanManager::PlanManager(Vehicle* vehicle, MAV_MISSION_TYPE planType)
, _transactionInProgress(TransactionNone) , _transactionInProgress(TransactionNone)
, _resumeMission(false) , _resumeMission(false)
, _lastMissionRequest(-1) , _lastMissionRequest(-1)
, _missionItemCountToRead(-1)
, _currentMissionIndex(-1) , _currentMissionIndex(-1)
, _lastCurrentIndex(-1) , _lastCurrentIndex(-1)
{ {
_ackTimeoutTimer = new QTimer(this); _ackTimeoutTimer = new QTimer(this);
_ackTimeoutTimer->setSingleShot(true); _ackTimeoutTimer->setSingleShot(true);
_ackTimeoutTimer->setInterval(_ackTimeoutMilliseconds);
connect(_ackTimeoutTimer, &QTimer::timeout, this, &PlanManager::_ackTimeout); connect(_ackTimeoutTimer, &QTimer::timeout, this, &PlanManager::_ackTimeout);
} }
...@@ -244,6 +244,24 @@ void PlanManager::_ackTimeout(void) ...@@ -244,6 +244,24 @@ void PlanManager::_ackTimeout(void)
void PlanManager::_startAckTimeout(AckType_t ack) 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; _expectedAck = ack;
_ackTimeoutTimer->start(); _ackTimeoutTimer->start();
} }
...@@ -317,6 +335,7 @@ void PlanManager::_handleMissionCount(const mavlink_message_t& message) ...@@ -317,6 +335,7 @@ void PlanManager::_handleMissionCount(const mavlink_message_t& message)
for (int i=0; i<missionCount.count; i++) { for (int i=0; i<missionCount.count; i++) {
_itemIndicesToRead << i; _itemIndicesToRead << i;
} }
_missionItemCountToRead = missionCount.count;
_requestNextMissionItem(); _requestNextMissionItem();
} }
} }
...@@ -460,7 +479,7 @@ void PlanManager::_handleMissionItem(const mavlink_message_t& message, bool miss ...@@ -460,7 +479,7 @@ void PlanManager::_handleMissionItem(const mavlink_message_t& message, bool miss
return; return;
} }
emit progressPct((double)seq / (double)_missionItems.count()); emit progressPct((double)seq / (double)_missionItemCountToRead);
_retryCount = 0; _retryCount = 0;
if (_itemIndicesToRead.count() == 0) { if (_itemIndicesToRead.count() == 0) {
......
...@@ -28,11 +28,11 @@ Q_DECLARE_LOGGING_CATEGORY(PlanManagerLog) ...@@ -28,11 +28,11 @@ Q_DECLARE_LOGGING_CATEGORY(PlanManagerLog)
class PlanManager : public QObject class PlanManager : public QObject
{ {
Q_OBJECT Q_OBJECT
public: public:
PlanManager(Vehicle* vehicle, MAV_MISSION_TYPE planType); PlanManager(Vehicle* vehicle, MAV_MISSION_TYPE planType);
~PlanManager(); ~PlanManager();
bool inProgress(void) const; bool inProgress(void) const;
const QList<MissionItem*>& missionItems(void) { return _missionItems; } const QList<MissionItem*>& missionItems(void) { return _missionItems; }
...@@ -41,11 +41,11 @@ public: ...@@ -41,11 +41,11 @@ public:
/// Last current mission item reported while in Mission flight mode /// Last current mission item reported while in Mission flight mode
int lastCurrentIndex(void) const { return _lastCurrentIndex; } int lastCurrentIndex(void) const { return _lastCurrentIndex; }
/// Load the mission items from the vehicle /// Load the mission items from the vehicle
/// Signals newMissionItemsAvailable when done /// Signals newMissionItemsAvailable when done
void loadFromVehicle(void); void loadFromVehicle(void);
/// Writes the specified set of mission items to the vehicle /// 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. /// 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 /// @param missionItems Items to send to vehicle
...@@ -70,9 +70,12 @@ public: ...@@ -70,9 +70,12 @@ public:
} ErrorCode_t; } ErrorCode_t;
// These values are public so the unit test can set appropriate signal wait times // 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; 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; static const int _maxRetryCount = 5;
signals: signals:
void newMissionItemsAvailable (bool removeAllRequested); void newMissionItemsAvailable (bool removeAllRequested);
void inProgressChanged (bool inProgress); void inProgressChanged (bool inProgress);
...@@ -88,7 +91,7 @@ signals: ...@@ -88,7 +91,7 @@ signals:
private slots: private slots:
void _mavlinkMessageReceived(const mavlink_message_t& message); void _mavlinkMessageReceived(const mavlink_message_t& message);
void _ackTimeout(void); void _ackTimeout(void);
protected: protected:
typedef enum { typedef enum {
AckNone, ///< State machine is idle AckNone, ///< State machine is idle
...@@ -134,17 +137,18 @@ protected: ...@@ -134,17 +137,18 @@ protected:
Vehicle* _vehicle; Vehicle* _vehicle;
MAV_MISSION_TYPE _planType; MAV_MISSION_TYPE _planType;
LinkInterface* _dedicatedLink; LinkInterface* _dedicatedLink;
QTimer* _ackTimeoutTimer; QTimer* _ackTimeoutTimer;
AckType_t _expectedAck; AckType_t _expectedAck;
int _retryCount; int _retryCount;
TransactionType_t _transactionInProgress; TransactionType_t _transactionInProgress;
bool _resumeMission; bool _resumeMission;
QList<int> _itemIndicesToWrite; ///< List of mission items which still need to be written to vehicle QList<int> _itemIndicesToWrite; ///< List of mission items which still need to be written to vehicle
QList<int> _itemIndicesToRead; ///< List of mission items which still need to be requested from vehicle QList<int> _itemIndicesToRead; ///< List of mission items which still need to be requested from vehicle
int _lastMissionRequest; ///< Index of item last requested by MISSION_REQUEST int _lastMissionRequest; ///< Index of item last requested by MISSION_REQUEST
int _missionItemCountToRead;///< Count of all mission items to read
QList<MissionItem*> _missionItems; ///< Set of mission items on vehicle QList<MissionItem*> _missionItems; ///< Set of mission items on vehicle
QList<MissionItem*> _writeMissionItems; ///< Set of mission items currently being written to vehicle QList<MissionItem*> _writeMissionItems; ///< Set of mission items currently being written to vehicle
int _currentMissionIndex; int _currentMissionIndex;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment