Paparazzi UAS  v5.8.2_stable-0-g6260b7c
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
ins_gps_passthrough.c
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2004-2012 The Paparazzi Team
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 
29 #include "subsystems/ins.h"
30 
31 #include <inttypes.h>
32 #include <math.h>
33 
34 #include "state.h"
35 #include "subsystems/gps.h"
36 
37 #ifndef USE_INS_NAV_INIT
38 #define USE_INS_NAV_INIT TRUE
39 PRINT_CONFIG_MSG("USE_INS_NAV_INIT defaulting to TRUE")
40 #endif
41 
42 #if USE_INS_NAV_INIT
43 #include "generated/flight_plan.h"
44 #endif
45 
47 
49  struct LtpDef_i ltp_def;
51 
52  /* output LTP NED */
56 };
57 
59 
60 #if PERIODIC_TELEMETRY
62 
63 static void send_ins(struct transport_tx *trans, struct link_device *dev)
64 {
65  pprz_msg_send_INS(trans, dev, AC_ID,
69 }
70 
71 static void send_ins_z(struct transport_tx *trans, struct link_device *dev)
72 {
73  static const float fake_baro_z = 0.0;
74  pprz_msg_send_INS_Z(trans, dev, AC_ID,
75  (float *)&fake_baro_z, &ins_gp.ltp_pos.z,
77 }
78 
79 static void send_ins_ref(struct transport_tx *trans, struct link_device *dev)
80 {
81  static const float fake_qfe = 0.0;
82  if (ins_gp.ltp_initialized) {
83  pprz_msg_send_INS_REF(trans, dev, AC_ID,
86  &ins_gp.ltp_def.hmsl, (float *)&fake_qfe);
87  }
88 }
89 #endif
90 
92 {
93 
94 #if USE_INS_NAV_INIT
95  struct LlaCoor_i llh_nav0; /* Height above the ellipsoid */
96  llh_nav0.lat = NAV_LAT0;
97  llh_nav0.lon = NAV_LON0;
98  /* NAV_ALT0 = ground alt above msl, NAV_MSL0 = geoid-height (msl) over ellipsoid */
99  llh_nav0.alt = NAV_ALT0 + NAV_MSL0;
100 
101  struct EcefCoor_i ecef_nav0;
102  ecef_of_lla_i(&ecef_nav0, &llh_nav0);
103 
104  ltp_def_from_ecef_i(&ins_gp.ltp_def, &ecef_nav0);
105  ins_gp.ltp_def.hmsl = NAV_ALT0;
107 
109 #else
111 #endif
112 
116 
117 #if PERIODIC_TELEMETRY
118  register_periodic_telemetry(DefaultPeriodic, PPRZ_MSG_ID_INS, send_ins);
119  register_periodic_telemetry(DefaultPeriodic, PPRZ_MSG_ID_INS_Z, send_ins_z);
120  register_periodic_telemetry(DefaultPeriodic, PPRZ_MSG_ID_INS_REF, send_ins_ref);
121 #endif
122 }
123 
125 {
131 }
132 
134 {
135  struct LlaCoor_i lla = {
137  .lon = state.ned_origin_i.lla.lon,
138  .alt = gps.lla_pos.alt
139  };
143 }
144 
145 
146 #include "subsystems/abi.h"
148 static void gps_cb(uint8_t sender_id __attribute__((unused)),
149  uint32_t stamp __attribute__((unused)),
150  struct GpsState *gps_s)
151 {
152  if (gps_s->fix < GPS_FIX_3D) {
153  return;
154  }
155  if (!ins_gp.ltp_initialized) {
157  }
158 
159  /* simply scale and copy pos/speed from gps */
160  struct NedCoor_i gps_pos_cm_ned;
161  ned_of_ecef_point_i(&gps_pos_cm_ned, &ins_gp.ltp_def, &gps_s->ecef_pos);
162  INT32_VECT3_SCALE_2(ins_gp.ltp_pos, gps_pos_cm_ned,
165 
166  struct NedCoor_i gps_speed_cm_s_ned;
167  ned_of_ecef_vect_i(&gps_speed_cm_s_ned, &ins_gp.ltp_def, &gps_s->ecef_vel);
168  INT32_VECT3_SCALE_2(ins_gp.ltp_speed, gps_speed_cm_s_ned,
171 }
172 
174 {
176  AbiBindMsgGPS(ABI_BROADCAST, &gps_ev, gps_cb);
177 }
#define INT32_VECT3_SCALE_2(_a, _b, _num, _den)
static void stateSetPositionNed_i(struct NedCoor_i *ned_pos)
Set position from local NED coordinates (int).
Definition: state.h:514
Event structure to store callbacks in a linked list.
Definition: abi_common.h:65
int32_t z
in centimeters
definition of the local (flat earth) coordinate system
Generic transmission transport header.
Definition: transport.h:89
Periodic telemetry system header (includes downlink utility and generated code).
vector in EarthCenteredEarthFixed coordinates
int32_t y
in centimeters
#define INT32_VECT3_ZERO(_v)
Main include for ABI (AirBorneInterface).
struct NedCoor_i ltp_speed
Integrated Navigation System interface.
void ins_reset_altitude_ref(void)
INS altitude reference reset.
#define INT32_SPEED_OF_CM_S_DEN
vector in Latitude, Longitude and Altitude
static void stateSetSpeedNed_i(struct NedCoor_i *ned_speed)
Set ground speed in local NED coordinates (int).
Definition: state.h:746
void ins_gps_passthrough_register(void)
#define GPS_FIX_3D
3D GPS fix
Definition: gps.h:43
void ltp_def_from_lla_i(struct LtpDef_i *def, struct LlaCoor_i *lla)
int32_t z
Down.
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.
struct EcefCoor_i ecef
Reference point in ecef.
int32_t hmsl
Height above mean sea level in mm.
#define FALSE
Definition: std.h:5
int32_t alt
in millimeters above WGS84 reference ellipsoid
int32_t y
East.
#define TRUE
Definition: std.h:4
int32_t hmsl
height above mean sea level in mm
Definition: gps.h:71
data structure for GPS information
Definition: gps.h:67
#define INT32_POS_OF_CM_NUM
static void stateSetLocalOrigin_i(struct LtpDef_i *ltp_def)
Set the local (flat earth) coordinate frame origin (int).
Definition: state.h:440
Device independent GPS code (interface)
int32_t x
North.
unsigned long uint32_t
Definition: types.h:18
struct EcefCoor_i ecef_pos
position in ECEF in cm
Definition: gps.h:68
PRINT_CONFIG_MSG("USE_INS_NAV_INIT defaulting to TRUE")
struct LlaCoor_i lla
Reference point in lla.
#define DefaultPeriodic
Set default periodic telemetry.
Definition: telemetry.h:66
int32_t lon
in degrees*1e7
static void gps_cb(uint8_t sender_id, uint32_t stamp, struct GpsState *gps_s)
struct NedCoor_i ltp_accel
static const struct usb_device_descriptor dev
Definition: usb_ser_hw.c:69
struct LtpDef_i ned_origin_i
Definition of the local (flat earth) coordinate system.
Definition: state.h:162
struct NedCoor_i ltp_pos
#define INT32_POS_OF_CM_DEN
unsigned char uint8_t
Definition: types.h:14
API to get/set the generic vehicle states.
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.
vector in North East Down coordinates
void ins_gps_passthrough_init(void)
#define INT32_SPEED_OF_CM_S_NUM
struct InsGpsPassthrough ins_gp
int32_t x
in centimeters
#define ABI_BROADCAST
Broadcast address.
Definition: abi_common.h:56
void ecef_of_lla_i(struct EcefCoor_i *out, struct LlaCoor_i *in)
struct EcefCoor_i ecef_vel
speed ECEF in cm/s
Definition: gps.h:72
void ins_reset_local_origin(void)
INS local origin reset.
struct LlaCoor_i lla_pos
position in LLA (lat,lon: deg*1e7; alt: mm over ellipsoid)
Definition: gps.h:69
static abi_event gps_ev
Simply converts GPS ECEF position and velocity to NED and passes it through to the state interface...
int32_t lat
in degrees*1e7
uint8_t fix
status of fix
Definition: gps.h:82
void ins_register_impl(InsInit init)
Definition: ins.c:53
struct GpsState gps
global GPS state
Definition: gps.c:41
void ltp_def_from_ecef_i(struct LtpDef_i *def, struct EcefCoor_i *ecef)
struct State state
Definition: state.c:36
int8_t register_periodic_telemetry(struct periodic_telemetry *_pt, uint8_t _id, telemetry_cb _cb)
Register a telemetry callback function.
Definition: telemetry.c:46
struct LtpDef_i ltp_def