Paparazzi UAS  v4.2.2_stable-4-gcc32f65
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros 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 "autopilot.h"
11 #include "subsystems/gps.h"
12 #include "estimator.h"
14 #include "math/pprz_geodetic_int.h"
15 
16 // currently needed for nav_utm_zone0
18 
19 #include <caml/mlvalues.h>
20 
21 
22 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) {
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.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  utm_f.zone = nav_utm_zone0;
39  utm_of_lla_f(&utm_f, &lla_f);
40  LLA_BFP_OF_REAL(gps.lla_pos, lla_f);
41  gps.utm_pos.east = utm_f.east*100;
42  gps.utm_pos.north = utm_f.north*100;
44  x = y = z; /* Just to get rid of the "unused arg" warning */
45  y = x; /* Just to get rid of the "unused arg" warning */
46 #else // GPS_USE_LATLONG
47  gps.utm_pos.east = Int_val(x);
48  gps.utm_pos.north = Int_val(y);
49  gps.utm_pos.zone = Int_val(z);
50  lat = lon; /* Just to get rid of the "unused arg" warning */
51  lon = lat; /* Just to get rid of the "unused arg" warning */
52 #endif // GPS_USE_LATLONG
53 
54 
56  gps.nb_channels=7;
57  int i;
58  static int time;
59  time++;
60  for(i = 0; i < gps.nb_channels; i++) {
61  gps.svinfos[i].svid = 7 + i;
62  gps.svinfos[i].elev = (cos(((100*i)+time)/100.) + 1) * 45;
63  gps.svinfos[i].azim = (time/gps.nb_channels + 50 * i) % 360;
64  gps.svinfos[i].cno = 40 + sin((time+i*10)/100.) * 10.;
65  gps.svinfos[i].flags = ((time/10) % (i+1) == 0 ? 0x00 : 0x01);
66  gps.svinfos[i].qi = (int)((time / 1000.) + i) % 8;
67  }
68  gps.pdop = gps.sacc = gps.pacc = 500+200*sin(time/100.);
69  gps.num_sv = 7;
70 
71  //gps_verbose_downlink = !launch;
72  //gps_downlink();
73 
75 
76  return Val_unit;
77 }
78 
79 /* Second binding required because number of args > 5 */
80 value sim_use_gps_pos_bytecode(value *a, int argn) {
81  assert(argn == 11);
82  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]);
83 }
84 
85 void ubxsend_cfg_rst(uint16_t a __attribute__ ((unused)), uint8_t b __attribute__ ((unused))) {
86  return;
87 }
88 
unsigned short uint16_t
Definition: types.h:16
struct LlaCoor_i lla_pos
position in LLA (lat,lon: rad*1e7; alt: mm over ellipsoid)
Definition: gps.h:64
struct NedCoor_i ned_vel
speed NED in cm/s
Definition: gps.h:68
int32_t course
GPS heading in rad*1e7 (CW/north)
Definition: gps.h:71
uint32_t sacc
speed accuracy in cm/s
Definition: gps.h:73
uint8_t zone
UTM zone number.
void ubxsend_cfg_rst(uint16_t a __attribute__((unused)), uint8_t b __attribute__((unused)))
Definition: sim_gps.c:85
uint16_t pdop
position dilution of precision scaled by 100
Definition: gps.h:75
uint8_t nav_utm_zone0
Definition: common_nav.c:43
int32_t hmsl
height above mean sea level in mm
Definition: gps.h:66
float lat
in radians
uint8_t fix
status of fix
Definition: gps.h:77
int16_t week
GPS week.
Definition: gps.h:78
uint8_t qi
quality bitfield (GPS receiver specific)
Definition: gps.h:55
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:79
int16_t azim
azimuth in deg
Definition: gps.h:58
value sim_use_gps_pos_bytecode(value *a, int argn)
Definition: sim_gps.c:80
uint8_t zone
UTM zone number.
int16_t gspeed
norm of 2d ground speed in cm/s
Definition: gps.h:69
float north
in meters
Device independent GPS code (interface)
position in UTM coordinates Units: meters
#define LLA_BFP_OF_REAL(_o, _i)
Paparazzi fixed point math for geodetic calculations.
int32_t north
in centimeters
bool_t gps_available
Definition: gps_sim.c:24
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:22
struct SVinfo svinfos[GPS_NB_CHANNELS]
holds information from the Space Vehicles (Satellites)
Definition: gps.h:82
#define TRUE
Definition: imu_chimu.h:144
int32_t east
in centimeters
uint32_t pacc
position accuracy in cm
Definition: gps.h:72
uint8_t flags
bitfield with GPS receiver specific flags
Definition: gps.h:54
unsigned char uint8_t
Definition: types.h:14
int8_t elev
elevation in deg
Definition: gps.h:57
uint8_t svid
Satellite ID.
Definition: gps.h:53
State estimation, fusioning sensors.
struct UtmCoor_i utm_pos
position in UTM (north,east: cm; alt: mm over ellipsoid)
Definition: gps.h:65
float lon
in radians
static struct point c
Definition: discsurvey.c:13
float east
in meters
__attribute__((always_inline))
Definition: i2c_arch.c:35
struct GpsState gps
global GPS state
Definition: gps.c:31
uint8_t cno
Carrier to Noise Ratio (Signal Strength) in dbHz.
Definition: gps.h:56
void utm_of_lla_f(struct UtmCoor_f *utm, struct LlaCoor_f *lla)
uint8_t nb_channels
Number of scanned satellites.
Definition: gps.h:81
uint8_t num_sv
number of sat in fix
Definition: gps.h:76