Skip to content

Commit e2c0e5c

Browse files
MissionBase: replay the gimbal and trigger cached items only upon reaching resume waypoint (#23484)
* Fix: replay the mission cached items only upon reaching resume waypoint * Refactoring Split camera mode mission items from gimbal ones so to have a finer control over the relative replays * Chore: fix formatting --------- Co-authored-by: Silvan Fuhrer <silvan@auterion.com>
1 parent aad607e commit e2c0e5c

2 files changed

Lines changed: 47 additions & 16 deletions

File tree

src/modules/navigator/mission_base.cpp

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,7 @@ MissionBase::on_activation()
235235
checkClimbRequired(_mission.current_seq);
236236
set_mission_items();
237237

238+
_mission_activation_index = _mission.current_seq;
238239
_inactivation_index = -1; // reset
239240

240241
// reset cruise speed
@@ -293,17 +294,27 @@ MissionBase::on_active()
293294
_align_heading_necessary = false;
294295
}
295296

296-
// replay gimbal and camera commands immediately after resuming mission
297-
if (haveCachedGimbalOrCameraItems()) {
298-
replayCachedGimbalCameraItems();
297+
// Replay camera mode commands immediately upon mission resume
298+
if (haveCachedCameraModeItems()) {
299+
replayCachedCameraModeItems();
299300
}
300301

301-
// replay trigger commands upon raching the resume waypoint if the trigger relay flag is set
302-
if (cameraWasTriggering() && is_mission_item_reached_or_completed()) {
303-
replayCachedTriggerItems();
304-
}
305302

306-
replayCachedSpeedChangeItems();
303+
// Replay cached mission commands once the last mission waypoint is re-reached after the mission interruption.
304+
// Each replay function also clears the cached items afterwards
305+
if (_mission.current_seq > _mission_activation_index) {
306+
// replay gimbal commands
307+
if (haveCachedGimbalItems()) {
308+
replayCachedGimbalItems();
309+
}
310+
311+
// replay trigger commands
312+
if (cameraWasTriggering()) {
313+
replayCachedTriggerItems();
314+
}
315+
316+
replayCachedSpeedChangeItems();
317+
}
307318

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

1258-
void MissionBase::replayCachedGimbalCameraItems()
1269+
void MissionBase::replayCachedGimbalItems()
12591270
{
12601271
if (_last_gimbal_configure_item.nav_cmd > 0) {
12611272
issue_command(_last_gimbal_configure_item);
@@ -1266,7 +1277,10 @@ void MissionBase::replayCachedGimbalCameraItems()
12661277
issue_command(_last_gimbal_control_item);
12671278
_last_gimbal_control_item = {}; // delete cached item
12681279
}
1280+
}
12691281

1282+
void MissionBase::replayCachedCameraModeItems()
1283+
{
12701284
if (_last_camera_mode_item.nav_cmd > 0) {
12711285
issue_command(_last_camera_mode_item);
12721286
_last_camera_mode_item = {}; // delete cached item
@@ -1297,11 +1311,15 @@ void MissionBase::resetItemCache()
12971311
_last_camera_trigger_item = {};
12981312
}
12991313

1300-
bool MissionBase::haveCachedGimbalOrCameraItems()
1314+
bool MissionBase::haveCachedGimbalItems()
13011315
{
13021316
return _last_gimbal_configure_item.nav_cmd > 0 ||
1303-
_last_gimbal_control_item.nav_cmd > 0 ||
1304-
_last_camera_mode_item.nav_cmd > 0;
1317+
_last_gimbal_control_item.nav_cmd > 0;
1318+
}
1319+
1320+
bool MissionBase::haveCachedCameraModeItems()
1321+
{
1322+
return _last_camera_mode_item.nav_cmd > 0;
13051323
}
13061324

13071325
bool MissionBase::cameraWasTriggering()

src/modules/navigator/mission_base.h

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,7 @@ class MissionBase : public MissionBlock, public ModuleParams
328328
mission_s _mission; /**< Currently active mission*/
329329
float _mission_init_climb_altitude_amsl{NAN}; /**< altitude AMSL the vehicle will climb to when mission starts */
330330
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.
331+
int _mission_activation_index{-1}; /**< Index of the mission item that will bring the vehicle back to a mission waypoint */
331332

332333
int32_t _load_mission_index{-1}; /**< Mission inted of loaded mission items in dataman cache*/
333334
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*/
@@ -398,9 +399,14 @@ class MissionBase : public MissionBlock, public ModuleParams
398399
void updateCachedItemsUpToIndex(int end_index);
399400

400401
/**
401-
* @brief Replay the cached gimbal and camera mode items
402+
* @brief Replay the cached gimbal items
402403
*/
403-
void replayCachedGimbalCameraItems();
404+
void replayCachedGimbalItems();
405+
406+
/**
407+
* @brief Replay the cached camera mode items
408+
*/
409+
void replayCachedCameraModeItems();
404410

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

417423
/**
418-
* @brief Check if there are cached gimbal or camera mode items to be replayed
424+
* @brief Check if there are cached gimbal items to be replayed
425+
*
426+
* @return true if there are cached items
427+
*/
428+
bool haveCachedGimbalItems();
429+
430+
/**
431+
* @brief Check if there are cached camera mode items to be replayed
419432
*
420433
* @return true if there are cached items
421434
*/
422-
bool haveCachedGimbalOrCameraItems();
435+
bool haveCachedCameraModeItems();
423436

424437
/**
425438
* @brief Check if the camera was triggering

0 commit comments

Comments
 (0)