Paparazzi UAS  v7.0_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, see
18  * <http://www.gnu.org/licenses/>.
19  */
20 
21 #include "modules/imu/imu_nps.h"
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  // Set the default scaling
38  const struct Int32Rates gyro_scale[2] = {
39  {NPS_GYRO_SENSITIVITY_PP_NUM, NPS_GYRO_SENSITIVITY_QQ_NUM, NPS_GYRO_SENSITIVITY_RR_NUM},
40  {NPS_GYRO_SENSITIVITY_PP_DEN, NPS_GYRO_SENSITIVITY_QQ_DEN, NPS_GYRO_SENSITIVITY_RR_DEN}
41  };
42  const struct Int32Rates gyro_neutral = {
43  NPS_GYRO_NEUTRAL_P, NPS_GYRO_NEUTRAL_Q, NPS_GYRO_NEUTRAL_R
44  };
45  const struct Int32Vect3 accel_scale[2] = {
46  {NPS_ACCEL_SENSITIVITY_XX_NUM, NPS_ACCEL_SENSITIVITY_YY_NUM, NPS_ACCEL_SENSITIVITY_ZZ_NUM},
47  {NPS_ACCEL_SENSITIVITY_XX_DEN, NPS_ACCEL_SENSITIVITY_YY_DEN, NPS_ACCEL_SENSITIVITY_ZZ_DEN}
48  };
49  const struct Int32Vect3 accel_neutral = {
50  NPS_ACCEL_NEUTRAL_X, NPS_ACCEL_NEUTRAL_Y, NPS_ACCEL_NEUTRAL_Z
51  };
52  const struct Int32Vect3 mag_scale[2] = {
53  {NPS_MAG_SENSITIVITY_XX_NUM, NPS_MAG_SENSITIVITY_YY_NUM, NPS_MAG_SENSITIVITY_ZZ_NUM},
54  {NPS_MAG_SENSITIVITY_XX_DEN, NPS_MAG_SENSITIVITY_YY_DEN, NPS_MAG_SENSITIVITY_ZZ_DEN}
55  };
56  const struct Int32Vect3 mag_neutral = {
57  NPS_MAG_NEUTRAL_X, NPS_MAG_NEUTRAL_Y, NPS_MAG_NEUTRAL_Z
58  };
59  imu_set_defaults_gyro(IMU_NPS_ID, NULL, &gyro_neutral, gyro_scale);
61  imu_set_defaults_mag(IMU_NPS_ID, NULL, &mag_neutral, mag_scale);
62 }
63 
64 
66 {
67  RATES_ASSIGN(imu_nps.gyro, sensors.gyro.value.x, sensors.gyro.value.y, sensors.gyro.value.z);
68  VECT3_COPY(imu_nps.accel, sensors.accel.value);
69 
70  // set availability flags...
71  imu_nps.accel_available = true;
72  imu_nps.gyro_available = true;
73 }
74 
75 
76 void imu_feed_mag(void)
77 {
78  VECT3_COPY(imu_nps.mag, sensors.mag.value);
79  imu_nps.mag_available = true;
80 }
81 
82 
83 void imu_nps_event(void)
84 {
85  uint32_t now_ts = get_sys_time_usec();
86  if (imu_nps.gyro_available) {
87  AbiSendMsgIMU_GYRO_RAW(IMU_NPS_ID, now_ts, &imu_nps.gyro, 1, NPS_PROPAGATE, NAN);
88  imu_nps.gyro_available = false;
89  }
91  AbiSendMsgIMU_ACCEL_RAW(IMU_NPS_ID, now_ts, &imu_nps.accel, 1, NPS_PROPAGATE, NAN);
92  imu_nps.accel_available = false;
93  }
94  if (imu_nps.mag_available) {
95  AbiSendMsgIMU_MAG_RAW(IMU_NPS_ID, now_ts, &imu_nps.mag);
96  imu_nps.mag_available = false;
97  }
98 }
Main include for ABI (AirBorneInterface).
#define IMU_NPS_ID
#define sensors(...)
Definition: cc2500_compat.h:68
uint32_t get_sys_time_usec(void)
Get the time in microseconds since startup.
Definition: sys_time_arch.c:71
#define RATES_ASSIGN(_ra, _p, _q, _r)
Definition: pprz_algebra.h:330
#define VECT3_COPY(_a, _b)
Definition: pprz_algebra.h:140
angular rates
void imu_set_defaults_mag(uint8_t abi_id, const struct Int32RMat *imu_to_sensor, const struct Int32Vect3 *neutral, const struct Int32Vect3 *scale)
Set the defaults for a mag sensor WARNING: Should be called before sensor is publishing messages to e...
Definition: imu.c:551
void imu_set_defaults_accel(uint8_t abi_id, const struct Int32RMat *imu_to_sensor, const struct Int32Vect3 *neutral, const struct Int32Vect3 *scale)
Set the defaults for a accel sensor WARNING: Should be called before sensor is publishing messages to...
Definition: imu.c:521
void imu_set_defaults_gyro(uint8_t abi_id, const struct Int32RMat *imu_to_sensor, const struct Int32Rates *neutral, const struct Int32Rates *scale)
Set the defaults for a gyro sensor WARNING: Should be called before sensor is publishing messages to ...
Definition: imu.c:491
Inertial Measurement Unit interface.
void imu_feed_mag(void)
Definition: imu_nps.c:76
void imu_feed_gyro_accel(void)
Definition: imu_nps.c:65
void imu_nps_event(void)
Definition: imu_nps.c:83
struct ImuNps imu_nps
Definition: imu_nps.c:28
void imu_nps_init(void)
Definition: imu_nps.c:30
struct Int32Rates gyro
Definition: imu_nps.h:33
struct Int32Vect3 accel
Definition: imu_nps.h:34
uint8_t gyro_available
Definition: imu_nps.h:31
struct Int32Vect3 mag
Definition: imu_nps.h:35
uint8_t mag_available
Definition: imu_nps.h:29
uint8_t accel_available
Definition: imu_nps.h:30
Definition: imu_nps.h:28
static const struct Int32Vect3 accel_neutral
Definition: navdata.c:104
static const struct Int32Vect3 mag_scale[2]
Default mag scale.
Definition: navdata.c:111
static const struct Int32Rates gyro_scale[2]
Default gyro scale.
Definition: navdata.c:92
static const struct Int32Vect3 accel_scale[2]
Default accel scale/neutral.
Definition: navdata.c:100
unsigned int uint32_t
Typedef defining 32 bit unsigned int type.
Definition: vl53l1_types.h:78