Paparazzi UAS  v5.0.5_stable-7-g4b8bbb7
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures 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"
18 #include "subsystems/nav.h"
21 #include "subsystems/commands.h"
23 #include "ap_downlink.h"
24 #include "sim_uart.h"
26 #include "generated/flight_plan.h"
27 
28 #include "generated/modules.h"
29 
30 #include <caml/mlvalues.h>
31 #include <caml/memory.h>
32 
33 
34 /* Dummy definitions to replace the ones from the files not compiled in the
35  simulator */
40 bool_t launch;
45 
46 
47 
49 
51  sensors_task();
52  attitude_loop();
54  modules_periodic_task();
57  event_task_ap();
59  return unit;
60 }
61 
63  monitor_task();
64  return unit;
65 }
66 
69  return unit;
70 }
71 
72 
73 float ftimeofday(void) {
74  struct timeval t;
75  struct timezone z;
76  gettimeofday(&t, &z);
77  return (t.tv_sec + t.tv_usec/1e6);
78 }
79 
81  init_fbw();
82  init_ap();
83 #ifdef SIM_UART
84  /* open named pipe */
85  char link_pipe_name[128];
86 #ifdef SIM_XBEE
87  sprintf(link_pipe_name, "/tmp/pprz_xbee");
88 #else
89  sprintf(link_pipe_name, "/tmp/pprz_link_%d", AC_ID);
90 #endif
91  struct stat st;
92  if (stat(link_pipe_name, &st)) {
93  if (mkfifo(link_pipe_name, 0644) == -1) {
94  perror("make pipe");
95  exit (10);
96  }
97  }
98  if ( !(pipe_stream = fopen(link_pipe_name, "w")) ) {
99  perror("open pipe");
100  exit (10);
101  }
102 #endif
103 
104  return unit;
105 }
106 
108  electrical.vsupply = Int_val(bat);
109  return Val_unit;
110 }
111 
112 
113 value get_commands(value val_commands) {
114  int i;
115 
116  for(i=0; i < COMMANDS_NB; i++)
117  Store_field(val_commands, i, Val_int(commands[i]));
118 
119  return Val_int(commands[COMMAND_THROTTLE]);
120 }
121 
123  int n = string_length(s);
124  char *ss = String_val(s);
125  assert(n <= MSG_SIZE);
126 
127  int i;
128  for(i = 0; i < n; i++)
129  dl_buffer[i] = ss[i];
130 
131  dl_parse_msg();
132  return Val_unit;
133 }
134 
136 void adc_buf_channel(void* a __attribute__ ((unused)),
137  void* b __attribute__ ((unused)),
138  void* c __attribute__ ((unused))) {
139 }
void monitor_task(void)
monitor stuff run at 1Hz
Definition: main_ap.c:601
unsigned short uint16_t
Definition: types.h:16
void event_task_fbw(void)
Definition: main_fbw.c:133
uint8_t ac_id
Definition: sim_ap.c:48
void periodic_task_fbw(void)
Definition: main_fbw.c:227
float alt_roll_pgain
Definition: sim_ap.c:42
bool_t launch
Definition: sim_ap.c:40
value get_commands(value val_commands)
Definition: sim_ap.c:113
value sim_monitor_task(value unit)
Definition: sim_ap.c:62
value sim_periodic_task(value unit)
Definition: sim_ap.c:50
uint16_t value
ADC1+2 interrupt hander.
Definition: adc_arch.c:577
void navigation_task(void)
Compute desired_course.
Definition: main_ap.c:444
bool_t rc_event_2
Definition: sim_ap.c:39
AP ( AutoPilot ) process API.
void init_fbw(void)
Definition: main_fbw.c:75
uint8_t gps_nb_ovrn
Definition: sim_ap.c:41
value set_datalink_message(value s)
Definition: sim_ap.c:122
uint16_t vsupply
supply voltage in decivolts
Definition: electrical.h:8
value sim_nav_task(value unit)
Definition: sim_ap.c:67
Simulation of uart transmission on an Unix pipe.
FILE * pipe_stream
Definition: sim_uart.c:3
void init_ap(void)
Definition: main_ap.c:166
Fixed wing horizontal control.
#define MSG_SIZE
Definition: main_demo5.c:58
Vertical control for fixed wing vehicles.
value update_bat(value bat)
Definition: sim_ap.c:107
Device independent GPS code (interface)
void event_task_ap(void)
Definition: main_ap.c:628
value sim_init(value unit)
Definition: sim_ap.c:80
Hardware independent code for commands handling.
uint8_t ir_estim_mode
Definition: sim_ap.c:36
void reporting_task(void)
Send a series of initialisation messages followed by a stream of periodic ones.
Definition: main_ap.c:422
uint16_t datalink_time
Definition: sim_ap.c:44
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:73
void electrical_periodic(void)
uint8_t dl_buffer[MSG_SIZE]
Definition: main_demo5.c:59
uint8_t link_fbw_fbw_nb_err
Definition: sim_ap.c:41
uint8_t inflight_calib_mode
Definition: sim_ap.c:38
bool_t rc_event_1
Definition: sim_ap.c:39
static struct point c
Definition: discsurvey.c:39
uint8_t vertical_mode
Definition: sim_ap.c:37
void adc_buf_channel(void *a, void *b, void *c)
Required by electrical.
Definition: sim_ap.c:136
void attitude_loop(void)
Definition: main_ap.c:512
struct Electrical electrical
float roll_rate_pgain
Definition: sim_ap.c:43
Information relative to the other aircrafts.
void sensors_task(void)
Run at PERIODIC_FREQUENCY (60Hz if not defined)
Definition: main_ap.c:564
uint8_t link_fbw_nb_err
Definition: sim_ap.c:41