Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: replay the mission cached items only upon reaching resume waypoint #23484

Merged
merged 4 commits into from
Aug 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 30 additions & 12 deletions src/modules/navigator/mission_base.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@ MissionBase::on_activation()
checkClimbRequired(_mission.current_seq);
set_mission_items();

_mission_activation_index = _mission.current_seq;
_inactivation_index = -1; // reset

// reset cruise speed
Expand Down Expand Up @@ -293,17 +294,27 @@ MissionBase::on_active()
_align_heading_necessary = false;
}

// replay gimbal and camera commands immediately after resuming mission
if (haveCachedGimbalOrCameraItems()) {
replayCachedGimbalCameraItems();
// Replay camera mode commands immediately upon mission resume
if (haveCachedCameraModeItems()) {
replayCachedCameraModeItems();
}

// replay trigger commands upon raching the resume waypoint if the trigger relay flag is set
if (cameraWasTriggering() && is_mission_item_reached_or_completed()) {
replayCachedTriggerItems();
}

replayCachedSpeedChangeItems();
// Replay cached mission commands once the last mission waypoint is re-reached after the mission interruption.
// Each replay function also clears the cached items afterwards
if (_mission.current_seq > _mission_activation_index) {
// replay gimbal commands
if (haveCachedGimbalItems()) {
replayCachedGimbalItems();
}

// replay trigger commands
if (cameraWasTriggering()) {
replayCachedTriggerItems();
}

replayCachedSpeedChangeItems();
}

/* lets check if we reached the current mission item */
if (_mission_type != MissionType::MISSION_TYPE_NONE && is_mission_item_reached_or_completed()) {
Expand Down Expand Up @@ -1255,7 +1266,7 @@ void MissionBase::cacheItem(const mission_item_s &mission_item)
}
}

void MissionBase::replayCachedGimbalCameraItems()
void MissionBase::replayCachedGimbalItems()
{
if (_last_gimbal_configure_item.nav_cmd > 0) {
issue_command(_last_gimbal_configure_item);
Expand All @@ -1266,7 +1277,10 @@ void MissionBase::replayCachedGimbalCameraItems()
issue_command(_last_gimbal_control_item);
_last_gimbal_control_item = {}; // delete cached item
}
}

void MissionBase::replayCachedCameraModeItems()
{
if (_last_camera_mode_item.nav_cmd > 0) {
issue_command(_last_camera_mode_item);
_last_camera_mode_item = {}; // delete cached item
Expand Down Expand Up @@ -1297,11 +1311,15 @@ void MissionBase::resetItemCache()
_last_camera_trigger_item = {};
}

bool MissionBase::haveCachedGimbalOrCameraItems()
bool MissionBase::haveCachedGimbalItems()
{
return _last_gimbal_configure_item.nav_cmd > 0 ||
_last_gimbal_control_item.nav_cmd > 0 ||
_last_camera_mode_item.nav_cmd > 0;
_last_gimbal_control_item.nav_cmd > 0;
}

bool MissionBase::haveCachedCameraModeItems()
{
return _last_camera_mode_item.nav_cmd > 0;
}

bool MissionBase::cameraWasTriggering()
Expand Down
21 changes: 17 additions & 4 deletions src/modules/navigator/mission_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,7 @@ class MissionBase : public MissionBlock, public ModuleParams
mission_s _mission; /**< Currently active mission*/
float _mission_init_climb_altitude_amsl{NAN}; /**< altitude AMSL the vehicle will climb to when mission starts */
int _inactivation_index{-1}; // index of mission item at which the mission was paused. Used to resume survey missions at previous waypoint to not lose images.
int _mission_activation_index{-1}; /**< Index of the mission item that will bring the vehicle back to a mission waypoint */

int32_t _load_mission_index{-1}; /**< Mission inted of loaded mission items in dataman cache*/
int32_t _dataman_cache_size_signed; /**< Size of the dataman cache. A negativ value indicates that previous mission items should be loaded, a positiv value the next mission items*/
Expand Down Expand Up @@ -398,9 +399,14 @@ class MissionBase : public MissionBlock, public ModuleParams
void updateCachedItemsUpToIndex(int end_index);

/**
* @brief Replay the cached gimbal and camera mode items
* @brief Replay the cached gimbal items
*/
void replayCachedGimbalCameraItems();
void replayCachedGimbalItems();

/**
* @brief Replay the cached camera mode items
*/
void replayCachedCameraModeItems();

/**
* @brief Replay the cached trigger items
Expand All @@ -415,11 +421,18 @@ class MissionBase : public MissionBlock, public ModuleParams
void replayCachedSpeedChangeItems();

/**
* @brief Check if there are cached gimbal or camera mode items to be replayed
* @brief Check if there are cached gimbal items to be replayed
*
* @return true if there are cached items
*/
bool haveCachedGimbalItems();

/**
* @brief Check if there are cached camera mode items to be replayed
*
* @return true if there are cached items
*/
bool haveCachedGimbalOrCameraItems();
bool haveCachedCameraModeItems();

/**
* @brief Check if the camera was triggering
Expand Down
Loading