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_umarim.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 
32 #include <math.h>
33 #include "imu_umarim.h"
34 #include "mcu_periph/i2c.h"
35 #include "generated/airframe.h"
36 
37 // Downlink
38 #include "mcu_periph/uart.h"
39 #include "messages.h"
41 
42 
43 #ifndef UMARIM_ACCEL_RANGE
44 #define UMARIM_ACCEL_RANGE ADXL345_RANGE_16G
45 #endif
47 
48 #ifndef UMARIM_ACCEL_RATE
49 #define UMARIM_ACCEL_RATE ADXL345_RATE_50HZ
50 #endif
52 
53 
54 /* default gyro internal lowpass frequency and sample rate divider */
55 #if !defined UMARIM_GYRO_LOWPASS && !defined UMARIM_GYRO_SMPLRT_DIV
56 #define UMARIM_GYRO_LOWPASS ITG3200_DLPF_20HZ
57 #define UMARIM_GYRO_SMPLRT_DIV 19
58 PRINT_CONFIG_MSG("Gyro output rate is 50Hz")
59 #endif
62 
64 
65 void imu_impl_init(void)
66 {
68  // ITG3200
69  itg3200_init(&imu_umarim.itg, &(IMU_UMARIM_I2C_DEV), ITG3200_ADDR_ALT);
70  // change the default configuration
73 
75  // ADXL345
76  adxl345_i2c_init(&imu_umarim.adxl, &(IMU_UMARIM_I2C_DEV), ADXL345_ADDR_ALT);
77  // change the default data rate
78  imu_umarim.adxl.config.rate = UMARIM_ACCEL_RATE;
79  imu_umarim.adxl.config.range = UMARIM_ACCEL_RANGE;
80 
81  imu_umarim.gyr_valid = FALSE;
82  imu_umarim.acc_valid = FALSE;
83 }
84 
85 void imu_periodic( void )
86 {
87  // Start reading the latest gyroscope data
89 
90  // Start reading the latest accelerometer data
92 
93  //RunOnceEvery(10,imu_umarim_downlink_raw());
94 }
95 
97 {
100 }
101 
102 
103 void imu_umarim_event( void )
104 {
105  // If the itg3200 I2C transaction has succeeded: convert the data
111  }
112 
113  // If the adxl345 I2C transaction has succeeded: convert the data
119  }
120 }
121 
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 UMARIM_GYRO_LOWPASS
Definition: imu_umarim.c:56
int32_t p
in rad/s with INT32_RATE_FRAC
#define RATES_COPY(_a, _b)
Definition: pprz_algebra.h:326
#define ADXL345_ADDR_ALT
Definition: adxl345_regs.h:33
struct ImuUmarim imu_umarim
Definition: imu_umarim.c:63
struct Int32Rates gyro_unscaled
unscaled gyroscope measurements
Definition: imu.h:49
struct Int32Rates rates
data as angular rates in gyro coordinate system
Definition: itg3200.h:77
union Adxl345_I2c::@21 data
enum Adxl345Ranges range
g Range
Definition: adxl345.h:52
void imu_impl_init(void)
Definition: imu_umarim.c:65
struct Int16Vect3 vect
data vector in accel coordinate system
Definition: adxl345_i2c.h:46
#define FALSE
Definition: imu_chimu.h:141
union Itg3200::@30 data
void imu_periodic(void)
Definition: imu_umarim.c:85
volatile bool_t acc_valid
Definition: imu_umarim.h:110
void imu_umarim_downlink_raw(void)
Definition: imu_umarim.c:96
struct Adxl345_I2c adxl
Definition: imu_umarim.h:112
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
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 UMARIM_GYRO_SMPLRT_DIV
Definition: imu_umarim.c:57
struct Itg3200 itg
Definition: imu_umarim.h:111
void adxl345_i2c_init(struct Adxl345_I2c *adxl, struct i2c_periph *i2c_p, uint8_t addr)
Definition: adxl345_i2c.c:36
#define TRUE
Definition: imu_chimu.h:144
volatile bool_t data_available
data ready flag
Definition: itg3200.h:75
#define VECT3_ASSIGN(_a, _x, _y, _z)
Definition: pprz_algebra.h:107
void imu_umarim_event(void)
Definition: imu_umarim.c:103
enum Adxl345Rates rate
Data Output Rate.
Definition: adxl345.h:53
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
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 UMARIM_ACCEL_RATE
Definition: imu_umarim.c:49
#define ITG3200_ADDR_ALT
Definition: itg3200_regs.h:32
volatile bool_t gyr_valid
Definition: imu_umarim.h:109
volatile bool_t data_available
data ready flag
Definition: adxl345_i2c.h:44
#define UMARIM_ACCEL_RANGE
Definition: imu_umarim.c:44
Architecture independent I2C (Inter-Integrated Circuit Bus) API.