altos: Support accel-only IMU configurations
authorKeith Packard <keithp@keithp.com>
Sun, 2 Aug 2020 20:07:01 +0000 (13:07 -0700)
committerKeith Packard <keithp@keithp.com>
Thu, 22 Oct 2020 04:33:58 +0000 (21:33 -0700)
This doesn't compute orientation, just allows for calibrating and recording
3-axis acceleration data.

Signed-off-by: Keith Packard <keithp@keithp.com>
src/kernel/ao_sample.c
src/kernel/ao_sample.h

index 67f20aff9093b5941a3ccee9ffc5e6e752f96479..91cf113e3a6ae58880be274bec43653154e485fe 100644 (file)
@@ -44,10 +44,12 @@ alt_t               ao_sample_height;
 #if HAS_ACCEL
 accel_t                ao_sample_accel;
 #endif
-#if HAS_GYRO
+#if HAS_IMU
 accel_t                ao_sample_accel_along;
 accel_t                ao_sample_accel_across;
 accel_t                ao_sample_accel_through;
+#endif
+#if HAS_GYRO
 gyro_t         ao_sample_roll;
 gyro_t         ao_sample_pitch;
 gyro_t         ao_sample_yaw;
@@ -73,10 +75,13 @@ accel_t             ao_accel_2g;            /* factory accel calibration */
 int32_t                ao_accel_scale;         /* sensor to m/s² conversion */
 #endif
 
-#if HAS_GYRO
+#if HAS_IMU
 accel_t                ao_ground_accel_along;
 accel_t                ao_ground_accel_across;
 accel_t                ao_ground_accel_through;
+#endif
+
+#if HAS_GYRO
 int32_t                ao_ground_pitch;
 int32_t                ao_ground_yaw;
 int32_t                ao_ground_roll;
@@ -91,10 +96,12 @@ int32_t ao_sample_pres_sum;
 #if HAS_ACCEL
 int32_t ao_sample_accel_sum;
 #endif
-#if HAS_GYRO
+#if HAS_IMU
 int32_t ao_sample_accel_along_sum;
 int32_t ao_sample_accel_across_sum;
 int32_t        ao_sample_accel_through_sum;
+#endif
+#if HAS_GYRO
 int32_t ao_sample_pitch_sum;
 int32_t ao_sample_yaw_sum;
 int32_t        ao_sample_roll_sum;
@@ -114,10 +121,12 @@ ao_sample_preflight_add(void)
 #if HAS_BARO
        ao_sample_pres_sum += ao_sample_pres;
 #endif
-#if HAS_GYRO
+#if HAS_IMU
        ao_sample_accel_along_sum += ao_sample_accel_along;
        ao_sample_accel_across_sum += ao_sample_accel_across;
        ao_sample_accel_through_sum += ao_sample_accel_through;
+#endif
+#if HAS_GYRO
        ao_sample_pitch_sum += ao_sample_pitch;
        ao_sample_yaw_sum += ao_sample_yaw;
        ao_sample_roll_sum += ao_sample_roll;
@@ -184,10 +193,13 @@ ao_sample_preflight_set(void)
        ao_ground_height = pres_to_altitude(ao_ground_pres);
        ao_sample_pres_sum = 0;
 #endif
-#if HAS_GYRO
+#if HAS_IMU
        ao_ground_accel_along = ao_sample_accel_along_sum >> 9;
        ao_ground_accel_across = ao_sample_accel_across_sum >> 9;
        ao_ground_accel_through = ao_sample_accel_through_sum >> 9;
+
+#endif
+#if HAS_GYRO
        ao_ground_pitch = ao_sample_pitch_sum;
        ao_ground_yaw = ao_sample_yaw_sum;
        ao_ground_roll = ao_sample_roll_sum;
@@ -353,10 +365,12 @@ ao_sample(void)
 #if HAS_ACCEL
                ao_sample_accel = ao_data_accel(ao_data);
 #endif
-#if HAS_GYRO
+#if HAS_IMU
                ao_sample_accel_along = ao_data_along(ao_data);
                ao_sample_accel_across = ao_data_across(ao_data);
                ao_sample_accel_through = ao_data_through(ao_data);
+#endif
+#if HAS_GYRO
                ao_sample_pitch = ao_data_pitch(ao_data);
                ao_sample_yaw = ao_data_yaw(ao_data);
                ao_sample_roll = ao_data_roll(ao_data);
@@ -393,13 +407,15 @@ ao_sample_init(void)
        ao_sample_accel_sum = 0;
        ao_sample_accel = 0;
 #endif
-#if HAS_GYRO
+#if HAS_IMU
        ao_sample_accel_along_sum = 0;
        ao_sample_accel_across_sum = 0;
        ao_sample_accel_through_sum = 0;
        ao_sample_accel_along = 0;
        ao_sample_accel_across = 0;
        ao_sample_accel_through = 0;
+#endif
+#if HAS_GYRO
        ao_sample_pitch_sum = 0;
        ao_sample_yaw_sum = 0;
        ao_sample_roll_sum = 0;
index 4c51a58c3f0a0089f893f3004a239b3e37d7b3cf..04e97e7b29f0c309b1a1a6710cad314d18731dbb 100644 (file)
@@ -133,16 +133,21 @@ extern accel_t    ao_ground_accel;        /* startup acceleration */
 extern accel_t         ao_accel_2g;            /* factory accel calibration */
 extern int32_t ao_accel_scale;         /* sensor to m/s² conversion */
 #endif
-#if HAS_GYRO
+#if HAS_IMU
 extern accel_t ao_ground_accel_along;
 extern accel_t ao_ground_accel_across;
 extern accel_t ao_ground_accel_through;
-extern int32_t ao_ground_pitch;        /* * 512 */
-extern int32_t ao_ground_yaw;          /* * 512 */
-extern int32_t ao_ground_roll;         /* * 512 */
 extern accel_t ao_sample_accel_along;
 extern accel_t ao_sample_accel_across;
 extern accel_t ao_sample_accel_through;
+#endif
+#if HAS_GYRO
+#ifndef HAS_IMU
+#define HAS_IMU        1
+#endif
+extern int32_t ao_ground_pitch;        /* * 512 */
+extern int32_t ao_ground_yaw;          /* * 512 */
+extern int32_t ao_ground_roll;         /* * 512 */
 extern gyro_t  ao_sample_roll;
 extern gyro_t  ao_sample_pitch;
 extern gyro_t  ao_sample_yaw;