Skip to content

Commit

Permalink
[sim] moving the old ocaml simulator to NPS (#3167)
Browse files Browse the repository at this point in the history
- the exact same basic model is now a NPS FDM
- sim target still woks, it is just an alias to NPS with the proper FDM
- the old ocaml files are removed
- AHRS and INS are bypassed, since the accelerations are not well calculated by the model
  • Loading branch information
gautierhattenberger committed Nov 7, 2023
1 parent dfb08fa commit 41451d5
Show file tree
Hide file tree
Showing 52 changed files with 376 additions and 2,304 deletions.
8 changes: 1 addition & 7 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -343,14 +343,8 @@ test_all_confs: all opencv_bebop
test_math:
make -C tests/math

# super simple simulator test, needs X
# always uses conf/conf.xml, so that needs to contain the appropriate aircrafts
# (only Microjet right now)
test_sim: all
prove tests/sim

.PHONY: all print_build_version _print_building _save_build_version init dox ground_segment ground_segment.opt \
subdirs $(SUBDIRS) conf ext libpprz libpprzlink.update libpprzlink.install cockpit cockpit.opt tmtc tmtc.opt generators\
static sim_static opencv_bebop\
clean cleanspaces ab_clean dist_clean distclean dist_clean_irreversible \
test test_examples test_math test_sim test_all_confs
test test_examples test_math test_all_confs
159 changes: 1 addition & 158 deletions conf/Makefile.sim
Original file line number Diff line number Diff line change
@@ -1,158 +1 @@
# Hey Emacs, this is a -*- makefile -*-
#
# Copyright (C) 2006 Pascal Brisset, Antoine 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.
#

#
# This is the common Makefile for the sim target.
#

# this should not be needed
SRC_ARCH = arch/sim

include $(PAPARAZZI_SRC)/sw/Makefile.ocaml

CC = gcc
SIMDIR = $(PAPARAZZI_SRC)/sw/simulator
CAMLINCLUDES = -I $(LIBPPRZDIR) -I $(SIMDIR) -I $(OBJDIR)
PKG = -package glibivy,pprz
LINKPKG = $(PKG) -linkpkg -dllpath-pkg pprz,pprzlink
SIMSITLML = $(OBJDIR)/simsitl.ml
SITLCMA = $(SIMDIR)/sitl.cma
OPT ?= 2

# Launch with "make Q=''" to get full command display
Q=@

#
# End of configuration part.
#

INCLUDES += -I $(shell $(OCAMLC) -where)

CFLAGS = -W -Wall
CFLAGS += $(INCLUDES)
CFLAGS += $($(TARGET).CFLAGS)
CFLAGS += $(USER_CFLAGS) $(BOARD_CFLAGS)
CFLAGS += -fPIC
CFLAGS += -O$(OPT)
CFLAGS += -g
CFLAGS += -std=gnu99
CFLAGS += $(shell pkg-config --cflags-only-I ivy-glib)
CFLAGS += -D_GNU_SOURCE
CFLAGS += -DPPRZLINK_UNALIGNED_ACCESS=1

LDFLAGS = -lm
LDFLAGS += $(BOARD_LDFLAGS)

LIBFLAGS = -shared

UNAME = $(shell uname -s)
ifeq ($(UNAME),Darwin)
LIBFLAGS = -dynamiclib -undefined suppress -flat_namespace
endif

# build sim in custom mode for ARM systems for now...
MNAME = $(shell uname -m)
ifneq (,$(findstring arm,$(MNAME)))
SIMSITLCUSTOM=TRUE
endif

ifdef SIMSITLCUSTOM
CAMLINCLUDES += $(shell ocamlfind query -r -i-format lablgtk2) $(shell ocamlfind query -r -i-format xml-light) $(shell ocamlfind query -r -i-format glibivy)
CAMLCMAS = unix.cma str.cma xml-light.cma glibivy-ocaml.cma lib-pprz.cma lablgtk.cma
endif


#
# General rules
#

$(TARGET).srcsnd = $(notdir $($(TARGET).srcs))
$(TARGET).objso = $($(TARGET).srcs:%.c=$(OBJDIR)/%.o)
$(TARGET).objs = $($(TARGET).objso:%.S=$(OBJDIR)/%.o)

all compile: $(OBJDIR) $(OBJDIR)/simsitl

$(OBJDIR):
@echo CREATING object dir $(OBJDIR)
@test -d $(OBJDIR) || mkdir -p $(OBJDIR)

# shared library of the C autopilot part
# Note: On darwin the file should actually have the .dylib ending but ocamlc
# only assumes that .so files are shared libraries, even though this is only
# correct on linux.
autopilot.so : $($(TARGET).objs)
@echo BUILD $@
$(Q)$(CC) $(LIBFLAGS) $^ -o $(OBJDIR)/$@

ifdef SIMSITLCUSTOM
$(OBJDIR)/simsitl : $($(TARGET).objs) $(SITLCMA) $(SIMSITLML)
@echo LD $@
$(Q)$(OCAMLC) -g -custom $(CAMLINCLUDES) -o $@ $(CAMLCMAS) $^
else
$(OBJDIR)/simsitl : autopilot.so $(SITLCMA) $(SIMSITLML)
@echo LD $@
$(Q)$(OCAMLC) -g $(CAMLINCLUDES) -o $@ $(LINKPKG) $^ -dllpath $(OBJDIR) -dllpath $(SIMDIR)
endif


# The id of the A/C is hardcoded in the code (to be improved with dynlink ?)
$(SIMSITLML) : $(SIMDIR)/simsitl.ml
@echo "Sim.ac_name := \"$(AIRCRAFT)\"" > $@
@cat $< >> $@

%.s: %.c
$(CC) $(CFLAGS) -S -o $@ $<

%.s: %.cpp
$(CC) $(CFLAGS) -S -o $@ $<

$(OBJDIR)/%.s: %.c
@echo CC $@
$(Q)test -d $(dir $@) || mkdir -p $(dir $@)
$(CC) $(CFLAGS) -S -o $@ $<

$(OBJDIR)/%.s: %.cpp
@echo CC $@
$(Q)test -d $(dir $@) || mkdir -p $(dir $@)
$(CC) $(CFLAGS) -S -o $@ $<

$(OBJDIR)/%.o: %.c $(OBJDIR)/../Makefile.ac
@echo CC $@
$(Q)test -d $(dir $@) || mkdir -p $(dir $@)
$(Q)$(CC) -MMD $(CFLAGS) -c -o $@ $<

$(OBJDIR)/%.o: %.cpp $(OBJDIR)/../Makefile.ac
@echo CC $@
$(Q)test -d $(dir $@) || mkdir -p $(dir $@)
$(Q)$(CC) -MMD $(CFLAGS) -c -o $@ $<

.PHONY: all compile

#
# Dependencies
#

DEPS = $(addprefix $(OBJDIR)/,$($(TARGET).srcs:.c=.d))

ifneq ($(MAKECMDGOALS),clean)
-include $(DEPS)
endif
include $(PAPARAZZI_SRC)/conf/Makefile.nps
2 changes: 1 addition & 1 deletion conf/modules/actuators_nps.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<depends>actuators</depends>
<provides>actuators</provides>
</dep>
<makefile target="nps">
<makefile target="sim|nps">
<file_arch name="actuators_pwm_arch.c"/>
</makefile>
</module>
Expand Down
19 changes: 19 additions & 0 deletions conf/modules/fdm_fixedwing_sim.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<!DOCTYPE module SYSTEM "module.dtd">

<module name="fdm_fixedwing_sim" dir="fdm">
<doc>
<description>
Basic fixedwing FDM for NPS simulator

This flight dynamic model is the copy of the legacy simulator that was written in OCaml.
Its only purpose is to allow to test the flight plans with a very simple airplane model.
</description>
</doc>
<header/>
<makefile target="sim|nps|hitl">
<define name="NPS_BYPASS_AHRS" value="TRUE"/>
<define name="NPS_BYPASS_INS" value="TRUE"/>
<file name="nps_fdm_fixedwing_sim.c" dir="nps"/>
</makefile>
</module>

2 changes: 1 addition & 1 deletion conf/modules/firmwares/fixedwing.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
<makefile target="!fbw">
<file name="main_ap.c" dir="."/>
</makefile>
<makefile target="nps">
<makefile target="sim|nps">
<define name="AP"/>
<file name="nps_autopilot_fixedwing.c" dir="nps"/>
</makefile>
Expand Down
2 changes: 1 addition & 1 deletion conf/modules/gps_nps.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
</header>
<init fun="gps_nps_init()"/>
<periodic fun="gps_nps_periodic_check()" freq="1." autorun="TRUE"/>
<makefile target="nps">
<makefile target="sim|nps">
<file name="gps_sim_nps.c"/>
<define name="GPS_TYPE_H" value="modules/gps/gps_sim_nps.h" type="string"/>
<test>
Expand Down
2 changes: 1 addition & 1 deletion conf/modules/imu_common.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
</header>
<init fun="imu_init()"/>

<makefile target="!sim|fbw">
<makefile target="!fbw">
<define name="USE_IMU"/>
<file name="imu.c"/>
<test/>
Expand Down
2 changes: 1 addition & 1 deletion conf/modules/imu_nps.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<init fun="imu_nps_init()"/>
<event fun="imu_nps_event()"/>

<makefile target="nps">
<makefile target="sim|nps">
<file name="imu_nps.c"/>
</makefile>
</module>
3 changes: 0 additions & 3 deletions conf/modules/ins_arduimu.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,5 @@
<makefile target="ap">
<file name="ins_arduimu.c"/>
</makefile>
<makefile target="sim">
<file_arch name="ins_arduimu.c"/>
</makefile>
</module>

3 changes: 0 additions & 3 deletions conf/modules/ins_arduimu_basic.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,5 @@
<makefile target="ap">
<file name="ins_arduimu_basic.c"/>
</makefile>
<makefile target="sim">
<file_arch name="ins_arduimu_basic.c"/>
</makefile>
</module>

4 changes: 2 additions & 2 deletions conf/modules/ins_nps.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<file name="ins_gps_passthrough.h"/>
</header>
<init fun="ins_gps_passthrough_init()"/>
<makefile target="nps">
<makefile target="sim|nps">
<file name="imu.c" dir="modules/imu"/>
<file name="imu_nps.c" dir="modules/imu"/>
<define name="USE_IMU"/>
Expand All @@ -34,7 +34,7 @@
<file name="ins.c"/>
<file name="ins_gps_passthrough.c"/>
</makefile>
<makefile target="nps" firmware="fixedwing">
<makefile target="sim|nps" firmware="fixedwing">
<define name="INS_TYPE_H" value="modules/ins/ins_gps_passthrough.h" type="string"/>
<file name="ins.c"/>
<file name="ins_gps_passthrough_utm.c"/>
Expand Down
1 change: 0 additions & 1 deletion conf/modules/system_core.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
<define name="USE_COMMANDS"/>
<file_arch name="sys_time_arch.c" dir="mcu_periph"/>
<file_arch name="led_hw.c" dir="." cond="ifeq ($(ARCH), stm32)"/>
<file_arch name="led_hw.c" dir="." cond="ifeq ($(TARGET), sim)"/>
<flag name="LDFLAGS" value="lrt" cond="ifeq ($(ARCH), linux)"/>
<raw>
VPATH += $(PAPARAZZI_HOME)/var/share
Expand Down
2 changes: 1 addition & 1 deletion conf/modules/targets/nps.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<provides>baro,airspeed,sonar,incidence,temperature</provides>
<suggests>gps_nps,imu_nps,ins_nps,actuators_nps,telemetry_nps</suggests>
</dep>
<makefile target="nps">
<makefile target="sim|nps">
<define name="AP"/>
<define name="SITL"/>
<file name="nps_electrical.c" dir="$(NPS_DIR)"/>
Expand Down
2 changes: 1 addition & 1 deletion conf/modules/targets/nps_common.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<dep>
<depends>math</depends>
</dep>
<makefile target="nps|hitl">
<makefile target="sim|nps|hitl">
<configure name="BARO_PERIODIC_FREQUENCY" default="50"/>
<configure name="NPS_DIR" value="nps"/>
<raw>
Expand Down
19 changes: 1 addition & 18 deletions conf/modules/targets/sim.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,26 +11,9 @@
</description>
</doc>
<dep>
<depends>system_core,electrical,settings,actuators_dummy,@gps,@ins,@ahrs</depends>
<suggests>gps_sim,imu_sim,ins_sim,ahrs_sim,baro_sim,telemetry_sim</suggests>
<depends>targets/nps,fdm_fixedwing_sim</depends>
</dep>
<makefile target="sim">
<define name="SITL"/>
<define name="AP"/>
<file name="main_bare.c" dir="."/>
<file_arch name="sim_ap.c" dir="."/>
<file_arch name="sim_gps.c" dir="."/>
<file_arch name="sim_adc_generic.c" dir="."/>
<file_arch name="sim_ahrs.c" dir="."/>
<file_arch name="sim_airspeed.c" dir="."/>
<raw>
UNAME = $(shell uname -s)
ifeq ("$(UNAME)","Darwin")
sim.CFLAGS += $(shell if test -d /opt/paparazzi/include; then echo "-I/opt/paparazzi/include"; elif test -d /opt/local/include; then echo "-I/opt/local/include"; fi)
endif

sim.CFLAGS += $(CPPFLAGS)
</raw>
</makefile>
</module>

2 changes: 1 addition & 1 deletion conf/modules/telemetry_nps.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
</header>
<init fun="pprz_dl_init()"/>
<event fun="pprz_dl_event()"/>
<makefile target="nps">
<makefile target="sim|nps">
<configure name="MODEM_DEV" default="UDP0" case="upper|lower"/>
<configure name="MODEM_PORT_OUT" default="4242"/>
<configure name="MODEM_PORT_IN" default="4243"/>
Expand Down
2 changes: 1 addition & 1 deletion conf/modules/udp.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<file_arch name="udp_arch.c" dir="mcu_periph"/>
<file name="udp_socket.c" dir="arch/linux" cond="ifeq ($(ARCH), linux)"/>
</makefile>
<makefile target="nps">
<makefile target="sim|nps">
<include name="arch/linux"/>
<file name="udp_socket.c" dir="arch/linux"/>
</makefile>
Expand Down
20 changes: 0 additions & 20 deletions sw/airborne/arch/sim/led_hw.c

This file was deleted.

19 changes: 0 additions & 19 deletions sw/airborne/arch/sim/led_hw.h

This file was deleted.

0 comments on commit 41451d5

Please sign in to comment.