Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion src/main/navigation/navigation_fw_launch.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@

#define SWING_LAUNCH_MIN_ROTATION_RATE DEGREES_TO_RADIANS(100) // expect minimum 100dps rotation rate
#define LAUNCH_MOTOR_IDLE_SPINUP_TIME 1500 // ms
#define THROW_LAUNCH_ACCEL_HOLD_TIME 1000 // ms, throw acceleration is remembered this long while waiting for the GPS speed to catch up
#if !defined(UNUSED)
#define UNUSED(x) ((void)(x))
#endif
Expand Down Expand Up @@ -123,6 +124,7 @@ typedef struct fixedWingLaunchData_s {

static EXTENDED_FASTRAM fixedWingLaunchData_t fwLaunch;
static bool idleMotorAboutToStart;
static timeUs_t forwardAccelHighTimeUs;

static const fixedWingLaunchStateDescriptor_t launchStateMachine[FW_LAUNCH_STATE_COUNT] = {

Expand Down Expand Up @@ -414,16 +416,28 @@ static fixedWingLaunchEvent_t fwLaunchState_FW_LAUNCH_STATE_MOTOR_IDLE(timeUs_t
static fixedWingLaunchEvent_t fwLaunchState_FW_LAUNCH_STATE_WAIT_DETECTION(timeUs_t currentTimeUs)
{
if (throttleStickIsLow()) {
forwardAccelHighTimeUs = 0;
return FW_LAUNCH_EVENT_THROTTLE_LOW; // go back to FW_LAUNCH_STATE_WAIT_THROTTLE
}

const float swingVelocity = (fabsf(imuMeasuredRotationBF.z) > SWING_LAUNCH_MIN_ROTATION_RATE) ? (imuMeasuredAccelBF.y / imuMeasuredRotationBF.z) : 0;
const bool isForwardAccelerationHigh = (imuMeasuredAccelBF.x > navConfig()->fw.launch_accel_thresh);
const bool isAircraftAlmostLevel = (calculateCosTiltAngle() >= cos_approx(DEGREES_TO_RADIANS(navConfig()->fw.launch_max_angle)));

if (isForwardAccelerationHigh) {
forwardAccelHighTimeUs = currentTimeUs;
Comment thread
qodo-free-for-open-source-projects[bot] marked this conversation as resolved.
}
// The acceleration peak of a throw is over long before the GPS speed follows, so a peak seen shortly before still counts.
// Without this the throw launch would trigger on accelerometer noise alone, or on a GPS speed glitch while the aircraft is held still.
const timeDelta_t forwardAccelAgeUs = cmpTimeUs(currentTimeUs, forwardAccelHighTimeUs);
if (forwardAccelAgeUs < 0 || forwardAccelAgeUs >= MS2US(THROW_LAUNCH_ACCEL_HOLD_TIME)) {
forwardAccelHighTimeUs = 0;
}
const bool wasForwardAccelerationHigh = forwardAccelHighTimeUs != 0;

const bool isBungeeLaunched = isForwardAccelerationHigh && isAircraftAlmostLevel;
const bool isSwingLaunched = (swingVelocity > navConfig()->fw.launch_velocity_thresh) && (imuMeasuredAccelBF.x > 0);
const bool isForwardLaunched = isGPSHeadingValid() && (gpsSol.groundSpeed > navConfig()->fw.launch_velocity_thresh) && (imuMeasuredAccelBF.x > 0);
const bool isForwardLaunched = isGPSHeadingValid() && (gpsSol.groundSpeed > navConfig()->fw.launch_velocity_thresh) && wasForwardAccelerationHigh;

applyThrottleIdleLogic(false);

Expand Down Expand Up @@ -591,6 +605,8 @@ void applyFixedWingLaunchController(timeUs_t currentTimeUs)

void resetFixedWingLaunchController(timeUs_t currentTimeUs)
{
forwardAccelHighTimeUs = 0;

if (navConfig()->fw.launch_manual_throttle) {
// no detection or motor control required with manual launch throttle
// so start at launch in progress
Expand Down