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_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 }
unsigned short uint16_t
Definition: types.h:16
void attitude_loop(void)
uint8_t ac_id
Definition: sim_ap.c:48
float alt_roll_pgain
Definition: sim_ap.c:39
Communication between fbw and ap processes.
static uint32_t s
#define SIM_UPDATE_DL
Definition: sim_ap.c:45
#define DOWNLINK_DEVICE
value get_commands(value val_commands)
Definition: sim_ap.c:126
value sim_monitor_task(value unit)
Definition: sim_ap.c:82
value sim_periodic_task(value unit)
Definition: sim_ap.c:65
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:137
value sim_nav_task(value unit)
Definition: sim_ap.c:88
void navigation_task(void)
Compute desired_course.
float vsupply
supply voltage in V
Definition: electrical.h:45
void event_task_fbw(void)
Definition: main_fbw.c:421
void periodic_task_fbw(void)
Definition: main_fbw.c:434
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:362
Vertical control for fixed wing vehicles.
value update_bat(value bat)
Definition: sim_ap.c:113
value update_dl_status(value dl_enabled)
Definition: sim_ap.c:119
Device independent GPS code (interface)
value sim_sys_time_task(value unit)
needs to be called at SYS_TIME_FREQUENCY
Definition: sim_ap.c:59
value sim_init(value unit)
Definition: sim_ap.c:105
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:123
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:97
void autopilot_periodic(void)
AP periodic call.
Definition: autopilot.c:135
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:66
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:155
AP ( AutoPilot ) process API.
float roll_rate_pgain
Definition: sim_ap.c:40
uint8_t link_fbw_nb_err
Definition: sim_ap.c:38