Skip to content

Commit

Permalink
Refactoring
Browse files Browse the repository at this point in the history
Split camera mode mission items from gimbal ones so to have a finer control over the relative replays
  • Loading branch information
StefanoColli committed Aug 13, 2024
1 parent 28f4eca commit df16c68
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 15 deletions.
33 changes: 23 additions & 10 deletions src/modules/navigator/mission_base.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ MissionBase::on_activation()
checkClimbRequired(_mission.current_seq);
set_mission_items();

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

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

// Replay camera mode commands immediately upon mission resume
if (haveCachedCameraModeItems()){
replayCachedCameraModeItems();
}


// 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 > _replay_index)
if (_mission.current_seq > _mission_activation_index)
{
// replay gimbal and camera commands immediately after resuming mission
if (haveCachedGimbalOrCameraItems()) {
replayCachedGimbalCameraItems();
// replay gimbal commands
if (haveCachedGimbalItems()) {
replayCachedGimbalItems();
}

// replay trigger commands upon
// replay trigger commands
if (cameraWasTriggering()) {
replayCachedTriggerItems();
}
Expand Down Expand Up @@ -1261,7 +1267,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 @@ -1272,7 +1278,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 @@ -1303,11 +1312,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
22 changes: 17 additions & 5 deletions src/modules/navigator/mission_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +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 _replay_index{-1}; /**< Index of the mission item that will bring the drone back to a mission waypoint */
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 @@ -399,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 @@ -416,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

0 comments on commit df16c68

Please sign in to comment.