Paparazzi UAS  v5.8.2_stable-0-g6260b7c
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
gps_sim_nps.c
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2008-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 
23 #include "subsystems/gps.h"
24 #include "subsystems/abi.h"
25 #include "nps_sensors.h"
26 #include "nps_fdm.h"
27 
28 #if GPS_USE_LATLONG
29 /* currently needed to get nav_utm_zone0 */
32 #endif
33 
34 bool_t gps_has_fix;
35 
37 {
38  // FIXME, set proper time instead of hardcoded to May 2014
39  gps.week = 1794;
40  gps.tow = fdm.time * 1000;
41 
42  gps.ecef_pos.x = sensors.gps.ecef_pos.x * 100.;
43  gps.ecef_pos.y = sensors.gps.ecef_pos.y * 100.;
44  gps.ecef_pos.z = sensors.gps.ecef_pos.z * 100.;
45  gps.ecef_vel.x = sensors.gps.ecef_vel.x * 100.;
46  gps.ecef_vel.y = sensors.gps.ecef_vel.y * 100.;
47  gps.ecef_vel.z = sensors.gps.ecef_vel.z * 100.;
48  //ecef pos seems to be based on geocentric model, hence we get a very high alt when converted to lla
49  gps.lla_pos.lat = DegOfRad(sensors.gps.lla_pos.lat) * 1e7;
50  gps.lla_pos.lon = DegOfRad(sensors.gps.lla_pos.lon) * 1e7;
51  gps.lla_pos.alt = sensors.gps.lla_pos.alt * 1000.;
52  gps.hmsl = sensors.gps.hmsl * 1000.;
53 
54  /* calc NED speed from ECEF */
55  struct LtpDef_d ref_ltp;
56  ltp_def_from_ecef_d(&ref_ltp, &sensors.gps.ecef_pos);
57  struct NedCoor_d ned_vel_d;
58  ned_of_ecef_vect_d(&ned_vel_d, &ref_ltp, &sensors.gps.ecef_vel);
59  gps.ned_vel.x = ned_vel_d.x * 100;
60  gps.ned_vel.y = ned_vel_d.y * 100;
61  gps.ned_vel.z = ned_vel_d.z * 100;
62 
63  /* horizontal and 3d ground speed in cm/s */
64  gps.gspeed = sqrt(ned_vel_d.x * ned_vel_d.x + ned_vel_d.y * ned_vel_d.y) * 100;
65  gps.speed_3d = sqrt(ned_vel_d.x * ned_vel_d.x + ned_vel_d.y * ned_vel_d.y + ned_vel_d.z * ned_vel_d.z) * 100;
66 
67  /* ground course in radians * 1e7 */
68  gps.course = atan2(ned_vel_d.y, ned_vel_d.x) * 1e7;
69 
70 #if GPS_USE_LATLONG
71  /* Computes from (lat, long) in the referenced UTM zone */
72  struct LlaCoor_f lla_f;
74  struct UtmCoor_f utm_f;
75  utm_f.zone = nav_utm_zone0;
76  /* convert to utm */
77  utm_of_lla_f(&utm_f, &lla_f);
78  /* copy results of utm conversion */
79  gps.utm_pos.east = utm_f.east * 100;
80  gps.utm_pos.north = utm_f.north * 100;
83 #endif
84 
85  if (gps_has_fix) {
86  gps.fix = GPS_FIX_3D;
87  } else {
89  }
90 
91  // publish gps data
92  uint32_t now_ts = get_sys_time_usec();
95  if (gps.fix == GPS_FIX_3D) {
98  }
99  AbiSendMsgGPS(GPS_SIM_ID, now_ts, &gps);
100 }
101 
103 {
104  gps_has_fix = TRUE;
105 }
int32_t z
in centimeters
int32_t north
in centimeters
vector in North East Down coordinates Units: meters
float east
in meters
float north
in meters
int32_t y
in centimeters
uint16_t week
GPS week.
Definition: gps.h:83
Main include for ABI (AirBorneInterface).
uint8_t nav_utm_zone0
Definition: common_nav.c:44
position in UTM coordinates Units: meters
int32_t east
in centimeters
uint16_t speed_3d
norm of 3d speed in cm/s
Definition: gps.h:75
#define GPS_FIX_3D
3D GPS fix
Definition: gps.h:43
int32_t z
Down.
struct UtmCoor_i utm_pos
position in UTM (north,east: cm; alt: mm over ellipsoid)
Definition: gps.h:70
double x
in meters
uint32_t last_3dfix_ticks
cpu time ticks at last valid 3D fix
Definition: gps.h:89
void gps_impl_init()
GPS initialization.
Definition: gps_sim_nps.c:102
int32_t alt
in millimeters above WGS84 reference ellipsoid
static uint32_t get_sys_time_usec(void)
Get the time in microseconds since startup.
Definition: sys_time_arch.h:39
int32_t y
East.
uint32_t last_msg_time
cpu time in sec at last received GPS message
Definition: gps.h:92
void gps_feed_value()
Definition: gps_sim_nps.c:36
uint8_t zone
UTM zone number.
Paparazzi floating point math for geodetic calculations.
vector in Latitude, Longitude and Altitude
#define TRUE
Definition: std.h:4
int32_t hmsl
height above mean sea level in mm
Definition: gps.h:71
uint32_t tow
GPS time of week in ms.
Definition: gps.h:84
#define GPS_FIX_NONE
No GPS fix.
Definition: gps.h:41
Device independent GPS code (interface)
int32_t x
North.
unsigned long uint32_t
Definition: types.h:18
struct EcefCoor_i ecef_pos
position in ECEF in cm
Definition: gps.h:68
definition of the local (flat earth) coordinate system
int32_t lon
in degrees*1e7
#define GPS_SIM_ID
uint8_t zone
UTM zone number.
volatile uint32_t nb_sec_rem
remainder of seconds since startup in CPU_TICKS
Definition: sys_time.h:70
void ltp_def_from_ecef_d(struct LtpDef_d *def, struct EcefCoor_d *ecef)
uint32_t last_3dfix_time
cpu time in sec at last valid 3D fix
Definition: gps.h:90
int32_t alt
in millimeters above WGS84 reference ellipsoid
int32_t course
GPS course over ground in rad*1e7, [0, 2*Pi]*1e7 (CW/north)
Definition: gps.h:76
volatile uint32_t nb_sec
full seconds since startup
Definition: sys_time.h:69
bool_t gps_has_fix
Definition: gps_sim_nps.c:34
uint32_t last_msg_ticks
cpu time ticks at last received GPS message
Definition: gps.h:91
double z
in meters
int32_t x
in centimeters
uint16_t gspeed
norm of 2d ground speed in cm/s
Definition: gps.h:74
struct EcefCoor_i ecef_vel
speed ECEF in cm/s
Definition: gps.h:72
struct LlaCoor_i lla_pos
position in LLA (lat,lon: deg*1e7; alt: mm over ellipsoid)
Definition: gps.h:69
int32_t lat
in degrees*1e7
uint8_t fix
status of fix
Definition: gps.h:82
struct NedCoor_i ned_vel
speed NED in cm/s
Definition: gps.h:73
double y
in meters
struct GpsState gps
global GPS state
Definition: gps.c:41
#define LLA_FLOAT_OF_BFP(_o, _i)
void utm_of_lla_f(struct UtmCoor_f *utm, struct LlaCoor_f *lla)
void ned_of_ecef_vect_d(struct NedCoor_d *ned, struct LtpDef_d *def, struct EcefCoor_d *ecef)