Paparazzi UAS v7.1_unstable
Paparazzi is a free software Unmanned Aircraft System.
Loading...
Searching...
No Matches
ins_float_invariant_wrapper.c
Go to the documentation of this file.
1/*
2 * Copyright (C) 2012-2013 Jean-Philippe Condomines, Gautier Hattenberger
3 * 2015 Felix Ruess <felix.ruess@gmail.com>
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, see
19 * <http://www.gnu.org/licenses/>.
20 */
21
27
29#include "modules/core/abi.h"
30#include "mcu_periph/sys_time.h"
31#include "message_pragmas.h"
32#if USE_AHRS_ALIGNER
34#endif
35
36#ifndef INS_FINV_FILTER_ID
37#define INS_FINV_FILTER_ID 2
38#endif
39
42
45
46#if PERIODIC_TELEMETRY && !INS_FINV_USE_UTM
48#include "state.h"
49static void send_ins_ref(struct transport_tx *trans, struct link_device *dev)
50{
51 float foo = 0.;
52 if (state.ned_initialized_i) {
53 struct EcefCoor_i ecef = stateGetEcefOrigin_i();
54 struct LlaCoor_i lla = stateGetLlaOrigin_i();
56 pprz_msg_send_INS_REF(trans, dev, AC_ID, &ecef.x, &ecef.y, &ecef.z, &lla.lat, &lla.lon, &lla.alt, &hmsl, &foo);
57 }
58}
59
60static void send_filter_status(struct transport_tx *trans, struct link_device *dev)
61{
63 uint8_t mde = 3;
64 uint16_t val = 0;
65 if (!ins_float_inv.is_aligned) { mde = 2; }
67 /* set lost if no new gyro measurements for 50ms */
68 if (t_diff > 50000) { mde = 5; }
69 pprz_msg_send_STATE_FILTER_STATUS(trans, dev, AC_ID, &id, &mde, &val);
70}
71#endif
72
73
74/*
75 * ABI bindings
76 */
78#ifndef INS_FINV_BARO_ID
79#define INS_FINV_BARO_ID AIR_DATA_SENDER_ID
80#endif
82
83
84#ifndef INS_FINV_IMU_ID
85#define INS_FINV_IMU_ID ABI_BROADCAST
86#endif
88
89
90#if USE_MAGNETOMETER
91#ifndef INS_FINV_MAG_ID
92#define INS_FINV_MAG_ID ABI_BROADCAST
93#endif
95#else
96PRINT_CONFIG_MSG("INS invariant use GPS heading as magnetometer")
97#endif
98
102#ifndef INS_FINV_GPS_ID
103#define INS_FINV_GPS_ID GPS_MULTI_ID
104#endif
106
111#if USE_MAGNETOMETER
114#endif
117
118static void baro_cb(uint8_t __attribute__((unused)) sender_id, __attribute__((unused)) uint32_t stamp, float pressure)
119{
121}
122
128static void gyro_cb(uint8_t sender_id __attribute__((unused)),
129 uint32_t stamp, struct Int32Rates *gyro)
130{
131 struct FloatRates gyro_f;
132 RATES_FLOAT_OF_BFP(gyro_f, *gyro);
133
134#if USE_AHRS_ALIGNER
135 if (ins_float_inv.reset) {
137 }
138#endif
139
140#if USE_AUTO_INS_FREQ || !defined(INS_PROPAGATE_FREQUENCY)
141 PRINT_CONFIG_MSG("Calculating dt for INS float_invariant propagation.")
142 /* timestamp in usec when last callback was received */
143 static uint32_t last_stamp = 0;
144
145 if (last_stamp > 0) {
146 float dt = (float)(stamp - last_stamp) * 1e-6;
148 }
149 last_stamp = stamp;
150#else
151 PRINT_CONFIG_MSG("Using fixed INS_PROPAGATE_FREQUENCY for INS float_invariant propagation.")
152 PRINT_CONFIG_VAR(INS_PROPAGATE_FREQUENCY)
153 const float dt = 1. / (INS_PROPAGATE_FREQUENCY);
155#endif
156
157 ins_finv_last_stamp = stamp;
158}
159
160static void accel_cb(uint8_t sender_id __attribute__((unused)),
161 uint32_t stamp __attribute__((unused)),
162 struct Int32Vect3 *accel)
163{
165}
166
167static void aligner_cb(uint8_t __attribute__((unused)) sender_id,
168 uint32_t stamp __attribute__((unused)),
169 struct Int32Rates *lp_gyro, struct Int32Vect3 *lp_accel,
170 struct Int32Vect3 *lp_mag)
171{
172 if (!ins_float_inv.is_aligned) {
173 /* convert to float */
174 struct FloatRates gyro_f;
175 RATES_FLOAT_OF_BFP(gyro_f, *lp_gyro);
176 struct FloatVect3 accel_f;
177 ACCELS_FLOAT_OF_BFP(accel_f, *lp_accel);
178 struct FloatVect3 mag_f;
179 MAGS_FLOAT_OF_BFP(mag_f, *lp_mag);
180 ins_float_invariant_align(&gyro_f, &accel_f, &mag_f);
181 }
182}
183
184#if USE_MAGNETOMETER
185static void mag_cb(uint8_t sender_id __attribute__((unused)),
186 uint32_t stamp __attribute__((unused)),
187 struct Int32Vect3 *mag)
188{
189 if (ins_float_inv.is_aligned) {
190 struct FloatVect3 mag_f;
191 MAGS_FLOAT_OF_BFP(mag_f, *mag);
193 }
194}
195
196static void geo_mag_cb(uint8_t sender_id __attribute__((unused)), struct FloatVect3 *h)
197{
198 ins_float_inv.mag_h = *h;
199}
200#endif
201
202static void gps_cb(uint8_t sender_id __attribute__((unused)),
203 uint32_t stamp __attribute__((unused)),
204 struct GpsState *gps_s)
205{
207}
208
209static void reset_cb(uint8_t sender_id UNUSED, uint8_t flag)
210{
211 switch (flag) {
212 case INS_RESET_REF:
214 break;
217 break;
218 default:
219 // unsupported cases
220 break;
221 }
222}
223
225{
226 // aligner
227#if USE_AHRS_ALIGNER
229#endif
230
232
233 // Bind to ABI messages
234 AbiBindMsgBARO_ABS(INS_FINV_BARO_ID, &baro_ev, baro_cb);
235 AbiBindMsgIMU_GYRO(INS_FINV_IMU_ID, &gyro_ev, gyro_cb);
236 AbiBindMsgIMU_ACCEL(INS_FINV_IMU_ID, &accel_ev, accel_cb);
237 AbiBindMsgIMU_LOWPASSED(ABI_BROADCAST, &aligner_ev, aligner_cb);
238#if USE_MAGNETOMETER
239 AbiBindMsgIMU_MAG(INS_FINV_MAG_ID, &mag_ev, mag_cb);
240 AbiBindMsgGEO_MAG(ABI_BROADCAST, &geo_mag_ev, geo_mag_cb);
241#endif
242 AbiBindMsgGPS(INS_FINV_GPS_ID, &gps_ev, gps_cb);
243 AbiBindMsgINS_RESET(ABI_BROADCAST, &reset_ev, reset_cb);
244
245#if PERIODIC_TELEMETRY && !INS_FINV_USE_UTM
247 register_periodic_telemetry(DefaultPeriodic, PPRZ_MSG_ID_STATE_FILTER_STATUS, send_filter_status);
248#endif
249}
static void h(const real32_T x[7], const real32_T q[4], real32_T y[6])
Main include for ABI (AirBorneInterface).
struct abi_struct abi_event
Definition abi_common.h:101
#define ABI_BROADCAST
Broadcast address.
Definition abi_common.h:80
void ahrs_aligner_init(void)
static void gyro_cb(uint8_t sender_id, uint32_t stamp, struct Int32Rates *gyro)
static abi_event gyro_ev
void ahrs_aligner_restart(void)
Interface to align the AHRS via low-passed measurements at startup.
static void gps_cb(uint8_t sender_id, uint32_t stamp, struct GpsState *gps_s)
static abi_event mag_ev
static void mag_cb(uint8_t sender_id, uint32_t stamp, struct Int32Vect3 *mag)
static abi_event aligner_ev
static abi_event geo_mag_ev
static void send_filter_status(struct transport_tx *trans, struct link_device *dev)
static void geo_mag_cb(uint8_t sender_id, struct FloatVect3 *h)
static void aligner_cb(uint8_t sender_id, uint32_t stamp, struct Int32Rates *lp_gyro, struct Int32Vect3 *lp_accel, struct Int32Vect3 *lp_mag)
static abi_event gps_ev
#define UNUSED(x)
uint32_t get_sys_time_usec(void)
Get the time in microseconds since startup.
static struct uart_periph * dev
static abi_event accel_ev
static void accel_cb(uint8_t sender_id, uint32_t stamp, struct Int32Vect3 *accel)
data structure for GPS information
Definition gps.h:90
angular rates
#define MAGS_FLOAT_OF_BFP(_ef, _ei)
#define RATES_FLOAT_OF_BFP(_rf, _ri)
#define ACCELS_FLOAT_OF_BFP(_ef, _ei)
angular rates
int32_t lat
in degrees*1e7
int32_t alt
in millimeters above WGS84 reference ellipsoid
int32_t z
in centimeters
int32_t x
in centimeters
int32_t y
in centimeters
int32_t lon
in degrees*1e7
vector in EarthCenteredEarthFixed coordinates
vector in Latitude, Longitude and Altitude
struct State state
Definition state.c:36
int32_t stateGetHmslOrigin_i(void)
Get the HMSL of the frame origin (int).
Definition state.c:196
struct LlaCoor_i stateGetLlaOrigin_i(void)
Get the LLA position of the frame origin (int).
Definition state.c:130
struct EcefCoor_i stateGetEcefOrigin_i(void)
Get the ECEF position of the frame origin (int).
Definition state.c:166
#define INS_RESET_VERTICAL_REF
Definition ins.h:37
#define INS_RESET_REF
flags for INS reset
Definition ins.h:36
static void reset_cb(uint8_t sender_id, uint8_t flag)
static abi_event reset_ev
abi_event baro_ev
static void baro_cb(uint8_t sender_id, uint32_t stamp, float pressure)
static void send_ins_ref(struct transport_tx *trans, struct link_device *dev)
Definition ins_ekf2.cpp:608
void ins_float_invariant_reset_ref(void)
void ins_float_invariant_align(struct FloatRates *lp_gyro, struct FloatVect3 *lp_accel, struct FloatVect3 *lp_mag)
void ins_float_invariant_propagate(struct FloatRates *gyro, struct FloatVect3 *accel, float dt)
void ins_float_invariant_init(void)
void ins_float_invariant_update_gps(struct GpsState *gps_s)
void ins_float_invariant_update_mag(struct FloatVect3 *mag)
struct InsFloatInv ins_float_inv
void ins_float_invariant_update_baro(float pressure)
void ins_float_invariant_reset_vertical_ref(void)
static void gps_cb(uint8_t sender_id, uint32_t stamp, struct GpsState *gps_s)
#define INS_FINV_MAG_ID
magnetometer
static void gyro_cb(uint8_t sender_id, uint32_t stamp, struct Int32Rates *gyro)
Call ins_float_invariant_propagate on new gyro measurements.
static void mag_cb(uint8_t sender_id, uint32_t stamp, struct Int32Vect3 *mag)
#define INS_FINV_BARO_ID
baro
static void send_ins_ref(struct transport_tx *trans, struct link_device *dev)
static void reset_cb(uint8_t sender_id UNUSED, uint8_t flag)
#define INS_FINV_IMU_ID
IMU (gyro, accel).
#define INS_FINV_GPS_ID
ABI binding for gps data.
static void send_filter_status(struct transport_tx *trans, struct link_device *dev)
static void baro_cb(uint8_t sender_id, uint32_t stamp, float pressure)
static void accel_cb(uint8_t sender_id, uint32_t stamp, struct Int32Vect3 *accel)
static void geo_mag_cb(uint8_t sender_id, struct FloatVect3 *h)
static void aligner_cb(uint8_t sender_id, uint32_t stamp, struct Int32Rates *lp_gyro, struct Int32Vect3 *lp_accel, struct Int32Vect3 *lp_mag)
void ins_float_invariant_wrapper_init(void)
static uint32_t ins_finv_last_stamp
last gyro msg timestamp
static struct FloatVect3 ins_finv_accel
last accel measurement
#define INS_FINV_FILTER_ID
Paparazzi specific wrapper to run INVARIANT filter.
PRINT_CONFIG_MSG("USE_INS_NAV_INIT defaulting to TRUE")
uint16_t foo
Definition main_demo5.c:58
PRINT_CONFIG_VAR(ONELOOP_ANDI_FILT_CUTOFF)
API to get/set the generic vehicle states.
Architecture independent timing functions.
int16_t register_periodic_telemetry(struct periodic_telemetry *_pt, uint16_t _id, telemetry_cb _cb)
Register a telemetry callback function.
Definition telemetry.c:51
Periodic telemetry system header (includes downlink utility and generated code).
#define DefaultPeriodic
Set default periodic telemetry.
Definition telemetry.h:66
uint16_t val[TCOUPLE_NB]
unsigned short uint16_t
Typedef defining 16 bit unsigned short type.
int int32_t
Typedef defining 32 bit int type.
unsigned int uint32_t
Typedef defining 32 bit unsigned int type.
unsigned char uint8_t
Typedef defining 8 bit unsigned char type.