Paparazzi UAS  v5.8.2_stable-0-g6260b7c
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
imu_apogee.c
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2013 Gautier Hattenberger
3  *
4  * This file is part of paparazzi.
5  *
6  * paparazzi is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2, or (at your option)
9  * any later version.
10  *
11  * paparazzi is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with paparazzi; see the file COPYING. If not, write to
18  * the Free Software Foundation, 59 Temple Place - Suite 330,
19  * Boston, MA 02111-1307, USA.
20  */
21 
30 #include <math.h>
32 #include "mcu_periph/i2c.h"
33 #include "led.h"
34 #include "subsystems/abi.h"
35 
36 // Downlink
37 #include "mcu_periph/uart.h"
38 #include "messages.h"
40 
41 #ifndef IMU_APOGEE_CHAN_X
42 #define IMU_APOGEE_CHAN_X 0
43 #endif
44 #ifndef IMU_APOGEE_CHAN_Y
45 #define IMU_APOGEE_CHAN_Y 1
46 #endif
47 #ifndef IMU_APOGEE_CHAN_Z
48 #define IMU_APOGEE_CHAN_Z 2
49 #endif
50 
51 #if !defined APOGEE_LOWPASS_FILTER && !defined APOGEE_SMPLRT_DIV
52 #define APOGEE_LOWPASS_FILTER MPU60X0_DLPF_42HZ
53 #define APOGEE_SMPLRT_DIV 9
54 PRINT_CONFIG_MSG("Gyro/Accel output rate is 100Hz")
55 #endif
56 PRINT_CONFIG_VAR(APOGEE_SMPLRT_DIV)
57 PRINT_CONFIG_VAR(APOGEE_LOWPASS_FILTER)
58 
59 #ifndef APOGEE_GYRO_RANGE
60 #define APOGEE_GYRO_RANGE MPU60X0_GYRO_RANGE_1000
61 #endif
62 PRINT_CONFIG_VAR(APOGEE_GYRO_RANGE)
63 
64 #ifndef APOGEE_ACCEL_RANGE
65 #define APOGEE_ACCEL_RANGE MPU60X0_ACCEL_RANGE_8G
66 #endif
67 PRINT_CONFIG_VAR(APOGEE_ACCEL_RANGE)
68 
70 
71 // baro config will be done later in bypass mode
72 bool_t configure_baro_slave(Mpu60x0ConfigSet mpu_set, void *mpu);
73 
74 bool_t configure_baro_slave(Mpu60x0ConfigSet mpu_set __attribute__((unused)), void *mpu __attribute__((unused)))
75 {
76  return TRUE;
77 }
78 
79 void imu_impl_init(void)
80 {
82  // MPU-60X0
83  mpu60x0_i2c_init(&imu_apogee.mpu, &(IMU_APOGEE_I2C_DEV), MPU60X0_ADDR_ALT);
84  // change the default configuration
89  // set MPU in bypass mode for the baro
93 }
94 
95 void imu_periodic(void)
96 {
97  // Start reading the latest gyroscope data
99 
100  //RunOnceEvery(10,imu_apogee_downlink_raw());
101 }
102 
104 {
105  DOWNLINK_SEND_IMU_GYRO_RAW(DefaultChannel, DefaultDevice, &imu.gyro_unscaled.p, &imu.gyro_unscaled.q,
106  &imu.gyro_unscaled.r);
107  DOWNLINK_SEND_IMU_ACCEL_RAW(DefaultChannel, DefaultDevice, &imu.accel_unscaled.x, &imu.accel_unscaled.y,
108  &imu.accel_unscaled.z);
109 }
110 
111 
113 {
114  uint32_t now_ts = get_sys_time_usec();
115 
116  // If the itg3200 I2C transaction has succeeded: convert the data
119  struct Int32Rates rates = {
123  };
124  RATES_COPY(imu.gyro_unscaled, rates);
125  struct Int32Vect3 accel = {
129  };
130  VECT3_COPY(imu.accel_unscaled, accel);
134  AbiSendMsgIMU_GYRO_INT32(IMU_BOARD_ID, now_ts, &imu.gyro);
135  AbiSendMsgIMU_ACCEL_INT32(IMU_BOARD_ID, now_ts, &imu.accel);
136  }
137 }
138 
struct Mpu60x0_I2c mpu
Definition: imu_apogee.h:98
angular rates
arch independent UART (Universal Asynchronous Receiver/Transmitter) API
Driver for the IMU on the Apogee board.
void mpu60x0_i2c_event(struct Mpu60x0_I2c *mpu)
Definition: mpu60x0_i2c.c:82
void imu_scale_gyro(struct Imu *_imu)
Definition: ahrs_gx3.c:349
#define IMU_BOARD_ID
void mpu60x0_i2c_init(struct Mpu60x0_I2c *mpu, struct i2c_periph *i2c_p, uint8_t addr)
Definition: mpu60x0_i2c.c:31
void imu_scale_accel(struct Imu *_imu)
Definition: ahrs_gx3.c:350
bool_t configure_baro_slave(Mpu60x0ConfigSet mpu_set, void *mpu)
Definition: imu_apogee.c:74
struct Mpu60x0Config config
Definition: mpu60x0_i2c.h:68
union Mpu60x0_I2c::@41 data_accel
#define VECT3_COPY(_a, _b)
Definition: pprz_algebra.h:139
#define MPU60X0_ADDR_ALT
Definition: mpu60x0_regs.h:33
Main include for ABI (AirBorneInterface).
uint8_t smplrt_div
Sample rate divider.
Definition: mpu60x0.h:74
void imu_periodic(void)
optional.
Definition: imu_apogee.c:95
enum Mpu60x0GyroRanges gyro_range
deg/s Range
Definition: mpu60x0.h:76
#define APOGEE_GYRO_RANGE
Definition: imu_apogee.c:60
enum Mpu60x0AccelRanges accel_range
g Range
Definition: mpu60x0.h:77
union Mpu60x0_I2c::@42 data_rates
enum Mpu60x0DLPF dlpf_cfg
Digital Low Pass Filter.
Definition: mpu60x0.h:75
#define FALSE
Definition: std.h:5
Mpu60x0I2cSlaveConfigure configure
Definition: mpu60x0.h:70
static uint32_t get_sys_time_usec(void)
Get the time in microseconds since startup.
Definition: sys_time_arch.h:39
void imu_impl_init(void)
must be defined by underlying hardware
Definition: imu_apogee.c:79
int32_t r
in rad/s with INT32_RATE_FRAC
struct Int32Rates gyro_unscaled
unscaled gyroscope measurements
Definition: imu.h:50
#define TRUE
Definition: std.h:4
struct Int32Vect3 accel
accelerometer measurements in m/s^2 in BFP with INT32_ACCEL_FRAC
Definition: imu.h:43
#define IMU_APOGEE_CHAN_Y
Definition: imu_apogee.c:45
struct Imu imu
global IMU state
Definition: imu_aspirin2.c:43
unsigned long uint32_t
Definition: types.h:18
uint8_t nb_slaves
number of used I2C slaves
Definition: mpu60x0.h:89
PRINT_CONFIG_MSG("USE_INS_NAV_INIT defaulting to TRUE")
#define APOGEE_LOWPASS_FILTER
Definition: imu_apogee.c:52
void imu_apogee_event(void)
Definition: imu_apogee.c:112
#define IMU_APOGEE_CHAN_Z
Definition: imu_apogee.c:48
#define IMU_APOGEE_CHAN_X
Definition: imu_apogee.c:42
struct Mpu60x0I2cSlave slaves[5]
I2C slaves.
Definition: mpu60x0.h:90
signed long int32_t
Definition: types.h:19
bool_t i2c_bypass
Bypass MPU I2C.
Definition: mpu60x0.h:87
void imu_apogee_downlink_raw(void)
Definition: imu_apogee.c:103
int32_t p
in rad/s with INT32_RATE_FRAC
arch independent LED (Light Emitting Diodes) API
struct Int32Vect3 accel_unscaled
unscaled accelerometer measurements
Definition: imu.h:51
static void mpu60x0_i2c_periodic(struct Mpu60x0_I2c *mpu)
convenience function: read or start configuration if not already initialized
Definition: mpu60x0_i2c.h:79
#define APOGEE_ACCEL_RANGE
Definition: imu_apogee.c:65
#define RATES_COPY(_a, _b)
Definition: pprz_algebra.h:336
int32_t q
in rad/s with INT32_RATE_FRAC
void(* Mpu60x0ConfigSet)(void *mpu, uint8_t _reg, uint8_t _val)
Configuration function prototype.
Definition: mpu60x0.h:64
struct ImuApogee imu_apogee
Definition: imu_apogee.c:69
volatile bool_t data_available
data ready flag
Definition: mpu60x0_i2c.h:57
struct Int32Rates gyro
gyroscope measurements in rad/s in BFP with INT32_RATE_FRAC
Definition: imu.h:42
Architecture independent I2C (Inter-Integrated Circuit Bus) API.
#define APOGEE_SMPLRT_DIV
Definition: imu_apogee.c:53