altos/easymega-v2.0: Handle different mpu9250 orientation
authorKeith Packard <keithp@keithp.com>
Sun, 21 Oct 2018 00:26:53 +0000 (17:26 -0700)
committerKeith Packard <keithp@keithp.com>
Sun, 21 Oct 2018 00:31:57 +0000 (17:31 -0700)
The mpu9250 on EasyMega v2.0 is rotated 90° compared with EasyMega v1
and TeleMega IMU devices.

Signed-off-by: Keith Packard <keithp@keithp.com>
src/easymega-v2.0/ao_pins.h
src/kernel/ao_data.h
src/kernel/ao_log.h

index 6217b5d2376f487d168560668a1c71d4415d0368..399654f0ed6f598ed1fa9fb2f5559436181724c4 100644 (file)
@@ -69,7 +69,7 @@
 #define AO_CONFIG_MAX_SIZE                     1024
 #define LOG_ERASE_MARK                         0x55
 #define LOG_MAX_ERASE                          128
-#define AO_LOG_FORMAT                          AO_LOG_FORMAT_TELEMEGA
+#define AO_LOG_FORMAT                          AO_LOG_FORMAT_EASYMEGA_2
 
 #define HAS_EEPROM             1
 #define USE_INTERNAL_FLASH     0
@@ -306,6 +306,18 @@ struct ao_adc {
 #define AO_MPU9250_SPI_CS_PIN  13
 #define HAS_IMU                        1
 
+#define ao_data_along(packet)  ((packet)->mpu9250.accel_x)
+#define ao_data_across(packet) (-(packet)->mpu9250.accel_y)
+#define ao_data_through(packet)        ((packet)->mpu9250.accel_z)
+
+#define ao_data_roll(packet)   ((packet)->mpu9250.gyro_x)
+#define ao_data_pitch(packet)  (-(packet)->mpu9250.gyro_y)
+#define ao_data_yaw(packet)    ((packet)->mpu9250.gyro_z)
+
+#define ao_data_mag_along(packet)      ((packet)->mpu9250.mag_y)
+#define ao_data_mag_across(packet)     (-(packet)->mpu9250.mag_x)
+#define ao_data_mag_through(packet)    ((packet)->mpu9250.mag_z)
+
 /* ADXL375 */
 
 #define HAS_ADXL375            1
index 3918f4e04e4b9cf6931fcb5aaa85ad50695bc083..dda5de4c6638bc62161619c677f4a877c345c5b9 100644 (file)
@@ -382,6 +382,7 @@ typedef int16_t angle_t;    /* in degrees */
 /* X axis is aligned in the other board axis (across) */
 /* Z axis is aligned perpendicular to the board (through) */
 
+#ifndef ao_data_along
 #define ao_data_along(packet)  ((packet)->mpu9250.accel_y)
 #define ao_data_across(packet) ((packet)->mpu9250.accel_x)
 #define ao_data_through(packet)        ((packet)->mpu9250.accel_z)
@@ -389,6 +390,7 @@ typedef int16_t angle_t;    /* in degrees */
 #define ao_data_roll(packet)   ((packet)->mpu9250.gyro_y)
 #define ao_data_pitch(packet)  ((packet)->mpu9250.gyro_x)
 #define ao_data_yaw(packet)    ((packet)->mpu9250.gyro_z)
+#endif
 
 static inline float ao_convert_gyro(float sensor)
 {
@@ -425,9 +427,11 @@ typedef int16_t ao_mag_t;          /* in raw sample units */
  * sensors. Also, the Z axis is flipped in sign.
  */
 
+#ifndef ao_data_mag_along
 #define ao_data_mag_along(packet)      ((packet)->mpu9250.mag_x)
 #define ao_data_mag_across(packet)     ((packet)->mpu9250.mag_y)
 #define ao_data_mag_through(packet)    ((packet)->mpu9250.mag_z)
+#endif
 
 #endif
 
index a97159625b83a883d9ca1fb4148f0fa9ea740abd..04f00d3ec3bd211545e948896994ebff3777736b 100644 (file)
@@ -55,6 +55,7 @@ extern enum ao_flight_state ao_log_state;
 #define AO_LOG_FORMAT_TELEFIRETWO      13      /* 32-byte test stand data */
 #define AO_LOG_FORMAT_EASYMINI2                14      /* 16-byte MS5607 baro only, 3.3V supply, stm32f042 SoC */
 #define AO_LOG_FORMAT_TELEMEGA_3       15      /* 32 byte typed telemega records with 32 bit gyro cal and mpu9250 */
+#define AO_LOG_FORMAT_EASYMEGA_2       16      /* 32 byte typed telemega records with 32 bit gyro cal, mpu9250 rotated 90° and adxl375 */
 #define AO_LOG_FORMAT_NONE             127     /* No log at all */
 
 /* Return the flight number from the given log slot, 0 if none, -slot on failure */
@@ -474,7 +475,7 @@ struct ao_log_gps {
        } u;
 };
 
-#if AO_LOG_FORMAT == AO_LOG_FOMAT_TELEMEGA_OLD || AO_LOG_FORMAT == AO_LOG_FORMAT_TELEMEGA || AO_LOG_FORMAT == AO_LOG_FORMAT_TELEMEGA_3
+#if AO_LOG_FORMAT == AO_LOG_FOMAT_TELEMEGA_OLD || AO_LOG_FORMAT == AO_LOG_FORMAT_TELEMEGA || AO_LOG_FORMAT == AO_LOG_FORMAT_TELEMEGA_3 || AO_LOG_FORMAT == AO_LOG_FORMAT_EASYMEGA_2
 typedef struct ao_log_mega ao_log_type;
 #endif