mirror of
https://github.com/betaflight/betaflight.git
synced 2025-07-16 12:55:19 +03:00
Merge branch 'gps_rescue_update_fix' of https://github.com/codecae/betaflight
This commit is contained in:
commit
ce4a95f33d
4 changed files with 84 additions and 83 deletions
|
@ -924,10 +924,6 @@ static FAST_CODE_NOINLINE void subTaskMainSubprocesses(timeUs_t currentTimeUs)
|
|||
}
|
||||
#endif
|
||||
|
||||
#ifdef USE_GPS_RESCUE
|
||||
updateGPSRescueState();
|
||||
#endif
|
||||
|
||||
#ifdef USE_SDCARD
|
||||
afatfs_poll();
|
||||
#endif
|
||||
|
|
|
@ -109,79 +109,81 @@ void updateGPSRescueState(void)
|
|||
|
||||
switch (rescueState.phase) {
|
||||
case RESCUE_IDLE:
|
||||
idleTasks();
|
||||
break;
|
||||
idleTasks();
|
||||
break;
|
||||
case RESCUE_INITIALIZE:
|
||||
if (hoverThrottle == 0) { //no actual throttle data yet, let's use the default.
|
||||
hoverThrottle = gpsRescueConfig()->throttleHover;
|
||||
}
|
||||
if (hoverThrottle == 0) { //no actual throttle data yet, let's use the default.
|
||||
hoverThrottle = gpsRescueConfig()->throttleHover;
|
||||
}
|
||||
|
||||
rescueState.phase = RESCUE_ATTAIN_ALT;
|
||||
FALLTHROUGH;
|
||||
rescueState.phase = RESCUE_ATTAIN_ALT;
|
||||
FALLTHROUGH;
|
||||
case RESCUE_ATTAIN_ALT:
|
||||
// Get to a safe altitude at a low velocity ASAP
|
||||
if (ABS(rescueState.intent.targetAltitude - rescueState.sensor.currentAltitude) < 1000) {
|
||||
rescueState.phase = RESCUE_CROSSTRACK;
|
||||
}
|
||||
// Get to a safe altitude at a low velocity ASAP
|
||||
if (ABS(rescueState.intent.targetAltitude - rescueState.sensor.currentAltitude) < 1000) {
|
||||
rescueState.phase = RESCUE_CROSSTRACK;
|
||||
}
|
||||
|
||||
rescueState.intent.targetGroundspeed = 500;
|
||||
rescueState.intent.targetAltitude = MAX(gpsRescueConfig()->initialAltitude * 100, rescueState.sensor.maxAltitude + 1500);
|
||||
rescueState.intent.crosstrack = true;
|
||||
rescueState.intent.minAngleDeg = 10;
|
||||
rescueState.intent.maxAngleDeg = 15;
|
||||
break;
|
||||
rescueState.intent.targetGroundspeed = 500;
|
||||
rescueState.intent.targetAltitude = MAX(gpsRescueConfig()->initialAltitude * 100, rescueState.sensor.maxAltitude + 1500);
|
||||
rescueState.intent.crosstrack = true;
|
||||
rescueState.intent.minAngleDeg = 10;
|
||||
rescueState.intent.maxAngleDeg = 15;
|
||||
break;
|
||||
case RESCUE_CROSSTRACK:
|
||||
if (rescueState.sensor.distanceToHome < gpsRescueConfig()->descentDistance) {
|
||||
rescueState.phase = RESCUE_LANDING_APPROACH;
|
||||
}
|
||||
if (rescueState.sensor.distanceToHome < gpsRescueConfig()->descentDistance) {
|
||||
rescueState.phase = RESCUE_LANDING_APPROACH;
|
||||
}
|
||||
|
||||
// We can assume at this point that we are at or above our RTH height, so we need to try and point to home and tilt while maintaining alt
|
||||
// Is our altitude way off? We should probably kick back to phase RESCUE_ATTAIN_ALT
|
||||
rescueState.intent.targetGroundspeed = gpsRescueConfig()->rescueGroundspeed;
|
||||
rescueState.intent.targetAltitude = MAX(gpsRescueConfig()->initialAltitude * 100, rescueState.sensor.maxAltitude + 1500);
|
||||
rescueState.intent.crosstrack = true;
|
||||
rescueState.intent.minAngleDeg = 15;
|
||||
rescueState.intent.maxAngleDeg = gpsRescueConfig()->angle;
|
||||
break;
|
||||
// We can assume at this point that we are at or above our RTH height, so we need to try and point to home and tilt while maintaining alt
|
||||
// Is our altitude way off? We should probably kick back to phase RESCUE_ATTAIN_ALT
|
||||
rescueState.intent.targetGroundspeed = gpsRescueConfig()->rescueGroundspeed;
|
||||
rescueState.intent.targetAltitude = MAX(gpsRescueConfig()->initialAltitude * 100, rescueState.sensor.maxAltitude + 1500);
|
||||
rescueState.intent.crosstrack = true;
|
||||
rescueState.intent.minAngleDeg = 15;
|
||||
rescueState.intent.maxAngleDeg = gpsRescueConfig()->angle;
|
||||
break;
|
||||
case RESCUE_LANDING_APPROACH:
|
||||
// We are getting close to home in the XY plane, get Z where it needs to be to move to landing phase
|
||||
if (rescueState.sensor.distanceToHome < 10 && rescueState.sensor.currentAltitude <= 1000) {
|
||||
rescueState.phase = RESCUE_LANDING;
|
||||
}
|
||||
// We are getting close to home in the XY plane, get Z where it needs to be to move to landing phase
|
||||
if (rescueState.sensor.distanceToHome < 10 && rescueState.sensor.currentAltitude <= 1000) {
|
||||
rescueState.phase = RESCUE_LANDING;
|
||||
}
|
||||
|
||||
// Only allow new altitude and new speed to be equal or lower than the current values (to prevent parabolic movement on overshoot)
|
||||
int32_t newAlt = gpsRescueConfig()->initialAltitude * 100 * rescueState.sensor.distanceToHome / gpsRescueConfig()->descentDistance;
|
||||
int32_t newSpeed = gpsRescueConfig()->rescueGroundspeed * rescueState.sensor.distanceToHome / gpsRescueConfig()->descentDistance;
|
||||
// Only allow new altitude and new speed to be equal or lower than the current values (to prevent parabolic movement on overshoot)
|
||||
int32_t newAlt = gpsRescueConfig()->initialAltitude * 100 * rescueState.sensor.distanceToHome / gpsRescueConfig()->descentDistance;
|
||||
int32_t newSpeed = gpsRescueConfig()->rescueGroundspeed * rescueState.sensor.distanceToHome / gpsRescueConfig()->descentDistance;
|
||||
|
||||
rescueState.intent.targetAltitude = constrain(newAlt, 100, rescueState.intent.targetAltitude);
|
||||
rescueState.intent.targetGroundspeed = constrain(newSpeed, 100, rescueState.intent.targetGroundspeed);
|
||||
rescueState.intent.crosstrack = true;
|
||||
rescueState.intent.minAngleDeg = 10;
|
||||
rescueState.intent.maxAngleDeg = 20;
|
||||
break;
|
||||
rescueState.intent.targetAltitude = constrain(newAlt, 100, rescueState.intent.targetAltitude);
|
||||
rescueState.intent.targetGroundspeed = constrain(newSpeed, 100, rescueState.intent.targetGroundspeed);
|
||||
rescueState.intent.crosstrack = true;
|
||||
rescueState.intent.minAngleDeg = 10;
|
||||
rescueState.intent.maxAngleDeg = 20;
|
||||
break;
|
||||
case RESCUE_LANDING:
|
||||
// We have reached the XYZ envelope to be considered at "home". We need to land gently and check our accelerometer for abnormal data.
|
||||
// At this point, do not let the target altitude go up anymore, so if we overshoot, we dont' move in a parabolic trajectory
|
||||
// We have reached the XYZ envelope to be considered at "home". We need to land gently and check our accelerometer for abnormal data.
|
||||
// At this point, do not let the target altitude go up anymore, so if we overshoot, we dont' move in a parabolic trajectory
|
||||
|
||||
// If we are over 120% of average magnitude, just disarm since we're pretty much home
|
||||
if (rescueState.sensor.accMagnitude > rescueState.sensor.accMagnitudeAvg * 1.5) {
|
||||
disarm();
|
||||
rescueState.phase = RESCUE_COMPLETE;
|
||||
}
|
||||
// If we are over 120% of average magnitude, just disarm since we're pretty much home
|
||||
if (rescueState.sensor.accMagnitude > rescueState.sensor.accMagnitudeAvg * 1.5) {
|
||||
disarm();
|
||||
rescueState.phase = RESCUE_COMPLETE;
|
||||
}
|
||||
|
||||
rescueState.intent.targetGroundspeed = 0;
|
||||
rescueState.intent.targetAltitude = 0;
|
||||
rescueState.intent.crosstrack = true;
|
||||
rescueState.intent.minAngleDeg = 0;
|
||||
rescueState.intent.maxAngleDeg = 15;
|
||||
break;
|
||||
rescueState.intent.targetGroundspeed = 0;
|
||||
rescueState.intent.targetAltitude = 0;
|
||||
rescueState.intent.crosstrack = true;
|
||||
rescueState.intent.minAngleDeg = 0;
|
||||
rescueState.intent.maxAngleDeg = 15;
|
||||
break;
|
||||
case RESCUE_COMPLETE:
|
||||
rescueStop();
|
||||
break;
|
||||
rescueStop();
|
||||
break;
|
||||
case RESCUE_ABORT:
|
||||
disarm();
|
||||
rescueStop();
|
||||
break;
|
||||
disarm();
|
||||
rescueStop();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
performSanityChecks();
|
||||
|
|
|
@ -531,6 +531,9 @@ void gpsUpdate(timeUs_t currentTimeUs)
|
|||
if (sensors(SENSOR_GPS)) {
|
||||
updateGpsIndicator(currentTimeUs);
|
||||
}
|
||||
#if defined(USE_GPS_RESCUE)
|
||||
updateGPSRescueState();
|
||||
#endif
|
||||
}
|
||||
|
||||
static void gpsNewData(uint16_t c)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue