Paparazzi UAS  v7.0_unstable
Paparazzi is a free software Unmanned Aircraft System.
gps.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2003-2011 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 
27 #ifndef GPS_H
28 #define GPS_H
29 
30 #ifdef __cplusplus
31 extern "C" {
32 #endif
33 
34 #include "std.h"
35 #include "math/pprz_geodetic_int.h"
37 
38 #include "mcu_periph/sys_time.h"
39 #include "generated/airframe.h"
40 
41 #define GPS_FIX_NONE 0x00
42 #define GPS_FIX_2D 0x02
43 #define GPS_FIX_3D 0x03
44 #define GPS_FIX_DGPS 0x04
45 #define GPS_FIX_RTK 0x05
46 
47 #define GPS_VALID_POS_ECEF_BIT 0
48 #define GPS_VALID_POS_LLA_BIT 1
49 #define GPS_VALID_POS_UTM_BIT 2
50 #define GPS_VALID_VEL_ECEF_BIT 3
51 #define GPS_VALID_VEL_NED_BIT 4
52 #define GPS_VALID_HMSL_BIT 5
53 #define GPS_VALID_COURSE_BIT 6
54 
55 #ifndef GPS_NB_CHANNELS
56 #define GPS_NB_CHANNELS 40
57 #endif
58 
59 #define GPS_MODE_AUTO 0
60 #define GPS_MODE_PRIMARY 1
61 #define GPS_MODE_SECONDARY 2
62 
63 #ifndef MULTI_GPS_MODE
64 #define MULTI_GPS_MODE GPS_MODE_AUTO
65 #endif
66 
67 /* expand GpsId(PRIMARY_GPS) to e.g. GPS_UBX_ID */
68 #define __GpsId(_x) _x ## _ID
69 #define _GpsId(_x) __GpsId(_x)
70 #define GpsId(_x) _GpsId(_x)
71 
72 
73 extern uint8_t multi_gps_mode;
74 
76 struct SVinfo {
83 };
84 
86 struct GpsState {
89 
90  struct EcefCoor_i ecef_pos;
91  struct LlaCoor_i lla_pos;
92  struct UtmCoor_i utm_pos;
94  struct EcefCoor_i ecef_vel;
95  struct NedCoor_i ned_vel;
109 
111  struct SVinfo svinfos[GPS_NB_CHANNELS];
112 
118 };
119 
121 struct GpsTimeSync {
125 };
126 
128 struct GpsRelposNED {
146 };
147 extern struct GpsRelposNED gps_relposned;
148 
150 extern struct GpsState gps;
151 
152 #ifdef GPS_TYPE_H
153 #include GPS_TYPE_H
154 #endif
155 #ifdef GPS_SECONDARY_TYPE_H
156 #include GPS_SECONDARY_TYPE_H
157 #endif
158 
160 extern void gps_init(void);
161 
163 extern void gps_inject_data(uint8_t packet_id, uint8_t length, uint8_t *data);
164 
165 extern void gps_parse_GPS_INJECT(uint8_t *buf);
166 extern void gps_parse_RTCM_INJECT(uint8_t *buf);
167 
173 extern bool gps_fix_valid(void);
174 
175 // Compatibility macros
176 #define GpsFixValid() gps_fix_valid()
177 #if USE_GPS
178 #define GpsIsLost() !GpsFixValid()
179 #endif
180 
184 #ifndef GPS_TIMEOUT
185 #define GPS_TIMEOUT 2
186 #endif
187 
191 extern void gps_periodic_check(struct GpsState *gps_s);
192 
193 // FIXME not used, to be removed ?
194 static inline bool gps_has_been_good(void)
195 {
196  static bool gps_had_valid_fix = false;
197  if (GpsFixValid()) {
198  gps_had_valid_fix = true;
199  }
200  return gps_had_valid_fix;
201 }
202 
204 static inline float gps_time_since_last_3dfix(void)
205 {
206  return (float)(gps.last_3dfix_time + (float)(gps.last_3dfix_ticks) / sys_time.cpu_ticks_per_sec);
207 }
208 
209 
210 /*
211  * For GPS time synchronizaiton...
212  */
213 extern struct GpsTimeSync gps_time_sync;
214 
220 extern uint32_t gps_tow_from_sys_ticks(uint32_t sys_ticks);
221 
228 extern struct LlaCoor_f lla_float_from_gps(struct GpsState *gps_s);
229 
236 extern struct LlaCoor_i lla_int_from_gps(struct GpsState *gps_s);
237 
244 extern struct EcefCoor_f ecef_float_from_gps(struct GpsState *gps_s);
245 
252 extern struct EcefCoor_i ecef_int_from_gps(struct GpsState *gps_s);
253 
260 extern struct EcefCoor_f ecef_vel_float_from_gps(struct GpsState *gps_s);
261 
268 extern struct EcefCoor_i ecef_vel_int_from_gps(struct GpsState *gps_s);
269 
276 extern struct NedCoor_f ned_vel_float_from_gps(struct GpsState *gps_s);
277 
284 extern struct NedCoor_i ned_vel_int_from_gps(struct GpsState *gps_s);
285 
293 extern struct UtmCoor_f utm_float_from_gps(struct GpsState *gps_s, uint8_t zone);
294 
302 extern struct UtmCoor_i utm_int_from_gps(struct GpsState *gps_s, uint8_t zone);
303 
311 extern uint16_t gps_day_number(uint16_t year, uint8_t month, uint8_t day);
312 
320 extern uint16_t gps_week_number(uint16_t year, uint8_t month, uint8_t day);
321 
322 #ifdef __cplusplus
323 }
324 #endif
325 
326 #endif /* GPS_H */
int16_t azim
azimuth in deg
Definition: gps.h:82
uint8_t multi_gps_mode
Definition: gps.c:77
uint32_t tow
GPS time of week in ms.
Definition: gps.h:108
uint8_t qi
quality bitfield (GPS receiver specific)
Definition: gps.h:79
int32_t hmsl
height above mean sea level (MSL) in mm
Definition: gps.h:93
struct UtmCoor_f utm_float_from_gps(struct GpsState *gps_s, uint8_t zone)
Convenience function to get utm position in float from GPS structure.
Definition: gps.c:549
static float gps_time_since_last_3dfix(void)
Returns the time since last 3D fix in seconds (float)
Definition: gps.h:204
uint16_t refStationId
Definition: gps.h:130
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:516
uint32_t iTOW
Definition: gps.h:129
int8_t elev
elevation in deg
Definition: gps.h:81
struct LlaCoor_i lla_pos
position in LLA (lat,lon: deg*1e7; alt: mm over ellipsoid)
Definition: gps.h:91
uint32_t sacc
speed accuracy in cm/s
Definition: gps.h:102
struct UtmCoor_i utm_pos
position in UTM (north,east: cm; alt: mm over MSL)
Definition: gps.h:92
uint32_t cacc
course accuracy in rad*1e7
Definition: gps.h:103
int32_t course
GPS course over ground in rad*1e7, [0, 2*Pi]*1e7 (CW/north)
Definition: gps.h:98
int32_t t0_tow_frac
fractional ns remainder of tow [ms], range -500000 .. 500000
Definition: gps.h:123
uint8_t gnssFixOK
Definition: gps.h:145
uint32_t accD
Definition: gps.h:141
uint8_t cno
Carrier to Noise Ratio (Signal Strength) in dbHz.
Definition: gps.h:80
uint32_t accE
Definition: gps.h:140
struct EcefCoor_f ecef_vel_float_from_gps(struct GpsState *gps_s)
Get GPS ecef velocity (float) Converted on the fly if not available.
Definition: gps.c:481
struct EcefCoor_i ecef_pos
position in ECEF in cm
Definition: gps.h:90
struct GpsTimeSync gps_time_sync
Definition: gps.c:70
struct UtmCoor_i utm_int_from_gps(struct GpsState *gps_s, uint8_t zone)
Convenience function to get utm position in int from GPS structure.
Definition: gps.c:574
uint32_t hacc
horizontal accuracy in cm
Definition: gps.h:100
uint16_t gps_week_number(uint16_t year, uint8_t month, uint8_t day)
Number of weeks since navigation epoch (6 January 1980)
Definition: gps.c:621
void gps_parse_GPS_INJECT(uint8_t *buf)
Definition: gps.c:396
uint32_t last_3dfix_ticks
cpu time ticks at last valid 3D fix
Definition: gps.h:113
struct GpsState gps
global GPS state
Definition: gps.c:69
struct LlaCoor_i lla_int_from_gps(struct GpsState *gps_s)
Get GPS lla (integer) Converted on the fly if not available.
Definition: gps.c:436
int32_t relPosN
Definition: gps.h:131
struct EcefCoor_i ecef_vel_int_from_gps(struct GpsState *gps_s)
Get GPS ecef velocity (integer) Converted on the fly if not available.
Definition: gps.c:494
struct EcefCoor_i ecef_vel
speed ECEF in cm/s
Definition: gps.h:94
uint32_t t0_ticks
hw clock ticks when GPS message is received
Definition: gps.h:124
struct EcefCoor_f ecef_float_from_gps(struct GpsState *gps_s)
Get GPS ecef pos (float) Converted on the fly if not available.
Definition: gps.c:452
#define GPS_NB_CHANNELS
Definition: gps.h:56
void gps_parse_RTCM_INJECT(uint8_t *buf)
Definition: gps.c:409
uint16_t pdop
position dilution of precision scaled by 100
Definition: gps.h:104
uint8_t diffSoln
Definition: gps.h:144
struct NedCoor_i ned_vel
speed NED in cm/s
Definition: gps.h:95
uint32_t last_msg_time
cpu time in sec at last received GPS message
Definition: gps.h:116
uint32_t t0_tow
GPS time of week in ms from last message.
Definition: gps.h:122
void gps_inject_data(uint8_t packet_id, uint8_t length, uint8_t *data)
GPS packet injection (default empty)
Definition: gps.c:390
uint8_t svid
Satellite ID.
Definition: gps.h:77
int8_t relPosHPN
Definition: gps.h:134
uint8_t nb_channels
Number of scanned satellites.
Definition: gps.h:110
uint32_t last_3dfix_time
cpu time in sec at last valid 3D fix
Definition: gps.h:114
uint32_t pacc
position accuracy in cm
Definition: gps.h:99
struct EcefCoor_i ecef_int_from_gps(struct GpsState *gps_s)
Get GPS ecef pos (integer) Converted on the fly if not available.
Definition: gps.c:465
uint16_t gspeed
norm of 2d ground speed in cm/s
Definition: gps.h:96
uint8_t valid_fields
bitfield indicating valid fields (GPS_VALID_x_BIT)
Definition: gps.h:87
uint8_t comp_id
id of current gps
Definition: gps.h:88
struct NedCoor_i ned_vel_int_from_gps(struct GpsState *gps_s)
Get GPS ned velocity (integer) Converted on the fly if not available.
Definition: gps.c:529
struct LlaCoor_f lla_float_from_gps(struct GpsState *gps_s)
Get GPS lla (float) Converted on the fly if not available.
Definition: gps.c:423
uint8_t carrSoln
Definition: gps.h:142
uint32_t vacc
vertical accuracy in cm
Definition: gps.h:101
#define GpsFixValid()
Definition: gps.h:176
uint8_t relPosValid
Definition: gps.h:143
void gps_init(void)
initialize the global GPS state
Definition: gps.c:321
float relPosLength
Definition: gps.h:137
int32_t relPosE
Definition: gps.h:132
int32_t relPosD
Definition: gps.h:133
float relPosHeading
Definition: gps.h:138
uint16_t speed_3d
norm of 3d speed in cm/s
Definition: gps.h:97
int8_t relPosHPD
Definition: gps.h:136
uint32_t gps_tow_from_sys_ticks(uint32_t sys_ticks)
Convert time in sys_time ticks to GPS time of week.
Definition: gps.c:365
uint16_t gps_day_number(uint16_t year, uint8_t month, uint8_t day)
Number of days since navigation epoch (6 January 1980)
Definition: gps.c:611
bool gps_fix_valid(void)
Check if GPS fix is valid.
Definition: gps.c:282
uint32_t accN
Definition: gps.h:139
struct SVinfo svinfos[GPS_NB_CHANNELS]
holds information from the Space Vehicles (Satellites)
Definition: gps.h:111
static bool gps_has_been_good(void)
Definition: gps.h:194
void gps_periodic_check(struct GpsState *gps_s)
Periodic GPS check.
Definition: gps.c:266
uint8_t flags
bitfield with GPS receiver specific flags
Definition: gps.h:78
uint16_t reset
hotstart, warmstart, coldstart
Definition: gps.h:117
uint32_t last_msg_ticks
cpu time ticks at last received GPS message
Definition: gps.h:115
struct GpsRelposNED gps_relposned
Definition: gps.c:71
int8_t relPosHPE
Definition: gps.h:135
uint8_t num_sv
number of sat in fix
Definition: gps.h:105
uint16_t week
GPS week.
Definition: gps.h:107
uint8_t fix
status of fix
Definition: gps.h:106
data structures for GPS with RTK capabilities
Definition: gps.h:128
data structure for GPS information
Definition: gps.h:86
data structure for GPS time sync
Definition: gps.h:121
data structure for Space Vehicle Information of a single satellite
Definition: gps.h:76
uint8_t zone
UTM zone number.
vector in EarthCenteredEarthFixed coordinates
vector in Latitude, Longitude and Altitude
vector in North East Down coordinates
position in UTM coordinates
Paparazzi floating point math for geodetic calculations.
uint8_t zone
UTM zone number.
vector in EarthCenteredEarthFixed coordinates
vector in Latitude, Longitude and Altitude
vector in North East Down coordinates Units: meters
position in UTM coordinates Units: meters
Paparazzi fixed point math for geodetic calculations.
Architecture independent timing functions.
uint32_t cpu_ticks_per_sec
cpu ticks per second
Definition: sys_time.h:80
unsigned short uint16_t
Typedef defining 16 bit unsigned short type.
Definition: vl53l1_types.h:88
int int32_t
Typedef defining 32 bit int type.
Definition: vl53l1_types.h:83
unsigned int uint32_t
Typedef defining 32 bit unsigned int type.
Definition: vl53l1_types.h:78
short int16_t
Typedef defining 16 bit short type.
Definition: vl53l1_types.h:93
unsigned char uint8_t
Typedef defining 8 bit unsigned char type.
Definition: vl53l1_types.h:98
signed char int8_t
Typedef defining 8 bit char type.
Definition: vl53l1_types.h:103