Paparazzi UAS  v7.0_unstable
Paparazzi is a free software Unmanned Aircraft System.
gps.c File Reference

Device independent GPS code. More...

#include "modules/core/abi.h"
#include "modules/gps/gps.h"
#include "led.h"
#include "modules/core/settings.h"
#include "generated/settings.h"
#include "math/pprz_geodetic_wgs84.h"
#include "math/pprz_geodetic.h"
#include "modules/datalink/telemetry.h"
#include "state.h"
+ Include dependency graph for gps.c:

Go to the source code of this file.

Macros

#define GPS_RELPOS_MAX   3
 
#define MSEC_PER_WEEK   (1000*60*60*24*7)
 
#define TIME_TO_SWITCH   5000
 

Functions

static void send_svinfo_id (struct transport_tx *trans, struct link_device *dev, uint8_t svid)
 
static void send_svinfo (struct transport_tx *trans, struct link_device *dev)
 send SVINFO message (regardless of state) More...
 
static void send_svinfo_available (struct transport_tx *trans, struct link_device *dev)
 send SVINFO message if updated. More...
 
static void send_gps (struct transport_tx *trans, struct link_device *dev)
 
static void send_gps_relpos (struct transport_tx *trans, struct link_device *dev)
 
static void send_gps_int (struct transport_tx *trans, struct link_device *dev)
 
static void send_gps_lla (struct transport_tx *trans, struct link_device *dev)
 
static void send_gps_sol (struct transport_tx *trans, struct link_device *dev)
 
void gps_periodic_check (struct GpsState *gps_s)
 Periodic GPS check. More...
 
bool gps_fix_valid (void)
 Check if GPS fix is valid. More...
 
static void gps_cb (uint8_t sender_id, uint32_t stamp, struct GpsState *gps_s)
 
static void gps_relpos_cb (uint8_t sender_id, uint32_t stamp, struct RelPosNED *relpos)
 
void gps_init (void)
 initialize the global GPS state More...
 
uint32_t gps_tow_from_sys_ticks (uint32_t sys_ticks)
 Convert time in sys_time ticks to GPS time of week. More...
 
void WEAK gps_inject_data (uint8_t packet_id, uint8_t length, uint8_t *data)
 Default parser for GPS injected data. More...
 
void gps_parse_GPS_INJECT (uint8_t *buf)
 
void gps_parse_RTCM_INJECT (uint8_t *buf)
 
struct LlaCoor_f lla_float_from_gps (struct GpsState *gps_s)
 Get GPS lla (float) Converted on the fly if not available. More...
 
struct LlaCoor_i lla_int_from_gps (struct GpsState *gps_s)
 Get GPS lla (integer) Converted on the fly if not available. More...
 
struct EcefCoor_f ecef_float_from_gps (struct GpsState *gps_s)
 Get GPS ecef pos (float) Converted on the fly if not available. More...
 
struct EcefCoor_i ecef_int_from_gps (struct GpsState *gps_s)
 Get GPS ecef pos (integer) Converted on the fly if not available. More...
 
struct EcefCoor_f ecef_vel_float_from_gps (struct GpsState *gps_s)
 Get GPS ecef velocity (float) Converted on the fly if not available. More...
 
struct EcefCoor_i ecef_vel_int_from_gps (struct GpsState *gps_s)
 Get GPS ecef velocity (integer) Converted on the fly if not available. More...
 
struct NedCoor_f ned_vel_float_from_gps (struct GpsState *gps_s)
 Get GPS ned velocity (float) Converted on the fly if not available. More...
 
struct NedCoor_i ned_vel_int_from_gps (struct GpsState *gps_s)
 Get GPS ned velocity (integer) Converted on the fly if not available. More...
 
struct UtmCoor_f utm_float_from_gps (struct GpsState *gps_s, uint8_t zone)
 Convenience functions to get utm position from GPS state. More...
 
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. More...
 
uint16_t gps_day_number (uint16_t year, uint8_t month, uint8_t day)
 Number of days since navigation epoch (6 January 1980) More...
 
uint16_t gps_week_number (uint16_t year, uint8_t month, uint8_t day)
 Number of weeks since navigation epoch (6 January 1980) More...
 

