1
0
Fork 0
mirror of https://github.com/iNavFlight/inav.git synced 2025-07-25 09:16:01 +03:00

first build

This commit is contained in:
breadoven 2022-12-15 22:46:25 +00:00
parent 9de79f43ac
commit ce7ee28677
5 changed files with 77 additions and 10 deletions

View file

@ -346,6 +346,11 @@ static failsafeProcedure_e failsafeChooseFailsafeProcedure(void)
} }
} }
// Inhibit Failsafe if emergency landing triggered manually
if (posControl.flags.manualEmergLandActive) {
return FAILSAFE_PROCEDURE_NONE;
}
// Craft is closer than minimum failsafe procedure distance (if set to non-zero) // Craft is closer than minimum failsafe procedure distance (if set to non-zero)
// GPS must also be working, and home position set // GPS must also be working, and home position set
if (failsafeConfig()->failsafe_min_distance > 0 && if (failsafeConfig()->failsafe_min_distance > 0 &&

View file

@ -1788,9 +1788,13 @@ static navigationFSMEvent_t navOnEnteringState_NAV_STATE_WAYPOINT_FINISHED(navig
static navigationFSMEvent_t navOnEnteringState_NAV_STATE_EMERGENCY_LANDING_INITIALIZE(navigationFSMState_t previousState) static navigationFSMEvent_t navOnEnteringState_NAV_STATE_EMERGENCY_LANDING_INITIALIZE(navigationFSMState_t previousState)
{ {
// TODO:
UNUSED(previousState); UNUSED(previousState);
if ((posControl.flags.estPosStatus >= EST_USABLE)) {
resetPositionController();
setDesiredPosition(&navGetCurrentActualPositionAndVelocity()->pos, 0, NAV_POS_UPDATE_XY);
}
// Emergency landing MAY use common altitude controller if vertical position is valid - initialize it // Emergency landing MAY use common altitude controller if vertical position is valid - initialize it
// Make sure terrain following is not enabled // Make sure terrain following is not enabled
resetAltitudeController(false); resetAltitudeController(false);
@ -3437,7 +3441,10 @@ bool isNavHoldPositionActive(void)
return isLastMissionWaypoint() || NAV_Status.state == MW_NAV_STATE_HOLD_TIMED; return isLastMissionWaypoint() || NAV_Status.state == MW_NAV_STATE_HOLD_TIMED;
} }
// RTH mode (spiral climb and Home positions but excluding RTH Trackback point positions) and POSHOLD mode // RTH mode (spiral climb and Home positions but excluding RTH Trackback point positions) and POSHOLD mode
return (FLIGHT_MODE(NAV_RTH_MODE) && !posControl.flags.rthTrackbackActive) || FLIGHT_MODE(NAV_POSHOLD_MODE); // Also hold position during emergency landing if position valid
return (FLIGHT_MODE(NAV_RTH_MODE) && !posControl.flags.rthTrackbackActive) ||
FLIGHT_MODE(NAV_POSHOLD_MODE) ||
navigationIsExecutingAnEmergencyLanding();
} }
float getActiveWaypointSpeed(void) float getActiveWaypointSpeed(void)
@ -3612,6 +3619,35 @@ static bool isWaypointMissionValid(void)
return posControl.waypointListValid && (posControl.waypointCount > 0); return posControl.waypointListValid && (posControl.waypointCount > 0);
} }
static bool isManualEmergencyLandingActivated(void)
{
// Emergency landing initiated manually by toggling Poshold 4 times within 2 seconds
static timeMs_t timeout = 0;
static int8_t counter = 0;
static bool toggle;
timeMs_t currentTimeMs = millis();
if (timeout && currentTimeMs > timeout) {
timeout += 500;
counter--;
if (counter <= 0) {
timeout = 0;
}
}
if (IS_RC_MODE_ACTIVE(BOXNAVPOSHOLD)) {
if (!timeout) {
timeout = currentTimeMs + 2000;
}
counter += toggle;
toggle = false;
} else {
toggle = true;
}
constrain(counter, 0, 4);
return counter >= 4;
}
static navigationFSMEvent_t selectNavEventFromBoxModeInput(void) static navigationFSMEvent_t selectNavEventFromBoxModeInput(void)
{ {
static bool canActivateWaypoint = false; static bool canActivateWaypoint = false;
@ -3636,8 +3672,16 @@ static navigationFSMEvent_t selectNavEventFromBoxModeInput(void)
posControl.flags.rthTrackbackActive = isExecutingRTH; posControl.flags.rthTrackbackActive = isExecutingRTH;
} }
/* Emergency landing triggered by failsafe when Failsafe procedure set to Landing */ // Emergency landing initiated manually. Cancelled when throttle high.
if (posControl.flags.forcedEmergLandingActivated) { if (isManualEmergencyLandingActivated()) {
posControl.flags.manualEmergLandActive = true;
} else if (posControl.flags.manualEmergLandActive && checkStickPosition(THR_HI)) {
posControl.flags.manualEmergLandActive = false;
return NAV_FSM_EVENT_SWITCH_TO_IDLE;
}
/* Emergency landing triggered by failsafe Landing or manually initiated */
if (posControl.flags.forcedEmergLandingActivated || posControl.flags.manualEmergLandActive) {
return NAV_FSM_EVENT_SWITCH_TO_EMERGENCY_LANDING; return NAV_FSM_EVENT_SWITCH_TO_EMERGENCY_LANDING;
} }
@ -3855,7 +3899,7 @@ bool navigationPositionEstimateIsHealthy(void)
navArmingBlocker_e navigationIsBlockingArming(bool *usedBypass) navArmingBlocker_e navigationIsBlockingArming(bool *usedBypass)
{ {
const bool navBoxModesEnabled = IS_RC_MODE_ACTIVE(BOXNAVRTH) || IS_RC_MODE_ACTIVE(BOXNAVWP) || IS_RC_MODE_ACTIVE(BOXNAVPOSHOLD) || (STATE(FIXED_WING_LEGACY) && IS_RC_MODE_ACTIVE(BOXNAVALTHOLD)) || (STATE(FIXED_WING_LEGACY) && (IS_RC_MODE_ACTIVE(BOXNAVCOURSEHOLD) || IS_RC_MODE_ACTIVE(BOXNAVCRUISE))); const bool navBoxModesEnabled = IS_RC_MODE_ACTIVE(BOXNAVRTH) || IS_RC_MODE_ACTIVE(BOXNAVWP) || IS_RC_MODE_ACTIVE(BOXNAVPOSHOLD) || (STATE(FIXED_WING_LEGACY) && IS_RC_MODE_ACTIVE(BOXNAVALTHOLD)) || (STATE(FIXED_WING_LEGACY) && (IS_RC_MODE_ACTIVE(BOXNAVCOURSEHOLD) || IS_RC_MODE_ACTIVE(BOXNAVCRUISE)));
if (usedBypass) { if (usedBypass) {
*usedBypass = false; *usedBypass = false;
} }

View file

@ -743,8 +743,6 @@ bool isFixedWingLandingDetected(void)
*-----------------------------------------------------------*/ *-----------------------------------------------------------*/
void applyFixedWingEmergencyLandingController(timeUs_t currentTimeUs) void applyFixedWingEmergencyLandingController(timeUs_t currentTimeUs)
{ {
rcCommand[ROLL] = pidAngleToRcCommand(failsafeConfig()->failsafe_fw_roll_angle, pidProfile()->max_angle_inclination[FD_ROLL]);
rcCommand[YAW] = -pidRateToRcCommand(failsafeConfig()->failsafe_fw_yaw_rate, currentControlRateProfile->stabilized.rates[FD_YAW]);
rcCommand[THROTTLE] = currentBatteryProfile->failsafe_throttle; rcCommand[THROTTLE] = currentBatteryProfile->failsafe_throttle;
if (posControl.flags.estAltStatus >= EST_USABLE) { if (posControl.flags.estAltStatus >= EST_USABLE) {
@ -756,6 +754,19 @@ void applyFixedWingEmergencyLandingController(timeUs_t currentTimeUs)
} else { } else {
rcCommand[PITCH] = pidAngleToRcCommand(failsafeConfig()->failsafe_fw_pitch_angle, pidProfile()->max_angle_inclination[FD_PITCH]); rcCommand[PITCH] = pidAngleToRcCommand(failsafeConfig()->failsafe_fw_pitch_angle, pidProfile()->max_angle_inclination[FD_PITCH]);
} }
// Hold position of possible
if (posControl.flags.estPosStatus >= EST_USABLE) {
applyFixedWingPositionController(currentTimeUs);
if (isRollAdjustmentValid) {
// ROLL >0 right, <0 left
int16_t rollCorrection = constrain(posControl.rcAdjustment[ROLL], -DEGREES_TO_DECIDEGREES(navConfig()->fw.max_bank_angle), DEGREES_TO_DECIDEGREES(navConfig()->fw.max_bank_angle));
rcCommand[ROLL] = pidAngleToRcCommand(rollCorrection, pidProfile()->max_angle_inclination[FD_ROLL]);
}
} else {
rcCommand[ROLL] = pidAngleToRcCommand(failsafeConfig()->failsafe_fw_roll_angle, pidProfile()->max_angle_inclination[FD_ROLL]);
rcCommand[YAW] = -pidRateToRcCommand(failsafeConfig()->failsafe_fw_yaw_rate, currentControlRateProfile->stabilized.rates[FD_YAW]);
}
} }
/*----------------------------------------------------------- /*-----------------------------------------------------------

View file

@ -852,6 +852,14 @@ static void applyMulticopterEmergencyLandingController(timeUs_t currentTimeUs)
// Update throttle controller // Update throttle controller
rcCommand[THROTTLE] = posControl.rcAdjustment[THROTTLE]; rcCommand[THROTTLE] = posControl.rcAdjustment[THROTTLE];
// Hold position if possible
if ((posControl.flags.estPosStatus >= EST_USABLE)) {
applyMulticopterPositionController(currentTimeUs);
} else {
rcCommand[ROLL] = 0;
rcCommand[PITCH] = 0;
}
} }
/*----------------------------------------------------------- /*-----------------------------------------------------------

View file

@ -104,14 +104,13 @@ typedef struct navigationFlags_s {
bool forcedRTHActivated; bool forcedRTHActivated;
bool forcedEmergLandingActivated; bool forcedEmergLandingActivated;
bool wpMissionPlannerActive; // Activation status of WP mission planner
/* Landing detector */ /* Landing detector */
bool resetLandingDetector; bool resetLandingDetector;
bool wpMissionPlannerActive; // Activation status of WP mission planner
bool rthTrackbackActive; // Activation status of RTH trackback bool rthTrackbackActive; // Activation status of RTH trackback
bool wpTurnSmoothingActive; // Activation status WP turn smoothing bool wpTurnSmoothingActive; // Activation status WP turn smoothing
bool manualEmergLandActive; // Activation status of manual emergency landing
} navigationFlags_t; } navigationFlags_t;
typedef struct { typedef struct {