Paparazzi UAS  v5.18.0_stable
Paparazzi is a free software Unmanned Aircraft System.
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
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 
Itg3200Config::smplrt_div
uint8_t smplrt_div
Sample rate divider.
Definition: itg3200.h:53
Imu::gyro_unscaled
struct Int32Rates gyro_unscaled
unscaled gyroscope measurements
Definition: imu.h:46
imu_umarim
struct ImuUmarim imu_umarim
Definition: imu_umarim.c:64
Adxl345Config::range
enum Adxl345Ranges range
g Range
Definition: adxl345.h:52
Itg3200::config
struct Itg3200Config config
Definition: itg3200.h:80
ITG3200_ADDR_ALT
#define ITG3200_ADDR_ALT
Definition: itg3200_regs.h:32
adxl345_i2c_event
void adxl345_i2c_event(struct Adxl345_I2c *adxl)
Definition: adxl345_i2c.c:114
itg3200_init
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
abi.h
Imu::accel
struct Int32Vect3 accel
accelerometer measurements in m/s^2 in BFP with INT32_ACCEL_FRAC
Definition: imu.h:39
Int32Rates::q
int32_t q
in rad/s with INT32_RATE_FRAC
Definition: pprz_algebra_int.h:181
ADXL345_ADDR_ALT
#define ADXL345_ADDR_ALT
Definition: adxl345_regs.h:33
imu_umarim_periodic
void imu_umarim_periodic(void)
Definition: imu_umarim.c:83
Int32Vect3::z
int32_t z
Definition: pprz_algebra_int.h:91
Adxl345Config::rate
enum Adxl345Rates rate
Data Output Rate.
Definition: adxl345.h:53
Adxl345_I2c::config
struct Adxl345Config config
Definition: adxl345_i2c.h:49
uint32_t
unsigned long uint32_t
Definition: types.h:18
UMARIM_ACCEL_RATE
#define UMARIM_ACCEL_RATE
Definition: imu_umarim.c:50
adxl345_i2c_init
void adxl345_i2c_init(struct Adxl345_I2c *adxl, struct i2c_periph *i2c_p, uint8_t addr)
Definition: adxl345_i2c.c:36
IMU_BOARD_ID
#define IMU_BOARD_ID
Definition: abi_sender_ids.h:275
imu_umarim_event
void imu_umarim_event(void)
Definition: imu_umarim.c:103
adxl345_i2c_periodic
static void adxl345_i2c_periodic(struct Adxl345_I2c *adxl)
convenience function: read or start configuration if not already initialized
Definition: adxl345_i2c.h:59
Imu::accel_unscaled
struct Int32Vect3 accel_unscaled
unscaled accelerometer measurements
Definition: imu.h:47
UMARIM_GYRO_LOWPASS
#define UMARIM_GYRO_LOWPASS
Definition: imu_umarim.c:57
get_sys_time_usec
uint32_t get_sys_time_usec(void)
Get the time in microseconds since startup.
Definition: sys_time_arch.c:68
Int32Rates::p
int32_t p
in rad/s with INT32_RATE_FRAC
Definition: pprz_algebra_int.h:180
uart.h
arch independent UART (Universal Asynchronous Receiver/Transmitter) API
UMARIM_GYRO_SMPLRT_DIV
#define UMARIM_GYRO_SMPLRT_DIV
Definition: imu_umarim.c:58
Itg3200Config::dlpf_cfg
enum Itg3200DLPF dlpf_cfg
Digital Low Pass Filter.
Definition: itg3200.h:55
imu_scale_gyro
void imu_scale_gyro(struct Imu *_imu)
Definition: imu_vectornav.c:43
Int32Vect3::y
int32_t y
Definition: pprz_algebra_int.h:90
ImuUmarim
Definition: imu_umarim.h:108
Itg3200::data
union Itg3200::@319 data
imu_umarim_downlink_raw
void imu_umarim_downlink_raw(void)
Definition: imu_umarim.c:94
imu
struct Imu imu
global IMU state
Definition: imu.c:108
PRINT_CONFIG_MSG
PRINT_CONFIG_MSG("USE_INS_NAV_INIT defaulting to TRUE")
ImuUmarim::adxl
struct Adxl345_I2c adxl
Definition: imu_umarim.h:110
Adxl345_I2c::data
union Adxl345_I2c::@304 data
Adxl345_I2c::data_available
volatile bool data_available
data ready flag
Definition: adxl345_i2c.h:44
Int32Vect3::x
int32_t x
Definition: pprz_algebra_int.h:89
VECT3_ASSIGN
#define VECT3_ASSIGN(_a, _x, _y, _z)
Definition: pprz_algebra.h:125
RATES_COPY
#define RATES_COPY(_a, _b)
Definition: pprz_algebra.h:337
imu_umarim.h
ImuUmarim::itg
struct Itg3200 itg
Definition: imu_umarim.h:109
i2c.h
Itg3200::data_available
volatile bool data_available
data ready flag
Definition: itg3200.h:75
Int32Rates::r
int32_t r
in rad/s with INT32_RATE_FRAC
Definition: pprz_algebra_int.h:182
imu_scale_accel
void imu_scale_accel(struct Imu *_imu)
Definition: imu_vectornav.c:44
imu_umarim_init
void imu_umarim_init(void)
Definition: imu_umarim.c:66
itg3200_event
void itg3200_event(struct Itg3200 *itg)
Definition: itg3200.c:126
UMARIM_ACCEL_RANGE
#define UMARIM_ACCEL_RANGE
Definition: imu_umarim.c:45
itg3200_periodic
static void itg3200_periodic(struct Itg3200 *itg)
convenience function: read or start configuration if not already initialized
Definition: itg3200.h:93
Imu::gyro
struct Int32Rates gyro
gyroscope measurements in rad/s in BFP with INT32_RATE_FRAC
Definition: imu.h:38