Variables

struct GpsState gps
 global GPS state More...
 
struct GpsTimeSync gps_time_sync
 
static struct RelPosNED gps_relposned [GPS_RELPOS_MAX] = {0}
 
uint8_t multi_gps_mode
 
static abi_event gps_ev
 
static abi_event gps_relpos_ev
 
static const uint16_t month_days [2][13]
 GPS week number roll-over workaround application note. More...
 

Detailed Description

Device independent GPS code.

This provides some general GPS functions and handles the selection of the currently active GPS (if multiple ones are used).

Each GPS implementation sends a GPS message via ABI for each new measurement, which can be received by any other part (either from all or only one specific GPS).

To make it easy to switch to the currently best (or simply the preferred) GPS at runtime, the multi_gps_mode can be set to GPS_MODE_PRIMARY, GPS_MODE_SECONDARY or GPS_MODE_AUTO. This re-sends the GPS message of the "selected" GPS with GPS_MULTI_ID as sender id. In the (default) GPS_MODE_AUTO mode, the GPS with the best fix is selected.

The global gps struct is also updated from the "selected" GPS and used to send the normal GPS telemetry messages.

Definition in file gps.c.

Macro Definition Documentation

◆ GPS_RELPOS_MAX

#define GPS_RELPOS_MAX   3

Definition at line 68 of file gps.c.

◆ MSEC_PER_WEEK

#define MSEC_PER_WEEK   (1000*60*60*24*7)

Definition at line 71 of file gps.c.

◆ TIME_TO_SWITCH

#define TIME_TO_SWITCH   5000

Definition at line 72 of file gps.c.

Function Documentation

◆ 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.

Parameters
[in]gps_spointer to the gps structure
Returns
ecef position in float (m)

Definition at line 437 of file gps.c.

References gps_inject_data().

+ Here is the call graph for this function:

◆ 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.

Parameters
[in]gps_spointer to the gps structure
Returns
ecef position in cm

Definition at line 437 of file gps.c.

Referenced by gps_cb(), ins_float_invariant_reset_ref(), ins_float_invariant_update_gps(), ins_int_update_gps(), and reset_ref().

+ Here is the caller graph for this function:

◆ 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.

Parameters
[in]gps_spointer to the gps structure
Returns
ecef velocity in float (m/s)

Definition at line 437 of file gps.c.

Referenced by gps_cb(), and ins_float_invariant_update_gps().

+ Here is the caller graph for this function:

◆ 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.

Parameters
[in]gps_spointer to the gps structure
Returns
ecef velocity in cm/s

Definition at line 437 of file gps.c.

Referenced by gps_cb(), and ins_int_update_gps().

+ Here is the caller graph for this function:

◆ gps_cb()

static void gps_cb ( uint8_t  sender_id,
uint32_t stamp  ,
struct GpsState gps_s 
)
static

Definition at line 308 of file gps.c.

References GpsState::comp_id, get_sys_time_usec(), gps, GPS_MULTI_ID, gps_time_sync, sys_time::nb_tick, GpsTimeSync::t0_ticks, GpsTimeSync::t0_tow, and GpsState::tow.

Referenced by gps_init().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ 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)

Parameters
[in]yearcurrent year
[in]monthcurrent month
[in]daycurrent day
Returns
number of days since navigation epoch

Definition at line 639 of file gps.c.

References month_days.

Referenced by gps_week_number().

+ Here is the caller graph for this function:

◆ gps_fix_valid()

bool gps_fix_valid ( void  )

Check if GPS fix is valid.

If GPS_FIX_TIMEOUT is configured, check for 3D fix with timeout, otherwise, returns the last value from GPS module

Definition at line 295 of file gps.c.

References GpsState::fix, get_sys_time_float(), gps, GPS_FIX_3D, and gps_time_since_last_3dfix().

+ Here is the call graph for this function:

◆ gps_init()

◆ gps_inject_data()

void WEAK gps_inject_data ( uint8_t  packet_id,
uint8_t  length,
uint8_t data 
)

Default parser for GPS injected data.

GPS packet injection (default empty)

Definition at line 418 of file gps.c.

Referenced by ecef_float_from_gps(), and gps_parse_GPS_INJECT().

