Paparazzi UAS v7.0_unstable
Paparazzi is a free software Unmanned Aircraft System.
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
ins_skeleton.c
Go to the documentation of this file.
1/*
2 * Copyright (C) 2016 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
28#include "modules/core/abi.h"
29#include "mcu_periph/sys_time.h"
30#include "message_pragmas.h"
31
32#include "state.h"
33
34#ifndef USE_INS_NAV_INIT
35#define USE_INS_NAV_INIT TRUE
36PRINT_CONFIG_MSG("USE_INS_NAV_INIT defaulting to TRUE")
37#endif
38
39/*
40 * ABI bindings
41 */
43#ifndef INS_MODULE_BARO_ID
44#if USE_BARO_BOARD
45#define INS_MODULE_BARO_ID BARO_BOARD_SENDER_ID
46#else
47#define INS_MODULE_BARO_ID ABI_BROADCAST
48#endif
49#endif
51
52
53#ifndef INS_MODULE_IMU_ID
54#define INS_MODULE_IMU_ID ABI_BROADCAST
55#endif
57
58
61#ifndef INS_MODULE_GPS_ID
62#define INS_MODULE_GPS_ID GPS_MULTI_ID
63#endif
65
70
72
74
88
89/***********************************************************
90 * ABI callback functions
91 **********************************************************/
92
109
110static void baro_cb(uint8_t __attribute__((unused)) sender_id, __attribute__((unused)) uint32_t stamp, float pressure)
111{
112 /* call module implementation */
113 ins_module_update_baro(pressure);
115}
116
118 uint32_t stamp, struct Int32Vect3 *accel)
119{
120 /* timestamp in usec when last callback was received */
121 static uint32_t last_stamp = 0;
122
123 if (last_stamp > 0) {
124 float dt = (float)(stamp - last_stamp) * 1e-6;
125 /* call module implementation */
126 ins_module_propagate(accel, dt);
128 }
129 last_stamp = stamp;
130}
131
132static void gps_cb(uint8_t sender_id __attribute__((unused)),
133 uint32_t stamp, struct GpsState *gps_s)
134{
135 /* timestamp in usec when last callback was received */
136 static uint32_t last_stamp = 0;
137
138 if (last_stamp > 0) {
139 float dt = (float)(stamp - last_stamp) * 1e-6;
140
141 /* copy GPS state */
143
146 }
147
148 if (gps_s->fix >= GPS_FIX_3D) {
149 /* call module implementation */
152 }
153 }
154 last_stamp = stamp;
155}
156
157/*********************************************************************
158 * weak functions that are used if not implemented in a module
159 ********************************************************************/
160
162{
163}
164
165void WEAK ins_module_update_baro(float pressure __attribute__((unused)))
166{
167}
168
169void WEAK ins_module_update_gps(struct GpsState *gps_s, float dt __attribute__((unused)))
170{
171 /* copy velocity from GPS */
172 if (bit_is_set(gps_s->valid_fields, GPS_VALID_VEL_NED_BIT)) {
173 /* convert speed from cm/s to m/s in BFP with INT32_SPEED_FRAC */
176 }
177 else if (bit_is_set(gps_s->valid_fields, GPS_VALID_VEL_ECEF_BIT)) {
178 /* convert ECEF to NED */
181 /* convert speed from cm/s to m/s in BFP with INT32_SPEED_FRAC */
184 }
185
186 /* copy position from GPS */
187 if (bit_is_set(gps_s->valid_fields, GPS_VALID_POS_ECEF_BIT)) {
188 /* convert ECEF to NED */
191 /* convert pos from cm to m in BFP with INT32_POS_FRAC */
194 }
195}
196
206
210
211
233
Main include for ABI (AirBorneInterface).
#define ABI_BROADCAST
Broadcast address.
Definition abi_common.h:58
Event structure to store callbacks in a linked list.
Definition abi_common.h:67
#define UNUSED(x)
int32_t hmsl
height above mean sea level (MSL) in mm
Definition gps.h:94
struct LlaCoor_i lla_pos
position in LLA (lat,lon: deg*1e7; alt: mm over ellipsoid)
Definition gps.h:92
#define GPS_VALID_VEL_ECEF_BIT
Definition gps.h:51
#define GPS_VALID_VEL_NED_BIT
Definition gps.h:52
struct EcefCoor_i ecef_pos
position in ECEF in cm
Definition gps.h:91
#define GPS_VALID_POS_ECEF_BIT
Definition gps.h:48
#define GPS_FIX_3D
3D GPS fix
Definition gps.h:44
uint8_t fix
status of fix
Definition gps.h:107
data structure for GPS information
Definition gps.h:87
#define VECT3_COPY(_a, _b)
#define INT32_POS_OF_CM_DEN
#define INT32_SPEED_OF_CM_S_NUM
#define INT32_SPEED_OF_CM_S_DEN
#define INT32_POS_OF_CM_NUM
#define INT32_VECT3_ZERO(_v)
void int32_rmat_transp_vmult(struct Int32Vect3 *vb, struct Int32RMat *m_b2a, struct Int32Vect3 *va)
rotate 3D vector by transposed rotation matrix.
#define INT32_VECT3_SCALE_2(_a, _b, _num, _den)
int32_t hmsl
Height above mean sea level in mm.
int32_t alt
in millimeters above WGS84 reference ellipsoid
struct LlaCoor_i lla
Reference point in lla.
void ltp_def_from_ecef_i(struct LtpDef_i *def, struct EcefCoor_i *ecef)
void ned_of_ecef_point_i(struct NedCoor_i *ned, struct LtpDef_i *def, struct EcefCoor_i *ecef)
Convert a point from ECEF to local NED.
void ned_of_ecef_vect_i(struct NedCoor_i *ned, struct LtpDef_i *def, struct EcefCoor_i *ecef)
Rotate a vector from ECEF to NED.
vector in North East Down coordinates
static void stateSetAccelNed_i(uint16_t id, struct NedCoor_i *ned_accel)
Set acceleration in NED coordinates (int).
Definition state.h:1127
static void stateSetAccelBody_i(uint16_t id, struct Int32Vect3 *body_accel)
Set acceleration in Body coordinates (int).
Definition state.h:1167
static struct Int32RMat * stateGetNedToBodyRMat_i(void)
Get vehicle body attitude rotation matrix (int).
Definition state.h:1282
static void stateSetLocalOrigin_i(uint16_t id, struct LtpDef_i *ltp_def)
Set the local (flat earth) coordinate frame origin (int).
Definition state.h:519
static void stateSetPositionNed_i(uint16_t id, struct NedCoor_i *ned_pos)
Set position from local NED coordinates (int).
Definition state.h:638
static void stateSetSpeedNed_i(uint16_t id, struct NedCoor_i *ned_speed)
Set ground speed in local NED coordinates (int).
Definition state.h:892
void ins_init_origin_i_from_flightplan(uint16_t id, struct LtpDef_i *ltp_def)
initialize the local origin (ltp_def in fixed point) from flight plan position
Definition ins.c:33
#define INS_RESET_REF
flags for INS reset
Definition ins.h:36
void WEAK ins_module_propagate(struct Int32Vect3 *accel, float dt)
static void gps_cb(uint8_t sender_id, uint32_t stamp, struct GpsState *gps_s)
#define INS_MODULE_GPS_ID
ABI binding for gps data.
void WEAK ins_module_reset_local_origin(void)
void ins_module_wrapper_init(void)
static abi_event accel_ev
static abi_event reset_ev
void WEAK ins_module_update_baro(float pressure)
static void reset_cb(uint8_t sender_id UNUSED, uint8_t flag)
static abi_event baro_ev
#define INS_MODULE_BARO_ID
baro
static void ins_ned_to_state(void)
copy position and speed to state interface
static void baro_cb(uint8_t sender_id, uint32_t stamp, float pressure)
void WEAK ins_module_init(void)
static void accel_cb(uint8_t sender_id, uint32_t stamp, struct Int32Vect3 *accel)
void WEAK ins_module_update_gps(struct GpsState *gps_s, float dt)
#define INS_MODULE_IMU_ID
IMU (accel)
struct InsModuleInt ins_module
global INS state
static abi_event gps_ev
Paparazzi specific wrapper to run simple module based INS.
struct NedCoor_i ltp_speed
velocity in m/s in BFP with INT32_SPEED_FRAC
struct NedCoor_i ltp_pos
position in m in BFP with INT32_POS_FRAC
struct LtpDef_i ltp_def
struct GpsState gps
internal copy of last GPS message
struct NedCoor_i ltp_accel
bool ltp_initialized
Ins implementation state (fixed point)
PRINT_CONFIG_MSG("USE_INS_NAV_INIT defaulting to TRUE")
uint16_t foo
Definition main_demo5.c:58
bool nps_bypass_ins
void sim_overwrite_ins(void)
PRINT_CONFIG_VAR(ONELOOP_ANDI_FILT_CUTOFF)
API to get/set the generic vehicle states.
Architecture independent timing functions.
unsigned int uint32_t
Typedef defining 32 bit unsigned int type.
unsigned char uint8_t
Typedef defining 8 bit unsigned char type.