Paparazzi UAS  v5.15_devel-111-g8fb4629
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures Namespaces 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 #include "subsystems/abi.h"
37 
38 // Downlink
39 #include "mcu_periph/uart.h"
40 #include "pprzlink/messages.h"
42 
43 
44 #ifndef UMARIM_ACCEL_RANGE
45 #define UMARIM_ACCEL_RANGE ADXL345_RANGE_16G
46 #endif
47 PRINT_CONFIG_VAR(UMARIM_ACCEL_RANGE)
48 
49 #ifndef UMARIM_ACCEL_RATE
50 #define UMARIM_ACCEL_RATE ADXL345_RATE_50HZ
51 #endif
52 PRINT_CONFIG_VAR(UMARIM_ACCEL_RATE)
53 
54 
55 /* default gyro internal lowpass frequency and sample rate divider */
56 #if !defined UMARIM_GYRO_LOWPASS && !defined UMARIM_GYRO_SMPLRT_DIV
57 #define UMARIM_GYRO_LOWPASS ITG3200_DLPF_20HZ
58 #define UMARIM_GYRO_SMPLRT_DIV 19
59 PRINT_CONFIG_MSG("Gyro output rate is 50Hz")
60 #endif
61 PRINT_CONFIG_VAR(UMARIM_GYRO_LOWPASS)
62 PRINT_CONFIG_VAR(UMARIM_GYRO_SMPLRT_DIV)
63 
65 
66 void imu_umarim_init(void)
67 {
69  // ITG3200
70  itg3200_init(&imu_umarim.itg, &(IMU_UMARIM_I2C_DEV), ITG3200_ADDR_ALT);
71  // change the default configuration
74 
76  // ADXL345
77  adxl345_i2c_init(&imu_umarim.adxl, &(IMU_UMARIM_I2C_DEV), ADXL345_ADDR_ALT);
78  // change the default data rate
79  imu_umarim.adxl.config.rate = UMARIM_ACCEL_RATE;
80  imu_umarim.adxl.config.range = UMARIM_ACCEL_RANGE;
81 }
82 
84 {
85  // Start reading the latest gyroscope data
87 
88  // Start reading the latest accelerometer data
90 
91  //RunOnceEvery(10,imu_umarim_downlink_raw());
92 }
93 
95 {
96  DOWNLINK_SEND_IMU_GYRO_RAW(DefaultChannel, DefaultDevice, &imu.gyro_unscaled.p, &imu.gyro_unscaled.q,
98  DOWNLINK_SEND_IMU_ACCEL_RAW(DefaultChannel, DefaultDevice, &imu.accel_unscaled.x, &imu.accel_unscaled.y,
100 }
101 
102 
104 {
105  uint32_t now_ts = get_sys_time_usec();
106 
107  // If the itg3200 I2C transaction has succeeded: convert the data
111  imu_umarim.itg.data_available = false;
113  AbiSendMsgIMU_GYRO_INT32(IMU_BOARD_ID, now_ts, &imu.gyro);
114  }
115 
116  // If the adxl345 I2C transaction has succeeded: convert the data
120  imu_umarim.adxl.data.vect.z);
123  AbiSendMsgIMU_ACCEL_INT32(IMU_BOARD_ID, now_ts, &imu.accel);
124  }
125 }
126 
void imu_umarim_periodic(void)
Definition: imu_umarim.c:83
arch independent UART (Universal Asynchronous Receiver/Transmitter) API
uint8_t smplrt_div
Sample rate divider.
Definition: itg3200.h:53
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:49
union Itg3200::@310 data
#define IMU_BOARD_ID
#define UMARIM_GYRO_LOWPASS
Definition: imu_umarim.c:57
struct Adxl345_I2c adxl
Definition: imu_umarim.h:110
enum Adxl345Rates rate
Data Output Rate.
Definition: adxl345.h:53
#define VECT3_ASSIGN(_a, _x, _y, _z)
Definition: pprz_algebra.h:125
Main include for ABI (AirBorneInterface).
#define ADXL345_ADDR_ALT
Definition: adxl345_regs.h:33
struct ImuUmarim imu_umarim
Definition: imu_umarim.c:64
struct Imu imu
global IMU state
Definition: imu.c:108
int32_t r
in rad/s with INT32_RATE_FRAC
void imu_umarim_downlink_raw(void)
Definition: imu_umarim.c:94
struct Int32Rates gyro_unscaled
unscaled gyroscope measurements
Definition: imu.h:46
struct Int32Vect3 accel
accelerometer measurements in m/s^2 in BFP with INT32_ACCEL_FRAC
Definition: imu.h:39
struct Adxl345Config config
Definition: adxl345_i2c.h:49
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
unsigned long uint32_t
Definition: types.h:18
PRINT_CONFIG_MSG("USE_INS_NAV_INIT defaulting to TRUE")
void imu_umarim_init(void)
Definition: imu_umarim.c:66
#define UMARIM_GYRO_SMPLRT_DIV
Definition: imu_umarim.c:58
void imu_scale_gyro(struct Imu *_imu)
Definition: imu_vectornav.c:43
void adxl345_i2c_init(struct Adxl345_I2c *adxl, struct i2c_periph *i2c_p, uint8_t addr)
Definition: adxl345_i2c.c:36
enum Itg3200DLPF dlpf_cfg
Digital Low Pass Filter.
Definition: itg3200.h:55
void imu_umarim_event(void)
Definition: imu_umarim.c:103
void itg3200_event(struct Itg3200 *itg)
Definition: itg3200.c:126
static void itg3200_periodic(struct Itg3200 *itg)
convenience function: read or start configuration if not already initialized
Definition: itg3200.h:93
int32_t p
in rad/s with INT32_RATE_FRAC
struct Int32Vect3 accel_unscaled
unscaled accelerometer measurements
Definition: imu.h:47
void imu_scale_accel(struct Imu *_imu)
Definition: imu_vectornav.c:44
#define RATES_COPY(_a, _b)
Definition: pprz_algebra.h:337
enum Adxl345Ranges range
g Range
Definition: adxl345.h:52
volatile bool data_available
data ready flag
Definition: itg3200.h:75
uint32_t get_sys_time_usec(void)
Get the time in microseconds since startup.
Definition: sys_time_arch.c:68
#define UMARIM_ACCEL_RATE
Definition: imu_umarim.c:50
struct Itg3200Config config
Definition: itg3200.h:80
#define ITG3200_ADDR_ALT
Definition: itg3200_regs.h:32
int32_t q
in rad/s with INT32_RATE_FRAC
union Adxl345_I2c::@299 data
#define UMARIM_ACCEL_RANGE
Definition: imu_umarim.c:45
volatile bool data_available
data ready flag
Definition: adxl345_i2c.h:44
struct Int32Rates gyro
gyroscope measurements in rad/s in BFP with INT32_RATE_FRAC
Definition: imu.h:38
Architecture independent I2C (Inter-Integrated Circuit Bus) API.
struct Itg3200 itg
Definition: imu_umarim.h:109