Paparazzi UAS  v6.2_unstable
Paparazzi is a free software Unmanned Aircraft System.
imu_nps.c
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2012 Felix Ruess <felix.ruess@gmail.com
3  *
4  * This file is part of paparazzi.
5  *
6  * paparazzi is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2, or (at your option)
9  * any later version.
10  *
11  * paparazzi is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with paparazzi; see the file COPYING. If not, write to
18  * the Free Software Foundation, 59 Temple Place - Suite 330,
19  * Boston, MA 02111-1307, USA.
20  */
21 
22 #include "modules/imu/imu.h"
23 #include "modules/core/abi.h"
24 #include "generated/airframe.h"
25 #include "modules/imu/imu_nps.h"
26 #include "nps_sensors.h"
27 
28 struct ImuNps imu_nps;
29 
30 void imu_nps_init(void)
31 {
32 
33  imu_nps.gyro_available = false;
34  imu_nps.mag_available = false;
35  imu_nps.accel_available = false;
36 
37 }
38 
39 
41 {
42 
43  RATES_ASSIGN(imu.gyro_unscaled, sensors.gyro.value.x, sensors.gyro.value.y, sensors.gyro.value.z);
44  VECT3_ASSIGN(imu.accel_unscaled, sensors.accel.value.x, sensors.accel.value.y, sensors.accel.value.z);
45 
46  // set availability flags...
47  imu_nps.accel_available = true;
48  imu_nps.gyro_available = true;
49 
50 }
51 
52 
53 void imu_feed_mag(void)
54 {
55 
56  VECT3_ASSIGN(imu.mag_unscaled, sensors.mag.value.x, sensors.mag.value.y, sensors.mag.value.z);
57  imu_nps.mag_available = true;
58 
59 }
60 
61 void imu_nps_event(void)
62 {
63  uint32_t now_ts = get_sys_time_usec();
64  if (imu_nps.gyro_available) {
65  imu_nps.gyro_available = false;
67  AbiSendMsgIMU_GYRO_INT32(IMU_BOARD_ID, now_ts, &imu.gyro);
68  }
70  imu_nps.accel_available = false;
72  AbiSendMsgIMU_ACCEL_INT32(IMU_BOARD_ID, now_ts, &imu.accel);
73  }
74  if (imu_nps.mag_available) {
75  imu_nps.mag_available = false;
77  AbiSendMsgIMU_MAG_INT32(IMU_BOARD_ID, now_ts, &imu.mag);
78  }
79 }
Imu::gyro_unscaled
struct Int32Rates gyro_unscaled
unscaled gyroscope measurements
Definition: imu.h:46
uint32_t
unsigned int uint32_t
Typedef defining 32 bit unsigned int type.
Definition: vl53l1_types.h:78
imu_nps
struct ImuNps imu_nps
Definition: imu_nps.c:28
imu_nps_init
void imu_nps_init(void)
Definition: imu_nps.c:30
abi.h
Imu::accel
struct Int32Vect3 accel
accelerometer measurements in m/s^2 in BFP with INT32_ACCEL_FRAC
Definition: imu.h:39
IMU_BOARD_ID
#define IMU_BOARD_ID
Definition: abi_sender_ids.h:291
imu_feed_gyro_accel
void imu_feed_gyro_accel(void)
Definition: imu_nps.c:40
imu_feed_mag
void imu_feed_mag(void)
Definition: imu_nps.c:53
imu_scale_gyro
void WEAK imu_scale_gyro(struct Imu *_imu)
Definition: imu.c:208
ImuNps::gyro_available
uint8_t gyro_available
Definition: imu_nps.h:75
Imu::accel_unscaled
struct Int32Vect3 accel_unscaled
unscaled accelerometer measurements
Definition: imu.h:47
get_sys_time_usec
uint32_t get_sys_time_usec(void)
Get the time in microseconds since startup.
Definition: sys_time_arch.c:75
imu.h
RATES_ASSIGN
#define RATES_ASSIGN(_ra, _p, _q, _r)
Definition: pprz_algebra.h:330
imu_scale_accel
void WEAK imu_scale_accel(struct Imu *_imu)
Definition: imu.c:219
nps_sensors.h
ImuNps::accel_available
uint8_t accel_available
Definition: imu_nps.h:74
imu
struct Imu imu
global IMU state
Definition: imu.c:108
imu_nps_event
void imu_nps_event(void)
Definition: imu_nps.c:61
ImuNps::mag_available
uint8_t mag_available
Definition: imu_nps.h:73
imu_nps.h
Imu::mag
struct Int32Vect3 mag
magnetometer measurements scaled to 1 in BFP with INT32_MAG_FRAC
Definition: imu.h:40
Imu::mag_unscaled
struct Int32Vect3 mag_unscaled
unscaled magnetometer measurements
Definition: imu.h:48
ImuNps
Definition: imu_nps.h:72
VECT3_ASSIGN
#define VECT3_ASSIGN(_a, _x, _y, _z)
Definition: pprz_algebra.h:125
imu_scale_mag
void WEAK imu_scale_mag(struct Imu *_imu)
Definition: imu.c:246
sensors
#define sensors(...)
Definition: cc2500_compat.h:68
Imu::gyro
struct Int32Rates gyro
gyroscope measurements in rad/s in BFP with INT32_RATE_FRAC
Definition: imu.h:38