QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
PlanManager Class Reference

The PlanManager class is the base class for the Mission, GeoFence and Rally Point managers. All of which use the new mavlink v2 mission protocol. More...

#include <PlanManager.h>

Inheritance diagram for PlanManager:
Collaboration diagram for PlanManager:

Public Types

enum  ErrorCode_t {
  InternalError , AckTimeoutError , ProtocolError , RequestRangeError ,
  ItemMismatchError , VehicleAckError , MissingRequestsError , MaxRetryExceeded ,
  MissionTypeMismatch
}
 Error codes returned in error signal. More...

Signals

void newMissionItemsAvailable (bool removeAllRequested)
void inProgressChanged (bool inProgress)
void error (int errorCode, const QString &errorMsg)
void currentIndexChanged (int currentIndex)
void lastCurrentIndexChanged (int lastCurrentIndex)
void progressPctChanged (double progressPercentPct)
void removeAllComplete (bool error)
void sendComplete (bool error)
void resumeMissionReady (void)
void resumeMissionUploadFail (void)

Public Member Functions

 PlanManager (Vehicle *vehicle, MAV_MISSION_TYPE planType)
 ~PlanManager ()
bool inProgress (void) const
const QList< MissionItem * > & missionItems (void)
int currentIndex (void) const
 Current mission item as reported by MISSION_CURRENT.
int lastCurrentIndex (void) const
 Last current mission item reported while in Mission flight mode.
void loadFromVehicle (void)
void writeMissionItems (const QList< MissionItem * > &missionItems)
void removeAll (void)

Static Public Attributes

static constexpr int _ackTimeoutMilliseconds = 1500
static constexpr int _retryTimeoutMilliseconds = 250
static constexpr int _maxRetryCount = 5
static constexpr int kTestAckTimeoutMs = 50
 Ack timeout used in unit tests (much shorter for faster tests).

Protected Types

enum  AckType_t {
  AckNone , AckMissionCount , AckMissionItem , AckMissionRequest ,
  AckMissionClearAll , AckGuidedItem
}
enum  TransactionType_t { TransactionNone , TransactionRead , TransactionWrite , TransactionRemoveAll }

Protected Member Functions

void _startAckTimeout (AckType_t ack)
bool _checkForExpectedAck (AckType_t receivedAck)
void _readTransactionComplete (void)
void _handleMissionCount (const mavlink_message_t &message)
void _handleMissionItem (const mavlink_message_t &message)
void _handleMissionRequest (const mavlink_message_t &message)
void _handleMissionAck (const mavlink_message_t &message)
void _requestNextMissionItem (void)
void _sendMissionItem (int seq)
void _clearMissionItems (void)
void _sendError (ErrorCode_t errorCode, const QString &errorMsg)
QString _ackTypeToString (AckType_t ackType)
QString _missionResultToString (MAV_MISSION_RESULT result)
void _finishTransaction (bool success, bool apmGuidedItemWrite=false)
void _requestList (void)
 Internal call to request list of mission items. May be called during a retry sequence.
void _writeMissionCount (void)
 This begins the write sequence with the vehicle. This may be called during a retry.
void _writeMissionItemsWorker (void)
void _clearAndDeleteMissionItems (void)
void _clearAndDeleteWriteMissionItems (void)
QString _lastMissionReqestString (MAV_MISSION_RESULT result)
void _removeAllWorker (void)
void _connectToMavlink (void)
void _disconnectFromMavlink (void)
QString _planTypeString (void)

Protected Attributes

Vehicle * _vehicle = nullptr
MAV_MISSION_TYPE _planType
QTimer * _ackTimeoutTimer = nullptr
AckType_t _expectedAck
int _retryCount
TransactionType_t _transactionInProgress
bool _resumeMission
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.
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 * > _writeMissionItems
 Set of mission items currently being written to vehicle.
int _currentMissionIndex
int _lastCurrentIndex

Detailed Description

The PlanManager class is the base class for the Mission, GeoFence and Rally Point managers. All of which use the new mavlink v2 mission protocol.

Definition at line 13 of file PlanManager.h.

Member Enumeration Documentation

◆ AckType_t

enum PlanManager::AckType_t
protected
Enumerator
AckNone 

