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 
40 #define GPS_FIX_NONE 0x00
41 #define GPS_FIX_2D 0x02
42 #define GPS_FIX_3D 0x03
43 #define GPS_FIX_DGPS 0x04
44 #define GPS_FIX_RTK 0x05
45 
46 #define GPS_VALID_POS_ECEF_BIT 0
47 #define GPS_VALID_POS_LLA_BIT 1
48 #define GPS_VALID_POS_UTM_BIT 2
49 #define GPS_VALID_VEL_ECEF_BIT 3
50 #define GPS_VALID_VEL_NED_BIT 4
51 #define GPS_VALID_HMSL_BIT 5
52 #define GPS_VALID_COURSE_BIT 6
53 
54 #ifndef GPS_NB_CHANNELS
55 #define GPS_NB_CHANNELS 40
56 #endif
57 
58 #define GPS_MODE_AUTO 0
59 #define GPS_MODE_PRIMARY 1
60 #define GPS_MODE_SECONDARY 2
61 
62 #ifndef MULTI_GPS_MODE
63 #define MULTI_GPS_MODE GPS_MODE_AUTO
64 #endif
65 
66 /* expand GpsId(PRIMARY_GPS) to e.g. GPS_UBX_ID */
67 #define __GpsId(_x) _x ## _ID
68 #define _GpsId(_x) __GpsId(_x)
69 #define GpsId(_x) _GpsId(_x)
70 
71 
72 extern uint8_t multi_gps_mode;
73 
75 struct SVinfo {
82 };
83 
85 struct GpsState {
88 
89  struct EcefCoor_i ecef_pos;
90  struct LlaCoor_i lla_pos;
91  struct UtmCoor_i utm_pos;
93  struct EcefCoor_i ecef_vel;
94  struct NedCoor_i ned_vel;
108 
110  struct SVinfo svinfos[GPS_NB_CHANNELS];
111 
117 };
118 
120 struct GpsTimeSync {
124 };
125 
127 struct GpsRelposNED {
143 };
144 
145 struct RtcmMan {
147  uint16_t MsgType; // Counter variables to count the number of Rtcm msgs in the input stream(for each msg type)
150  uint32_t Cnt187; // Counter variables to count the number of messages that failed Crc Check
154 };
155 
157 extern struct GpsState gps;
158 
159 #ifdef GPS_TYPE_H
160 #include GPS_TYPE_H
161 #endif
162 #ifdef GPS_SECONDARY_TYPE_H
163 #include GPS_SECONDARY_TYPE_H
164 #endif
165 
167 extern void gps_init(void);
168 
170 extern void gps_inject_data(uint8_t packet_id, uint8_t length, uint8_t *data);
171 
172 extern void gps_parse_GPS_INJECT(uint8_t *buf);
173 extern void gps_parse_RTCM_INJECT(uint8_t *buf);
174 
180 extern bool gps_fix_valid(void);
181 
182 // Compatibility macros
183 #define GpsFixValid() gps_fix_valid()
184 #if USE_GPS
185 #define GpsIsLost() !GpsFixValid()
186 #endif
187 
191 #ifndef GPS_TIMEOUT
192 #define GPS_TIMEOUT 2
193 #endif
194 
198 extern void gps_periodic_check(struct GpsState *gps_s);
199 
200 // FIXME not used, to be removed ?
201 static inline bool gps_has_been_good(void)
202 {
203  static bool gps_had_valid_fix = false;
204  if (GpsFixValid()) {
205  gps_had_valid_fix = true;
206  }
207  return gps_had_valid_fix;
208 }
209 
211 static inline float gps_time_since_last_3dfix(void)
212 {
213  return (float)(gps.last_3dfix_time + (float)(gps.last_3dfix_ticks) / sys_time.cpu_ticks_per_sec);
214 }
215 
216 
217 /*
218  * For GPS time synchronizaiton...
219  */
220 extern struct GpsTimeSync gps_time_sync;
221 
227 extern uint32_t gps_tow_from_sys_ticks(uint32_t sys_ticks);
228 
235 extern struct LlaCoor_f lla_float_from_gps(struct GpsState *gps_s);
236 
243 extern struct LlaCoor_i lla_int_from_gps(struct GpsState *gps_s);
244 
251 extern struct EcefCoor_f ecef_float_from_gps(struct GpsState *gps_s);
252 
259 extern struct EcefCoor_i ecef_int_from_gps(struct GpsState *gps_s);
260 
267 extern struct EcefCoor_f ecef_vel_float_from_gps(struct GpsState *gps_s);
268 
275 extern struct EcefCoor_i ecef_vel_int_from_gps(struct GpsState *gps_s);
276 
283 extern struct NedCoor_f ned_vel_float_from_gps(struct GpsState *gps_s);
284 
291 extern struct NedCoor_i ned_vel_int_from_gps(struct GpsState *gps_s);
292 
300 extern struct UtmCoor_f utm_float_from_gps(struct GpsState *gps_s, uint8_t zone);
301 
309 extern struct UtmCoor_i utm_int_from_gps(struct GpsState *gps_s, uint8_t zone);
310 
318 extern uint16_t gps_day_number(uint16_t year, uint8_t month, uint8_t day);
319 
327 extern uint16_t gps_week_number(uint16_t year, uint8_t month, uint8_t day);
328 
329 #ifdef __cplusplus
330 }
331 #endif
332 
333 #endif /* GPS_H */
int16_t azim
azimuth in deg
Definition: gps.h:81
uint8_t multi_gps_mode
Definition: gps.c:78
uint32_t tow
GPS time of week in ms.
Definition: gps.h:107
uint32_t Cnt105
Definition: gps.h:148
uint8_t qi
quality bitfield (GPS receiver specific)
Definition: gps.h:78
int32_t hmsl
height above mean sea level (MSL) in mm
Definition: gps.h:92
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:569
uint32_t Cnt187
Definition: gps.h:150
static float gps_time_since_last_3dfix(void)
Returns the time since last 3D fix in seconds (float)
Definition: gps.h:211
uint16_t refStationId
Definition: gps.h:129
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:536
uint32_t iTOW
Definition: gps.h:128
int8_t elev
elevation in deg
Definition: gps.h:80
struct LlaCoor_i lla_pos
position in LLA (lat,lon: deg*1e7; alt: mm over ellipsoid)
Definition: gps.h:90
uint32_t Crc177
Definition: gps.h:152
uint32_t sacc
speed accuracy in cm/s
Definition: gps.h:101
struct UtmCoor_i utm_pos
position in UTM (north,east: cm; alt: mm over MSL)
Definition: gps.h:91
uint32_t cacc
course accuracy in rad*1e7
Definition: gps.h:102
int32_t course
GPS course over ground in rad*1e7, [0, 2*Pi]*1e7 (CW/north)
Definition: gps.h:97
int32_t t0_tow_frac
fractional ns remainder of tow [ms], range -500000 .. 500000
Definition: gps.h:122
uint8_t gnssFixOK
Definition: gps.h:142
uint32_t accD
Definition: gps.h:138
uint32_t Crc187
Definition: gps.h:153
uint8_t cno
Carrier to Noise Ratio (Signal Strength) in dbHz.
Definition: gps.h:79
uint32_t accE
Definition: gps.h:137
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:501
struct EcefCoor_i ecef_pos
position in ECEF in cm
Definition: gps.h:89
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:594
uint32_t hacc
horizontal accuracy in cm
Definition: gps.h:99
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:641
void gps_parse_GPS_INJECT(uint8_t *buf)
Definition: gps.c:416
uint32_t last_3dfix_ticks
cpu time ticks at last valid 3D fix
Definition: gps.h:112
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:456
int32_t relPosN
Definition: gps.h:130
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:514
struct EcefCoor_i ecef_vel
speed ECEF in cm/s
Definition: gps.h:93
uint32_t t0_ticks
hw clock ticks when GPS message is received
Definition: gps.h:123
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:472
#define GPS_NB_CHANNELS
Definition: gps.h:55
uint32_t Crc105
Definition: gps.h:151
uint16_t RefStation
Definition: gps.h:146
void gps_parse_RTCM_INJECT(uint8_t *buf)
Definition: gps.c:429
uint16_t pdop
position dilution of precision scaled by 100
Definition: gps.h:103
uint8_t diffSoln
Definition: gps.h:141
struct NedCoor_i ned_vel
speed NED in cm/s
Definition: gps.h:94
uint32_t last_msg_time
cpu time in sec at last received GPS message
Definition: gps.h:115
uint32_t t0_tow
GPS time of week in ms from last message.
Definition: gps.h:121
void gps_inject_data(uint8_t packet_id, uint8_t length, uint8_t *data)
GPS packet injection (default empty)
Definition: gps.c:410
uint8_t svid
Satellite ID.
Definition: gps.h:76
int8_t relPosHPN
Definition: gps.h:133
uint32_t Cnt177
Definition: gps.h:149
uint8_t nb_channels
Number of scanned satellites.
Definition: gps.h:109
uint32_t last_3dfix_time
cpu time in sec at last valid 3D fix
Definition: gps.h:113
uint32_t pacc
position accuracy in cm
Definition: gps.h:98
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:485
uint16_t gspeed
norm of 2d ground speed in cm/s
Definition: gps.h:95
uint8_t valid_fields
bitfield indicating valid fields (GPS_VALID_x_BIT)
Definition: gps.h:86
uint8_t comp_id
id of current gps
Definition: gps.h:87
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:549
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:443
uint8_t carrSoln
Definition: gps.h:139
uint32_t vacc
vertical accuracy in cm
Definition: gps.h:100
#define GpsFixValid()
Definition: gps.h:183
uint8_t relPosValid
Definition: gps.h:140
void gps_init(void)
initialize the global GPS state
Definition: gps.c:333
int32_t relPosE
Definition: gps.h:131
int32_t relPosD
Definition: gps.h:132
uint16_t speed_3d
norm of 3d speed in cm/s
Definition: gps.h:96
int8_t relPosHPD
Definition: gps.h:135
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:385
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:631
bool gps_fix_valid(void)
Check if GPS fix is valid.
Definition: gps.c:294
uint32_t accN
Definition: gps.h:136
struct SVinfo svinfos[GPS_NB_CHANNELS]
holds information from the Space Vehicles (Satellites)
Definition: gps.h:110
static bool gps_has_been_good(void)
Definition: gps.h:201
void gps_periodic_check(struct GpsState *gps_s)
Periodic GPS check.
Definition: gps.c:278
uint8_t flags
bitfield with GPS receiver specific flags
Definition: gps.h:77
uint16_t reset
hotstart, warmstart, coldstart
Definition: gps.h:116
uint32_t last_msg_ticks
cpu time ticks at last received GPS message
Definition: gps.h:114
int8_t relPosHPE
Definition: gps.h:134
uint16_t MsgType
Definition: gps.h:147
uint8_t num_sv
number of sat in fix
Definition: gps.h:104
uint16_t week
GPS week.
Definition: gps.h:106
uint8_t fix
status of fix
Definition: gps.h:105
data structures for GPS with RTK capabilities
Definition: gps.h:127
data structure for GPS information
Definition: gps.h:85
data structure for GPS time sync
Definition: gps.h:120
Definition: gps.h:145
data structure for Space Vehicle Information of a single satellite
Definition: gps.h:75
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