Paparazzi UAS  v6.2_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 #define MODULES_C
5 
6 #include <stdio.h>
7 #include <assert.h>
8 #include <sys/time.h>
9 #include <sys/stat.h>
10 #include <time.h>
11 #include <string.h>
12 #include "std.h"
13 #include "main_ap.h"
14 #include "autopilot.h"
15 #include "modules/gps/gps.h"
16 #include "generated/settings.h"
20 #include "modules/core/commands.h"
23 #include "generated/flight_plan.h"
24 
25 #include "generated/modules.h"
26 
27 #include <caml/mlvalues.h>
28 #include <caml/memory.h>
29 
30 
31 /* Dummy definitions to replace the ones from the files not compiled in the
32  simulator */
42 
43 #ifndef SIM_UPDATE_DL
44 #define SIM_UPDATE_DL TRUE
45 #endif
46 
48 
49 #if PERIODIC_FREQUENCY != 60
50 #warning "Simple OCaml sim can currently only handle a PERIODIC_FREQUENCY of 60Hz"
51 #endif
52 
53 #if SYS_TIME_FREQUENCY != 120
54 #warning "Simple OCaml sim can currently only handle a SYS_TIME_FREQUENCY of 120Hz"
55 #endif
56 
58 value sim_sys_time_task(value unit)
59 {
61  return unit;
62 }
63 
64 value sim_periodic_task(value unit)
65 {
67  main_ap_event();
68  return unit;
69 }
70 
71 float ftimeofday(void)
72 {
73  struct timeval t;
74  struct timezone z;
75  gettimeofday(&t, &z);
76  return (t.tv_sec + t.tv_usec / 1e6);
77 }
78 
79 value sim_init(value unit)
80 {
81  modules_mcu_init();
82  main_ap_init();
83 
84  return unit;
85 }
86 
87 value update_bat(value bat)
88 {
89  electrical.vsupply = (float)Int_val(bat) / 10.;
90  return Val_unit;
91 }
92 
93 value update_dl_status(value dl_enabled)
94 {
95  ivy_tp.ivy_dl_enabled = Int_val(dl_enabled);
96  return Val_unit;
97 }
98 
99 
100 value get_commands(value val_commands)
101 {
102  int i;
103 
104  for (i = 0; i < COMMANDS_NB; i++) {
105  Store_field(val_commands, i, Val_int(commands[i]));
106  }
107 
108  return Val_int(commands[COMMAND_THROTTLE]);
109 }
110 
112 {
113  int n = string_length(s);
114  char *ss = String_val(s);
115  assert(n <= MSG_SIZE);
116 
117  int i;
118  for (i = 0; i < n; i++) {
119  dl_buffer[i] = ss[i];
120  }
121 
122  dl_msg_available = true;
124 
125  return Val_unit;
126 }
127 
main_ap_init
void main_ap_init(void)
Definition: main_ap.c:76
get_commands
value get_commands(value val_commands)
Definition: sim_ap.c:100
dl_buffer
uint8_t dl_buffer[MSG_SIZE]
Definition: main_demo5.c:63
vertical_mode
uint8_t vertical_mode
Definition: sim_ap.c:34
uint8_t
unsigned char uint8_t
Typedef defining 8 bit unsigned char type.
Definition: vl53l1_types.h:98
link_fbw_nb_err
uint8_t link_fbw_nb_err
Definition: sim_ap.c:37
rc_event_2
bool rc_event_2
Definition: sim_ap.c:36
gps_nb_ovrn
uint8_t gps_nb_ovrn
Definition: sim_ap.c:37
set_datalink_message
value set_datalink_message(value s)
Definition: sim_ap.c:111
s
static uint32_t s
Definition: light_scheduler.c:33
stabilization_attitude.h
commands
pprz_t commands[COMMANDS_NB]
Definition: commands.c:30
datalink_nb_msgs
uint16_t datalink_nb_msgs
Definition: sim_ap.c:41
Electrical::vsupply
float vsupply
supply voltage in V
Definition: electrical.h:45
main_ap_periodic
void main_ap_periodic(void)
Definition: main_ap.c:121
sim_sys_time_task
value sim_sys_time_task(value unit)
needs to be called at SYS_TIME_FREQUENCY
Definition: sim_ap.c:58
MSG_SIZE
#define MSG_SIZE
Definition: main_demo5.c:62
telemetry.h
std.h
main_ap.h
update_dl_status
value update_dl_status(value dl_enabled)
Definition: sim_ap.c:93
gps.h
Device independent GPS code (interface)
sim_init
value sim_init(value unit)
Definition: sim_ap.c:79
rc_event_1
bool rc_event_1
Definition: sim_ap.c:36
ivy_tp
struct ivy_transport ivy_tp
IVY transport structure.
Definition: ivy_dl.c:29
autopilot.h
update_bat
value update_bat(value bat)
Definition: sim_ap.c:87
ftimeofday
float ftimeofday(void)
Definition: sim_ap.c:71
dl_msg_available
bool dl_msg_available
Definition: main_demo5.c:60
nav.h
inflight_calib_mode
uint8_t inflight_calib_mode
Definition: sim_ap.c:35
ir_estim_mode
uint8_t ir_estim_mode
Definition: sim_ap.c:33
datalink_time
uint16_t datalink_time
Definition: sim_ap.c:40
DOWNLINK_DEVICE
#define DOWNLINK_DEVICE
Definition: stereocam_droplet.c:57
unit
static unit_t unit
Definition: nav.c:31
commands.h
Hardware independent code for commands handling.
electrical
struct Electrical electrical
Definition: electrical.c:66
roll_rate_pgain
float roll_rate_pgain
Definition: sim_ap.c:39
ac_id
uint8_t ac_id
Definition: sim_ap.c:47
link_fbw_fbw_nb_err
uint8_t link_fbw_fbw_nb_err
Definition: sim_ap.c:37
uint16_t
unsigned short uint16_t
Typedef defining 16 bit unsigned short type.
Definition: vl53l1_types.h:88
alt_roll_pgain
float alt_roll_pgain
Definition: sim_ap.c:38
sys_tick_handler
static void sys_tick_handler(void)
Definition: sys_time_arch.c:142
main_ap_event
void main_ap_event(void)
Definition: main_ap.c:148
sim_periodic_task
value sim_periodic_task(value unit)
Definition: sim_ap.c:64
SIM_UPDATE_DL
#define SIM_UPDATE_DL
Definition: sim_ap.c:44
guidance_v.h