diff --git a/Makefile b/Makefile
index bcde9d87d9..18679bbfcc 100644
--- a/Makefile
+++ b/Makefile
@@ -138,7 +138,7 @@ ac_h : tools static_h
sim_ac: ac_h sim_sitl
hard_ac: ac_h fbw ap
-ac: sim_ac hard_ac
+ac: hard_ac
doxygen:
mkdir -p dox
diff --git a/conf/Makefile.arm7 b/conf/Makefile.arm7
index e422a6677c..a7482f2738 100644
--- a/conf/Makefile.arm7
+++ b/conf/Makefile.arm7
@@ -26,7 +26,6 @@
# This is the common Makefile for the arm7-target.
#
-OBJDIR = $(PAPARAZZI_HOME)/var/$(AIRCRAFT)/$(TARGET)
SRC_ARCH = $(PAPARAZZI_SRC)/sw/airborne/arm7
CC = arm-elf-gcc -mmcu=$($(TARGET).ARCH)
diff --git a/conf/Makefile.avr b/conf/Makefile.avr
index 3eed8ed50f..15cab4d996 100644
--- a/conf/Makefile.avr
+++ b/conf/Makefile.avr
@@ -27,7 +27,6 @@
# Edit the configuration part to suit your local install
#
-OBJDIR = $(PAPARAZZI_HOME)/var/$(AIRCRAFT)/$(TARGET)
SRC_ARCH = $(PAPARAZZI_SRC)/sw/airborne/avr
CC = $(ATMELBIN)/avr-gcc -mmcu=$($(TARGET).ARCH)
diff --git a/conf/Makefile.sim b/conf/Makefile.sim
index 8e4c348d53..56f1997cd4 100644
--- a/conf/Makefile.sim
+++ b/conf/Makefile.sim
@@ -27,11 +27,12 @@
# Edit the configuration part to suit your local install
#
-OBJDIR = $(PAPARAZZI_HOME)/var/$(AIRCRAFT)/$(TARGET)
SRC_ARCH = $(PAPARAZZI_SRC)/sw/airborne/sim
-CC = gcc
-LD = $(CC)
+CC = gcc
+OCAMLC = ocamlc
+CAMLINCLUDES = -I +lablgtk2 -I $(PAPARAZZI_SRC)/sw/lib/ocaml -I $(PAPARAZZI_SRC)/sw/simulator
+SITLCMA = $(PAPARAZZI_SRC)/sw/simulator/sitl.cma
#
@@ -41,7 +42,6 @@ LD = $(CC)
CFLAGS = \
-W -Wall \
- $(ATMEL_INCLUDES) \
$(INCLUDES) \
-Wstrict-prototypes \
$($(TARGET).CFLAGS) \
@@ -58,43 +58,10 @@ $(TARGET).srcsnd = $(notdir $($(TARGET).srcs))
$(TARGET).objso = $($(TARGET).srcsnd:%.c=$(OBJDIR)/%.o)
$(TARGET).objs = $($(TARGET).objso:%.S=$(OBJDIR)/%.o)
+all compile: $(OBJDIR)/simsitl
-all compile: $($(TARGET).objs) $(OBJDIR)/$(TARGET).elf
-#all:
-# @echo !!!!!!!
-# @echo $($(TARGET).objs)
-# @echo !!!!!!!
-
-load upload: $(TARGET).install
-
-
-#
-# Fuses
-#
-
-rd_fuses: check_arch
- $(UISP) $(ISP_FLAGS) --rd_fuses
-
-wr_fuses : check_arch
- $(UISP) $(ISP_FLAGS) --wr_fuse_h=$($(TARGET).HIGH_FUSE)
- $(UISP) $(ISP_FLAGS) --wr_fuse_l=$($(TARGET).LOW_FUSE)
- $(UISP) $(ISP_FLAGS) --wr_fuse_e=$($(TARGET).EXT_FUSE)
- $(UISP) $(ISP_FLAGS) --wr_lock=$($(TARGET).LOCK_FUSE)
-
-TMPFILE = '/tmp/check_fuses.tmp'
-
-check_fuses: check_arch
- @echo "##### Check of fuses #####"
- @$(UISP) $(ISP_FLAGS) --rd_fuses >$(TMPFILE)
- @if (grep -i 'Fuse Low Byte' $(TMPFILE) | cut -c24- | grep -iq $($(TARGET).LOW_FUSE)) && (grep -i 'Fuse High Byte' $(TMPFILE) |cut -c24- | grep -iq $($(TARGET).HIGH_FUSE)) && (grep -i 'Fuse Extended Byte' $(TMPFILE) |cut -c24- | grep -iq $($(TARGET).EXT_FUSE)) && (grep -i 'Lock Bits' $(TMPFILE) |cut -c24- | grep -iq $($(TARGET).LOCK_FUSE)); then echo "-> Fuses are Ok"; rm $(TMPFILE); else echo "-> Wrong fuses. Type 'make wr_fuses'"; rm $(TMPFILE); exit 1; fi
-
-
-$(OBJDIR)/%.elf: $($(TARGET).objs)
- $(LD) \
- $(LOCAL_LDFLAGS) \
- $^ \
- -o $@ \
- $(LDFLAGS)
+$(OBJDIR)/simsitl : $($(TARGET).objs) $(SITLCMA)
+ $(OCAMLC) -custom $(CAMLINCLUDES) -o $@ glibivy-ocaml.cma lib-pprz.cma lablgtk.cma gtkInit.cmo $^
%.s: %.c
@@ -113,7 +80,6 @@ $(OBJDIR)/%.o: $(SRC_ARCH)/%.S
$(CC) $(CFLAGS) -c -o $@ $<
-
avr_clean:
rm -rf $(OBJDIR)
diff --git a/conf/airframes/plaster1.xml b/conf/airframes/plaster1.xml
index 14f2368f57..737f57c178 100755
--- a/conf/airframes/plaster1.xml
+++ b/conf/airframes/plaster1.xml
@@ -109,30 +109,13 @@
include $(PAPARAZZI_SRC)/conf/autopilot/v1_2_1.makefile
+include $(PAPARAZZI_SRC)/conf/autopilot/twin_mcu_avr.makefile
-fbw.srcs += commands.c
+ap.CFLAGS += -DDOWNLINK -DUSE_UART0 -DDOWNLINK_TRANSPORT=PprzTransport -DDOWNLINK_AP_DEVICE=uart0
+ap.srcs += pprz_transport.c downlink.c
-fbw.CFLAGS += -DACTUATORS=\"servos_4017.h\" -DSERVOS_4017
-fbw.srcs += $(SRC_ARCH)/servos_4017.c
-
-fbw.CFLAGS += -DRADIO_CONTROL
-fbw.srcs += radio_control.c $(SRC_ARCH)/ppm_hw.c
-
-fbw.CFLAGS += -DDOWNLINK -DUSE_UART0 -DDOWNLINK_TRANSPORT=PprzTransport -DDOWNLINK_FBW_DEVICE=uart0
-fbw.srcs += pprz_transport.c downlink.c $(SRC_ARCH)/uart_hw.c
-
-fbw.CFLAGS += -DINTER_MCU -DMCU_SPI_LINK
-fbw.srcs += inter_mcu.c $(SRC_ARCH)/spi_hw.c
-
-fbw.CFLAGS += -DDEBUG
-
-ap.CFLAGS += -DDOWNLINK -DUSE_UART0 -DDOWNLINK_TRANSPORT=PprzTransport -DDOWNLINK_AP_DEVICE=uart0
-ap.srcs += pprz_transport.c downlink.c $(SRC_ARCH)/uart_hw.c
-
-ap.CFLAGS += -DMCU_SPI_LINK
-ap.srcs += inter_mcu.c link_mcu.c $(SRC_ARCH)/link_mcu_ap.c $(SRC_ARCH)/spi_hw.c
-
-ap.CFLAGS += -DGPS -DUBX -DINFRARED -DRADIO_CONTROL
+# ap.CFLAGS += -DMODEM
+# ap.srcs += $(SRC_ARCH)/modem_hw.c
diff --git a/conf/airframes/twinstar1.xml b/conf/airframes/twinstar1.xml
index 55f58e2f78..e245603827 100644
--- a/conf/airframes/twinstar1.xml
+++ b/conf/airframes/twinstar1.xml
@@ -103,15 +103,12 @@
-
-
-include $(PAPARAZZI_SRC)/conf/autopilot/sitl.makefile
+include $(PAPARAZZI_SRC)/conf/autopilot/v1_2_1.makefile
+include $(PAPARAZZI_SRC)/conf/autopilot/twin_mcu_avr.makefile
-ap.CFLAGS += -Werror
+include $(PAPARAZZI_SRC)/conf/autopilot/sitl.makefile
+sim.CFLAGS += -Werror
# ap.CFLAGS += -DDATALINK
# ap.EXTRA_SRCS += traffic_info.c datalink.c
diff --git a/conf/autopilot/sitl.makefile b/conf/autopilot/sitl.makefile
index fc9c97d51c..6dff78c1a2 100644
--- a/conf/autopilot/sitl.makefile
+++ b/conf/autopilot/sitl.makefile
@@ -1,11 +1,9 @@
-ARCHI=sim
-
-ap.ARCHDIR = $(ARCHI)
-ap.ARCH = sitl
-ap.TARGET = autopilot
-ap.TARGETDIR = autopilot
-ap.CFLAGS += -DAP -DFBW
-# ap.CFLAGS += -DGPS -DUBX -DINFRARED -DRADIO_CONTROL -DDOWNLINK
+sim.ARCHDIR = $(ARCHI)
+sim.ARCH = sitl
+sim.TARGET = autopilot
+sim.TARGETDIR = autopilot
+sim.CFLAGS += -DSITL -DAP -DFBW -DRADIO_CONTROL -DINTER_MCU
+# ap.CFLAGS += -DGPS -DUBX -DINFRARED -DDOWNLINK
#ap.CFLAGS += -DACTUATORS=\"servos_4017.h\" -DSERVOS_4017
#ap.srcs += $(SRC_ARCH)/servos_4017.c
-ap.srcs = radio_control.c downlink.c commands.c gps_ubx.c gps.c inter_mcu.c link_mcu.c infrared.c pid.c nav.c estimator.c mainloop.c cam.c sys_time.c main_fbw.c main_ap.c main.c
+sim.srcs = radio_control.c downlink.c commands.c gps.c inter_mcu.c link_mcu.c infrared.c pid.c nav.c estimator.c cam.c sys_time.c main_fbw.c main_ap.c $(SRC_ARCH)/ppm_hw.c $(SRC_ARCH)/sim_gps.c $(SRC_ARCH)/sim_ir.c $(SRC_ARCH)/sim_ap.c
diff --git a/conf/autopilot/twin_avr.makefile b/conf/autopilot/twin_avr.makefile
index 1ab2790012..730265ed1e 100644
--- a/conf/autopilot/twin_avr.makefile
+++ b/conf/autopilot/twin_avr.makefile
@@ -8,8 +8,7 @@ ap.LOW_FUSE = a0
ap.HIGH_FUSE = 99
ap.EXT_FUSE = ff
ap.LOCK_FUSE = ff
-ap.CFLAGS += -DAP -DMODEM
-ap.srcs = gps_ubx.c gps.c main_ap.c $(SRC_ARCH)/modem_hw.c $(SRC_ARCH)/adc_hw.c infrared.c pid.c nav.c estimator.c mainloop.c cam.c sys_time.c main.c
+ap.CFLAGS += -DAP
fbw.ARCHDIR = $(ARCHI)
fbw.ARCH = atmega8
@@ -20,4 +19,3 @@ fbw.HIGH_FUSE = cb
fbw.EXT_FUSE = ff
fbw.LOCK_FUSE = ff
fbw.CFLAGS += -DFBW
-fbw.srcs = $(SRC_ARCH)/adc_hw.c sys_time.c main_fbw.c main.c
diff --git a/conf/autopilot/twin_mcu.makefile b/conf/autopilot/twin_mcu.makefile
new file mode 100644
index 0000000000..37cbaead19
--- /dev/null
+++ b/conf/autopilot/twin_mcu.makefile
@@ -0,0 +1,6 @@
+ap.srcs += main_ap.c sys_time.c main.c inter_mcu.c link_mcu.c gps_ubx.c gps.c infrared.c pid.c nav.c estimator.c cam.c
+ap.CFLAGS += -DMCU_SPI_LINK -DGPS -DUBX -DINFRARED -DRADIO_CONTROL -DINTER_MCU
+
+fbw.srcs += sys_time.c main_fbw.c main.c commands.c radio_control.c pprz_transport.c downlink.c inter_mcu.c
+fbw.CFLAGS += -DRADIO_CONTROL -DDOWNLINK -DUSE_UART0 -DDOWNLINK_TRANSPORT=PprzTransport -DDOWNLINK_FBW_DEVICE=uart0 -DINTER_MCU -DMCU_SPI_LINK
+
diff --git a/conf/autopilot/twin_mcu_avr.makefile b/conf/autopilot/twin_mcu_avr.makefile
new file mode 100644
index 0000000000..5fbe89921f
--- /dev/null
+++ b/conf/autopilot/twin_mcu_avr.makefile
@@ -0,0 +1,8 @@
+include $(PAPARAZZI_SRC)/conf/autopilot/twin_avr.makefile
+include $(PAPARAZZI_SRC)/conf/autopilot/twin_mcu.makefile
+
+ap.srcs += $(SRC_ARCH)/adc_hw.c $(SRC_ARCH)/uart_hw.c $(SRC_ARCH)/link_mcu_ap.c $(SRC_ARCH)/spi_hw.c
+ap.CFLAGS += -DGPS_LINK=uart1
+
+fbw.CFLAGS += -DACTUATORS=\"servos_4017.h\" -DSERVOS_4017 -DADC
+fbw.srcs += $(SRC_ARCH)/adc_hw.c $(SRC_ARCH)/servos_4017.c $(SRC_ARCH)/ppm_hw.c $(SRC_ARCH)/uart_hw.c $(SRC_ARCH)/spi_hw.c
diff --git a/sw/airborne/Makefile b/sw/airborne/Makefile
index 5e89a1d8ac..0d62354c1b 100644
--- a/sw/airborne/Makefile
+++ b/sw/airborne/Makefile
@@ -21,6 +21,7 @@
#
+OBJDIR = $(PAPARAZZI_HOME)/var/$(AIRCRAFT)/$(TARGET)
VARINCLUDE=$(PAPARAZZI_HOME)/var/include
ACINCLUDE = $(PAPARAZZI_HOME)/var/$(AIRCRAFT)
diff --git a/sw/airborne/ap_downlink.h b/sw/airborne/ap_downlink.h
index 9bf3dcd3bf..c3fb78a051 100644
--- a/sw/airborne/ap_downlink.h
+++ b/sw/airborne/ap_downlink.h
@@ -33,13 +33,8 @@
extern uint8_t telemetry_mode_Ap;
#include "downlink.h"
-#ifdef SITL
-#include "sitl_messages.h"
-#else
-#include "modem.h"
#include "messages.h"
#include "periodic.h"
-#endif
#if DOWNLINK
#define Downlink(x) x
@@ -58,7 +53,15 @@ extern uint8_t telemetry_mode_Ap;
#define PERIODIC_SEND_DEBUG_MCU_LINK() {}
#endif
+
+#ifdef MODEM
+#include "modem.h"
#define PERIODIC_SEND_DEBUG_MODEM() DOWNLINK_SEND_DEBUG_MODEM(&modem_nb_ovrn)
+#else
+#define PERIODIC_SEND_DEBUG_MODEM()
+#endif
+
+
#define PERIODIC_SEND_ATTITUDE() Downlink({ \
int8_t phi = DegOfRad(estimator_phi); \
int8_t psi = DegOfRad(estimator_psi); \
diff --git a/sw/airborne/autopilot.h b/sw/airborne/autopilot.h
index b992ebd8a0..3ba27e995c 100644
--- a/sw/airborne/autopilot.h
+++ b/sw/airborne/autopilot.h
@@ -111,10 +111,11 @@ extern bool_t launch;
void periodic_task( void );
void telecommand_task(void);
+#ifdef RADIO_CONTROL
#include "radio_control.h"
static inline void autopilot_process_radio_control ( void ) {
pprz_mode = PPRZ_MODE_OF_PULSE(rc_values[RADIO_MODE], 0);
-
}
+#endif
#endif /* AUTOPILOT_H */
diff --git a/sw/airborne/avr/interrupt_hw.h b/sw/airborne/avr/interrupt_hw.h
index c6b732a754..64a7bc6a0c 100644
--- a/sw/airborne/avr/interrupt_hw.h
+++ b/sw/airborne/avr/interrupt_hw.h
@@ -25,6 +25,12 @@
* \brief AVR Low level interrupt handling
*
*/
+
+#ifndef INTERRUPT_HW_H
+#define INTERRUPT_HW_H
+
#include
#define int_enable() sei()
+
+#endif /* INTERRUPT_HW_H */
diff --git a/sw/airborne/gps.h b/sw/airborne/gps.h
index 8db1346c51..2fd02e5ef1 100644
--- a/sw/airborne/gps.h
+++ b/sw/airborne/gps.h
@@ -71,16 +71,22 @@ struct svinfo {
extern struct svinfo gps_svinfos[GPS_NB_CHANNELS];
+#define GPS_FIX_VALID(gps_mode) (gps_mode == 3)
+
#ifdef UBX
-#include "ubx.h"
+#include "gps_ubx.h"
#endif
#ifndef SITL
#include "uart.h"
-#define GpsBuffer() uart1ChAvailable()
-#define ReadGpsBuffer() { while (uart1ChAvailable()) parse_ubx(uart1Getch()); }
-#define GpsUartSend1(c) uart1_transmit(c)
+#define __GpsLink(dev, _x) dev##_x
+#define _GpsLink(dev, _x) __GpsLink(dev, _x)
+#define GpsLink(_x) _GpsLink(GPS_LINK, _x)
+
+#define GpsBuffer() GpsLink(ChAvailable())
+#define ReadGpsBuffer() { while (GpsLink(ChAvailable())) parse_ubx(GpsLink(Getch())); }
+#define GpsUartSend1(c) GpsLink(_transmit(c))
#endif
diff --git a/sw/airborne/gps_ubx.c b/sw/airborne/gps_ubx.c
index 25fb2dfc7a..3f54117ae9 100644
--- a/sw/airborne/gps_ubx.c
+++ b/sw/airborne/gps_ubx.c
@@ -34,7 +34,7 @@
#include "flight_plan.h"
#include "uart.h"
#include "gps.h"
-#include "ubx.h"
+#include "gps_ubx.h"
uint32_t gps_itow;
int32_t gps_alt;
diff --git a/sw/airborne/ubx.h b/sw/airborne/gps_ubx.h
similarity index 97%
rename from sw/airborne/ubx.h
rename to sw/airborne/gps_ubx.h
index 925486f5b2..81f60ee9bd 100644
--- a/sw/airborne/ubx.h
+++ b/sw/airborne/gps_ubx.h
@@ -55,8 +55,6 @@ extern uint8_t send_ck_a, send_ck_b;
#include "ubx_protocol.h"
-#define GPS_FIX_VALID(gps_mode) (gps_mode == 3)
-
extern void parse_ubx( uint8_t c );
#define GpsParse(_gps_buffer, _gps_buffer_size) { \
diff --git a/sw/airborne/inter_mcu.h b/sw/airborne/inter_mcu.h
index db9b2f4b64..224deb8529 100644
--- a/sw/airborne/inter_mcu.h
+++ b/sw/airborne/inter_mcu.h
@@ -32,6 +32,14 @@
#ifndef INTER_MCU_H
#define INTER_MCU_H
+/** Fly by wire modes */
+#define FBW_MODE_MANUAL 0
+#define FBW_MODE_AUTO 1
+#define FBW_MODE_FAILSAFE 2
+#define FBW_MODE_OF_PPRZ(mode) ((mode) < TRESHOLD_MANUAL_PPRZ ? FBW_MODE_MANUAL : FBW_MODE_AUTO)
+
+#ifdef INTER_MCU
+
#include
#include "std.h"
@@ -72,12 +80,6 @@ typedef union {
struct from_ap_msg from_ap;
} inter_mcu_msg;
-/** Fly by wire modes */
-
-#define FBW_MODE_MANUAL 0
-#define FBW_MODE_AUTO 1
-#define FBW_MODE_FAILSAFE 2
-#define FBW_MODE_OF_PPRZ(mode) ((mode) < TRESHOLD_MANUAL_PPRZ ? FBW_MODE_MANUAL : FBW_MODE_AUTO)
// Status bits from FBW to AUTOPILOT
#define STATUS_RADIO_OK 0
@@ -135,7 +137,7 @@ static inline void to_autopilot_from_rc_values (void) {
rc_values_contains_avg_channels = FALSE;
}
msg->ppm_cpt = last_ppm_cpt;
- msg->vsupply = VoltageOfAdc(vsupply_adc_buf.sum/vsupply_adc_buf.av_nb_sample) * 10;
+ msg->vsupply = fbw_vsupply_decivolt;
#if defined IMU_3DMG || defined IMU_ANALOG
msg->euler_dot[0] = roll_dot;
msg->euler_dot[1] = pitch_dot;
@@ -165,5 +167,6 @@ static inline void inter_mcu_periodic_task(void) {
#endif /* FBW */
+#endif /* INTER_MCU */
#endif /* INTER_MCU_H */
diff --git a/sw/airborne/main_ap.c b/sw/airborne/main_ap.c
index fd87d292ff..d6d5c45b6a 100644
--- a/sw/airborne/main_ap.c
+++ b/sw/airborne/main_ap.c
@@ -24,6 +24,8 @@
#include
+#include "interrupt_hw.h"
+#include "init_hw.h"
#include "adc.h"
#include "pid.h"
#include "gps.h"
@@ -367,7 +369,7 @@ static void navigation_task( void ) {
* - do navigation with \a navigation_task
*
*/
-inline void periodic_task( void ) {
+inline void periodic_task_ap( void ) {
static uint8_t _20Hz = 0;
static uint8_t _10Hz = 0;
static uint8_t _4Hz = 0;
@@ -467,3 +469,175 @@ inline void periodic_task( void ) {
fatal_error_nb++;
}
}
+
+
+
+
+#ifdef MCU_SPI_LINK /** ap alone, using SPI to communicate with fbw */
+#include "spi.h"
+#include "link_mcu_ap.h"
+#endif
+/** #else statically linked with fbw */
+
+
+#ifdef TELEMETER
+#include "srf08.h"
+#endif
+
+#ifdef AHRS
+#include "ahrs.h"
+#endif // AHRS
+
+
+void init_ap( void ) {
+#ifdef LED
+ led_init();
+#endif
+#ifndef FBW /** Dual mcus : init done in main_fbw */
+ hw_init();
+ sys_time_init();
+#ifdef ADC
+ adc_init();
+#endif
+#endif
+
+ /************* Sensors initialization ***************/
+#ifdef INFRARED
+ ir_init();
+#endif
+#ifdef GPS
+ gps_init();
+#endif
+#ifdef TELEMETER
+ srf08_init();
+#endif
+#if USE_UART0
+ uart0_init_tx();
+ uart0_init_rx();
+#endif //IMU
+
+
+ /************* Links initialization ***************/
+#if defined MCU_SPI_LINK
+ spi_init();
+ link_fbw_init();
+#endif
+#ifdef MODEM
+ modem_init();
+#endif
+#ifdef WAVECARD
+ /** Reset the wavecard during the init pause */
+ wc_reset();
+#endif
+
+ /************ Internal status ***************/
+ estimator_init();
+ nav_init();
+
+
+ /** - start interrupt task */
+ int_enable();
+
+ /** - wait 0.5s (for modem init ?) */
+ uint8_t init_cpt = 30;
+ while (init_cpt) {
+ if (sys_time_periodic())
+ init_cpt--;
+ }
+#ifdef WAVECARD
+ wc_end_reset();
+#endif
+
+#if defined AHRS
+ /** - ahrs init(do_calibration)
+ * - Warning if do_calibration is TRUE this will provide an asynchronous
+ * - calibration process, and it will take some calls to ahrs_update() to
+ * - end. So Don't take off before ahrs_state == AHRS_RUNNING
+ */
+ ahrs_init(TRUE);
+#endif //AHRS
+
+ /** - enter mainloop:
+ * - do periodic task by calling \a periodic_task
+ * - parse and use GPS messages with \a parse_gps_msg and \a use_gps_pos
+ * - receive radio control task from fbw and use it with
+ * \a telecommand_task
+ */
+}
+
+
+void event_task_ap( void ) {
+#ifdef GPS
+ if (GpsBuffer()) {
+ ReadGpsBuffer();
+ /* if (IO1PIN & LED_2_BIT) */
+ /* IO1CLR = LED_2_BIT; */
+ /* else */
+ /* IO1SET = LED_2_BIT; */
+ }
+ if (gps_msg_received) {
+ /* parse and use GPS messages */
+ parse_gps_msg();
+ gps_msg_received = FALSE;
+ if (gps_pos_available) {
+ use_gps_pos();
+ gps_pos_available = FALSE;
+ }
+ }
+#endif /** GPS */
+#ifdef WAVECARD
+ if (wc_msg_received) {
+ wc_parse_payload();
+ wc_msg_received = FALSE;
+ }
+#endif /** WAVECARD */
+
+#ifdef MAXSTREAM
+ if (maxstream_msg_received) {
+ maxstream_parse_payload();
+ maxstream_msg_received = FALSE;
+ }
+#endif /** MAXSTREAM */
+
+#ifdef DATALINK
+ if (dl_msg_available) {
+ dl_parse_msg();
+ dl_msg_available = FALSE;
+ }
+#endif
+#ifdef TELEMETER
+ /** Handling of data sent by the device (initiated by srf08_receive() */
+ if (srf08_received) {
+ srf08_received = FALSE;
+ srf08_read();
+ }
+ if (srf08_got) {
+ srf08_got = FALSE;
+ srf08_copy();
+ DOWNLINK_SEND_RANGEFINDER(&srf08_range);
+ }
+#endif
+
+ if (from_fbw_receive_valid) {
+ /* receive radio control task from fbw */
+ from_fbw_receive_valid = FALSE;
+ telecommand_task();
+
+#ifdef IMU_3DMG
+ DOWNLINK_SEND_IMU(&from_fbw.euler_dot[0], &from_fbw.euler_dot[1], &from_fbw.euler_dot[2], &from_fbw.euler[0], &from_fbw.euler[1], &from_fbw.euler[2]);
+ estimator_update_state_3DMG();
+#elif defined IMU_ANALOG
+ /** -Saving now the pqr values from the fbw struct since
+ * -it's not safe always
+ * only if gyro are connected to fbw
+ */
+#if defined AHRS && ((!defined IMU_GYROS_CONNECTED_TO_AP) || (!IMU_GYROS_CONNECTED_TO_AP))
+ /* it can be called at 20 hz and gyros data come from the fbw so call have to be here */
+ ahrs_gyro_update();
+#endif //!IMU_GYROS_CONNECTED_TO_AP
+ int16_t dummy;
+ // DOWNLINK_SEND_IMU_3DMG(&from_fbw.euler_dot[0], &from_fbw.euler_dot[1], &from_fbw.euler_dot[2], &dummy, &dummy, &dummy);
+#endif //IMU
+
+ }
+}
diff --git a/sw/airborne/main_fbw.c b/sw/airborne/main_fbw.c
index 836153edcf..376e1298f0 100644
--- a/sw/airborne/main_fbw.c
+++ b/sw/airborne/main_fbw.c
@@ -50,9 +50,12 @@
#include "control_grz.h"
#endif
+#ifdef ADC
#include "adc.h"
struct adc_buf vsupply_adc_buf;
+#endif
+uint8_t fbw_vsupply_decivolt;
uint8_t fbw_mode;
@@ -82,8 +85,11 @@ void init_fbw( void ) {
#endif
#endif
+#ifdef ADC
adc_init();
adc_buf_channel(ADC_CHANNEL_VSUPPLY, &vsupply_adc_buf, DEFAULT_AV_NB_SAMPLE);
+#endif
+
#if defined IMU_3DMG || defined IMU_ANALOG
imu_init();
#endif
@@ -134,6 +140,10 @@ void event_task_fbw( void) {
}
#endif
+#ifdef ADC
+ fbw_vsupply_decivolt = VoltageOfAdc(vsupply_adc_buf.sum/vsupply_adc_buf.av_nb_sample) * 10;
+#endif
+
#ifdef INTER_MCU
inter_mcu_event_task();
if (ap_ok && fbw_mode == FBW_MODE_AUTO) {
@@ -194,5 +204,7 @@ void periodic_task_fbw( void ) {
fbw_downlink_periodic_task();
#endif
+#ifdef ACTUATORS
SetActuatorsFromCommands(commands);
+#endif
}
diff --git a/sw/airborne/main_fbw.h b/sw/airborne/main_fbw.h
index 356d05cd5d..54689c65ab 100644
--- a/sw/airborne/main_fbw.h
+++ b/sw/airborne/main_fbw.h
@@ -29,6 +29,7 @@
#include "adc.h"
extern uint8_t fbw_mode;
+extern uint8_t fbw_vsupply_decivolt;
extern bool_t failsafe_mode;
extern struct adc_buf vsupply_adc_buf;
diff --git a/sw/airborne/mainloop.c b/sw/airborne/mainloop.c
deleted file mode 100644
index fbf37adf8a..0000000000
--- a/sw/airborne/mainloop.c
+++ /dev/null
@@ -1,216 +0,0 @@
-/* $Id$ */
-/** \mainpage Paparazzi airborne
- * \author Copyright (C) 2003 \b Pascal \b Brisset, \b Antoine \b Drouin
- *
- * This file is part of paparazzi.
- *
- * paparazzi is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2, or (at your option)
- * any later version.
- *
- * paparazzi is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with paparazzi; see the file COPYING. If not, write to
- * the Free Software Foundation, 59 Temple Place - Suite 330,
- * Boston, MA 02111-1307, USA.
- *
- */
-/** \file mainloop.c
- * \brief Main loop used in the autopilot microcontroler
- */
-
-#include "main_ap.h"
-#include "init_hw.h"
-#include "interrupt_hw.h"
-#include "sys_time.h"
-#include "adc.h"
-#include "autopilot.h"
-#include "gps.h"
-#include "nav.h"
-#include "infrared.h"
-#include "estimator.h"
-#include "downlink.h"
-#include "datalink.h"
-#include "wavecard.h"
-#include "maxstream.h"
-#include "downlink.h"
-#include "led.h"
-#include "inter_mcu.h"
-#include "modem.h"
-
-#ifdef MCU_SPI_LINK /** ap alone, using SPI to communicate with fbw */
-#include "spi.h"
-#include "link_mcu_ap.h"
-#endif
-/** #else statically linked with fbw */
-
-
-#ifdef TELEMETER
-#include "srf08.h"
-#endif
-
-#ifdef AHRS
-#include "ahrs.h"
-#endif // AHRS
-
-
-void init_ap( void ) {
-#ifdef LED
- led_init();
-#endif
-#ifndef FBW /** Dual mcus : init done in main_fbw */
- hw_init();
- sys_time_init();
-#ifdef ADC
- adc_init();
-#endif
-#endif
-
- /************* Sensors initialization ***************/
-#ifdef INFRARED
- ir_init();
-#endif
-#ifdef GPS
- gps_init();
-#endif
-#ifdef TELEMETER
- srf08_init();
-#endif
-#if defined IMU_3DMG || defined IMU_ANALOG || defined WAVECARD || defined MAXSTREAM || DOWNLINK_AP_DEVICE == uart0
- uart0_init_tx();
- uart0_init_rx();
-#endif //IMU
-
-
- /************* Links initialization ***************/
-#if defined MCU_SPI_LINK
- spi_init();
- link_fbw_init();
-#endif
-#ifdef MODEM
- modem_init();
-#endif
-#ifdef WAVECARD
- /** Reset the wavecard during the init pause */
- wc_reset();
-#endif
-
- /************ Internal status ***************/
- estimator_init();
- nav_init();
-
-
- /** - start interrupt task */
- int_enable();
-
- /** - wait 0.5s (for modem init ?) */
- uint8_t init_cpt = 30;
- while (init_cpt) {
- if (sys_time_periodic())
- init_cpt--;
- }
-#ifdef WAVECARD
- wc_end_reset();
-#endif
-
-#if defined AHRS
- /** - ahrs init(do_calibration)
- * - Warning if do_calibration is TRUE this will provide an asynchronous
- * - calibration process, and it will take some calls to ahrs_update() to
- * - end. So Don't take off before ahrs_state == AHRS_RUNNING
- */
- ahrs_init(TRUE);
-#endif //AHRS
-
- /** - enter mainloop:
- * - do periodic task by calling \a periodic_task
- * - parse and use GPS messages with \a parse_gps_msg and \a use_gps_pos
- * - receive radio control task from fbw and use it with
- * \a telecommand_task
- */
-}
-
-void periodic_task_ap( void) {
- periodic_task();
-}
-
-void event_task_ap( void ) {
-#ifdef GPS
- if (GpsBuffer()) {
- ReadGpsBuffer();
- /* if (IO1PIN & LED_2_BIT) */
- /* IO1CLR = LED_2_BIT; */
- /* else */
- /* IO1SET = LED_2_BIT; */
- }
- if (gps_msg_received) {
- /* parse and use GPS messages */
- parse_gps_msg();
- gps_msg_received = FALSE;
- if (gps_pos_available) {
- use_gps_pos();
- gps_pos_available = FALSE;
- }
- }
-#endif /** GPS */
-#ifdef WAVECARD
- if (wc_msg_received) {
- wc_parse_payload();
- wc_msg_received = FALSE;
- }
-#endif /** WAVECARD */
-
-#ifdef MAXSTREAM
- if (maxstream_msg_received) {
- maxstream_parse_payload();
- maxstream_msg_received = FALSE;
- }
-#endif /** MAXSTREAM */
-
-#ifdef DATALINK
- if (dl_msg_available) {
- dl_parse_msg();
- dl_msg_available = FALSE;
- }
-#endif
-#ifdef TELEMETER
- /** Handling of data sent by the device (initiated by srf08_receive() */
- if (srf08_received) {
- srf08_received = FALSE;
- srf08_read();
- }
- if (srf08_got) {
- srf08_got = FALSE;
- srf08_copy();
- DOWNLINK_SEND_RANGEFINDER(&srf08_range);
- }
-#endif
-
- if (from_fbw_receive_valid) {
- /* receive radio control task from fbw */
- from_fbw_receive_valid = FALSE;
- telecommand_task();
-
-#ifdef IMU_3DMG
- DOWNLINK_SEND_IMU(&from_fbw.euler_dot[0], &from_fbw.euler_dot[1], &from_fbw.euler_dot[2], &from_fbw.euler[0], &from_fbw.euler[1], &from_fbw.euler[2]);
- estimator_update_state_3DMG();
-#elif defined IMU_ANALOG
- /** -Saving now the pqr values from the fbw struct since
- * -it's not safe always
- * only if gyro are connected to fbw
- */
-#if defined AHRS && ((!defined IMU_GYROS_CONNECTED_TO_AP) || (!IMU_GYROS_CONNECTED_TO_AP))
- /* it can be called at 20 hz and gyros data come from the fbw so call have to be here */
- ahrs_gyro_update();
-#endif //!IMU_GYROS_CONNECTED_TO_AP
- int16_t dummy;
- // DOWNLINK_SEND_IMU_3DMG(&from_fbw.euler_dot[0], &from_fbw.euler_dot[1], &from_fbw.euler_dot[2], &dummy, &dummy, &dummy);
-#endif //IMU
-
- }
-}
diff --git a/sw/airborne/pid.h b/sw/airborne/pid.h
index 57f00c9df5..7a3a64e11e 100644
--- a/sw/airborne/pid.h
+++ b/sw/airborne/pid.h
@@ -26,6 +26,7 @@
#define PID_H
#include
+#include "paparazzi.h"
#include "inter_mcu.h"
extern float desired_roll;
diff --git a/sw/airborne/pprz_transport.h b/sw/airborne/pprz_transport.h
index 8ea403130c..107b0b7521 100644
--- a/sw/airborne/pprz_transport.h
+++ b/sw/airborne/pprz_transport.h
@@ -84,5 +84,6 @@ extern uint8_t ck_a, ck_b;
#define PprzTransportPutUint32ByAddr(_x) PprzTransportPut4ByteByAddr(_x)
#define PprzTransportPutFloatByAddr(_x) PprzTransportPut4ByteByAddr(_x)
+
#endif /* PPRZ_TRANSPORT_H */
diff --git a/sw/airborne/sim/init_hw.h b/sw/airborne/sim/init_hw.h
new file mode 100644
index 0000000000..32a393b484
--- /dev/null
+++ b/sw/airborne/sim/init_hw.h
@@ -0,0 +1,6 @@
+#ifndef INIT_HW_H
+#define INIT_HW_H
+
+static inline void hw_init(void) {}
+
+#endif /* INIT_HW_H */
diff --git a/sw/airborne/sim/interrupt_hw.h b/sw/airborne/sim/interrupt_hw.h
new file mode 100644
index 0000000000..12561a990c
--- /dev/null
+++ b/sw/airborne/sim/interrupt_hw.h
@@ -0,0 +1,6 @@
+#ifndef INTERRUPT_HW_H
+#define INTERRUPT_HW_H
+
+#define int_enable() {}
+
+#endif /* INTERRUPT_HW_H */
diff --git a/sw/airborne/sim/ppm_hw.c b/sw/airborne/sim/ppm_hw.c
new file mode 100644
index 0000000000..9016143c1f
--- /dev/null
+++ b/sw/airborne/sim/ppm_hw.c
@@ -0,0 +1,16 @@
+#include
+#include "ppm.h"
+
+uint16_t ppm_pulses[ PPM_NB_PULSES ];
+bool_t ppm_valid;
+
+
+value update_rc_channel(value c, value v) {
+ ppm_pulses[Int_val(c)] = Double_val(v);
+ return Val_unit;
+}
+
+value send_ppm(value unit) {
+ ppm_valid = TRUE;
+ return Val_unit;
+}
diff --git a/sw/airborne/sim/ppm_hw.h b/sw/airborne/sim/ppm_hw.h
new file mode 100644
index 0000000000..7b6b0e0a9d
--- /dev/null
+++ b/sw/airborne/sim/ppm_hw.h
@@ -0,0 +1,6 @@
+#ifndef PPM_HW_H
+#define PPM_HW_H
+
+static inline void ppm_init( void ) {}
+
+#endif /* PPM_HW_H */
diff --git a/sw/airborne/sim/sim_ap.c b/sw/airborne/sim/sim_ap.c
new file mode 100644
index 0000000000..46d9259edd
--- /dev/null
+++ b/sw/airborne/sim/sim_ap.c
@@ -0,0 +1,107 @@
+/* Definitions and declarations required to compile autopilot code on a
+ i386 architecture. Bindings for OCaml. */
+
+#include
+#include
+#include
+#include
+#include "std.h"
+#include "inter_mcu.h"
+#include "autopilot.h"
+#include "estimator.h"
+#include "gps.h"
+#include "traffic_info.h"
+#include "flight_plan.h"
+#include "nav.h"
+#include "pid.h"
+#include "infrared.h"
+#include "cam.h"
+#include "commands.h"
+#include "main_ap.h"
+
+#include
+#include
+
+uint8_t ir_estim_mode;
+uint8_t vertical_mode;
+uint8_t inflight_calib_mode;
+bool_t rc_event_1, rc_event_2;
+bool_t launch;
+uint8_t gps_nb_ovrn, modem_nb_ovrn, link_fbw_fbw_nb_err, link_fbw_nb_err;
+
+
+uint8_t ac_id;
+
+value sim_periodic_task(value _unit __attribute__ ((unused))) {
+ periodic_task_ap();
+ return Val_unit;
+}
+
+
+float ftimeofday(void) {
+ struct timeval t;
+ struct timezone z;
+ gettimeofday(&t, &z);
+ return (t.tv_sec + t.tv_usec/1e6);
+}
+
+value sim_init(value id) {
+ init_ap();
+ ac_id = Int_val(id);
+ return Val_unit;
+}
+
+value update_bat(value bat) {
+ fbw_vsupply_decivolt = Int_val(bat);
+ return Val_unit;
+}
+
+
+value get_commands(value val_commands) {
+ int i;
+
+ for(i=0; i < COMMANDS_NB; i++)
+ Store_field(val_commands, i, Val_int(commands[i]));
+
+ return Val_int(commands[COMMAND_THROTTLE]);
+}
+
+value set_ac_info_native(value ac_id, value ux, value uy, value course, value alt, value gspeed) {
+ SetAcInfo(Int_val(ac_id), Double_val(ux), Double_val(uy),
+ Double_val(course), Double_val(alt), Double_val(gspeed));
+ return Val_unit;
+}
+
+value set_ac_info(value * argv, int argn) {
+ assert (argn == 6);
+ return set_ac_info_native(argv[0], argv[1], argv[2], argv[3],argv[4], argv[5]);
+}
+
+
+
+value move_waypoint(value wp_id, value ux, value uy, value a) {
+ MoveWaypoint(Int_val(wp_id), Double_val(ux), Double_val(uy), Double_val(a));
+ return Val_unit;
+}
+
+value goto_block(value block_id) {
+ nav_goto_block(Int_val(block_id));
+ return Val_unit;
+}
+
+value send_event(value event_id) {
+ uint8_t event = Int_val(event_id);
+ switch (event) {
+ case 1 : rc_event_1 = TRUE; break; // FIXME !
+ case 2 : rc_event_2 = TRUE; break;
+ default: ;
+ }
+ return Val_unit;
+}
+
+value dl_setting(value index __attribute__ ((unused)),
+ value val __attribute__ ((unused))) {
+ /** DlSetting macro may be empty: unused attr to get rif of the warning */
+ DlSetting(Int_val(index), Double_val(val));
+ return Val_unit;
+}
diff --git a/sw/airborne/sim/sim_gps.c b/sw/airborne/sim/sim_gps.c
new file mode 100644
index 0000000000..432318c954
--- /dev/null
+++ b/sw/airborne/sim/sim_gps.c
@@ -0,0 +1,59 @@
+/* OCaml binding to link the simulator to autopilot functions. */
+
+#include
+#include
+#include
+
+/** From airborne/autopilot/ */
+#include "airframe.h"
+#include "flight_plan.h"
+#include "autopilot.h"
+#include "gps.h"
+
+#include
+
+uint8_t gps_mode;
+uint32_t gps_itow; /* ms */
+int32_t gps_alt; /* m */
+uint16_t gps_gspeed; /* cm/s */
+int16_t gps_climb; /* cm/s */
+int16_t gps_course; /* decideg */
+int32_t gps_utm_east, gps_utm_north;
+uint8_t gps_utm_zone;
+struct svinfo gps_svinfos[GPS_NB_CHANNELS];
+uint8_t gps_nb_channels = 0;
+
+value sim_use_gps_pos(value x, value y, value z, value c, value a, value s, value cl, value t, value m) {
+ gps_mode = (Bool_val(m) ? 3 : 0);
+ gps_utm_east = Int_val(x);
+ gps_utm_north = Int_val(y);
+ gps_utm_zone = Int_val(z);
+ gps_course = DegOfRad(Double_val(c)) * 10.;
+ gps_alt = Double_val(a) * 100.;
+ gps_gspeed = Double_val(s) * 100.;
+ gps_climb = Double_val(cl) * 100.;
+ gps_itow = Double_val(t) * 1000.;
+
+ /** Space vehicle info simulation */
+ gps_nb_channels=7;
+ int i;
+ static int time;
+ time++;
+ for(i = 0; i < gps_nb_channels; i++) {
+ gps_svinfos[i].svid = 7 + i;
+ gps_svinfos[i].elev = (cos(((100*i)+time)/100.) + 1) * 45;
+ gps_svinfos[i].azim = (time/gps_nb_channels + 50 * i) % 360;
+ gps_svinfos[i].cno = 40 + sin(time/100.) * 10.;
+ gps_svinfos[i].flags = 0x01;
+ gps_svinfos[i].qi = (int)((time / 1000.) + i) % 8;
+ }
+
+ use_gps_pos(); /* From main.c */
+ return Val_unit;
+}
+
+/* Second binding required because number of args > 5 */
+value sim_use_gps_pos_bytecode(value *a, int argn) {
+ assert(argn == 9);
+ return sim_use_gps_pos(a[0],a[1],a[2],a[3],a[4],a[5],a[6],a[7], a[8]);
+}
diff --git a/sw/airborne/sim/sim_ir.c b/sw/airborne/sim/sim_ir.c
new file mode 100644
index 0000000000..2087c0c9f5
--- /dev/null
+++ b/sw/airborne/sim/sim_ir.c
@@ -0,0 +1,27 @@
+/** \file sim_ir.c
+ * \brief Regroup functions to simulate autopilot/infrared.c
+ *
+ * Infrared soft simulation. OCaml binding.
+ */
+
+
+#include
+#include "infrared.h"
+#include "airframe.h"
+
+#include
+
+void ir_gain_calib(void) {
+}
+
+value set_ir(value roll, value top) {
+ ir_roll = Int_val(roll);
+ ir_top = Int_val(top);
+ return Val_unit;
+}
+
+/** Required by infrared.c:ir_init() */
+void adc_buf_channel(void* a __attribute__ ((unused)),
+ void* b __attribute__ ((unused)),
+ void* c __attribute__ ((unused))) {
+}
diff --git a/sw/airborne/sim/sys_time_hw.h b/sw/airborne/sim/sys_time_hw.h
new file mode 100644
index 0000000000..964a8f565f
--- /dev/null
+++ b/sw/airborne/sim/sys_time_hw.h
@@ -0,0 +1,11 @@
+#ifndef SYS_TIME_HW_H
+#define SYS_TIME_HW_H
+
+#define SYS_TICS_OF_USEC(x) (x)
+#define SIGNED_SYS_TICS_OF_USEC(x) (x)
+
+static inline void sys_time_init( void ) {}
+
+#define sys_time_periodic() TRUE
+
+#endif /* SYS_TIME_HW_H */
diff --git a/sw/airborne/sim/uart_hw.h b/sw/airborne/sim/uart_hw.h
new file mode 100644
index 0000000000..e69de29bb2
diff --git a/sw/simulator/Makefile b/sw/simulator/Makefile
index 2bc8848034..5320833450 100644
--- a/sw/simulator/Makefile
+++ b/sw/simulator/Makefile
@@ -2,8 +2,7 @@
#
# Copied from autopilot (autopilot.sf.net) thanx alot Trammell
#
-# Copyright (C) 2003 Trammell Hudson
-# Copyright (C) 2003 Pascal Brisset, Antoine Drouin
+# Copyright (C) 2003-2006 Pascal Brisset, Antoine Drouin
#
# This file is part of paparazzi.
#
@@ -25,20 +24,17 @@
include ../../conf/Makefile.local
ACDIR= $(PAPARAZZI_HOME)/var/$(AIRCRAFT)
-OBJDIR= $(ACDIR)/sim
-
-ifeq ($(MAKECMDGOALS),sim_sitl)
-include $(ACDIR)/Makefile.ac
-endif
SIMHML = stdlib.ml data.ml flightModel.ml gps.ml hitl.ml sim.ml
SIMHCMO=$(SIMHML:%.ml=%.cmo)
SIMSML = stdlib.ml data.ml flightModel.ml gps.ml sitl.ml sim.ml
SIMSCMO=$(SIMSML:%.ml=%.cmo)
SIMSCMX=$(SIMSML:%.ml=%.cmx)
-SIMSC = sim_ir.c sim_gps.c sim_ap.c sys_time.c estimator.c infrared.c gps.c pid.c nav.c radio_control.c main_ap.c cam.c traffic_info.c
-SIMSO=$(SIMSC:%.c=$(OBJDIR)/%.o)
-SIMSA=sims.cma
+
+#SIMSC = sim_ir.c sim_gps.c sim_ap.c sys_time.c estimator.c infrared.c gps.c pid.c nav.c radio_control.c main_ap.c cam.c traffic_info.c
+#SIMSO=$(SIMSC:%.c=$(OBJDIR)/%.o)
+#SIMSA=sims.cma
+SIMSO = $(sim.srcs:.c=$(OBJDIR)/%.o)
OCAMLC = ocamlc
OCAMLOPT=ocamlopt -p
@@ -49,22 +45,19 @@ AIRBORNE = ../airborne
VARINCLUDE=$(PAPARAZZI_HOME)/var/include
ACINCLUDE = $(PAPARAZZI_HOME)/var/$(AIRCRAFT)
-MESSAGES = ../../conf/messages.xml
-GEN_DOWNLINK = $(TOOLS)/gen_sim_downlink.out
SIMDIR=$(shell echo `pwd`)
-#all : simhitl.out sitl.cma $(GEN_DOWNLINK)
-all : gaia sitl.cma $(GEN_DOWNLINK) fg.o
+all : gaia sitl.cma fg.o
sim_sitl : $(OBJDIR)/simsitl
simhitl.out : $(SIMHCMO) simhitl.cmo
$(OCAMLC) $(INCLUDES) -o $@ str.cma xml-light.cma unix.cma lib.cma lablgtk.cma gtkInit.cmo $^
-sitl.cma : fg.o $(SIMSCMO)
+sitl.cma : $(SIMSCMO)
ocamlc -o $@ -a $^
fg.o : fg.c
@@ -73,12 +66,11 @@ fg.o : fg.c
sitl.cmxa : $(SIMSCMX)
ocamlopt -o $@ -a $^
-$(OBJDIR)/$(SIMSA) : $(SIMSO)
- @touch $(OBJDIR)/dummy.ml
- @cd $(OBJDIR); ocamlmklib -o sims $^ dummy.ml
+#$(OBJDIR)/$(SIMSA) : $(SIMSO)
+# @touch $(OBJDIR)/dummy.ml
+# @cd $(OBJDIR); ocamlmklib -o sims $^ dummy.ml
+
-$(OBJDIR)/simsitl : $(OBJDIR)/$(SIMSA) $(OBJDIR)/simsitl.ml
- $(OCAMLC) -custom $(INCLUDES) -o $@ glibivy-ocaml.cma lib-pprz.cma lablgtk.cma gtkInit.cmo -I $(OBJDIR) $(SIMSA) sitl.cma $(OBJDIR)/simsitl.ml
gaia : gaia.cmo
$(OCAMLC) -custom $(INCLUDES) -o $@ glibivy-ocaml.cma lib-pprz.cma lablgtk.cma gtkInit.cmo $<
@@ -99,9 +91,6 @@ $(OBJDIR)/sim_ap.o : $(AIRBORNE)/traffic_info.h $(AIRBORNE)/nav.h
$(OBJDIR)/main_ap.c : $(OBJDIR)/sitl_messages.h $(AIRBORNE)/main_ap.c
cp $(AIRBORNE)/main_ap.c $(@)
-$(OBJDIR)/sitl_messages.h : $(MESSAGES) $(GEN_DOWNLINK)
- $(GEN_DOWNLINK) $< > $@
-
$(OBJDIR)/simsitl.cmo : $(OBJDIR)/simsitl.ml
$(OCAMLC) $(INCLUDES) -c -o $@ $<
diff --git a/sw/simulator/sitl.ml b/sw/simulator/sitl.ml
index 78454bf228..77123e7b37 100644
--- a/sw/simulator/sitl.ml
+++ b/sw/simulator/sitl.ml
@@ -50,7 +50,7 @@ module Make(A:Data.MISSION) = struct
let rservos = ref [||]
let adj_bat = GData.adjustment ~value:12.5 ~lower:0. ~upper:23. ~step_incr:0.1 ()
- external set_servos : Stdlib.us array -> int = "set_servos"
+ external get_commands : Stdlib.us array -> int = "get_commands"
(** Returns gaz servo value (us) *)
let energy = ref 0.
@@ -58,7 +58,7 @@ module Make(A:Data.MISSION) = struct
let update_servos =
let accu = ref 0. in
fun bat_button () ->
- let gaz = set_servos !rservos in
+ let gaz = get_commands !rservos in
(* 100% = 1W *)
if bat_button#active then
let energy = float (gaz-1000) /. 1000. *. servos_period in
@@ -72,8 +72,7 @@ module Make(A:Data.MISSION) = struct
(* Radio command handling *)
external update_channel : int -> float -> unit = "update_rc_channel"
- external set_radio_status : bool -> unit = "set_radio_status"
- external set_really_lost : bool -> unit = "set_really_lost"
+ external send_ppm : unit = "send_ppm"
let inverted = ["ROLL"; "PITCH"; "YAW"; "GAIN1"; "GAIN2"]
@@ -106,13 +105,7 @@ module Make(A:Data.MISSION) = struct
rc_channels;
ignore (on_off#connect#toggled (fun () -> sliders#coerce#misc#set_sensitive on_off#active; set_radio_status on_off#active));
- let monitor_on_off =
- let t = ref 0 in
- fun () ->
- incr t;
- if on_off#active then t := 0;
- set_really_lost (!t > 2) in
- Stdlib.timer 1. monitor_on_off; (** FIXME: should use time_scale *)
+ Stdlib.timer 0.1 send_ppm; (** FIXME: should use time_scale *)
window#show ()
external periodic_task : unit -> unit = "sim_periodic_task"
diff --git a/sw/tools/Makefile b/sw/tools/Makefile
index d8e8223545..81cc69bb3b 100644
--- a/sw/tools/Makefile
+++ b/sw/tools/Makefile
@@ -3,7 +3,7 @@ OCAMLC=ocamlc -I ../lib/ocaml
OCAMLLEX=ocamllex
OCAMLYACC=ocamlyacc
-all: gen_aircraft.out gen_airframe.out gen_calib.out gen_messages.out gen_ubx.out gen_flight_plan.out gen_radio.out gen_sim_downlink.out gen_dl.out extract_makefile.out gen_control.out gen_periodic.out
+all: gen_aircraft.out gen_airframe.out gen_calib.out gen_messages.out gen_ubx.out gen_flight_plan.out gen_radio.out gen_dl.out extract_makefile.out gen_control.out gen_periodic.out
FP_CMO = fp_syntax.cmo fp_parser.cmo fp_lexer.cmo fp_proc.cmo gen_flight_plan.ml
ABS_FP = $(FP_CMO:%=$$PAPARAZZI_SRC/sw/tools/%)
diff --git a/sw/tools/gen_sim_downlink.ml b/sw/tools/gen_sim_downlink.ml
deleted file mode 100644
index 2f21fd7b5a..0000000000
--- a/sw/tools/gen_sim_downlink.ml
+++ /dev/null
@@ -1,94 +0,0 @@
-open Printf
-
-let h_name = "MESSAGES_H"
-
-let id_of = fun xml -> ExtXml.attrib xml "name"
-
-(** No dereferencement for arrays *)
-let deref = fun xml -> try let _ = Xml.attrib xml "len" in "" with _ -> "*"
-
-let print_params = function
- [] -> ()
- | f::fields ->
- printf "%s" (id_of f);
- List.iter (fun f -> printf ", %s" (id_of f)) fields
-
-let types = [
- "uint8", "%hhu";
- "uint16", "%hu";
- "uint32", "%u" ;
- "int8", "%hhd";
- "int16", "%hd";
- "int32", "%d" ;
- "float", "%f"
-]
-
-let sprint_format = fun f ->
- try
- Xml.attrib f "format"
- with _ ->
- List.assoc (Xml.attrib f "type") types
-
-
-let freq = 10
-let buffer_length = 5
-let step = 1. /. float freq
-let nb_steps = (256 / freq) * freq
-
-let is_periodic = fun m -> try let _ = Xml.attrib m "period" in true with _ -> false
-let period_of = fun m -> float_of_string (Xml.attrib m "period")
-
-let gen_periodic = fun avr_h messages ->
- let periodic_messages = List.filter is_periodic messages in
-
- let scheduled_messages =
- List.map
- (fun m ->
- let p = period_of m in
- let period_steps = truncate (p /. step) in
- (period_steps, id_of m))
- periodic_messages in
-
- fprintf avr_h "#define PeriodicSend() { /* %dHz */ \\\n" freq;
- fprintf avr_h " static uint8_t i;\\\n";
- fprintf avr_h " if (i == %d) i = 0;\\\n" nb_steps;
- List.iter
- (fun (p, id) ->
- fprintf avr_h " if (i %% %d == 0) PERIODIC_SEND_%s();\\\n" p id)
- scheduled_messages;
- fprintf avr_h " i++;\\\n}\n"
-
-
-
-let fprint_formats = fun c fields ->
- List.iter (fun f -> fprintf c " %s" (sprint_format f)) fields
-
-let fprint_args = fun c fields ->
- List.iter (fun f -> fprintf c ", %s(%s)" (deref f) (id_of f)) fields
-
-let one_message = fun m ->
- let id = id_of m
- and fields = Xml.children m in
- printf "#define DOWNLINK_SEND_%s(" id;
- print_params fields;
- printf "){ \\\n";
- printf " IvySendMsg(\"%%d %s %a\",ac_id%a); \\\n" id fprint_formats fields fprint_args fields;
- printf "}\n\n"
-
-let _ =
- if Array.length Sys.argv <> 2 then
- failwith (sprintf "Usage: %s " Sys.argv.(0));
- let xml = Xml2h.start_and_begin Sys.argv.(1) h_name in
- let xml = ExtXml.child xml ~select:(fun x -> Xml.attrib x "name"="telemetry") "class" in
- let messages = (Xml.children xml) in
-
- printf "#include \n";
- printf "extern uint8_t ac_id;\n";
- printf "extern uint8_t modem_nb_ovrn;\n";
-
- List.iter one_message messages;
-
- gen_periodic stdout messages;
-
- Xml2h.finish h_name
-