Paparazzi UAS  v5.8.2_stable-0-g6260b7c
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"
17 #include "generated/settings.h"
21 #include "subsystems/commands.h"
25 #include "generated/flight_plan.h"
26 
27 #include "generated/modules.h"
28 
29 #include <caml/mlvalues.h>
30 #include <caml/memory.h>
31 
32 
33 /* Dummy definitions to replace the ones from the files not compiled in the
34  simulator */
39 bool_t launch;
45 
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 
59 {
61  return unit;
62 }
63 
65 {
66  sensors_task();
67  attitude_loop();
69  modules_periodic_task();
72  event_task_ap();
74  return unit;
75 }
76 
78 {
79  monitor_task();
80  return unit;
81 }
82 
84 {
86  return unit;
87 }
88 
89 
90 float ftimeofday(void)
91 {
92  struct timeval t;
93  struct timezone z;
94  gettimeofday(&t, &z);
95  return (t.tv_sec + t.tv_usec / 1e6);
96 }
97 
99 {
100  init_fbw();
101  init_ap();
102 
103  return unit;
104 }
105 
107 {
108  electrical.vsupply = Int_val(bat);
109  return Val_unit;
110 }
111 
113 {
114  ivy_tp.ivy_dl_enabled = Int_val(dl_enabled);
115  return Val_unit;
116 }
117 
118 
119 value get_commands(value val_commands)
120 {
121  int i;
122 
123  for (i = 0; i < COMMANDS_NB; i++) {
124  Store_field(val_commands, i, Val_int(commands[i]));
125  }
126 
127  return Val_int(commands[COMMAND_THROTTLE]);
128 }
129 
131 {
132  int n = string_length(s);
133  char *ss = String_val(s);
134  assert(n <= MSG_SIZE);
135 
136  int i;
137  for (i = 0; i < n; i++) {
138  dl_buffer[i] = ss[i];
139  }
140 
142  DlCheckAndParse();
143 
144  return Val_unit;
145 }
146 
148 void adc_buf_channel(void *a __attribute__((unused)),
149  void *b __attribute__((unused)),
150  void *c __attribute__((unused)))
151 {
152 }
void monitor_task(void)
monitor stuff run at 1Hz
Definition: main_ap.c:659
unsigned short uint16_t
Definition: types.h:16
uint8_t ac_id
Definition: sim_ap.c:47
float alt_roll_pgain
Definition: sim_ap.c:41
bool_t launch
Definition: sim_ap.c:39
Communication between fbw and ap processes.
static void sys_tick_handler(void)
value get_commands(value val_commands)
Definition: sim_ap.c:119
value sim_monitor_task(value unit)
Definition: sim_ap.c:77
value sim_periodic_task(value unit)
Definition: sim_ap.c:64
uint16_t value
Definition: adc_arch.c:586
Periodic telemetry system header (includes downlink utility and generated code).
void navigation_task(void)
Compute desired_course.
Definition: main_ap.c:500
bool_t rc_event_2
Definition: sim_ap.c:38
AP ( AutoPilot ) process API.
uint8_t gps_nb_ovrn
Definition: sim_ap.c:40
value set_datalink_message(value s)
Definition: sim_ap.c:130
struct ivy_transport ivy_tp
Definition: ivy_transport.c:38
value sim_nav_task(value unit)
Definition: sim_ap.c:83
void event_task_fbw(void)
Definition: main_fbw.c:190
void periodic_task_fbw(void)
Definition: main_fbw.c:304
void init_ap(void)
Definition: main_ap.c:175
bool_t dl_msg_available
Definition: main_demo5.c:61
uint16_t datalink_nb_msgs
Definition: sim_ap.c:44
Fixed wing horizontal control.
#define MSG_SIZE
Definition: main_demo5.c:63
#define TRUE
Definition: std.h:4
void init_fbw(void)
Definition: main_fbw.c:116
Vertical control for fixed wing vehicles.
value update_bat(value bat)
Definition: sim_ap.c:106
value update_dl_status(value dl_enabled)
Definition: sim_ap.c:112
Device independent GPS code (interface)
value sim_sys_time_task(value unit)
needs to be called at SYS_TIME_FREQUENCY
Definition: sim_ap.c:58
void event_task_ap(void)
Definition: main_ap.c:691
value sim_init(value unit)
Definition: sim_ap.c:98
Hardware independent code for commands handling.
uint8_t ir_estim_mode
Definition: sim_ap.c:35
void reporting_task(void)
Send a series of initialisation messages followed by a stream of periodic ones.
Definition: main_ap.c:472
void electrical_periodic(void)
Definition: electrical.c:121
uint16_t datalink_time
Definition: sim_ap.c:43
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:90
uint16_t vsupply
supply voltage in decivolts
Definition: electrical.h:48
uint8_t dl_buffer[MSG_SIZE]
Definition: main_demo5.c:64
uint8_t link_fbw_fbw_nb_err
Definition: sim_ap.c:40
uint8_t inflight_calib_mode
Definition: sim_ap.c:37
struct Electrical electrical
Definition: electrical.c:65
bool_t rc_event_1
Definition: sim_ap.c:38
uint8_t vertical_mode
Definition: sim_ap.c:36
void adc_buf_channel(void *a, void *b, void *c)
Required by electrical.
Definition: sim_ap.c:148
void attitude_loop(void)
Definition: main_ap.c:564
float roll_rate_pgain
Definition: sim_ap.c:42
Information relative to the other aircrafts.
void sensors_task(void)
Run at PERIODIC_FREQUENCY (60Hz if not defined)
Definition: main_ap.c:617
uint8_t link_fbw_nb_err
Definition: sim_ap.c:40