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