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