Paparazzi UAS  v5.15_devel-230-gc96ce27
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/gps_sim.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,
21  value lon)
22 {
23  gps.fix = (Bool_val(m) ? 3 : 0);
24  gps.course = Double_val(c) * 1e7;
26  gps.hmsl = Double_val(a) * 1000.;
28  gps.gspeed = Double_val(s) * 100.;
29  gps.ned_vel.x = gps.gspeed * cos(Double_val(c));
30  gps.ned_vel.y = gps.gspeed * sin(Double_val(c));
31  gps.ned_vel.z = -Double_val(cl) * 100.;
33  gps.week = 0; // FIXME
34  gps.tow = Double_val(t) * 1000.;
35 
36  struct LlaCoor_f lla_f;
37  lla_f.lat = Double_val(lat);
38  lla_f.lon = Double_val(lon);
39  //TODO set alt above ellipsoid, use hmsl for now
40  lla_f.alt = Double_val(a);
41  LLA_BFP_OF_REAL(gps.lla_pos, lla_f);
43 
44  gps.utm_pos.east = Int_val(x);
45  gps.utm_pos.north = Int_val(y);
47  gps.utm_pos.zone = Int_val(z);
49 
51  gps.nb_channels = 7;
52  int i;
53  static int time;
54  time++;
55  for (i = 0; i < gps.nb_channels; i++) {
56  gps.svinfos[i].svid = 7 + i;
57  gps.svinfos[i].elev = (cos(((100 * i) + time) / 100.) + 1) * 45;
58  gps.svinfos[i].azim = (time / gps.nb_channels + 50 * i) % 360;
59  gps.svinfos[i].cno = 40 + sin((time + i * 10) / 100.) * 10.;
60  gps.svinfos[i].flags = ((time / 10) % (i + 1) == 0 ? 0x00 : 0x01);
61  gps.svinfos[i].qi = (int)((time / 1000.) + i) % 8;
62  }
63  gps.pdop = gps.sacc = gps.pacc = 500 + 200 * sin(time / 100.);
64  gps.num_sv = 7;
65 
67 
68  return Val_unit;
69 }
70 
71 /* Second binding required because number of args > 5 */
72 value sim_use_gps_pos_bytecode(value *a, int argn)
73 {
74  assert(argn == 11);
75  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]);
76 }
77 
78 void ubxsend_cfg_rst(uint16_t a __attribute__((unused)), uint8_t b __attribute__((unused)))
79 {
80  return;
81 }
82 
uint8_t qi
quality bitfield (GPS receiver specific)
Definition: gps.h:80
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:112
int16_t azim
azimuth in deg
Definition: gps.h:83
static uint32_t s
uint32_t pacc
position accuracy in cm
Definition: gps.h:100
uint8_t nb_channels
Number of scanned satellites.
Definition: gps.h:111
#define GPS_VALID_VEL_NED_BIT
Definition: gps.h:52
uint8_t valid_fields
bitfield indicating valid fields (GPS_VALID_x_BIT)
Definition: gps.h:88
uint16_t week
GPS week.
Definition: gps.h:108
void gps_sim_publish(void)
Definition: gps_sim.c:30
int32_t east
in centimeters
uint8_t svid
Satellite ID.
Definition: gps.h:78
int32_t z
Down.
struct UtmCoor_i utm_pos
position in UTM (north,east: cm; alt: mm over MSL)
Definition: gps.h:93
int8_t elev
elevation in deg
Definition: gps.h:82
uint32_t sacc
speed accuracy in cm/s
Definition: gps.h:103
int32_t y
East.
uint8_t zone
UTM zone number.
Paparazzi floating point math for geodetic calculations.
#define GPS_VALID_COURSE_BIT
Definition: gps.h:54
vector in Latitude, Longitude and Altitude
value sim_use_gps_pos_bytecode(value *a, int argn)
Definition: sim_gps.c:72
int32_t hmsl
height above mean sea level (MSL) in mm
Definition: gps.h:94
uint8_t cno
Carrier to Noise Ratio (Signal Strength) in dbHz.
Definition: gps.h:81
uint32_t tow
GPS time of week in ms.
Definition: gps.h:109
uint16_t pdop
position dilution of precision scaled by 100
Definition: gps.h:105
int32_t x
North.
#define GPS_VALID_HMSL_BIT
Definition: gps.h:53
Paparazzi fixed point math for geodetic calculations.
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 (normally above WGS84 reference ellipsoid)
int32_t alt
in millimeters (above WGS84 reference ellipsoid or above MSL)
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:99
#define LLA_BFP_OF_REAL(_o, _i)
uint8_t flags
bitfield with GPS receiver specific flags
Definition: gps.h:79
float lon
in radians
#define GPS_VALID_POS_LLA_BIT
Definition: gps.h:49
uint8_t num_sv
number of sat in fix
Definition: gps.h:106
uint16_t gspeed
norm of 2d ground speed in cm/s
Definition: gps.h:97
float lat
in radians
void ubxsend_cfg_rst(uint16_t a, uint8_t b)
Definition: sim_gps.c:78
struct LlaCoor_i lla_pos
position in LLA (lat,lon: deg*1e7; alt: mm over ellipsoid)
Definition: gps.h:92
uint8_t fix
status of fix
Definition: gps.h:107
#define GPS_VALID_POS_UTM_BIT
Definition: gps.h:50
struct NedCoor_i ned_vel
speed NED in cm/s
Definition: gps.h:96
struct GpsState gps
global GPS state
Definition: gps.c:69