Paparazzi UAS  v4.0.4_stable-3-gf39211a
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();
58  event_task_ap();
60  return unit;
61 }
62 
63 value sim_monitor_task(value unit) {
64  monitor_task();
65  return unit;
66 }
67 
68 value sim_nav_task(value unit) {
70  return unit;
71 }
72 
73 
74 float ftimeofday(void) {
75  struct timeval t;
76  struct timezone z;
77  gettimeofday(&t, &z);
78  return (t.tv_sec + t.tv_usec/1e6);
79 }
80 
81 value sim_init(value unit) {
82  init_fbw();
83  init_ap();
84 #ifdef SIM_UART
85  /* open named pipe */
86  char link_pipe_name[128];
87 #ifdef SIM_XBEE
88  sprintf(link_pipe_name, "/tmp/pprz_xbee");
89 #else
90  sprintf(link_pipe_name, "/tmp/pprz_link_%d", AC_ID);
91 #endif
92  struct stat st;
93  if (stat(link_pipe_name, &st)) {
94  if (mkfifo(link_pipe_name, 0644) == -1) {
95  perror("make pipe");
96  exit (10);
97  }
98  }
99  if ( !(pipe_stream = fopen(link_pipe_name, "w")) ) {
100  perror("open pipe");
101  exit (10);
102  }
103 #endif
104 
105  return unit;
106 }
107 
108 value update_bat(value bat) {
109  electrical.vsupply = Int_val(bat);
110  return Val_unit;
111 }
112 
113 
114 value get_commands(value val_commands) {
115  int i;
116 
117  for(i=0; i < COMMANDS_NB; i++)
118  Store_field(val_commands, i, Val_int(commands[i]));
119 
120  return Val_int(commands[COMMAND_THROTTLE]);
121 }
122 
123 value set_datalink_message(value s) {
124  int n = string_length(s);
125  char *ss = String_val(s);
126  assert(n <= MSG_SIZE);
127 
128  int i;
129  for(i = 0; i < n; i++)
130  dl_buffer[i] = ss[i];
131 
132  dl_parse_msg();
133  return Val_unit;
134 }
135 
137 void adc_buf_channel(void* a __attribute__ ((unused)),
138  void* b __attribute__ ((unused)),
139  void* c __attribute__ ((unused))) {
140 }
void monitor_task(void)
monitor stuff run at 1Hz
Definition: main_ap.c:576
unsigned short uint16_t
Definition: types.h:16
void event_task_fbw(void)
Definition: main_fbw.c:118
uint8_t ac_id
Definition: sim_ap.c:50
void periodic_task_fbw(void)
Definition: main_fbw.c:188
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:114
value sim_monitor_task(value unit)
Definition: sim_ap.c:63
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:63
uint8_t gps_nb_ovrn
Definition: sim_ap.c:42
value set_datalink_message(value s)
Definition: sim_ap.c:123
value sim_nav_task(value unit)
Definition: sim_ap.c:68
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
uint8_t vsupply
Definition: electrical.h:8
Vertical control for fixed wing vehicles.
value update_bat(value bat)
Definition: sim_ap.c:108
Device independent GPS code (interface)
void event_task_ap(void)
Definition: main_ap.c:606
value sim_init(value unit)
Definition: sim_ap.c:81
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
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:42
float ftimeofday(void)
Definition: sim_ap.c:74
void adc_buf_channel(void *a __attribute__((unused)), void *b __attribute__((unused)), void *c __attribute__((unused)))
Required by electrical.
Definition: sim_ap.c:137
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:522
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:546
uint8_t link_fbw_nb_err
Definition: sim_ap.c:42