Paparazzi UAS  v7.0_unstable
Paparazzi is a free software Unmanned Aircraft System.
ins_gps_passthrough_utm.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 
30 #include "modules/ins/ins.h"
31 
32 #include <inttypes.h>
33 #include <math.h>
34 
35 #include "state.h"
36 #include "modules/gps/gps.h"
38 
39 
40 #include "modules/core/abi.h"
44 #ifndef INS_PT_GPS_ID
45 #define INS_PT_GPS_ID GPS_MULTI_ID
46 #endif
49 
50 static void gps_cb(uint8_t sender_id __attribute__((unused)),
51  uint32_t stamp __attribute__((unused)),
52  struct GpsState *gps_s)
53 {
54  struct UtmCoor_f utm = utm_float_from_gps(gps_s, nav_utm_zone0);
55 
56  // set position
57  stateSetPositionUtm_f(MODULE_INS_GPS_PASSTHROUGH_ID, &utm);
58 
59  struct NedCoor_f ned_vel = ned_vel_float_from_gps(gps_s);
60  // set velocity
61  stateSetSpeedNed_f(MODULE_INS_GPS_PASSTHROUGH_ID, &ned_vel);
62 }
63 
65 static void reset_cb(uint8_t sender_id, uint8_t flag);
66 
67 
69 {
70  struct UtmCoor_f utm0 = { nav_utm_north0, nav_utm_east0, 0., nav_utm_zone0 };
71  stateSetLocalUtmOrigin_f(MODULE_INS_GPS_PASSTHROUGH_ID, &utm0);
72  stateSetPositionUtm_f(MODULE_INS_GPS_PASSTHROUGH_ID, &utm0);
73 
74  AbiBindMsgGPS(INS_PT_GPS_ID, &gps_ev, gps_cb);
75  AbiBindMsgINS_RESET(ABI_BROADCAST, &reset_ev, reset_cb);
76 }
77 
78 static void reset_ref(void)
79 {
80  struct UtmCoor_f utm = utm_float_from_gps(&gps, 0);
81  // reset state UTM ref
82  stateSetLocalUtmOrigin_f(MODULE_INS_GPS_PASSTHROUGH_ID, &utm);
83 }
84 
85 static void reset_vertical_ref(void)
86 {
87  struct UtmCoor_f utm = *stateGetUtmOrigin_f();
88  utm.alt = gps.hmsl / 1000.0f;
89  stateSetLocalUtmOrigin_f(MODULE_INS_GPS_PASSTHROUGH_ID, &utm);
90 }
91 
92 static void reset_cb(uint8_t sender_id UNUSED, uint8_t flag)
93 {
94  switch (flag) {
95  case INS_RESET_REF:
96  reset_ref();
97  break;
100  break;
101  default:
102  // unsupported cases
103  break;
104  }
105 }
106 
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
uint8_t last_wp UNUSED
int32_t nav_utm_east0
Definition: common_nav.c:48
uint8_t nav_utm_zone0
Definition: common_nav.c:50
int32_t nav_utm_north0
Definition: common_nav.c:49
struct UtmCoor_f utm_float_from_gps(struct GpsState *gps_s, uint8_t zone)
Convenience functions to get utm position from GPS state.
Definition: gps.c:577
struct NedCoor_f ned_vel_float_from_gps(struct GpsState *gps_s)
Get GPS ned velocity (float) Converted on the fly if not available.
Definition: gps.c:544
struct GpsState gps
global GPS state
Definition: gps.c:74
Device independent GPS code (interface)
int32_t hmsl
height above mean sea level (MSL) in mm
Definition: gps.h:94
data structure for GPS information
Definition: gps.h:87
static struct UtmCoor_f * stateGetUtmOrigin_f(void)
Get the coordinate UTM frame origin (int)
Definition: state.h:576
static void stateSetPositionUtm_f(uint16_t id, struct UtmCoor_f *utm_pos)
Set position from UTM coordinates (float).
Definition: state.h:698
static void stateSetLocalUtmOrigin_f(uint16_t id, struct UtmCoor_f *utm_def)
Set the local (flat earth) coordinate frame origin from UTM (float).
Definition: state.h:541
static void stateSetSpeedNed_f(uint16_t id, struct NedCoor_f *ned_speed)
Set ground speed in local NED coordinates (float).
Definition: state.h:947
Integrated Navigation System interface.
#define INS_RESET_VERTICAL_REF
Definition: ins.h:37
#define INS_RESET_REF
flags for INS reset
Definition: ins.h:36
Simply passes GPS through to the state interface.
static void reset_vertical_ref(void)
static void gps_cb(uint8_t sender_id, uint32_t stamp, struct GpsState *gps_s)
static void reset_cb(uint8_t sender_id, uint8_t flag)
static void reset_ref(void)
static abi_event reset_ev
void ins_gps_passthrough_init(void)
#define INS_PT_GPS_ID
ABI binding for gps data.
static abi_event gps_ev
Fixedwing Navigation library.
PRINT_CONFIG_VAR(ONELOOP_ANDI_FILT_CUTOFF)
float alt
in meters (above WGS84 reference ellipsoid or above MSL)
vector in North East Down coordinates Units: meters
position in UTM coordinates Units: meters
API to get/set the generic vehicle states.
unsigned int uint32_t
Typedef defining 32 bit unsigned int type.
Definition: vl53l1_types.h:78
unsigned char uint8_t
Typedef defining 8 bit unsigned char type.
Definition: vl53l1_types.h:98