Paparazzi UAS  v5.0.5_stable-7-g4b8bbb7
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
imu_navgo.c
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2011 Gautier Hattenberger
3  * Derived from Aspirin and ppzuavimu drivers
4  *
5  * This file is part of paparazzi.
6  *
7  * paparazzi is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2, or (at your option)
10  * any later version.
11  *
12  * paparazzi is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with paparazzi; see the file COPYING. If not, write to
19  * the Free Software Foundation, 59 Temple Place - Suite 330,
20  * Boston, MA 02111-1307, USA.
21  */
22 
33 #include <math.h>
34 #include "imu_navgo.h"
35 #include "mcu_periph/i2c.h"
36 #include "led.h"
37 
38 // Downlink
39 #include "mcu_periph/uart.h"
40 #include "messages.h"
42 
43 #ifndef DOWNLINK_DEVICE
44 #define DOWNLINK_DEVICE DOWNLINK_AP_DEVICE
45 #endif
46 
47 #ifndef NAVGO_ACCEL_RATE
48 #define NAVGO_ACCEL_RATE ADXL345_RATE_25HZ
49 #endif
50 PRINT_CONFIG_VAR(NAVGO_ACCEL_RATE)
51 
52 /* default gyro internal lowpass frequency and sample rate divider */
53 #if !defined NAVGO_GYRO_LOWPASS && !defined NAVGO_GYRO_SMPLRT_DIV
54 #define NAVGO_GYRO_LOWPASS ITG3200_DLPF_10HZ
55 #define NAVGO_GYRO_SMPLRT_DIV 1
56 PRINT_CONFIG_MSG("Gyro output rate is 500Hz")
57 #endif
58 PRINT_CONFIG_VAR(NAVGO_GYRO_LOWPASS)
59 PRINT_CONFIG_VAR(NAVGO_GYRO_SMPLRT_DIV)
60 
61 #if NAVGO_USE_MEDIAN_FILTER
62 #include "filters/median_filter.h"
63 struct MedianFilter3Int median_gyro, median_accel, median_mag;
64 #endif
65 
67 
68 void imu_impl_init(void)
69 {
71  // ITG3200
72  itg3200_init(&imu_navgo.itg, &(IMU_NAVGO_I2C_DEV), ITG3200_ADDR_ALT);
73  // change the default configuration
74  imu_navgo.itg.config.smplrt_div = NAVGO_GYRO_SMPLRT_DIV; // 500Hz sample rate since internal is 1kHz
76 
78  // ADXL345
79  adxl345_i2c_init(&imu_navgo.adxl, &(IMU_NAVGO_I2C_DEV), ADXL345_ADDR_ALT);
80  // change the default data rate
82 
84  // HMC58XX
85  hmc58xx_init(&imu_navgo.hmc, &(IMU_NAVGO_I2C_DEV), HMC58XX_ADDR);
86 
87 #if NAVGO_USE_MEDIAN_FILTER
88  // Init median filters
89  InitMedianFilterRatesInt(median_gyro);
90  InitMedianFilterVect3Int(median_accel);
91  InitMedianFilterVect3Int(median_mag);
92 #endif
93 
97 }
98 
99 void imu_periodic( void )
100 {
101  // Start reading the latest gyroscope data
103 
104  // Start reading the latest accelerometer data
105  // Periodicity is automatically adapted
106  // 3200 is the maximum output freq corresponding to the parameter 0xF
107  // A factor 2 is applied to reduice the delay without overloading the i2c
108  RunOnceEvery((PERIODIC_FREQUENCY/(2*3200>>(0xf-NAVGO_ACCEL_RATE))), adxl345_i2c_periodic(&imu_navgo.adxl));
109 
110  // Read HMC58XX at 100Hz (main loop for rotorcraft: 512Hz)
111  RunOnceEvery(5, hmc58xx_periodic(&imu_navgo.hmc));
112 
113  //RunOnceEvery(20,imu_navgo_downlink_raw());
114 }
115 
116 
118 {
122 }
123 
124 void imu_navgo_event( void )
125 {
126 
127  // If the itg3200 I2C transaction has succeeded: convert the data
131 #if NAVGO_USE_MEDIAN_FILTER
133 #endif
136  }
137 
138  // If the adxl345 I2C transaction has succeeded: convert the data
142 #if NAVGO_USE_MEDIAN_FILTER
144 #endif
147  }
148 
149  // HMC58XX event task
153 #if NAVGO_USE_MEDIAN_FILTER
155 #endif
158  }
159 
160 }
161 
void imu_navgo_event(void)
Definition: imu_navgo.c:124
void imu_periodic(void)
Definition: imu_navgo.c:99
arch independent UART (Universal Asynchronous Receiver/Transmitter) API
void itg3200_init(struct Itg3200 *itg, struct i2c_periph *i2c_p, uint8_t addr)
Initialize Itg3200 struct and set default config options.
Definition: itg3200.c:48
#define NAVGO_GYRO_SMPLRT_DIV
Definition: imu_navgo.c:55
union Hmc58xx::@20 data
int32_t p
in rad/s^2 with INT32_RATE_FRAC
#define ADXL345_ADDR_ALT
Definition: adxl345_regs.h:33
struct Int32Rates gyro_unscaled
unscaled gyroscope measurements
Definition: imu.h:48
void imu_navgo_downlink_raw(void)
Definition: imu_navgo.c:117
#define InitMedianFilterVect3Int(_f)
Definition: median_filter.h:86
struct Int32Rates rates
data as angular rates in gyro coordinate system
Definition: itg3200.h:77
struct Int16Vect3 vect
data vector in accel coordinate system
Definition: adxl345_i2c.h:46
#define UpdateMedianFilterRatesInt(_f, _v)
#define HMC58XX_ADDR
Definition: hmc58xx_regs.h:31
#define FALSE
Definition: imu_chimu.h:141
struct Int32Vect3 accel_unscaled
unscaled accelerometer measurements
Definition: imu.h:49
struct Itg3200Config config
Definition: itg3200.h:80
enum Itg3200DLPF dlpf_cfg
Digital Low Pass Filter.
Definition: itg3200.h:55
Interface for the IMU on the NavGo board.
static void adxl345_i2c_periodic(struct Adxl345_I2c *adxl)
convenience function: read or start configuration if not already initialized
Definition: adxl345_i2c.h:59
void adxl345_i2c_event(struct Adxl345_I2c *adxl)
Definition: adxl345_i2c.c:114
struct Imu imu
global IMU state
Definition: imu_aspirin2.c:50
#define NAVGO_ACCEL_RATE
Definition: imu_navgo.c:48
struct Int32Vect3 mag_unscaled
unscaled magnetometer measurements
Definition: imu.h:50
void adxl345_i2c_init(struct Adxl345_I2c *adxl, struct i2c_periph *i2c_p, uint8_t addr)
Definition: adxl345_i2c.c:36
struct Int16Vect3 vect
data vector in mag coordinate system
Definition: hmc58xx.h:67
#define TRUE
Definition: imu_chimu.h:144
#define UpdateMedianFilterVect3Int(_f, _v)
Definition: median_filter.h:95
volatile bool_t data_available
data ready flag
Definition: itg3200.h:75
#define VECT3_ASSIGN(_a, _x, _y, _z)
Definition: pprz_algebra.h:97
struct Adxl345_I2c adxl
Definition: imu_navgo.h:67
struct ImuNavgo imu_navgo
Definition: imu_navgo.c:66
#define RATES_ASSIGN(_ra, _p, _q, _r)
Definition: pprz_algebra.h:294
volatile bool_t gyr_valid
Definition: imu_navgo.h:63
static void hmc58xx_periodic(struct Hmc58xx *hmc)
convenience function: read or start configuration if not already initialized
Definition: hmc58xx.h:84
enum Adxl345Rates rate
Data Output Rate.
Definition: adxl345.h:53
void imu_impl_init(void)
Definition: imu_navgo.c:68
#define NAVGO_GYRO_LOWPASS
Definition: imu_navgo.c:54
void itg3200_event(struct Itg3200 *itg)
Definition: itg3200.c:125
static void itg3200_periodic(struct Itg3200 *itg)
convenience function: read or start configuration if not already initialized
Definition: itg3200.h:93
int32_t q
in rad/s^2 with INT32_RATE_FRAC
#define PERIODIC_FREQUENCY
Definition: imu_aspirin2.c:54
arch independent LED (Light Emitting Diodes) API
void hmc58xx_init(struct Hmc58xx *hmc, struct i2c_periph *i2c_p, uint8_t addr)
Initialize Hmc58xx struct and set default config options.
Definition: hmc58xx.c:62
#define VECT3_COPY(_a, _b)
Definition: pprz_algebra.h:111
volatile bool_t acc_valid
Definition: imu_navgo.h:64
struct Adxl345Config config
Definition: adxl345_i2c.h:49
uint8_t smplrt_div
Sample rate divider.
Definition: itg3200.h:53
union Adxl345_I2c::@17 data
int32_t r
in rad/s^2 with INT32_RATE_FRAC
#define InitMedianFilterRatesInt(_f)
Definition: median_filter.h:93
struct Itg3200 itg
Definition: imu_navgo.h:66
union Itg3200::@21 data
void hmc58xx_event(struct Hmc58xx *hmc)
Definition: hmc58xx.c:136
volatile bool_t data_available
data ready flag
Definition: hmc58xx.h:65
#define ITG3200_ADDR_ALT
Definition: itg3200_regs.h:32
struct Hmc58xx hmc
Definition: imu_navgo.h:68
volatile bool_t data_available
data ready flag
Definition: adxl345_i2c.h:44
volatile bool_t mag_valid
Definition: imu_navgo.h:65
Architecture independent I2C (Inter-Integrated Circuit Bus) API.