+ Here is the caller graph for this function:

◆ gps_parse_GPS_INJECT()

void gps_parse_GPS_INJECT ( uint8_t buf)

Definition at line 424 of file gps.c.

References gps_inject_data().

+ Here is the call graph for this function:

◆ gps_parse_RTCM_INJECT()

void gps_parse_RTCM_INJECT ( uint8_t buf)

Definition at line 437 of file gps.c.

◆ gps_periodic_check()

void gps_periodic_check ( struct GpsState gps_s)

Periodic GPS check.

Marks GPS as lost when no GPS message was received for GPS_TIMEOUT seconds

Definition at line 279 of file gps.c.

References GpsState::comp_id, GpsState::fix, gps, GPS_FIX_NONE, GPS_TIMEOUT, GpsState::last_msg_time, and sys_time::nb_sec.

Referenced by dw1000_arduino_periodic(), and gps_ubx_periodic_check().

+ Here is the caller graph for this function:

◆ gps_relpos_cb()

static void gps_relpos_cb ( uint8_t  sender_id,
uint32_t  stamp,
struct RelPosNED relpos 
)
static

Definition at line 334 of file gps.c.

References GPS_RELPOS_MAX, gps_relposned, and RelPosNED::reference_id.

Referenced by gps_init().

+ Here is the caller graph for this function:

◆ 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.

The resolution is sys_time.resolution

Returns
GPS tow in ms

Definition at line 393 of file gps.c.

References gps_time_sync, msec_of_sys_time_ticks(), MSEC_PER_WEEK, GpsTimeSync::t0_ticks, and GpsTimeSync::t0_tow.

Referenced by acInfoSetPositionEnu_f(), acInfoSetPositionEnu_i(), acInfoSetPositionLla_f(), acInfoSetPositionLla_i(), acInfoSetPositionUtm_f(), acInfoSetPositionUtm_i(), acInfoSetVelocityEnu_f(), acInfoSetVelocityEnu_i(), parse_acinfo_dl(), target_parse_target_pos(), and windturbine_periodic().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ 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)

Parameters
[in]yearcurrent year
[in]monthcurrent month
[in]daycurrent day
Returns
number of weeks since navigation epoch

Definition at line 649 of file gps.c.

References gps_day_number().

Referenced by gps_ubx_parse_nav_pvt().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ 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.

Parameters
[in]gps_spointer to the gps structure
Returns
lla position in float (rad), altitude ellipsoid (m)

Definition at line 437 of file gps.c.

◆ 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.

Parameters
[in]gps_spointer to the gps structure
Returns
lla position (lat,lon: deg*1e7; alt: mm over ellipsoid)

Definition at line 437 of file gps.c.

Referenced by gps_cb(), ins_float_invariant_reset_ref(), reset_ref(), and reset_vertical_ref().

+ Here is the caller graph for this function:

◆ 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.

Parameters
[in]gps_spointer to the gps structure
Returns
ned velocity in float (m/s)

Definition at line 437 of file gps.c.

Referenced by gps_cb(), ins_alt_float_update_gps(), and ins_float_invariant_update_gps().

+ Here is the caller graph for this function:

◆ 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.

Parameters
[in]gps_spointer to the gps structure
Returns
ned velocity in cm/s

Definition at line 437 of file gps.c.

◆ send_gps()

static void send_gps ( struct transport_tx *  trans,
struct link_device *  dev 
)
static

Definition at line 142 of file gps.c.

References GpsState::course, course, dev, UtmCoor_i::east, GpsState::fix, gps, GpsState::gspeed, GpsState::hmsl, msg, GpsState::ned_vel, UtmCoor_i::north, send_svinfo_available(), GpsState::tow, utm_int_from_gps(), GpsState::week, NedCoor_i::z, and UtmCoor_i::zone.

Referenced by gps_init().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ send_gps_int()

static void send_gps_int ( struct transport_tx *  trans,
struct link_device *  dev 
)
static

◆ send_gps_lla()

static void send_gps_lla ( struct transport_tx *  trans,
struct link_device *  dev 
)
static

Definition at line 218 of file gps.c.

