*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; version 2 of the License.
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
#include <ao_log.h>
#endif
-#if HAS_MPU6000
+#if HAS_MPU6000 || HAS_MPU9250
#include <ao_quaternion.h>
#endif
/* Main flight thread. */
__pdata enum ao_flight_state ao_flight_state; /* current flight state */
-__pdata uint16_t ao_boost_tick; /* time of launch detect */
+__pdata uint16_t ao_boost_tick; /* time of most recent boost detect */
+__pdata uint16_t ao_launch_tick; /* time of first boost detect */
__pdata uint16_t ao_motor_number; /* number of motors burned so far */
#if HAS_SENSOR_ERRORS
{
/* Set pad mode - we can fly! */
ao_flight_state = ao_flight_pad;
-#if HAS_USB && !HAS_FLIGHT_DEBUG && !HAS_SAMPLE_PROFILE
+#if HAS_USB && !HAS_FLIGHT_DEBUG && !HAS_SAMPLE_PROFILE && !DEBUG
/* Disable the USB controller in flight mode
* to save power
*/
)
{
ao_flight_state = ao_flight_boost;
- ao_boost_tick = ao_sample_tick;
+ ao_launch_tick = ao_boost_tick = ao_sample_tick;
/* start logging data */
ao_log_start();
* deceleration, or by waiting until the maximum burn duration
* (15 seconds) has past.
*/
- if ((ao_accel < AO_MSS_TO_ACCEL(-2.5) && ao_height > AO_M_TO_HEIGHT(100)) ||
+ if ((ao_accel < AO_MSS_TO_ACCEL(-2.5)) ||
(int16_t) (ao_sample_tick - ao_boost_tick) > BOOST_TICKS_MAX)
{
#if HAS_ACCEL
* number of seconds.
*/
if (ao_config.apogee_lockout) {
- if ((ao_sample_tick - ao_boost_tick) <
+ if ((int16_t) (ao_sample_tick - ao_launch_tick) <
AO_SEC_TO_TICKS(ao_config.apogee_lockout))
break;
}
* the measured altitude reasonably closely; otherwise
* we're probably transsonic.
*/
+#define AO_ERROR_BOUND 100
+
if (ao_speed < 0
#if !HAS_ACCEL
- && (ao_sample_alt >= AO_MAX_BARO_HEIGHT || ao_error_h_sq_avg < 100)
+ && (ao_sample_alt >= AO_MAX_BARO_HEIGHT || ao_error_h_sq_avg < AO_ERROR_BOUND)
#endif
)
{
#if HAS_ACCEL
else {
check_re_boost:
- ao_coast_avg_accel = ao_coast_avg_accel - (ao_coast_avg_accel >> 6) + (ao_accel >> 6);
+ ao_coast_avg_accel = ao_coast_avg_accel + ((ao_accel - ao_coast_avg_accel) >> 5);
if (ao_coast_avg_accel > AO_MSS_TO_ACCEL(20)) {
ao_boost_tick = ao_sample_tick;
ao_flight_state = ao_flight_boost;