State machine is idle.

AckMissionCount 

MISSION_COUNT message expected.

AckMissionItem 

MISSION_ITEM expected.

AckMissionRequest 

MISSION_REQUEST is expected, or MISSION_ACK to end sequence.

AckMissionClearAll 

MISSION_CLEAR_ALL sent, MISSION_ACK is expected.

AckGuidedItem 

MISSION_ACK expected in response to ArduPilot guided mode single item send.

Definition at line 84 of file PlanManager.h.

◆ ErrorCode_t

Error codes returned in error signal.

Enumerator
InternalError 
AckTimeoutError 

Timed out waiting for response from vehicle.

ProtocolError 

Incorrect protocol sequence from vehicle.

RequestRangeError 

Vehicle requested item out of range.

ItemMismatchError 

Vehicle returned item with seq # different than requested.

VehicleAckError 

Vehicle returned error in ack.

MissingRequestsError 

Vehicle did not request all items during write sequence.

MaxRetryExceeded 

Retry failed.

MissionTypeMismatch 

MAV_MISSION_TYPE does not match _planType.

Definition at line 45 of file PlanManager.h.

◆ TransactionType_t

Enumerator
TransactionNone 
TransactionRead 
TransactionWrite 
TransactionRemoveAll 

Definition at line 93 of file PlanManager.h.

Constructor & Destructor Documentation

◆ PlanManager()

◆ ~PlanManager()

PlanManager::~PlanManager ( )

Definition at line 33 of file PlanManager.cc.

Member Function Documentation

◆ _ackTypeToString()

QString PlanManager::_ackTypeToString ( AckType_t ackType)
protected

◆ _checkForExpectedAck()

bool PlanManager::_checkForExpectedAck ( AckType_t receivedAck)
protected

Checks the received ack against the expected ack. If they match the ack timeout timer will be stopped.

Returns
true: received ack matches expected ack

Definition at line 287 of file PlanManager.cc.

References _ackTimeoutTimer, _ackTypeToString(), _expectedAck, _planTypeString(), and AckNone.

Referenced by _handleMissionAck(), _handleMissionCount(), _handleMissionItem(), and _handleMissionRequest().

◆ _clearAndDeleteMissionItems()

void PlanManager::_clearAndDeleteMissionItems ( void )
protected

Definition at line 950 of file PlanManager.cc.

References _missionItems.

Referenced by _clearMissionItems(), _finishTransaction(), and removeAll().

◆ _clearAndDeleteWriteMissionItems()

void PlanManager::_clearAndDeleteWriteMissionItems ( void )
protected

◆ _clearMissionItems()

void PlanManager::_clearMissionItems ( void )
protected

Definition at line 498 of file PlanManager.cc.

References _clearAndDeleteMissionItems(), and _itemIndicesToRead.

Referenced by _requestList().

◆ _connectToMavlink()

void PlanManager::_connectToMavlink ( void )
protected

◆ _disconnectFromMavlink()

void PlanManager::_disconnectFromMavlink ( void )
protected

Definition at line 974 of file PlanManager.cc.

References _vehicle, and Vehicle::mavlinkMessageReceived().

Referenced by _finishTransaction().

◆ _finishTransaction()

◆ _handleMissionAck()

◆ _handleMissionCount()

◆ _handleMissionItem()

◆ _handleMissionRequest()

◆ _lastMissionReqestString()

◆ _missionResultToString()

QString PlanManager::_missionResultToString ( MAV_MISSION_RESULT result)
protected

Definition at line 774 of file PlanManager.cc.

References _lastMissionReqestString(), _planTypeString(), and error().

Referenced by _handleMissionAck().

◆ _planTypeString()

◆ _readTransactionComplete()

void PlanManager::_readTransactionComplete ( void )
protected

◆ _removeAllWorker()

void PlanManager::_removeAllWorker ( void )
protected

◆ _requestList()

void PlanManager::_requestList ( void )
protected

Internal call to request list of mission items. May be called during a retry sequence.

Definition at line 145 of file PlanManager.cc.

References _clearMissionItems(), _itemIndicesToRead, _planType, _planTypeString(), _retryCount, _startAckTimeout(), _vehicle, AckMissionCount, MAVLinkProtocol::getComponentId(), and MAVLinkProtocol::instance().

