Paparazzi UAS  v7.0_unstable
Paparazzi is a free software Unmanned Aircraft System.
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 "modules/gps/gps.h"
24 #include "modules/core/abi.h"
25 #include "nps_sensors.h"
26 #include "nps_fdm.h"
28 
29 struct GpsState gps_nps;
31 
32 void gps_feed_value(void)
33 {
34  // FIXME, set proper time instead of hardcoded to May 2014
35  gps_nps.week = 1794;
36  gps_nps.tow = fdm.time * 1000;
37 
38  gps_nps.ecef_pos.x = sensors.gps.ecef_pos.x * 100.;
39  gps_nps.ecef_pos.y = sensors.gps.ecef_pos.y * 100.;
40  gps_nps.ecef_pos.z = sensors.gps.ecef_pos.z * 100.;
42  gps_nps.ecef_vel.x = sensors.gps.ecef_vel.x * 100.;
43  gps_nps.ecef_vel.y = sensors.gps.ecef_vel.y * 100.;
44  gps_nps.ecef_vel.z = sensors.gps.ecef_vel.z * 100.;
46 
47  //ecef pos seems to be based on geocentric model, hence we get a very high alt when converted to lla
48  gps_nps.lla_pos.lat = DegOfRad(sensors.gps.lla_pos.lat) * 1e7;
49  gps_nps.lla_pos.lon = DegOfRad(sensors.gps.lla_pos.lon) * 1e7;
50  gps_nps.lla_pos.alt = sensors.gps.lla_pos.alt * 1000.;
52 
53  gps_nps.hmsl = sensors.gps.hmsl * 1000.;
55 
56  /* calc NED speed from ECEF */
57  struct LtpDef_d ref_ltp;
58  ltp_def_from_ecef_d(&ref_ltp, &sensors.gps.ecef_pos);
59  struct NedCoor_d ned_vel_d;
60  ned_of_ecef_vect_d(&ned_vel_d, &ref_ltp, &sensors.gps.ecef_vel);
61  gps_nps.ned_vel.x = ned_vel_d.x * 100;
62  gps_nps.ned_vel.y = ned_vel_d.y * 100;
63  gps_nps.ned_vel.z = ned_vel_d.z * 100;
65 
66  /* horizontal and 3d ground speed in cm/s */
67  gps_nps.gspeed = sqrt(ned_vel_d.x * ned_vel_d.x + ned_vel_d.y * ned_vel_d.y) * 100;
68  gps_nps.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;
69 
70 #if GpsId(PRIMARY_GPS) == GPS_DATALINK_ID
71  /* vehicle heading in radians * 1e7 */
73 #else
74  /* ground course in radians * 1e7 */
75  gps_nps.course = atan2(ned_vel_d.y, ned_vel_d.x) * 1e7;
76 #endif
78 
79  gps_nps.pacc = 650;
80  gps_nps.hacc = 450;
81  gps_nps.vacc = 200;
82  gps_nps.sacc = 100;
83  gps_nps.pdop = 650;
84 
85  if (gps_has_fix) {
86  gps_nps.num_sv = 11;
88  } else {
89  gps_nps.num_sv = 1;
91  }
92 
93  // publish gps data
94  uint32_t now_ts = get_sys_time_usec();
97  if (gps_nps.fix == GPS_FIX_3D) {
100  }
101  AbiSendMsgGPS(GPS_SIM_ID, now_ts, &gps_nps);
102 }
103 
104 void gps_nps_init(void)
105 {
106  gps_has_fix = true;
107 }
108 
Main include for ABI (AirBorneInterface).
#define GPS_SIM_ID
#define sensors(...)
Definition: cc2500_compat.h:68
uint32_t get_sys_time_usec(void)
Get the time in microseconds since startup.
Definition: sys_time_arch.c:71
Device independent GPS code (interface)
uint32_t tow
GPS time of week in ms.
Definition: gps.h:108
int32_t hmsl
height above mean sea level (MSL) in mm
Definition: gps.h:93
struct LlaCoor_i lla_pos
position in LLA (lat,lon: deg*1e7; alt: mm over ellipsoid)
Definition: gps.h:91
uint32_t sacc
speed accuracy in cm/s
Definition: gps.h:102
int32_t course
GPS course over ground in rad*1e7, [0, 2*Pi]*1e7 (CW/north)
Definition: gps.h:98
#define GPS_VALID_VEL_ECEF_BIT
Definition: gps.h:50
#define GPS_VALID_VEL_NED_BIT
Definition: gps.h:51
struct EcefCoor_i ecef_pos
position in ECEF in cm
Definition: gps.h:90
uint32_t hacc
horizontal accuracy in cm
Definition: gps.h:100
#define GPS_VALID_POS_LLA_BIT
Definition: gps.h:48
uint32_t last_3dfix_ticks
cpu time ticks at last valid 3D fix
Definition: gps.h:113
struct EcefCoor_i ecef_vel
speed ECEF in cm/s
Definition: gps.h:94
uint16_t pdop
position dilution of precision scaled by 100
Definition: gps.h:104
#define GPS_FIX_NONE
No GPS fix.
Definition: gps.h:41
#define GPS_VALID_POS_ECEF_BIT
Definition: gps.h:47
#define GPS_VALID_HMSL_BIT
Definition: gps.h:52
struct NedCoor_i ned_vel
speed NED in cm/s
Definition: gps.h:95
uint32_t last_msg_time
cpu time in sec at last received GPS message
Definition: gps.h:116
uint32_t last_3dfix_time
cpu time in sec at last valid 3D fix
Definition: gps.h:114
uint32_t pacc
position accuracy in cm
Definition: gps.h:99
uint16_t gspeed
norm of 2d ground speed in cm/s
Definition: gps.h:96
uint8_t valid_fields
bitfield indicating valid fields (GPS_VALID_x_BIT)
Definition: gps.h:87
uint32_t vacc
vertical accuracy in cm
Definition: gps.h:101
#define GPS_FIX_3D
3D GPS fix
Definition: gps.h:43
uint16_t speed_3d
norm of 3d speed in cm/s
Definition: gps.h:97
#define GPS_VALID_COURSE_BIT
Definition: gps.h:53
uint32_t last_msg_ticks
cpu time ticks at last received GPS message
Definition: gps.h:115
uint8_t num_sv
number of sat in fix
Definition: gps.h:105
uint16_t week
GPS week.
Definition: gps.h:107
uint8_t fix
status of fix
Definition: gps.h:106
data structure for GPS information
Definition: gps.h:86
void gps_feed_value(void)
Definition: gps_sim_nps.c:32
bool gps_has_fix
Definition: gps_sim_nps.c:30
struct GpsState gps_nps
Definition: gps_sim_nps.c:29
void gps_nps_init(void)
Definition: gps_sim_nps.c:104
double psi
in radians
double y
in meters
double z
in meters
double x
in meters
void ltp_def_from_ecef_d(struct LtpDef_d *def, struct EcefCoor_d *ecef)
void ned_of_ecef_vect_d(struct NedCoor_d *ned, struct LtpDef_d *def, struct EcefCoor_d *ecef)
definition of the local (flat earth) coordinate system
vector in North East Down coordinates Units: meters
int32_t lat
in degrees*1e7
int32_t alt
in millimeters above WGS84 reference ellipsoid
int32_t z
Down.
int32_t z
in centimeters
int32_t x
in centimeters
int32_t y
East.
int32_t y
in centimeters
int32_t lon
in degrees*1e7
int32_t x
North.
double time
Definition: nps_fdm.h:46
struct DoubleEulers ltp_to_body_eulers
Definition: nps_fdm.h:92
struct NpsFdm fdm
Holds all necessary NPS FDM state information.
volatile uint32_t nb_sec
full seconds since startup
Definition: sys_time.h:72
volatile uint32_t nb_sec_rem
remainder of seconds since startup in CPU_TICKS
Definition: sys_time.h:73
unsigned int uint32_t
Typedef defining 32 bit unsigned int type.
Definition: vl53l1_types.h:78