Paparazzi UAS  v4.2.2_stable-4-gcc32f65
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros 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  */
23 
24 #include <math.h>
25 #include "imu_navgo.h"
26 #include "mcu_periph/i2c.h"
27 #include "led.h"
28 
29 // Downlink
30 #include "mcu_periph/uart.h"
31 #include "messages.h"
33 
34 #ifndef DOWNLINK_DEVICE
35 #define DOWNLINK_DEVICE DOWNLINK_AP_DEVICE
36 #endif
37 
38 // Peripherials
39 
40 // Configure ITG3200
41 // ITG3200_I2C_DEVICE IMU_UMARIM_I2C_DEVICE
42 // ITG3200_I2C_ADDR ITG3200_ADDR_ALT
43 // ITG3200_SMPLRT_DIV 1
45 
46 // Configure ADXL345
47 // ADXL345_I2C_DEVICE IMU_UMARIM_I2C_DEVICE
48 // ADXL345_I2C_ADDR ADXL345_ADDR_ALT
50 
51 // Configure HMC58XX
52 #include "peripherals/hmc58xx.h"
53 
54 // Results
55 volatile bool_t gyr_valid;
56 volatile bool_t acc_valid;
57 volatile bool_t mag_valid;
58 
59 void imu_impl_init(void)
60 {
62  // ITG3200
63  itg3200_init();
64 
66  // ADXL345
67  adxl345_init();
68 
70  // HMC58XX
71  hmc58xx_init();
72 }
73 
74 void imu_periodic( void )
75 {
76  // Start reading the latest gyroscope data
78 
79  // Start reading the latest accelerometer data
80  // Periodicity is automatically adapted
81  // 3200 is the maximum output freq corresponding to the parameter 0xF
82  // A factor 2 is applied to reduice the delay without overloading the i2c
83  RunOnceEvery((PERIODIC_FREQUENCY/(2*3200>>(0xf-ADXL345_BW_RATE))),Adxl345Periodic());
84 
85  // Read HMC58XX at 100Hz (main loop for rotorcraft: 512Hz)
86  RunOnceEvery(5,Hmc58xxPeriodic());
87 
88  //RunOnceEvery(20,imu_navgo_downlink_raw());
89 }
90 
91 
93 {
97 }
98 
99 
100 void imu_navgo_event( void )
101 {
102 
103  // If the itg3200 I2C transaction has succeeded: convert the data
104  itg3200_event();
108  gyr_valid = TRUE;
109  }
110 
111  // If the adxl345 I2C transaction has succeeded: convert the data
112  adxl345_event();
116  acc_valid = TRUE;
117  }
118 
119  // HMC58XX event task
120  hmc58xx_event();
124  mag_valid = TRUE;
125  }
126 
127 }
128 
void imu_navgo_event(void)
Definition: imu_navgo.c:100
void imu_periodic(void)
Definition: imu_navgo.c:74
volatile bool_t mag_valid
Definition: imu_navgo.c:57
arch independent UART (Universal Asynchronous Receiver/Transmitter) API
void adxl345_event(void)
Definition: adxl345.i2c.c:116
struct Int16Vect3 hmc58xx_data
Definition: hmc58xx.c:39
void adxl345_init(void)
Definition: adxl345.i2c.c:49
int32_t p
in rad/s^2 with INT32_RATE_FRAC
void itg3200_init(void)
Definition: itg3200.c:49
#define Adxl345Periodic()
struct Int32Rates gyro_unscaled
unscaled gyroscope measurements
Definition: imu.h:48
void imu_navgo_downlink_raw(void)
Definition: imu_navgo.c:92
volatile bool_t itg3200_data_available
Definition: itg3200.c:38
void hmc58xx_event(void)
Definition: hmc58xx.c:109
struct Int16Vect3 adxl345_data
Definition: adxl345.i2c.c:40
void hmc58xx_init(void)
Definition: hmc58xx.c:48
#define PERIODIC_FREQUENCY
Definition: imu_aspirin2.c:54
#define FALSE
Definition: imu_chimu.h:141
volatile bool_t acc_valid
Definition: imu_navgo.c:56
struct Int32Vect3 accel_unscaled
unscaled accelerometer measurements
Definition: imu.h:49
#define Itg3200Periodic()
Definition: itg3200.extra.h:85
volatile bool_t adxl345_data_available
Definition: adxl345.i2c.c:38
struct Int32Rates itg3200_data
Definition: itg3200.c:40
struct Int32Vect3 mag_unscaled
unscaled magnetometer measurements
Definition: imu.h:50
#define TRUE
Definition: imu_chimu.h:144
#define VECT3_ASSIGN(_a, _x, _y, _z)
Definition: pprz_algebra.h:99
volatile bool_t hmc58xx_data_available
Definition: hmc58xx.c:37
volatile bool_t gyr_valid
Definition: imu_navgo.c:55
#define RATES_ASSIGN(_ra, _p, _q, _r)
Definition: pprz_algebra.h:296
void imu_impl_init(void)
Definition: imu_navgo.c:59
int32_t q
in rad/s^2 with INT32_RATE_FRAC
arch independent LED (Light Emitting Diodes) API
#define ADXL345_BW_RATE
struct Imu imu
global IMU state
Definition: imu_aspirin2.c:50
int32_t r
in rad/s^2 with INT32_RATE_FRAC
#define Hmc58xxPeriodic()
Definition: hmc58xx.h:91
void itg3200_event(void)
Definition: itg3200.c:116