Paparazzi UAS  v5.15_devel-109-gee85905
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
gps.c File Reference

Device independent GPS code. More...

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

Go to the source code of this file.

Macros

#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_rtk (struct transport_tx *trans, struct link_device *dev)
 
static void send_gps_rxmrtcm (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...
 
static void gps_cb (uint8_t sender_id, uint32_t stamp, struct GpsState *gps_s)
 
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...
 
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...
 

Variables

struct GpsState gps
 global GPS state More...
 
struct GpsTimeSync gps_time_sync
 
struct GpsRelposNED gps_relposned
 
struct RtcmMan rtcm_man
 
uint8_t multi_gps_mode
 
static abi_event gps_ev
 

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

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

Definition at line 66 of file gps.c.

Referenced by gps_tow_from_sys_ticks().

#define TIME_TO_SWITCH   5000

Definition at line 67 of file gps.c.

Function Documentation

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

Definition at line 282 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:

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 381 of file gps.c.

References gps_piksi_write(), and sbp_state.

+ Here is the call graph for this function:

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 264 of file gps.c.

Referenced by dw1000_arduino_periodic(), and intermcu_periodic().

+ Here is the caller graph for this function:

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 356 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(), trigger_ext_periodic(), and windturbine_periodic().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

Definition at line 125 of file gps.c.

References course, GpsState::course, dev, UtmCoor_i::east, GpsState::fix, gps, GpsState::gspeed, GpsState::hmsl, 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:

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

Definition at line 204 of file gps.c.

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

Referenced by gps_init().

+ Here is the caller graph for this function:

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

Definition at line 165 of file gps.c.

References RtcmMan::Cnt105, RtcmMan::Cnt177, RtcmMan::Cnt187, RtcmMan::Crc105, RtcmMan::Crc177, RtcmMan::Crc187, and rtcm_man.

Referenced by gps_init().

+ Here is the caller graph for this function:

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

Definition at line 227 of file gps.c.

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

Referenced by gps_init().

+ Here is the caller graph for this function:

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

send SVINFO message (regardless of state)

Definition at line 97 of file gps.c.

References 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:

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 109 of file gps.c.

References SVinfo::cno, 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:

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

Definition at line 85 of file gps.c.

References SVinfo::azim, SVinfo::cno, 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:

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 389 of file gps.c.

References UtmCoor_f::alt, UtmCoor_f::east, GPS_VALID_HMSL_BIT, GPS_VALID_POS_LLA_BIT, GPS_VALID_POS_UTM_BIT, UTM_FLOAT_OF_BFP, utm_of_lla_i(), wgs84_ellipsoid_to_geoid_i(), UtmCoor_f::zone, and UtmCoor_i::zone.

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

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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 415 of file gps.c.

References UtmCoor_i::alt, UtmCoor_i::east, GPS_VALID_HMSL_BIT, GPS_VALID_POS_LLA_BIT, GPS_VALID_POS_UTM_BIT, UTM_COPY, utm_of_lla_i(), wgs84_ellipsoid_to_geoid_i(), and UtmCoor_i::zone.

Referenced by send_gps().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Variable Documentation

abi_event gps_ev
static

Definition at line 281 of file gps.c.

struct GpsRelposNED gps_relposned

Definition at line 72 of file gps.c.

Referenced by gps_ubx_read_message(), and send_gps_rtk().

struct GpsTimeSync gps_time_sync

Definition at line 71 of file gps.c.

Referenced by gps_cb(), and gps_tow_from_sys_ticks().

uint8_t multi_gps_mode

Definition at line 79 of file gps.c.

struct RtcmMan rtcm_man

Definition at line 73 of file gps.c.

Referenced by gps_init(), gps_ubx_read_message(), and send_gps_rxmrtcm().