Paparazzi UAS  v6.2_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 GpsFixValid() (gps.fix >= GPS_FIX_3D)
47 #if USE_GPS
48 #define GpsIsLost() !GpsFixValid()
49 #endif
50 
51 #define GPS_VALID_POS_ECEF_BIT 0
52 #define GPS_VALID_POS_LLA_BIT 1
53 #define GPS_VALID_POS_UTM_BIT 2
54 #define GPS_VALID_VEL_ECEF_BIT 3
55 #define GPS_VALID_VEL_NED_BIT 4
56 #define GPS_VALID_HMSL_BIT 5
57 #define GPS_VALID_COURSE_BIT 6
58 
59 #ifndef GPS_NB_CHANNELS
60 #define GPS_NB_CHANNELS 40
61 #endif
62 
63 #define GPS_MODE_AUTO 0
64 #define GPS_MODE_PRIMARY 1
65 #define GPS_MODE_SECONDARY 2
66 
67 #ifndef MULTI_GPS_MODE
68 #define MULTI_GPS_MODE GPS_MODE_AUTO
69 #endif
70 
71 /* expand GpsId(PRIMARY_GPS) to e.g. GPS_UBX_ID */
72 #define __GpsId(_x) _x ## _ID
73 #define _GpsId(_x) __GpsId(_x)
74 #define GpsId(_x) _GpsId(_x)
75 
76 
77 extern uint8_t multi_gps_mode;
78 
80 struct SVinfo {
87 };
88 
90 struct GpsState {
93 
95  struct LlaCoor_i lla_pos;
96  struct UtmCoor_i utm_pos;
99  struct NedCoor_i ned_vel;
113 
116 
122 };
123 
125 struct GpsTimeSync {
129 };
130 
132 struct GpsRelposNED {
148 };
149 
150 struct RtcmMan {
152  uint16_t MsgType; // Counter variables to count the number of Rtcm msgs in the input stream(for each msg type)
155  uint32_t Cnt187; // Counter variables to count the number of messages that failed Crc Check
159 };
160 
162 extern struct GpsState gps;
163 
164 #ifdef GPS_TYPE_H
165 #include GPS_TYPE_H
166 #endif
167 #ifdef GPS_SECONDARY_TYPE_H
168 #include GPS_SECONDARY_TYPE_H
169 #endif
170 
172 extern void gps_init(void);
173 
175 extern void gps_inject_data(uint8_t packet_id, uint8_t length, uint8_t *data);
176 
177 extern void gps_parse_GPS_INJECT(uint8_t *buf);
178 extern void gps_parse_RTCM_INJECT(uint8_t *buf);
179 
181 #ifndef GPS_TIMEOUT
182 #define GPS_TIMEOUT 2
183 #endif
184 
185 static inline bool gps_has_been_good(void)
186 {
187  static bool gps_had_valid_fix = false;
188  if (GpsFixValid()) {
189  gps_had_valid_fix = true;
190  }
191  return gps_had_valid_fix;
192 }
193 
194 
198 extern void gps_periodic_check(struct GpsState *gps_s);
199 
200 
201 /*
202  * For GPS time synchronizaiton...
203  */
204 extern struct GpsTimeSync gps_time_sync;
205 
211 extern uint32_t gps_tow_from_sys_ticks(uint32_t sys_ticks);
212 
219 extern struct LlaCoor_f lla_float_from_gps(struct GpsState *gps_s);
220 
227 extern struct LlaCoor_i lla_int_from_gps(struct GpsState *gps_s);
228 
235 extern struct EcefCoor_f ecef_float_from_gps(struct GpsState *gps_s);
236 
243 extern struct EcefCoor_i ecef_int_from_gps(struct GpsState *gps_s);
244 
251 extern struct EcefCoor_f ecef_vel_float_from_gps(struct GpsState *gps_s);
252 
259 extern struct EcefCoor_i ecef_vel_int_from_gps(struct GpsState *gps_s);
260 
267 extern struct NedCoor_f ned_vel_float_from_gps(struct GpsState *gps_s);
268 
275 extern struct NedCoor_i ned_vel_int_from_gps(struct GpsState *gps_s);
276 
284 extern struct UtmCoor_f utm_float_from_gps(struct GpsState *gps_s, uint8_t zone);
285 
293 extern struct UtmCoor_i utm_int_from_gps(struct GpsState *gps_s, uint8_t zone);
294 
302 extern uint16_t gps_day_number(uint16_t year, uint8_t month, uint8_t day);
303 
311 extern uint16_t gps_week_number(uint16_t year, uint8_t month, uint8_t day);
312 
313 #ifdef __cplusplus
314 }
315 #endif
316 
317 #endif /* GPS_H */
ecef_vel_int_from_gps
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:484
lla_float_from_gps
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:413
GpsRelposNED::relPosHPE
int8_t relPosHPE
Definition: gps.h:139
int8_t
signed char int8_t
Typedef defining 8 bit char type.
Definition: vl53l1_types.h:103
GpsState::valid_fields
uint8_t valid_fields
bitfield indicating valid fields (GPS_VALID_x_BIT)
Definition: gps.h:91
uint32_t
unsigned int uint32_t
Typedef defining 32 bit unsigned int type.
Definition: vl53l1_types.h:78
uint8_t
unsigned char uint8_t
Typedef defining 8 bit unsigned char type.
Definition: vl53l1_types.h:98
NedCoor_f
vector in North East Down coordinates Units: meters
Definition: pprz_geodetic_float.h:63
SVinfo
data structure for Space Vehicle Information of a single satellite
Definition: gps.h:80
utm_int_from_gps
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:564
utm_float_from_gps
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:539
SVinfo::azim
int16_t azim
azimuth in deg
Definition: gps.h:86
GpsRelposNED::gnssFixOK
uint8_t gnssFixOK
Definition: gps.h:147
SVinfo::flags
uint8_t flags
bitfield with GPS receiver specific flags
Definition: gps.h:82
gps_parse_GPS_INJECT
void gps_parse_GPS_INJECT(uint8_t *buf)
Definition: gps.c:386
GpsRelposNED::accE
uint32_t accE
Definition: gps.h:142
GpsState::tow
uint32_t tow
GPS time of week in ms.
Definition: gps.h:112
ecef_float_from_gps
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:442
RtcmMan::Cnt105
uint32_t Cnt105
Definition: gps.h:153
GpsRelposNED::relPosD
int32_t relPosD
Definition: gps.h:137
SVinfo::qi
uint8_t qi
quality bitfield (GPS receiver specific)
Definition: gps.h:83
GpsTimeSync::t0_tow
uint32_t t0_tow
GPS time of week in ms from last message.
Definition: gps.h:126
gps_tow_from_sys_ticks
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:355
RtcmMan::Cnt177
uint32_t Cnt177
Definition: gps.h:154
GpsState::nb_channels
uint8_t nb_channels
Number of scanned satellites.
Definition: gps.h:114
pprz_geodetic_int.h
Paparazzi fixed point math for geodetic calculations.
GpsState
data structure for GPS information
Definition: gps.h:90
GpsState::pacc
uint32_t pacc
position accuracy in cm
Definition: gps.h:103
RtcmMan::MsgType
uint16_t MsgType
Definition: gps.h:152
GpsRelposNED::diffSoln
uint8_t diffSoln
Definition: gps.h:146
GpsState::sacc
uint32_t sacc
speed accuracy in cm/s
Definition: gps.h:106
GpsRelposNED::iTOW
uint32_t iTOW
Definition: gps.h:133
GpsState::vacc
uint32_t vacc
vertical accuracy in cm
Definition: gps.h:105
GpsRelposNED::relPosHPD
int8_t relPosHPD
Definition: gps.h:140
GpsState::ned_vel
struct NedCoor_i ned_vel
speed NED in cm/s
Definition: gps.h:99
GpsRelposNED::relPosE
int32_t relPosE
Definition: gps.h:136
RtcmMan::Cnt187
uint32_t Cnt187
Definition: gps.h:155
int16_t
short int16_t
Typedef defining 16 bit short type.
Definition: vl53l1_types.h:93
GpsState::last_msg_ticks
uint32_t last_msg_ticks
cpu time ticks at last received GPS message
Definition: gps.h:119
std.h
pprz_geodetic_float.h
Paparazzi floating point math for geodetic calculations.
lla_int_from_gps
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:426
GpsRelposNED::relPosN
int32_t relPosN
Definition: gps.h:135
SVinfo::cno
uint8_t cno
Carrier to Noise Ratio (Signal Strength) in dbHz.
Definition: gps.h:84
gps_periodic_check
void gps_periodic_check(struct GpsState *gps_s)
Periodic GPS check.
Definition: gps.c:264
GpsState::hacc
uint32_t hacc
horizontal accuracy in cm
Definition: gps.h:104
GpsState::fix
uint8_t fix
status of fix
Definition: gps.h:110
gps_day_number
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:601
gps_has_been_good
static bool gps_has_been_good(void)
Definition: gps.h:185
GpsState::speed_3d
uint16_t speed_3d
norm of 3d speed in cm/s
Definition: gps.h:101
multi_gps_mode
uint8_t multi_gps_mode
Definition: gps.c:78
ned_vel_int_from_gps
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:519
UtmCoor_f::zone
uint8_t zone
UTM zone number.
Definition: pprz_geodetic_float.h:85
GpsTimeSync
data structure for GPS time sync
Definition: gps.h:125
EcefCoor_i
vector in EarthCenteredEarthFixed coordinates
Definition: pprz_geodetic_int.h:50
GpsState::week
uint16_t week
GPS week.
Definition: gps.h:111
NedCoor_i
vector in North East Down coordinates
Definition: pprz_geodetic_int.h:68
ned_vel_float_from_gps
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:506
SVinfo::svid
uint8_t svid
Satellite ID.
Definition: gps.h:81
GpsTimeSync::t0_tow_frac
int32_t t0_tow_frac
fractional ns remainder of tow [ms], range -500000 .. 500000
Definition: gps.h:127
sys_time.h
Architecture independent timing functions.
GpsState::gspeed
uint16_t gspeed
norm of 2d ground speed in cm/s
Definition: gps.h:100
GpsRelposNED
data structures for GPS with RTK capabilities
Definition: gps.h:132
GpsState::reset
uint16_t reset
hotstart, warmstart, coldstart
Definition: gps.h:121
GpsRelposNED::refStationId
uint16_t refStationId
Definition: gps.h:134
GPS_NB_CHANNELS
#define GPS_NB_CHANNELS
Definition: gps.h:60
RtcmMan::Crc177
uint32_t Crc177
Definition: gps.h:157
GpsState::last_3dfix_time
uint32_t last_3dfix_time
cpu time in sec at last valid 3D fix
Definition: gps.h:118
RtcmMan::Crc105
uint32_t Crc105
Definition: gps.h:156
GpsState::last_3dfix_ticks
uint32_t last_3dfix_ticks
cpu time ticks at last valid 3D fix
Definition: gps.h:117
GpsState::utm_pos
struct UtmCoor_i utm_pos
position in UTM (north,east: cm; alt: mm over MSL)
Definition: gps.h:96
GpsState::comp_id
uint8_t comp_id
id of current gps
Definition: gps.h:92
gps
struct GpsState gps
global GPS state
Definition: gps.c:69
gps_init
void gps_init(void)
initialize the global GPS state
Definition: gps.c:308
GpsRelposNED::accD
uint32_t accD
Definition: gps.h:143
gps_time_sync
struct GpsTimeSync gps_time_sync
Definition: gps.c:70
GpsState::course
int32_t course
GPS course over ground in rad*1e7, [0, 2*Pi]*1e7 (CW/north)
Definition: gps.h:102
GpsState::last_msg_time
uint32_t last_msg_time
cpu time in sec at last received GPS message
Definition: gps.h:120
GpsState::ecef_pos
struct EcefCoor_i ecef_pos
position in ECEF in cm
Definition: gps.h:94
GpsFixValid
#define GpsFixValid()
Definition: gps.h:46
int32_t
int int32_t
Typedef defining 32 bit int type.
Definition: vl53l1_types.h:83
LlaCoor_i
vector in Latitude, Longitude and Altitude
Definition: pprz_geodetic_int.h:59
GpsState::lla_pos
struct LlaCoor_i lla_pos
position in LLA (lat,lon: deg*1e7; alt: mm over ellipsoid)
Definition: gps.h:95
EcefCoor_f
vector in EarthCenteredEarthFixed coordinates
Definition: pprz_geodetic_float.h:45
UtmCoor_f
position in UTM coordinates Units: meters
Definition: pprz_geodetic_float.h:81
GpsState::num_sv
uint8_t num_sv
number of sat in fix
Definition: gps.h:109
GpsRelposNED::accN
uint32_t accN
Definition: gps.h:141
GpsState::hmsl
int32_t hmsl
height above mean sea level (MSL) in mm
Definition: gps.h:97
GpsTimeSync::t0_ticks
uint32_t t0_ticks
hw clock ticks when GPS message is received
Definition: gps.h:128
RtcmMan::RefStation
uint16_t RefStation
Definition: gps.h:151
SVinfo::elev
int8_t elev
elevation in deg
Definition: gps.h:85
GpsState::pdop
uint16_t pdop
position dilution of precision scaled by 100
Definition: gps.h:108
UtmCoor_i
position in UTM coordinates
Definition: pprz_geodetic_int.h:86
ecef_int_from_gps
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:455
gps_week_number
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:611
GpsRelposNED::carrSoln
uint8_t carrSoln
Definition: gps.h:144
GpsRelposNED::relPosValid
uint8_t relPosValid
Definition: gps.h:145
GpsState::cacc
uint32_t cacc
course accuracy in rad*1e7
Definition: gps.h:107
gps_inject_data
void gps_inject_data(uint8_t packet_id, uint8_t length, uint8_t *data)
GPS packet injection (default empty)
Definition: gps.c:380
GpsState::ecef_vel
struct EcefCoor_i ecef_vel
speed ECEF in cm/s
Definition: gps.h:98
GpsRelposNED::relPosHPN
int8_t relPosHPN
Definition: gps.h:138
uint16_t
unsigned short uint16_t
Typedef defining 16 bit unsigned short type.
Definition: vl53l1_types.h:88
ecef_vel_float_from_gps
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:471
gps_parse_RTCM_INJECT
void gps_parse_RTCM_INJECT(uint8_t *buf)
Definition: gps.c:399
GpsState::svinfos
struct SVinfo svinfos[GPS_NB_CHANNELS]
holds information from the Space Vehicles (Satellites)
Definition: gps.h:115
RtcmMan::Crc187
uint32_t Crc187
Definition: gps.h:158
RtcmMan
Definition: gps.h:150
UtmCoor_i::zone
uint8_t zone
UTM zone number.
Definition: pprz_geodetic_int.h:90
LlaCoor_f
vector in Latitude, Longitude and Altitude
Definition: pprz_geodetic_float.h:54