Paparazzi UAS  v6.3_unstable
Paparazzi is a free software Unmanned Aircraft System.
sim_ap.c
Go to the documentation of this file.
1 /* Definitions and declarations required to compile autopilot code on a
2  i386 architecture. Bindings for OCaml. */
3 
4 #include <stdio.h>
5 #include <assert.h>
6 #include <sys/time.h>
7 #include <sys/stat.h>
8 #include <time.h>
9 #include <string.h>
10 #include "std.h"
11 #include "main_ap.h"
12 #include "autopilot.h"
13 #include "modules/gps/gps.h"
14 #include "generated/settings.h"
18 #include "modules/core/commands.h"
21 #include "generated/flight_plan.h"
22 
23 #include "generated/modules.h"
24 
25 #include <caml/mlvalues.h>
26 #include <caml/memory.h>
27 
28 
29 /* Dummy definitions to replace the ones from the files not compiled in the
30  simulator */
38 
39 #ifndef SIM_UPDATE_DL
40 #define SIM_UPDATE_DL TRUE
41 #endif
42 
44 
45 #if PERIODIC_FREQUENCY != 60
46 #warning "Simple OCaml sim can currently only handle a PERIODIC_FREQUENCY of 60Hz"
47 #endif
48 
49 #if SYS_TIME_FREQUENCY != 120
50 #warning "Simple OCaml sim can currently only handle a SYS_TIME_FREQUENCY of 120Hz"
51 #endif
52 
54 value sim_sys_time_task(value unit)
55 {
57  return unit;
58 }
59 
60 value sim_periodic_task(value unit)
61 {
63  main_ap_event();
64  return unit;
65 }
66 
67 float ftimeofday(void)
68 {
69  struct timeval t;
70  struct timezone z;
71  gettimeofday(&t, &z);
72  return (t.tv_sec + t.tv_usec / 1e6);
73 }
74 
75 value sim_init(value unit)
76 {
77  modules_mcu_init();
78  main_ap_init();
79 
80  return unit;
81 }
82 
83 value update_bat(value bat)
84 {
85  electrical.vsupply = (float)Int_val(bat) / 10.;
86  return Val_unit;
87 }
88 
89 value update_dl_status(value dl_enabled)
90 {
91  ivy_tp.ivy_dl_enabled = Int_val(dl_enabled);
92  return Val_unit;
93 }
94 
95 
96 value get_commands(value val_commands)
97 {
98  int i;
99 
100  for (i = 0; i < COMMANDS_NB; i++) {
101  Store_field(val_commands, i, Val_int(commands[i]));
102  }
103 
104  return Val_int(commands[COMMAND_THROTTLE]);
105 }
106 
108 {
109  int n = string_length(s);
110  char *ss = (char *)String_val(s);
111  assert(n <= MSG_SIZE);
112 
113  int i;
114  for (i = 0; i < n; i++) {
115  dl_buffer[i] = ss[i];
116  }
117 
118  dl_msg_available = true;
120 
121  return Val_unit;
122 }
123 
Core autopilot interface common to all firmwares.
static void sys_tick_handler(void)
pprz_t commands[COMMANDS_NB]
Definition: commands.c:30
Hardware independent code for commands handling.
struct Electrical electrical
Definition: electrical.c:66
float vsupply
supply voltage in V
Definition: electrical.h:45
Vertical control for fixed wing vehicles.
Fixed wing horizontal control.
Device independent GPS code (interface)
struct ivy_transport ivy_tp
IVY transport structure.
Definition: ivy_dl.c:29
static uint32_t s
void main_ap_periodic(void)
Definition: main_ap.c:119
void main_ap_event(void)
Definition: main_ap.c:146
void main_ap_init(void)
Definition: main_ap.c:79
Autopilot main loop.
uint8_t dl_buffer[MSG_SIZE]
Definition: main_demo5.c:63
bool dl_msg_available
Flag provided to control calls to dl_parse_msg.
Definition: main_demo5.c:60
#define MSG_SIZE
Definition: main_demo5.c:62
static unit_t unit
Definition: nav.c:31
Fixedwing Navigation library.
#define SIM_UPDATE_DL
Definition: sim_ap.c:40
uint8_t link_fbw_fbw_nb_err
Definition: sim_ap.c:35
bool rc_event_2
Definition: sim_ap.c:34
value update_dl_status(value dl_enabled)
Definition: sim_ap.c:89
value sim_periodic_task(value unit)
Definition: sim_ap.c:60
float alt_roll_pgain
Definition: sim_ap.c:36
bool rc_event_1
Definition: sim_ap.c:34
uint8_t ir_estim_mode
Definition: sim_ap.c:31
value sim_init(value unit)
Definition: sim_ap.c:75
value update_bat(value bat)
Definition: sim_ap.c:83
float ftimeofday(void)
Definition: sim_ap.c:67
uint8_t inflight_calib_mode
Definition: sim_ap.c:33
float roll_rate_pgain
Definition: sim_ap.c:37
uint8_t link_fbw_nb_err
Definition: sim_ap.c:35
value get_commands(value val_commands)
Definition: sim_ap.c:96
value sim_sys_time_task(value unit)
needs to be called at SYS_TIME_FREQUENCY
Definition: sim_ap.c:54
value set_datalink_message(value s)
Definition: sim_ap.c:107
uint8_t ac_id
Definition: sim_ap.c:43
uint8_t vertical_mode
Definition: sim_ap.c:32
uint8_t gps_nb_ovrn
Definition: sim_ap.c:35
#define DOWNLINK_DEVICE
Periodic telemetry system header (includes downlink utility and generated code).
unsigned char uint8_t
Typedef defining 8 bit unsigned char type.
Definition: vl53l1_types.h:98