mirror of
https://github.com/iNavFlight/inav.git
synced 2025-07-25 09:16:01 +03:00
first build
This commit is contained in:
parent
9de79f43ac
commit
ce7ee28677
5 changed files with 77 additions and 10 deletions
|
@ -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)
|
||||
// GPS must also be working, and home position set
|
||||
if (failsafeConfig()->failsafe_min_distance > 0 &&
|
||||
|
|
|
@ -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)
|
||||
{
|
||||
// TODO:
|
||||
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
|
||||
// Make sure terrain following is not enabled
|
||||
resetAltitudeController(false);
|
||||
|
@ -3437,7 +3441,10 @@ bool isNavHoldPositionActive(void)
|
|||
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
|
||||
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)
|
||||
|
@ -3612,6 +3619,35 @@ static bool isWaypointMissionValid(void)
|
|||
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 bool canActivateWaypoint = false;
|
||||
|
@ -3636,8 +3672,16 @@ static navigationFSMEvent_t selectNavEventFromBoxModeInput(void)
|
|||
posControl.flags.rthTrackbackActive = isExecutingRTH;
|
||||
}
|
||||
|
||||
/* Emergency landing triggered by failsafe when Failsafe procedure set to Landing */
|
||||
if (posControl.flags.forcedEmergLandingActivated) {
|
||||
// Emergency landing initiated manually. Cancelled when throttle high.
|
||||
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;
|
||||
}
|
||||
|
||||
|
|
|
@ -743,8 +743,6 @@ bool isFixedWingLandingDetected(void)
|
|||
*-----------------------------------------------------------*/
|
||||
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;
|
||||
|
||||
if (posControl.flags.estAltStatus >= EST_USABLE) {
|
||||
|
@ -756,6 +754,19 @@ void applyFixedWingEmergencyLandingController(timeUs_t currentTimeUs)
|
|||
} else {
|
||||
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]);
|
||||
}
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------
|
||||
|
|
|
@ -852,6 +852,14 @@ static void applyMulticopterEmergencyLandingController(timeUs_t currentTimeUs)
|
|||
|
||||
// Update throttle controller
|
||||
rcCommand[THROTTLE] = posControl.rcAdjustment[THROTTLE];
|
||||
|
||||
// Hold position if possible
|
||||
if ((posControl.flags.estPosStatus >= EST_USABLE)) {
|
||||
applyMulticopterPositionController(currentTimeUs);
|
||||
} else {
|
||||
rcCommand[ROLL] = 0;
|
||||
rcCommand[PITCH] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------
|
||||
|
|
|
@ -104,14 +104,13 @@ typedef struct navigationFlags_s {
|
|||
bool forcedRTHActivated;
|
||||
bool forcedEmergLandingActivated;
|
||||
|
||||
bool wpMissionPlannerActive; // Activation status of WP mission planner
|
||||
|
||||
/* Landing detector */
|
||||
bool resetLandingDetector;
|
||||
|
||||
bool wpMissionPlannerActive; // Activation status of WP mission planner
|
||||
bool rthTrackbackActive; // Activation status of RTH trackback
|
||||
|
||||
bool wpTurnSmoothingActive; // Activation status WP turn smoothing
|
||||
bool manualEmergLandActive; // Activation status of manual emergency landing
|
||||
} navigationFlags_t;
|
||||
|
||||
typedef struct {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue