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_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 "led.h"
36 
37 // Downlink
38 #include "mcu_periph/uart.h"
39 #include "messages.h"
41 
42 #ifndef DOWNLINK_DEVICE
43 #define DOWNLINK_DEVICE DOWNLINK_AP_DEVICE
44 #endif
45 
46 #ifndef UMARIM_ACCEL_RATE
47 #define UMARIM_ACCEL_RATE ADXL345_RATE_50HZ
48 #endif
49 PRINT_CONFIG_VAR(UMARIM_ACCEL_RATE)
50 
51 
52 /* default gyro internal lowpass frequency and sample rate divider */
53 #if !defined UMARIM_GYRO_LOWPASS && !defined UMARIM_GYRO_SMPLRT_DIV
54 #define UMARIM_GYRO_LOWPASS ITG3200_DLPF_20HZ
55 #define UMARIM_GYRO_SMPLRT_DIV 19
56 PRINT_CONFIG_MSG("Gyro output rate is 50Hz")
57 #endif
58 PRINT_CONFIG_VAR(UMARIM_GYRO_LOWPASS)
59 PRINT_CONFIG_VAR(UMARIM_GYRO_SMPLRT_DIV)
60 
62 
63 void imu_impl_init(void)
64 {
66  // ITG3200
67  itg3200_init(&imu_umarim.itg, &(IMU_UMARIM_I2C_DEV), ITG3200_ADDR_ALT);
68  // change the default configuration
71 
73  // ADXL345
74  adxl345_i2c_init(&imu_umarim.adxl, &(IMU_UMARIM_I2C_DEV), ADXL345_ADDR_ALT);
75  // change the default data rate
76  imu_umarim.adxl.config.rate = UMARIM_ACCEL_RATE;
77 
78  imu_umarim.gyr_valid = FALSE;
79  imu_umarim.acc_valid = FALSE;
80 }
81 
82 void imu_periodic( void )
83 {
84  // Start reading the latest gyroscope data
86 
87  // Start reading the latest accelerometer data
89 
90  //RunOnceEvery(10,imu_umarim_downlink_raw());
91 }
92 
94 {
97 }
98 
99 
100 void imu_umarim_event( void )
101 {
102  // If the itg3200 I2C transaction has succeeded: convert the data
108  }
109 
110  // If the adxl345 I2C transaction has succeeded: convert the data
116  }
117 }
118 
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:54
int32_t p
in rad/s^2 with INT32_RATE_FRAC
#define RATES_COPY(_a, _b)
Definition: pprz_algebra.h:301
#define ADXL345_ADDR_ALT
Definition: adxl345_regs.h:33
struct ImuUmarim imu_umarim
Definition: imu_umarim.c:61
struct Int32Rates gyro_unscaled
unscaled gyroscope measurements
Definition: imu.h:48
struct Int32Rates rates
data as angular rates in gyro coordinate system
Definition: itg3200.h:77
void imu_impl_init(void)
Definition: imu_umarim.c:63
struct Int16Vect3 vect
data vector in accel coordinate system
Definition: adxl345_i2c.h:46
#define FALSE
Definition: imu_chimu.h:141
void imu_periodic(void)
Definition: imu_umarim.c:82
volatile bool_t acc_valid
Definition: imu_umarim.h:110
void imu_umarim_downlink_raw(void)
Definition: imu_umarim.c:93
struct Adxl345_I2c adxl
Definition: imu_umarim.h:112
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
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 UMARIM_GYRO_SMPLRT_DIV
Definition: imu_umarim.c:55
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:97
void imu_umarim_event(void)
Definition: imu_umarim.c:100
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^2 with INT32_RATE_FRAC
arch independent LED (Light Emitting Diodes) API
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 UMARIM_ACCEL_RATE
Definition: imu_umarim.c:47
union Itg3200::@21 data
#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
Architecture independent I2C (Inter-Integrated Circuit Bus) API.