References LlaCoor_i::alt, GpsState::course, course, dev, GpsState::fix, gps, GpsState::gspeed, GpsState::hmsl, LlaCoor_i::lat, GpsState::lla_pos, LlaCoor_i::lon, msg, GpsState::ned_vel, GpsState::tow, GpsState::week, and NedCoor_i::z.

Referenced by gps_init().

+ Here is the caller graph for this function:

◆ send_gps_relpos()

static void send_gps_relpos ( struct transport_tx *  trans,
struct link_device *  dev 
)
static

◆ send_gps_sol()

static void send_gps_sol ( struct transport_tx *  trans,
struct link_device *  dev 
)
static

Definition at line 241 of file gps.c.

References dev, gps, GpsState::num_sv, GpsState::pacc, GpsState::pdop, and GpsState::sacc.

Referenced by gps_init().

+ Here is the caller graph for this function:

◆ send_svinfo()

static void send_svinfo ( struct transport_tx *  trans,
struct link_device *  dev 
)
static

send SVINFO message (regardless of state)

Definition at line 114 of file gps.c.

References dev, gps, GpsState::nb_channels, and send_svinfo_id().

Referenced by gps_init().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ send_svinfo_available()

static void send_svinfo_available ( struct transport_tx *  trans,
struct link_device *  dev 
)
inlinestatic

send SVINFO message if updated.

send SVINFO for all satellites while no GPS fix, after 3D fix, send avialable sats only when there is new information

Definition at line 126 of file gps.c.

References SVinfo::cno, dev, GpsState::fix, gps, GPS_FIX_3D, GPS_NB_CHANNELS, GpsState::nb_channels, send_svinfo_id(), and GpsState::svinfos.

Referenced by send_gps(), and send_gps_int().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ send_svinfo_id()

static void send_svinfo_id ( struct transport_tx *  trans,
struct link_device *  dev,
uint8_t  svid 
)
static

Definition at line 102 of file gps.c.

References SVinfo::azim, SVinfo::cno, dev, SVinfo::elev, SVinfo::flags, gps, GPS_NB_CHANNELS, SVinfo::qi, SVinfo::svid, and GpsState::svinfos.

Referenced by send_svinfo(), and send_svinfo_available().

+ Here is the caller graph for this function:

◆ utm_float_from_gps()

struct UtmCoor_f utm_float_from_gps ( struct GpsState gps_s,
uint8_t  zone 
)

Convenience functions to get utm position from GPS state.

Convenience function to get utm position in float from GPS structure.

Definition at line 437 of file gps.c.

Referenced by gps_cb(), ins_alt_float_update_gps(), ins_float_invariant_reset_ref(), ins_float_invariant_update_gps(), and reset_ref().

+ Here is the caller graph for this function:

◆ 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.

Beware that altitude is initialized to zero but not set to the correct value

Parameters
[in]gps_spointer to the gps structure
[in]zoneset the utm zone in which the position should be computed, 0 to try to get it automatically from lla position
Returns
utm position in fixed point (cm), altitude hmsl (mm).

Definition at line 437 of file gps.c.

Referenced by send_gps().

+ Here is the caller graph for this function:

Variable Documentation

◆ gps

◆ gps_ev

abi_event gps_ev
static

Definition at line 307 of file gps.c.

Referenced by gps_init().

◆ gps_relpos_ev

abi_event gps_relpos_ev
static

Definition at line 333 of file gps.c.

Referenced by gps_init().

◆ gps_relposned

struct RelPosNED gps_relposned[GPS_RELPOS_MAX] = {0}
static

Definition at line 1 of file gps.c.

Referenced by gps_relpos_cb(), and send_gps_relpos().

◆ gps_time_sync

struct GpsTimeSync gps_time_sync

Definition at line 1 of file gps.c.

Referenced by gps_cb(), and gps_tow_from_sys_ticks().

◆ month_days

const uint16_t month_days[2][13]
static
Initial value:
= {
{ 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365 },
{ 0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335, 366 }
}

GPS week number roll-over workaround application note.

Definition at line 631 of file gps.c.

Referenced by gps_day_number().

◆ multi_gps_mode

uint8_t multi_gps_mode

Definition at line 82 of file gps.c.

Referenced by gps_init().