Skip to content

Commit c0e120a

Browse files
authored
Merge pull request #10042 from breadoven/abo_trackback_logic_fix
RTH trackback code cleanup
2 parents b96c3d4 + c9779c2 commit c0e120a

File tree

3 files changed

+11
-14
lines changed

3 files changed

+11
-14
lines changed

src/main/navigation/navigation.c

+2-6
Original file line numberDiff line numberDiff line change
@@ -301,10 +301,6 @@ bool validateRTHSanityChecker(void);
301301
void updateHomePosition(void);
302302
bool abortLaunchAllowed(void);
303303

304-
// static bool rthAltControlStickOverrideCheck(unsigned axis);
305-
// static void updateRthTrackback(bool forceSaveTrackPoint);
306-
// static fpVector3_t * rthGetTrackbackPos(void);
307-
308304
#ifdef USE_FW_AUTOLAND
309305
static float getLandAltitude(void);
310306
static int32_t calcWindDiff(int32_t heading, int32_t windHeading);
@@ -1449,7 +1445,7 @@ static navigationFSMEvent_t navOnEnteringState_NAV_STATE_RTH_INITIALIZE(navigati
14491445
}
14501446
else {
14511447
// Switch to RTH trackback
1452-
if (rthTrackBackIsActive() && rth_trackback.activePointIndex >= 0 && !isWaypointMissionRTHActive()) {
1448+
if (rthTrackBackCanBeActivated() && rth_trackback.activePointIndex >= 0 && !isWaypointMissionRTHActive()) {
14531449
rthTrackBackUpdate(true); // save final trackpoint for altitude and max trackback distance reference
14541450
posControl.flags.rthTrackbackActive = true;
14551451
calculateAndSetActiveWaypointToLocalPosition(getRthTrackBackPosition());
@@ -1568,7 +1564,7 @@ static navigationFSMEvent_t navOnEnteringState_NAV_STATE_RTH_TRACKBACK(navigatio
15681564
return NAV_FSM_EVENT_SWITCH_TO_EMERGENCY_LANDING;
15691565
}
15701566

1571-
if (rthTrackBackSetNewPosition()) {
1567+
if (!rthTrackBackSetNewPosition()) {
15721568
return NAV_FSM_EVENT_SWITCH_TO_NAV_STATE_RTH_INITIALIZE;
15731569
}
15741570

src/main/navigation/rth_trackback.c

+8-7
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,10 @@
3737

3838
rth_trackback_t rth_trackback;
3939

40-
bool rthTrackBackIsActive(void)
40+
bool rthTrackBackCanBeActivated(void)
4141
{
42-
return navConfig()->general.flags.rth_trackback_mode == RTH_TRACKBACK_ON || (navConfig()->general.flags.rth_trackback_mode == RTH_TRACKBACK_FS && posControl.flags.forcedRTHActivated);
42+
return posControl.flags.estPosStatus >= EST_USABLE &&
43+
(navConfig()->general.flags.rth_trackback_mode == RTH_TRACKBACK_ON || (navConfig()->general.flags.rth_trackback_mode == RTH_TRACKBACK_FS && posControl.flags.forcedRTHActivated));
4344
}
4445

4546
void rthTrackBackUpdate(bool forceSaveTrackPoint)
@@ -127,7 +128,7 @@ void rthTrackBackUpdate(bool forceSaveTrackPoint)
127128
bool rthTrackBackSetNewPosition(void)
128129
{
129130
if (posControl.flags.estPosStatus == EST_NONE) {
130-
return false;
131+
return false; // will fall back to RTH initialize allowing full RTH to handle position loss correctly
131132
}
132133

133134
const int32_t distFromStartTrackback = CENTIMETERS_TO_METERS(calculateDistanceToDestination(&rth_trackback.pointsList[rth_trackback.lastSavedIndex]));
@@ -142,7 +143,7 @@ bool rthTrackBackSetNewPosition(void)
142143
if (rth_trackback.activePointIndex < 0 || cancelTrackback) {
143144
rth_trackback.WrapAroundCounter = rth_trackback.activePointIndex = -1;
144145
posControl.flags.rthTrackbackActive = false;
145-
return true; // Procede to home after final trackback point
146+
return false; // No more trackback points to set, procede to home
146147
}
147148

148149
if (isWaypointReached(&posControl.activeWaypoint.pos, &posControl.activeWaypoint.bearing)) {
@@ -161,7 +162,7 @@ bool rthTrackBackSetNewPosition(void)
161162
setDesiredPosition(getRthTrackBackPosition(), 0, NAV_POS_UPDATE_XY | NAV_POS_UPDATE_Z | NAV_POS_UPDATE_BEARING);
162163
}
163164

164-
return false;
165+
return true;
165166
}
166167

167168
fpVector3_t *getRthTrackBackPosition(void)
@@ -174,9 +175,9 @@ fpVector3_t *getRthTrackBackPosition(void)
174175
return &rth_trackback.pointsList[rth_trackback.activePointIndex];
175176
}
176177

177-
void resetRthTrackBack(void)
178+
void resetRthTrackBack(void)
178179
{
179180
rth_trackback.activePointIndex = -1;
180181
posControl.flags.rthTrackbackActive = false;
181-
rth_trackback.WrapAroundCounter = -1;
182+
rth_trackback.WrapAroundCounter = -1;
182183
}

src/main/navigation/rth_trackback.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ typedef struct
3535

3636
extern rth_trackback_t rth_trackback;
3737

38-
bool rthTrackBackIsActive(void);
38+
bool rthTrackBackCanBeActivated(void);
3939
bool rthTrackBackSetNewPosition(void);
4040
void rthTrackBackUpdate(bool forceSaveTrackPoint);
4141
fpVector3_t *getRthTrackBackPosition(void);

0 commit comments

Comments
 (0)