Referenced by loadFromVehicle().

◆ _requestNextMissionItem()

◆ _sendError()

void PlanManager::_sendError ( ErrorCode_t errorCode,
const QString & errorMsg )
protected

Definition at line 699 of file PlanManager.cc.

References _planTypeString(), and error().

Referenced by _handleMissionAck(), _handleMissionRequest(), and _requestNextMissionItem().

◆ _sendMissionItem()

void PlanManager::_sendMissionItem ( int seq)
protected

Sends a single mission item to the vehicle as part of a write transaction and (re-)starts the ack timeout. Used both for the initial send in response to MISSION_REQUEST(_INT), and to resend the last item if the final MISSION_ACK times out (the vehicle may have stored it but the ack got dropped on the way back).

Definition at line 551 of file PlanManager.cc.

References _planType, _planTypeString(), _startAckTimeout(), _vehicle, _writeMissionItems, AckMissionRequest, MissionItem::autoContinue(), MissionItem::command(), MissionItem::frame(), MAVLinkProtocol::getComponentId(), MAVLinkProtocol::instance(), MissionItem::param1(), MissionItem::param2(), MissionItem::param3(), MissionItem::param4(), MissionItem::param5(), MissionItem::param6(), and MissionItem::param7().

Referenced by _handleMissionRequest().

◆ _startAckTimeout()

◆ _writeMissionCount()

void PlanManager::_writeMissionCount ( void )
protected

This begins the write sequence with the vehicle. This may be called during a retry.

Definition at line 100 of file PlanManager.cc.

References _planType, _planTypeString(), _retryCount, _startAckTimeout(), _vehicle, _writeMissionItems, AckMissionRequest, MAVLinkProtocol::getComponentId(), and MAVLinkProtocol::instance().

Referenced by _writeMissionItemsWorker().

◆ _writeMissionItemsWorker()

◆ currentIndex()

int PlanManager::currentIndex ( void ) const
inline

Current mission item as reported by MISSION_CURRENT.

Definition at line 25 of file PlanManager.h.

References _currentMissionIndex.

Referenced by currentIndexChanged().

◆ currentIndexChanged

void PlanManager::currentIndexChanged ( int currentIndex)
signal

References currentIndex().

Referenced by _finishTransaction(), and removeAll().

◆ error

void PlanManager::error ( int errorCode,
const QString & errorMsg )
signal

◆ inProgress()

◆ inProgressChanged

void PlanManager::inProgressChanged ( bool inProgress)
signal

◆ lastCurrentIndex()

int PlanManager::lastCurrentIndex ( void ) const
inline

Last current mission item reported while in Mission flight mode.

Definition at line 28 of file PlanManager.h.

References _lastCurrentIndex.

Referenced by lastCurrentIndexChanged().

◆ lastCurrentIndexChanged

void PlanManager::lastCurrentIndexChanged ( int lastCurrentIndex)
signal

References lastCurrentIndex().

Referenced by _finishTransaction(), and removeAll().

◆ loadFromVehicle()

void PlanManager::loadFromVehicle ( void )

Load the mission items from the vehicle Signals newMissionItemsAvailable when done

Definition at line 125 of file PlanManager.cc.

References _connectToMavlink(), _planTypeString(), _requestList(), _retryCount, _vehicle, inProgress(), and TransactionRead.

◆ missionItems()

const QList< MissionItem * > & PlanManager::missionItems ( void )
inline

Definition at line 22 of file PlanManager.h.

References _missionItems.

Referenced by writeMissionItems().

◆ newMissionItemsAvailable

void PlanManager::newMissionItemsAvailable ( bool removeAllRequested)
signal

◆ progressPctChanged

void PlanManager::progressPctChanged ( double progressPercentPct)
signal

◆ removeAll()

void PlanManager::removeAll ( void )

◆ removeAllComplete

void PlanManager::removeAllComplete ( bool error)
signal

◆ resumeMissionReady

void PlanManager::resumeMissionReady ( void )
signal

Referenced by _finishTransaction().

◆ resumeMissionUploadFail

void PlanManager::resumeMissionUploadFail ( void )
signal

