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
sim_gps.c
Go to the documentation of this file.
1 /* OCaml binding to link the simulator to autopilot functions. */
2 
3 #include <assert.h>
4 #include <math.h>
5 #include <inttypes.h>
6 
8 #include "generated/airframe.h"
9 #include "generated/flight_plan.h"
10 #include "subsystems/gps.h"
12 #include "math/pprz_geodetic_int.h"
13 
14 // currently needed for nav_utm_zone0
16 
17 #include <caml/mlvalues.h>
18 
19 
21  value lon)
22 {
23  gps.fix = (Bool_val(m) ? 3 : 0);
24  gps.course = Double_val(c) * 1e7;
25  gps.hmsl = Double_val(a) * 1000.;
26  gps.gspeed = Double_val(s) * 100.;
27  gps.ned_vel.x = gps.gspeed * cos(Double_val(c));
28  gps.ned_vel.y = gps.gspeed * sin(Double_val(c));
29  gps.ned_vel.z = -Double_val(cl) * 100.;
30  gps.week = 0; // FIXME
31  gps.tow = Double_val(t) * 1000.;
32 
33  //TODO set alt above ellipsoid and hmsl
34 
35 #ifdef GPS_USE_LATLONG
36  struct LlaCoor_f lla_f;
37  struct UtmCoor_f utm_f;
38  lla_f.lat = Double_val(lat);
39  lla_f.lon = Double_val(lon);
40  lla_f.alt = Double_val(a);
41  utm_f.zone = nav_utm_zone0;
42  utm_of_lla_f(&utm_f, &lla_f);
43  LLA_BFP_OF_REAL(gps.lla_pos, lla_f);
44  gps.utm_pos.east = utm_f.east * 100;
45  gps.utm_pos.north = utm_f.north * 100;
47  x = y = z; /* Just to get rid of the "unused arg" warning */
48  y = x; /* Just to get rid of the "unused arg" warning */
49 #else // GPS_USE_LATLONG
50  gps.utm_pos.east = Int_val(x);
51  gps.utm_pos.north = Int_val(y);
52  gps.utm_pos.zone = Int_val(z);
53  lat = lon; /* Just to get rid of the "unused arg" warning */
54  lon = lat; /* Just to get rid of the "unused arg" warning */
55 #endif // GPS_USE_LATLONG
56 
57 
59  gps.nb_channels = 7;
60  int i;
61  static int time;
62  time++;
63  for (i = 0; i < gps.nb_channels; i++) {
64  gps.svinfos[i].svid = 7 + i;
65  gps.svinfos[i].elev = (cos(((100 * i) + time) / 100.) + 1) * 45;
66  gps.svinfos[i].azim = (time / gps.nb_channels + 50 * i) % 360;
67  gps.svinfos[i].cno = 40 + sin((time + i * 10) / 100.) * 10.;
68  gps.svinfos[i].flags = ((time / 10) % (i + 1) == 0 ? 0x00 : 0x01);
69  gps.svinfos[i].qi = (int)((time / 1000.) + i) % 8;
70  }
71  gps.pdop = gps.sacc = gps.pacc = 500 + 200 * sin(time / 100.);
72  gps.num_sv = 7;
73 
74  //gps_verbose_downlink = !launch;
75  //gps_downlink();
76 
78 
79  return Val_unit;
80 }
81 
82 /* Second binding required because number of args > 5 */
84 {
85  assert(argn == 11);
86  return sim_use_gps_pos(a[0], a[1], a[2], a[3], a[4], a[5], a[6], a[7], a[8], a[9], a[10]);
87 }
88 
89 void ubxsend_cfg_rst(uint16_t a __attribute__((unused)), uint8_t b __attribute__((unused)))
90 {
91  return;
92 }
93 
uint8_t qi
quality bitfield (GPS receiver specific)
Definition: gps.h:60
unsigned short uint16_t
Definition: types.h:16
int32_t north
in centimeters
struct SVinfo svinfos[GPS_NB_CHANNELS]
holds information from the Space Vehicles (Satellites)
Definition: gps.h:87
int16_t azim
azimuth in deg
Definition: gps.h:63
float east
in meters
uint32_t pacc
position accuracy in cm
Definition: gps.h:77
float north
in meters
uint8_t nb_channels
Number of scanned satellites.
Definition: gps.h:86
uint16_t value
Definition: adc_arch.c:586
uint16_t week
GPS week.
Definition: gps.h:83
void gps_sim_publish(void)
Definition: gps_sim.c:30
uint8_t nav_utm_zone0
Definition: common_nav.c:44
position in UTM coordinates Units: meters
int32_t east
in centimeters
uint8_t svid
Satellite ID.
Definition: gps.h:58
int32_t z
Down.
struct UtmCoor_i utm_pos
position in UTM (north,east: cm; alt: mm over ellipsoid)
Definition: gps.h:70
int8_t elev
elevation in deg
Definition: gps.h:62
uint32_t sacc
speed accuracy in cm/s
Definition: gps.h:78
int32_t y
East.
uint8_t zone
UTM zone number.
Paparazzi floating point math for geodetic calculations.
vector in Latitude, Longitude and Altitude
value sim_use_gps_pos_bytecode(value *a, int argn)
Definition: sim_gps.c:83
int32_t hmsl
height above mean sea level in mm
Definition: gps.h:71
uint8_t cno
Carrier to Noise Ratio (Signal Strength) in dbHz.
Definition: gps.h:61
uint32_t tow
GPS time of week in ms.
Definition: gps.h:84
Device independent GPS code (interface)
uint16_t pdop
position dilution of precision scaled by 100
Definition: gps.h:80
int32_t x
North.
Paparazzi fixed point math for geodetic calculations.
uint8_t zone
UTM zone number.
value sim_use_gps_pos(value x, value y, value z, value c, value a, value s, value cl, value t, value m, value lat, value lon)
From airborne/autopilot/.
Definition: sim_gps.c:20
float alt
in meters above WGS84 reference ellipsoid
unsigned char uint8_t
Definition: types.h:14
int32_t course
GPS course over ground in rad*1e7, [0, 2*Pi]*1e7 (CW/north)
Definition: gps.h:76
#define LLA_BFP_OF_REAL(_o, _i)
uint8_t flags
bitfield with GPS receiver specific flags
Definition: gps.h:59
float lon
in radians
uint8_t num_sv
number of sat in fix
Definition: gps.h:81
uint16_t gspeed
norm of 2d ground speed in cm/s
Definition: gps.h:74
float lat
in radians
void ubxsend_cfg_rst(uint16_t a, uint8_t b)
Definition: sim_gps.c:89
struct LlaCoor_i lla_pos
position in LLA (lat,lon: deg*1e7; alt: mm over ellipsoid)
Definition: gps.h:69
uint8_t fix
status of fix
Definition: gps.h:82
struct NedCoor_i ned_vel
speed NED in cm/s
Definition: gps.h:73
struct GpsState gps
global GPS state
Definition: gps.c:41
void utm_of_lla_f(struct UtmCoor_f *utm, struct LlaCoor_f *lla)