#if AO_MPU9250_SPI
-#define ao_mpu9250_spi_get() ao_spi_get(AO_MPU9250_SPI_BUS, AO_SPI_SPEED_1MHz)
+#ifndef AO_MPU9250_SPI_SPEED
+#define AO_MPU9250_SPI_SPEED AO_SPI_SPEED_1MHz
+#endif
+
+#define ao_mpu9250_spi_get() ao_spi_get(AO_MPU9250_SPI_BUS, AO_MPU9250_SPI_SPEED)
#define ao_mpu9250_spi_put() ao_spi_put(AO_MPU9250_SPI_BUS)
#define ao_mpu9250_spi_start() ao_spi_set_cs(AO_MPU9250_SPI_CS_PORT, \
*/
ao_cur_task = &ao_mpu9250_task;
- ao_spi_get(AO_MPU9250_SPI_BUS, AO_SPI_SPEED_1MHz);
+ ao_mpu9250_spi_get();
ao_cur_task = NULL;
#endif
ao_cmd_register(&ao_mpu9250_cmds[0]);
printf("manufacturer %s\n"
"product %s\n"
"serial-number %u\n"
-#if HAS_FLIGHT || HAS_TRACKER
+#if HAS_LOG && (HAS_FLIGHT || HAS_TRACKER)
"current-flight %u\n"
#endif
#if HAS_LOG
, ao_manufacturer
, ao_product
, ao_serial_number
-#if HAS_FLIGHT || HAS_TRACKER
+#if HAS_LOG && (HAS_FLIGHT || HAS_TRACKER)
, ao_flight_number
#endif
#if HAS_LOG
#endif
#if HAS_MPU9250
struct ao_mpu9250_sample mpu9250;
+#if !HAS_MMA655X
+ int16_t z_accel;
+#endif
#endif
#if HAS_HMC5883
struct ao_hmc5883_sample hmc5883;
#endif
-#if !HAS_BARO && HAS_ADC
-
-#define HAS_BARO 1
-
-typedef int16_t pres_t;
-typedef int16_t alt_t;
-
-#define ao_data_pres(packet) ((packet)->adc.pres)
-#define ao_data_temp(packet) ((packet)->adc.temp)
-#define pres_to_altitude(p) ao_pres_to_altitude(p)
-#define ao_data_pres_cook(p)
-
-#endif
-
/*
* Need a few macros to pull data from the sensors:
*
#endif
+#if !HAS_ACCEL && HAS_MPU9250
+
+#define HAS_ACCEL 1
+
+typedef int16_t accel_t;
+
+/* MPU9250 is hooked up so that positive y is positive acceleration */
+#define ao_data_accel(packet) ((packet)->z_accel)
+#define ao_data_accel_cook(packet) (-(packet)->mpu9250.accel_y)
+#define ao_data_set_accel(packet, accel) ((packet)->z_accel = (accel))
+#define ao_data_accel_invert(a) (-(a))
+
+#endif
+
#if !HAS_GYRO && HAS_MPU9250
#define HAS_GYRO 1
#if HAS_ACCEL
if (ao_config.accel_plus_g == 0 ||
ao_config.accel_minus_g == 0 ||
- ao_ground_accel < ao_config.accel_plus_g - ACCEL_NOSE_UP ||
- ao_ground_accel > ao_config.accel_minus_g + ACCEL_NOSE_UP ||
- ao_ground_height < -1000 ||
- ao_ground_height > 7000)
+ ao_ground_accel < ao_config.accel_plus_g - ACCEL_NOSE_UP
+#if HAS_BARO
+ || ao_ground_accel > ao_config.accel_minus_g + ACCEL_NOSE_UP
+ || ao_ground_height < -1000 || ao_ground_height > 7000
+#endif
+ )
{
/* Detected an accel value outside -1.5g to 1.5g
* (or uncalibrated values), so we go into invalid mode
ao_launch_tick = ao_boost_tick = ao_sample_tick;
/* start logging data */
+#if HAS_LOG
ao_log_start();
+#endif
#if HAS_TELEMETRY
/* Increase telemetry rate */
ao_v_t ao_speed;
ao_v_t ao_accel;
ao_v_t ao_max_height;
+#if HAS_BARO
static ao_k_t ao_avg_height_scaled;
ao_v_t ao_avg_height;
+#endif
ao_v_t ao_error_h;
#if !HAS_ACCEL || AO_FLIGHT_TEST
ao_k_speed += (ao_k_t) ao_accel * AO_K_STEP_100;
}
+#if HAS_BARO
static void
ao_kalman_err_height(void)
{
#endif
}
}
+#endif
+#if HAS_BARO
static void
ao_kalman_correct_baro(void)
{
ao_k_speed += (ao_k_t) AO_BARO_K1_100 * ao_error_h;
ao_k_accel += (ao_k_t) AO_BARO_K2_100 * ao_error_h;
}
+#endif
#if HAS_ACCEL
ao_error_a = (accel - ao_k_accel) >> 16;
}
-#ifndef FORCE_ACCEL
+#if !defined(FORCE_ACCEL) && HAS_BARO
static void
ao_kalman_correct_both(void)
{
{
ao_kalman_err_accel();
+#ifdef AO_FLIGHT_TEST
if ((int16_t) (ao_sample_tick - ao_sample_prev_tick) > 5) {
ao_k_height +=(ao_k_t) AO_ACCEL_K0_10 * ao_error_a;
ao_k_speed += (ao_k_t) AO_ACCEL_K1_10 * ao_error_a;
ao_k_accel += (ao_k_t) AO_ACCEL_K2_10 * ao_error_a;
return;
}
+#endif
ao_k_height += (ao_k_t) AO_ACCEL_K0_100 * ao_error_a;
ao_k_speed += (ao_k_t) AO_ACCEL_K1_100 * ao_error_a;
ao_k_accel += (ao_k_t) AO_ACCEL_K2_100 * ao_error_a;
ao_kalman(void)
{
ao_kalman_predict();
+#if HAS_BARO
#if HAS_ACCEL
if (ao_flight_state <= ao_flight_coast) {
#ifdef FORCE_ACCEL
} else
#endif
ao_kalman_correct_baro();
+#else
+ ao_kalman_correct_accel();
+#endif
ao_height = from_fix(ao_k_height);
ao_speed = from_fix(ao_k_speed);
ao_accel = from_fix(ao_k_accel);
if (ao_height > ao_max_height)
ao_max_height = ao_height;
+#if HAS_BARO
ao_avg_height_scaled = ao_avg_height_scaled - ao_avg_height + ao_sample_height;
#ifdef AO_FLIGHT_TEST
if ((int16_t) (ao_sample_tick - ao_sample_prev_tick) > 50)
else
#endif
ao_avg_height = (ao_avg_height_scaled + 63) >> 7;
+#endif
}
#endif
uint16_t ao_sample_tick; /* time of last data */
+#if HAS_BARO
pres_t ao_sample_pres;
alt_t ao_sample_alt;
alt_t ao_sample_height;
+#endif
#if HAS_ACCEL
accel_t ao_sample_accel;
#endif
* Sensor calibration values
*/
+#if HAS_BARO
pres_t ao_ground_pres; /* startup pressure */
alt_t ao_ground_height; /* MSL of ao_ground_pres */
+#endif
#if HAS_ACCEL
accel_t ao_ground_accel; /* startup acceleration */
static uint8_t ao_preflight; /* in preflight mode */
static uint16_t nsamples;
+#if HAS_BARO
int32_t ao_sample_pres_sum;
+#endif
#if HAS_ACCEL
int32_t ao_sample_accel_sum;
#endif
#if HAS_ACCEL
ao_sample_accel_sum += ao_sample_accel;
#endif
+#if HAS_BARO
ao_sample_pres_sum += ao_sample_pres;
+#endif
#if HAS_GYRO
ao_sample_accel_along_sum += ao_sample_accel_along;
ao_sample_accel_across_sum += ao_sample_accel_across;
ao_ground_accel = ao_sample_accel_sum >> 9;
ao_sample_accel_sum = 0;
#endif
+#if HAS_BARO
ao_ground_pres = ao_sample_pres_sum >> 9;
ao_ground_height = pres_to_altitude(ao_ground_pres);
ao_sample_pres_sum = 0;
+#endif
#if HAS_GYRO
ao_ground_accel_along = ao_sample_accel_along_sum >> 9;
ao_ground_accel_across = ao_sample_accel_across_sum >> 9;
{
ao_config_get();
nsamples = 0;
+#if HAS_BARO
ao_sample_pres_sum = 0;
ao_sample_pres = 0;
+#endif
#if HAS_ACCEL
ao_sample_accel_sum = 0;
ao_sample_accel = 0;