Referenced by _finishTransaction().

◆ sendComplete

void PlanManager::sendComplete ( bool error)
signal

◆ writeMissionItems()

void PlanManager::writeMissionItems ( const QList< MissionItem * > & missionItems)

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.

Parameters
missionItemsItems to send to vehicle Signals sendComplete when done

Definition at line 59 of file PlanManager.cc.

References _clearAndDeleteWriteMissionItems(), _planType, _planTypeString(), _vehicle, _writeMissionItems, _writeMissionItemsWorker(), MissionItem::command(), inProgress(), missionItems(), MissionItem::param1(), MissionItem::sequenceNumber(), MissionItem::setIsCurrentItem(), MissionItem::setParam1(), and MissionItem::setSequenceNumber().

Referenced by MissionController::sendItemsToVehicle(), GeoFenceManager::sendToVehicle(), and RallyPointManager::sendToVehicle().

Member Data Documentation

◆ _ackTimeoutMilliseconds

int PlanManager::_ackTimeoutMilliseconds = 1500
staticconstexpr

Definition at line 59 of file PlanManager.h.

Referenced by _startAckTimeout().

◆ _ackTimeoutTimer

QTimer* PlanManager::_ackTimeoutTimer = nullptr
protected

Definition at line 129 of file PlanManager.h.

Referenced by _checkForExpectedAck(), _startAckTimeout(), and PlanManager().

◆ _currentMissionIndex

int PlanManager::_currentMissionIndex
protected

◆ _expectedAck

AckType_t PlanManager::_expectedAck
protected

◆ _itemIndicesToRead

QList<int> PlanManager::_itemIndicesToRead
protected

List of mission items which still need to be requested from vehicle.

Definition at line 136 of file PlanManager.h.

Referenced by _clearMissionItems(), _finishTransaction(), _handleMissionCount(), _handleMissionItem(), _requestList(), and _requestNextMissionItem().

◆ _itemIndicesToWrite

QList<int> PlanManager::_itemIndicesToWrite
protected

List of mission items which still need to be written to vehicle.

Definition at line 135 of file PlanManager.h.

Referenced by _finishTransaction(), _handleMissionAck(), _handleMissionRequest(), and _writeMissionItemsWorker().

◆ _lastCurrentIndex

int PlanManager::_lastCurrentIndex
protected

◆ _lastMissionRequest

int PlanManager::_lastMissionRequest
protected

Index of item last requested by MISSION_REQUEST.

Definition at line 137 of file PlanManager.h.

Referenced by _handleMissionRequest(), _lastMissionReqestString(), _writeMissionItemsWorker(), and PlanManager().

◆ _maxRetryCount

int PlanManager::_maxRetryCount = 5
staticconstexpr

Definition at line 62 of file PlanManager.h.

◆ _missionItemCountToRead

int PlanManager::_missionItemCountToRead
protected

Count of all mission items to read.

Definition at line 138 of file PlanManager.h.

Referenced by _handleMissionCount(), _handleMissionItem(), and PlanManager().

◆ _missionItems

QList<MissionItem*> PlanManager::_missionItems
protected

Set of mission items on vehicle.

Definition at line 140 of file PlanManager.h.

Referenced by _clearAndDeleteMissionItems(), _finishTransaction(), _handleMissionItem(), MissionManager::generateResumeMission(), and missionItems().

◆ _planType

◆ _resumeMission

bool PlanManager::_resumeMission
protected

◆ _retryCount

◆ _retryTimeoutMilliseconds

int PlanManager::_retryTimeoutMilliseconds = 250
staticconstexpr

Definition at line 61 of file PlanManager.h.

Referenced by _startAckTimeout().

◆ _transactionInProgress

TransactionType_t PlanManager::_transactionInProgress
protected

◆ _vehicle

◆ _writeMissionItems

QList<MissionItem*> PlanManager::_writeMissionItems
protected

◆ kTestAckTimeoutMs

int PlanManager::kTestAckTimeoutMs = 50
staticconstexpr

Ack timeout used in unit tests (much shorter for faster tests).

Definition at line 65 of file PlanManager.h.

Referenced by _startAckTimeout().


The documentation for this class was generated from the following files: