mirror of
https://github.com/iNavFlight/inav.git
synced 2025-07-23 08:15:26 +03:00
Detect braking in cruise mode
This commit is contained in:
parent
4d5cc76fbb
commit
4400c0af0f
2 changed files with 38 additions and 1 deletions
|
@ -99,7 +99,11 @@ typedef enum {
|
|||
COMPASS_CALIBRATED = (1 << 8),
|
||||
ACCELEROMETER_CALIBRATED= (1 << 9),
|
||||
PWM_DRIVER_AVAILABLE = (1 << 10),
|
||||
HELICOPTER = (1 << 11)
|
||||
HELICOPTER = (1 << 11),
|
||||
NAV_CRUISE_ACCELERATING = (1 << 12),
|
||||
NAV_CRUISE_BRAKING = (1 << 13),
|
||||
NAV_HIGHSPEED_CRUISE = (1 << 14),
|
||||
NAV_CRUISE_STOPPED = (1 << 15)
|
||||
} stateFlags_t;
|
||||
|
||||
#define DISABLE_STATE(mask) (stateFlags &= ~(mask))
|
||||
|
|
|
@ -1962,6 +1962,39 @@ static bool adjustPositionFromRCInput(void)
|
|||
retValue = adjustFixedWingPositionFromRCInput();
|
||||
}
|
||||
else {
|
||||
|
||||
/*
|
||||
* Process states
|
||||
*/
|
||||
if (navConfig()->general.flags.user_control_mode == NAV_GPS_CRUISE) {
|
||||
const int16_t rcPitchAdjustment = applyDeadband(rcCommand[PITCH], rcControlsConfig()->pos_hold_deadband);
|
||||
const int16_t rcRollAdjustment = applyDeadband(rcCommand[ROLL], rcControlsConfig()->pos_hold_deadband);
|
||||
|
||||
/*
|
||||
* Case one, when we order to brake (sticks to the center) and we are moving above threshold
|
||||
* Speed is above 1m/s and sticks are centered
|
||||
*/
|
||||
if (!STATE(NAV_CRUISE_BRAKING) &&
|
||||
posControl.actualState.velXY > 100.0f &&
|
||||
!rcPitchAdjustment &&
|
||||
!rcRollAdjustment
|
||||
) {
|
||||
ENABLE_STATE(NAV_CRUISE_BRAKING);
|
||||
}
|
||||
|
||||
/*
|
||||
* Case when we were braking but copter finally stopped or we started to move the sticks
|
||||
*/
|
||||
if (STATE(NAV_CRUISE_BRAKING) && (
|
||||
posControl.actualState.velXY <= 100.0f ||
|
||||
rcPitchAdjustment ||
|
||||
rcRollAdjustment
|
||||
)) {
|
||||
DISABLE_STATE(NAV_CRUISE_BRAKING);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
retValue = adjustMulticopterPositionFromRCInput();
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue