Paparazzi UAS  v5.18.0_stable
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 "inter_mcu.h"
14 #include "autopilot.h"
15 #include "subsystems/gps.h"
16 #include "generated/settings.h"
20 #include "subsystems/commands.h"
24 #include "generated/flight_plan.h"
25 
26 #include "generated/modules.h"
27 
28 #include <caml/mlvalues.h>
29 #include <caml/memory.h>
30 
31 
32 /* Dummy definitions to replace the ones from the files not compiled in the
33  simulator */
43 
44 #ifndef SIM_UPDATE_DL
45 #define SIM_UPDATE_DL TRUE
46 #endif
47 
49 
50 #if PERIODIC_FREQUENCY != 60
51 #warning "Simple OCaml sim can currently only handle a PERIODIC_FREQUENCY of 60Hz"
52 #endif
53 
54 #if SYS_TIME_FREQUENCY != 120
55 #warning "Simple OCaml sim can currently only handle a SYS_TIME_FREQUENCY of 120Hz"
56 #endif
57 
59 value sim_sys_time_task(value unit)
60 {
62  return unit;
63 }
64 
65 value sim_periodic_task(value unit)
66 {
67  sensors_task();
68 #if USE_GENERATED_AUTOPILOT
70 #else
71  attitude_loop();
72 #endif
74  modules_periodic_task();
77  event_task_ap();
79  return unit;
80 }
81 
82 value sim_monitor_task(value unit)
83 {
84  monitor_task();
85  return unit;
86 }
87 
88 value sim_nav_task(value unit)
89 {
90 #if !USE_GENERATED_AUTOPILOT
92 #endif
93  return unit;
94 }
95 
96 
97 float ftimeofday(void)
98 {
99  struct timeval t;
100  struct timezone z;
101  gettimeofday(&t, &z);
102  return (t.tv_sec + t.tv_usec / 1e6);
103 }
104 
105 value sim_init(value unit)
106 {
107  init_fbw();
108  init_ap();
109 
110  return unit;
111 }
112 
113 value update_bat(value bat)
114 {
115  electrical.vsupply = (float)Int_val(bat) / 10.;
116  return Val_unit;
117 }
118 
119 value update_dl_status(value dl_enabled)
120 {
121  ivy_tp.ivy_dl_enabled = Int_val(dl_enabled);
122  return Val_unit;
123 }
124 
125 
126 value get_commands(value val_commands)
127 {
128  int i;
129 
130  for (i = 0; i < COMMANDS_NB; i++) {
131  Store_field(val_commands, i, Val_int(commands[i]));
132  }
133 
134  return Val_int(commands[COMMAND_THROTTLE]);
135 }
136 
138 {
139  int n = string_length(s);
140  char *ss = String_val(s);
141  assert(n <= MSG_SIZE);
142 
143  int i;
144  for (i = 0; i < n; i++) {
145  dl_buffer[i] = ss[i];
146  }
147 
148  dl_msg_available = true;
150 
151  return Val_unit;
152 }
153 
155 void adc_buf_channel(void *a __attribute__((unused)),
156  void *b __attribute__((unused)),
157  void *c __attribute__((unused)))
158 {
159 }
c
VIC slots used for the LPC2148 define name e g gps UART1_VIC_SLOT e g modem SPI1_VIC_SLOT SPI1 in mcu_periph spi_arch c or spi_slave_hs_arch c(and some others not using the SPI peripheral yet..) I2C0_VIC_SLOT 8 mcu_periph/i2c_arch.c I2C1_VIC_SLOT 9 mcu_periph/i2c_arch.c USB_VIC_SLOT 10 usb
sim_monitor_task
value sim_monitor_task(value unit)
Definition: sim_ap.c:82
get_commands
value get_commands(value val_commands)
Definition: sim_ap.c:126
dl_buffer
uint8_t dl_buffer[MSG_SIZE]
Definition: main_demo5.c:64
vertical_mode
uint8_t vertical_mode
Definition: sim_ap.c:35
uint16_t
unsigned short uint16_t
Definition: types.h:16
init_fbw
void init_fbw(void)
Definition: main_fbw.c:362
link_fbw_nb_err
uint8_t link_fbw_nb_err
Definition: sim_ap.c:38
rc_event_2
bool rc_event_2
Definition: sim_ap.c:37
init_ap
void init_ap(void)
Definition: main_ap.c:149
gps_nb_ovrn
uint8_t gps_nb_ovrn
Definition: sim_ap.c:38
set_datalink_message
value set_datalink_message(value s)
Definition: sim_ap.c:137
sim_nav_task
value sim_nav_task(value unit)
Definition: sim_ap.c:88
b
float b
Definition: wedgebug.c:202
s
static uint32_t s
Definition: light_scheduler.c:33
inter_mcu.h
stabilization_attitude.h
datalink_nb_msgs
uint16_t datalink_nb_msgs
Definition: sim_ap.c:42
Electrical::vsupply
float vsupply
supply voltage in V
Definition: electrical.h:45
sim_sys_time_task
value sim_sys_time_task(value unit)
needs to be called at SYS_TIME_FREQUENCY
Definition: sim_ap.c:59
MSG_SIZE
#define MSG_SIZE
Definition: main_demo5.c:63
telemetry.h
std.h
update_dl_status
value update_dl_status(value dl_enabled)
Definition: sim_ap.c:119
gps.h
Device independent GPS code (interface)
sim_init
value sim_init(value unit)
Definition: sim_ap.c:105
event_task_fbw
void event_task_fbw(void)
Definition: main_fbw.c:421
rc_event_1
bool rc_event_1
Definition: sim_ap.c:37
electrical_periodic
void electrical_periodic(void)
Definition: electrical.c:123
uint8_t
unsigned char uint8_t
Definition: types.h:14
ivy_tp
struct ivy_transport ivy_tp
IVY transport structure.
Definition: ivy_dl.c:29
attitude_loop
void attitude_loop(void)
Definition: autopilot_static.c:285
autopilot.h
update_bat
value update_bat(value bat)
Definition: sim_ap.c:113
main_ap.h
navigation_task
void navigation_task(void)
Compute desired_course.
Definition: autopilot_static.c:221
commands
static const ShellCommand commands[]
Definition: shell_arch.c:71
ftimeofday
float ftimeofday(void)
Definition: sim_ap.c:97
dl_msg_available
bool dl_msg_available
Definition: main_demo5.c:61
nav.h
autopilot_periodic
void autopilot_periodic(void)
AP periodic call.
Definition: autopilot.c:135
inflight_calib_mode
uint8_t inflight_calib_mode
Definition: sim_ap.c:36
ir_estim_mode
uint8_t ir_estim_mode
Definition: sim_ap.c:34
datalink_time
uint16_t datalink_time
Definition: sim_ap.c:41
reporting_task
void reporting_task(void)
Send a series of initialisation messages followed by a stream of periodic ones.
Definition: main_ap.c:283
DOWNLINK_DEVICE
#define DOWNLINK_DEVICE
Definition: stereocam_droplet.c:57
monitor_task
void monitor_task(void)
monitor stuff run at 1Hz
Definition: main_ap.c:334
sensors_task
void sensors_task(void)
Run at PERIODIC_FREQUENCY (60Hz if not defined)
Definition: main_ap.c:306
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:40
periodic_task_fbw
void periodic_task_fbw(void)
Definition: main_fbw.c:434
ac_id
uint8_t ac_id
Definition: sim_ap.c:48
link_fbw_fbw_nb_err
uint8_t link_fbw_fbw_nb_err
Definition: sim_ap.c:38
alt_roll_pgain
float alt_roll_pgain
Definition: sim_ap.c:39
sys_tick_handler
static void sys_tick_handler(void)
Definition: sys_time_arch.c:133
event_task_ap
void event_task_ap(void)
Definition: main_ap.c:369
sim_periodic_task
value sim_periodic_task(value unit)
Definition: sim_ap.c:65
SIM_UPDATE_DL
#define SIM_UPDATE_DL
Definition: sim_ap.c:45
adc_buf_channel
void adc_buf_channel(void *a, void *b, void *c)
Required by electrical.
Definition: sim_ap.c:155
guidance_v.h