Paparazzi UAS  v5.12_stable-4-g9b43e9b
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
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 
46 
47 #if PERIODIC_FREQUENCY != 60
48 #warning "Simple OCaml sim can currently only handle a PERIODIC_FREQUENCY of 60Hz"
49 #endif
50 
51 #if SYS_TIME_FREQUENCY != 120
52 #warning "Simple OCaml sim can currently only handle a SYS_TIME_FREQUENCY of 120Hz"
53 #endif
54 
56 value sim_sys_time_task(value unit)
57 {
59  return unit;
60 }
61 
62 value sim_periodic_task(value unit)
63 {
64  sensors_task();
65 #if USE_GENERATED_AUTOPILOT
67 #else
68  attitude_loop();
69 #endif
71  modules_periodic_task();
74  event_task_ap();
76  return unit;
77 }
78 
79 value sim_monitor_task(value unit)
80 {
81  monitor_task();
82  return unit;
83 }
84 
85 value sim_nav_task(value unit)
86 {
87 #if !USE_GENERATED_AUTOPILOT
89 #endif
90  return unit;
91 }
92 
93 
94 float ftimeofday(void)
95 {
96  struct timeval t;
97  struct timezone z;
98  gettimeofday(&t, &z);
99  return (t.tv_sec + t.tv_usec / 1e6);
100 }
101 
102 value sim_init(value unit)
103 {
104  init_fbw();
105  init_ap();
106 
107  return unit;
108 }
109 
110 value update_bat(value bat)
111 {
112  electrical.vsupply = Int_val(bat);
113  return Val_unit;
114 }
115 
116 value update_dl_status(value dl_enabled)
117 {
118  ivy_tp.ivy_dl_enabled = Int_val(dl_enabled);
119  return Val_unit;
120 }
121 
122 
123 value get_commands(value val_commands)
124 {
125  int i;
126 
127  for (i = 0; i < COMMANDS_NB; i++) {
128  Store_field(val_commands, i, Val_int(commands[i]));
129  }
130 
131  return Val_int(commands[COMMAND_THROTTLE]);
132 }
133 
134 value set_datalink_message(value s)
135 {
136  int n = string_length(s);
137  char *ss = String_val(s);
138  assert(n <= MSG_SIZE);
139 
140  int i;
141  for (i = 0; i < n; i++) {
142  dl_buffer[i] = ss[i];
143  }
144 
145  dl_msg_available = true;
147 
148  return Val_unit;
149 }
150 
152 void adc_buf_channel(void *a __attribute__((unused)),
153  void *b __attribute__((unused)),
154  void *c __attribute__((unused)))
155 {
156 }
unsigned short uint16_t
Definition: types.h:16
void attitude_loop(void)
uint8_t ac_id
Definition: sim_ap.c:45
float alt_roll_pgain
Definition: sim_ap.c:39
Communication between fbw and ap processes.
#define DOWNLINK_DEVICE
value get_commands(value val_commands)
Definition: sim_ap.c:123
value sim_monitor_task(value unit)
Definition: sim_ap.c:79
value sim_periodic_task(value unit)
Definition: sim_ap.c:62
Periodic telemetry system header (includes downlink utility and generated code).
void init_ap(void)
Definition: main_ap.c:149
bool rc_event_2
Definition: sim_ap.c:37
uint8_t gps_nb_ovrn
Definition: sim_ap.c:38
value set_datalink_message(value s)
Definition: sim_ap.c:134
value sim_nav_task(value unit)
Definition: sim_ap.c:85
void navigation_task(void)
Compute desired_course.
void event_task_fbw(void)
Definition: main_fbw.c:422
void periodic_task_fbw(void)
Definition: main_fbw.c:435
bool dl_msg_available
Definition: main_demo5.c:61
uint16_t datalink_nb_msgs
Definition: sim_ap.c:42
Fixed wing horizontal control.
bool rc_event_1
Definition: sim_ap.c:37
#define MSG_SIZE
Definition: main_demo5.c:63
static void sys_tick_handler(void)
void init_fbw(void)
Definition: main_fbw.c:363
Vertical control for fixed wing vehicles.
value update_bat(value bat)
Definition: sim_ap.c:110
value update_dl_status(value dl_enabled)
Definition: sim_ap.c:116
Device independent GPS code (interface)
value sim_sys_time_task(value unit)
needs to be called at SYS_TIME_FREQUENCY
Definition: sim_ap.c:56
value sim_init(value unit)
Definition: sim_ap.c:102
Hardware independent code for commands handling.
uint8_t ir_estim_mode
Definition: sim_ap.c:34
struct ivy_transport ivy_tp
IVY transport structure.
Definition: ivy_dl.c:29
void electrical_periodic(void)
Definition: electrical.c:121
uint16_t datalink_time
Definition: sim_ap.c:41
Core autopilot interface common to all firmwares.
unsigned char uint8_t
Definition: types.h:14
pprz_t commands[COMMANDS_NB]
Storage of intermediate command values.
Definition: commands.c:30
float ftimeofday(void)
Definition: sim_ap.c:94
uint16_t vsupply
supply voltage in decivolts
Definition: electrical.h:48
void autopilot_periodic(void)
AP periodic call.
Definition: autopilot.c:130
uint8_t dl_buffer[MSG_SIZE]
Definition: main_demo5.c:64
void reporting_task(void)
Send a series of initialisation messages followed by a stream of periodic ones.
Definition: main_ap.c:283
void monitor_task(void)
monitor stuff run at 1Hz
Definition: main_ap.c:334
uint8_t link_fbw_fbw_nb_err
Definition: sim_ap.c:38
uint8_t inflight_calib_mode
Definition: sim_ap.c:36
void sensors_task(void)
Run at PERIODIC_FREQUENCY (60Hz if not defined)
Definition: main_ap.c:306
struct Electrical electrical
Definition: electrical.c:65
void event_task_ap(void)
Definition: main_ap.c:369
uint8_t vertical_mode
Definition: sim_ap.c:35
void adc_buf_channel(void *a, void *b, void *c)
Required by electrical.
Definition: sim_ap.c:152
AP ( AutoPilot ) process API.
float roll_rate_pgain
Definition: sim_ap.c:40
uint8_t link_fbw_nb_err
Definition: sim_ap.c:38