Paparazzi UAS  v5.2.2_stable-0-gd6b9f29
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 
44 #ifndef NAVGO_ACCEL_RATE
45 #define NAVGO_ACCEL_RATE ADXL345_RATE_25HZ
46 #endif
48 
49 /* default gyro internal lowpass frequency and sample rate divider */
50 #if !defined NAVGO_GYRO_LOWPASS && !defined NAVGO_GYRO_SMPLRT_DIV
51 #define NAVGO_GYRO_LOWPASS ITG3200_DLPF_10HZ
52 #define NAVGO_GYRO_SMPLRT_DIV 1
53 PRINT_CONFIG_MSG("Gyro output rate is 500Hz")
54 #endif
57 
58 #if NAVGO_USE_MEDIAN_FILTER
59 #include "filters/median_filter.h"
60 struct MedianFilter3Int median_gyro, median_accel, median_mag;
61 #endif
62 
64 
65 void imu_impl_init(void)
66 {
68  // ITG3200
69  itg3200_init(&imu_navgo.itg, &(IMU_NAVGO_I2C_DEV), ITG3200_ADDR_ALT);
70  // change the default configuration
71  imu_navgo.itg.config.smplrt_div = NAVGO_GYRO_SMPLRT_DIV; // 500Hz sample rate since internal is 1kHz
73 
75  // ADXL345
76  adxl345_i2c_init(&imu_navgo.adxl, &(IMU_NAVGO_I2C_DEV), ADXL345_ADDR_ALT);
77  // change the default data rate
79 
81  // HMC58XX
82  hmc58xx_init(&imu_navgo.hmc, &(IMU_NAVGO_I2C_DEV), HMC58XX_ADDR);
83 
84 #if NAVGO_USE_MEDIAN_FILTER
85  // Init median filters
86  InitMedianFilterRatesInt(median_gyro);
87  InitMedianFilterVect3Int(median_accel);
89 #endif
90 
94 }
95 
96 void imu_periodic( void )
97 {
98  // Start reading the latest gyroscope data
100 
101  // Start reading the latest accelerometer data
102  // Periodicity is automatically adapted
103  // 3200 is the maximum output freq corresponding to the parameter 0xF
104  // A factor 2 is applied to reduice the delay without overloading the i2c
105  RunOnceEvery((PERIODIC_FREQUENCY/(2*3200>>(0xf-NAVGO_ACCEL_RATE))), adxl345_i2c_periodic(&imu_navgo.adxl));
106 
107  // Read HMC58XX at 100Hz (main loop for rotorcraft: 512Hz)
108  RunOnceEvery(5, hmc58xx_periodic(&imu_navgo.hmc));
109 
110  //RunOnceEvery(20,imu_navgo_downlink_raw());
111 }
112 
113 
115 {
119 }
120 
121 void imu_navgo_event( void )
122 {
123 
124  // If the itg3200 I2C transaction has succeeded: convert the data
128 #if NAVGO_USE_MEDIAN_FILTER
130 #endif
133  }
134 
135  // If the adxl345 I2C transaction has succeeded: convert the data
139 #if NAVGO_USE_MEDIAN_FILTER
141 #endif
144  }
145 
146  // HMC58XX event task
150 #if NAVGO_USE_MEDIAN_FILTER
152 #endif
155  }
156 
157 }
158 
void imu_navgo_event(void)
Definition: imu_navgo.c:121
void imu_periodic(void)
Definition: imu_navgo.c:96
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:52
int32_t p
in rad/s with INT32_RATE_FRAC
#define ADXL345_ADDR_ALT
Definition: adxl345_regs.h:33
struct Int32Rates gyro_unscaled
unscaled gyroscope measurements
Definition: imu.h:49
void imu_navgo_downlink_raw(void)
Definition: imu_navgo.c:114
#define InitMedianFilterVect3Int(_f)
Definition: median_filter.h:86
struct Int32Rates rates
data as angular rates in gyro coordinate system
Definition: itg3200.h:77
union Adxl345_I2c::@21 data
union Hmc58xx::@29 data
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
union Itg3200::@30 data
struct Int32Vect3 accel_unscaled
unscaled accelerometer measurements
Definition: imu.h:50
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:47
#define NAVGO_ACCEL_RATE
Definition: imu_navgo.c:45
struct Int32Vect3 mag_unscaled
unscaled magnetometer measurements
Definition: imu.h:51
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:107
struct Adxl345_I2c adxl
Definition: imu_navgo.h:67
struct MedianFilter3Int median_mag
Definition: imu_krooz.c:65
struct ImuNavgo imu_navgo
Definition: imu_navgo.c:63
#define RATES_ASSIGN(_ra, _p, _q, _r)
Definition: pprz_algebra.h:319
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:65
#define NAVGO_GYRO_LOWPASS
Definition: imu_navgo.c:51
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 with INT32_RATE_FRAC
#define PERIODIC_FREQUENCY
Definition: imu_aspirin2.c:51
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:75
#define VECT3_COPY(_a, _b)
Definition: pprz_algebra.h:129
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
int32_t r
in rad/s with INT32_RATE_FRAC
#define InitMedianFilterRatesInt(_f)
Definition: median_filter.h:93
struct Itg3200 itg
Definition: imu_navgo.h:66
void hmc58xx_event(struct Hmc58xx *hmc)
Definition: hmc58xx.c:151
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.