Corroded Paparazzi (#2355)

* Update AggieAir config

* Show total heap free space

* Conf fixes

* Initial commit of corroded paparazzi

* Added RNG support for ChibiOS

* Better build process for RUST modules

* Better description

* Fix typo

* Compile demo module for both NPS and AP targets, some rust magic had to happen

* Note in makefile

* Cleaner building of Rust modules

* Remove excess aiframes

* Prep work for enabling RNG on ChibiOS + STM32F4. Need to write a driver for ChibiOS-Contrib, so I am leaving that part for later

* RNG driver will eventually be a part of ChibiOS proper, hence simplify  the ifdef guards

* Clean up modules

* Changes in the rust builds

* Remove unsupported RNG for ChibiOS

* Better separate compatibility packages

* Minor fixes

* Fix halconf.h
This commit is contained in:
Michal Podhradsky
2018-12-13 05:19:08 -08:00
committed by Gautier Hattenberger
parent 21d35b9b29
commit c072a5405c
34 changed files with 1213 additions and 350 deletions
+29 -1
View File
@@ -153,7 +153,7 @@ print_version:
@echo "Paparazzi version" $(GIT_DESC)$(VERSION_MATCH) @echo "Paparazzi version" $(GIT_DESC)$(VERSION_MATCH)
@echo "-----------------------------------------------------------------------" @echo "-----------------------------------------------------------------------"
all_ac_h: $(SRCS_LIST) qt_project generate_keys all_ac_h: $(SRCS_LIST) qt_project generate_keys build_rust_modules
$(SRCS_LIST) : $(CONF_XML) $(AIRFRAME_H) $(MODULES_H) $(SETTINGS_H) $(MAKEFILE_AC) $(PERIODIC_H) $(SRCS_LIST) : $(CONF_XML) $(AIRFRAME_H) $(MODULES_H) $(SETTINGS_H) $(MAKEFILE_AC) $(PERIODIC_H)
@echo "TARGET: " $(TARGET) > $(SRCS_LIST) @echo "TARGET: " $(TARGET) > $(SRCS_LIST)
@@ -180,6 +180,34 @@ endif
endif endif
CARGO=$(shell which cargo) CARGO=$(shell which cargo)
# guard for simulation (NPS) target
ifneq (,$(findstring thumb, $(RUST_ARCH)))
# thumbv6 or 7
RUST_FEATURES+="not_std"
else
# using host architecture
RUST_FEATURES+="use_std"
endif
build_rust_modules:
ifneq ($(CARGO),)
ifneq ($(strip $(RUST_MODULES)),)
ifneq ($(RUST_ARCH),)
@echo PROCESSING RUST MODULES
@echo $(RUST_MODULES)
@echo RUST_FEATURES = $(RUST_FEATURES)
@$(foreach module_path, $(RUST_MODULES),\
echo Building $(module_path);\
cd $(module_path) && \
AC_GENERATED=$(AC_GENERATED) cargo build --target $(RUST_ARCH) --verbose --release --features $(RUST_FEATURES);)
else
@echo "Error: RUST_ARCH not specified, this board is likely not supported."
endif # Check Rust Arch
endif # No rust modules to process
else
@echo "Error: Cargo (Rust) not found, cannot build Rust modules. Please install xargo."
endif # Check if Cargo is present
generate_keys: generate_keys:
ifeq ($(GENERATE_KEYS),1) ifeq ($(GENERATE_KEYS),1)
ifneq ($(CARGO),) ifneq ($(CARGO),)
+2 -2
View File
@@ -320,10 +320,10 @@ UADEFS = $($(TARGET).CFLAGS) $(USER_CFLAGS) $(BOARD_CFLAGS)
UINCDIR = $(CHIBIOS)/os/license $(patsubst -I%,%,$(INCLUDES)) UINCDIR = $(CHIBIOS)/os/license $(patsubst -I%,%,$(INCLUDES))
# List the user directory to look for the libraries here # List the user directory to look for the libraries here
ULIBDIR = ULIBDIR = $(RUST_DIRS)
# List all user libraries here # List all user libraries here
ULIBS = -lm $(BOARD_LDFLAGS) ULIBS = -lm $(BOARD_LDFLAGS) $(RUST_LIBS)
# #
# End of user defines # End of user defines
+2
View File
@@ -61,6 +61,8 @@ CXXFLAGS += -D_GNU_SOURCE
LDFLAGS += $($(TARGET).LDFLAGS) LDFLAGS += $($(TARGET).LDFLAGS)
LDFLAGS += $(BOARD_LDFLAGS) LDFLAGS += $(BOARD_LDFLAGS)
LDFLAGS += $(patsubst %,-L%,$(DLIBDIR) $(RUST_DIRS))
LDFLAGS += $(RUST_LIBS)
# x86/64 and armv7 allow unaligned access # x86/64 and armv7 allow unaligned access
CFLAGS += -DPPRZLINK_UNALIGNED_ACCESS=1 CFLAGS += -DPPRZLINK_UNALIGNED_ACCESS=1
-341
View File
@@ -1,341 +0,0 @@
<!DOCTYPE airframe SYSTEM "../airframe.dtd">
<!-- Minion Airframe
aileron, elevator, rudder, flaps (optional)
TWOG - 4S compliant
UGEAR 2.0
Xbee modem in API mode
Airspeed Sensor - with Airspeed warning
-->
<airframe name="Pinot Ummarine Lite V2">
<!-- Servo Configuration -->
<servos>
<servo name="THROTTLE" no="0" min="1100" neutral="1100" max="1900"/>
<servo name="AILERON_RIGHT" no="1" min="1900" neutral="1500" max="1100"/>
<servo name="AILERON_LEFT" no="2" min="1900" neutral="1500" max="1100"/>
<servo name="ELEVATOR" no="3" min="1100" neutral="1500" max="1900"/>
<servo name="RUDDER" no="4" min="1100" neutral="1500" max="1900"/>
<servo name="FLAP" no="5" min="1900" neutral="1900" max="1100"/>
<servo name="KNOB" no="6" min="1100" neutral="1500" max="1900"/>
</servos>
<!-- Servo Command Structure -->
<commands>
<axis name="THROTTLE" failsafe_value="0"/>
<axis name="ROLL" failsafe_value="0"/>
<axis name="PITCH" failsafe_value="0"/>
<axis name="YAW" failsafe_value="0"/>
<axis name="FLAP" failsafe_value="0"/>
<axis name="CROW" failsafe_value="0"/>
</commands>
<!-- RC Command Structure -->
<rc_commands>
<set command="THROTTLE" value="@THROTTLE"/>
<set command="ROLL" value="@ROLL"/>
<set command="PITCH" value="@PITCH"/>
<set command="YAW" value="@YAW"/>
<set command="FLAP" value="@FLAP"/>
<set command="CROW" value="@KNOB"/>
</rc_commands>
<!-- Define RC commands to Servo in Auto Mode -->
<auto_rc_commands>
<set command="YAW" value="@YAW"/>
<set command="FLAP" value="@FLAP"/>
<set command="CROW" value="@KNOB"/>
</auto_rc_commands>
<!-- Define Mixing Parameters -->
<section name="MIXER">
<define name="AILERON_AILERON_RATE" value="0.9"/>
<define name="AILERON_CROW_RATE" value="0.6"/>
<define name="FLAP_CROW_RATE" value="1.0"/>
<define name="ELEV_CROW_RATE" value="0.35"/>
<define name="ELEV_ELEV_RATE" value="0.8"/>
</section>
<!-- Define RC commands to Servos in Manual -->
<command_laws>
<let var="aileron" value="@ROLL * AILERON_AILERON_RATE"/>
<let var="crow" value="@CROW * AILERON_CROW_RATE"/>
<let var="crowf" value="@CROW * FLAP_CROW_RATE"/>
<let var="elevf" value="@CROW * ELEV_CROW_RATE"/>
<let var="elevator" value="@PITCH * ELEV_ELEV_RATE"/>
<set servo="THROTTLE" value="@THROTTLE"/>
<set servo="AILERON_RIGHT" value="$aileron + $crow"/> <!--flip signs if necessary -->
<set servo="AILERON_LEFT" value=" - $aileron + $crow"/>
<set servo="ELEVATOR" value="$elevator - $elevf"/>
<set servo="RUDDER" value="@YAW"/>
<set servo="FLAP" value="$crowf"/>
<set servo="KNOB" value="@FLAP"/>
</command_laws>
<!-- Define Max Roll and Pitch setpoints in Auto1 -->
<section name="AUTO1" prefix="AUTO1_">
<define name="MAX_ROLL" value="0.6"/>
<define name="MAX_PITCH" value="0.6"/>
</section>
<!-- Define Roll, Pitch Neutrals -->
<section name="INS" prefix="INS_">
<define name="ROLL_NEUTRAL_DEFAULT" value="0" unit="deg"/>
<define name="PITCH_NEUTRAL_DEFAULT" value="0" unit="deg"/>
</section>
<!-- Define current estimator and Battery Level Warnings -->
<section name="BAT">
<define name="MILLIAMP_AT_FULL_THROTTLE" value="50000"/>
<define name="CURRENT_ESTIMATION_NONLINEARITY" value="1.3"/>
<define name="CATASTROPHIC_BAT_LEVEL" value="13.5" unit="V"/>
<define name="LOW_BAT_LEVEL" value="14.1" unit="V"/>
<define name="CRITIC_BAT_LEVEL" value="13.8" unit="V"/>
<define name="MAX_BAT_LEVEL" value="16.5" unit="V" />
<!--<define name="VoltageOfAdc(adc)" value="(0.029*adc)"/>-->
</section>
<!-- Define Airspeed Warnings for GCS (optional) -->
<section name="AIRSPEED_WARNING">
<define name="WARNING_AIRSPEED" value="12"/>
<define name="CRITIC_AIRSPEED" value="10"/>
<define name="CATASTROPHIC_AIRSPEED" value="8"/>
</section>
<section name="MISC">
<define name="NOMINAL_AIRSPEED" value="16." unit="m/s"/> <!-- GCS only -->
<define name="CARROT" value="5." unit="s"/> <!-- GCS only -->
<define name="KILL_MODE_DISTANCE" value="(1.5*MAX_DIST_FROM_HOME)"/>
<define name="CONTROL_RATE" value="60" unit="Hz"/>
<define name="XBEE_INIT" value="&quot;ATRN5\rATTT80\r&quot;"/>
<!-- ATRN - random delay for retransmits -->
<!-- ATTT - streaming limit before a delay is forced -->
<define name="ALT_KALMAN_ENABLED" value="TRUE"/>
<define name="DEFAULT_CIRCLE_RADIUS" value="150."/>
<define name="DEFAULT_LANDING_CIRCLE_RADIUS" value="150"/>
<define name="RC_LOST_MODE" value="AP_MODE_AUTO2"/>
</section>
<!-- Vertical Control done with Throttle and Pitch-->
<section name="VERTICAL CONTROL" prefix="V_CTL_">
<define name="POWER_CTL_BAT_NOMINAL" value="23.2" unit="volt"/>
<define name="ALTITUDE_PGAIN" value="0.136" unit="(m/s)/m"/> <!-- outer loop proportional gain -->
<define name="ALTITUDE_MAX_CLIMB" value="3." unit="m/s"/> <!-- outer loop saturation -->
<!-- auto throttle inner loop -->
<define name="AUTO_THROTTLE_NOMINAL_CRUISE_THROTTLE" value="0.42" unit="%"/>
<define name="AUTO_THROTTLE_MIN_CRUISE_THROTTLE" value="0.20" unit="%"/>
<define name="AUTO_THROTTLE_MAX_CRUISE_THROTTLE" value="0.70" unit="%"/>
<define name="AUTO_THROTTLE_LOITER_TRIM" value="1500" unit="pprz_t"/>
<define name="AUTO_THROTTLE_DASH_TRIM" value="-4000" unit="pprz_t"/>
<define name="AUTO_THROTTLE_CLIMB_THROTTLE_INCREMENT" value="0.05" unit="%/(m/s)"/>
<define name="AUTO_THROTTLE_PGAIN" value="0.010"/>
<define name="AUTO_THROTTLE_IGAIN" value="0.01"/>
<define name="AUTO_THROTTLE_DGAIN" value="0.00"/>
<define name="AUTO_THROTTLE_PITCH_OF_VZ_PGAIN" value="0.142"/>
<define name="AUTO_THROTTLE_PITCH_OF_VZ_DGAIN" value="0.00"/>
<define name="THROTTLE_SLEW_LIMITER" value="2" unit="s"/>
<!-- auto pitch inner loop -->
<define name="AUTO_PITCH_PGAIN" value="0.1"/>
<define name="AUTO_PITCH_IGAIN" value="0.025"/>
<define name="AUTO_PITCH_MAX_PITCH" value="0.31415" unit="rad"/>
<define name="AUTO_PITCH_MIN_PITCH" value="-0.31415" unit="rad"/>
<!-- landing control loop -->
<define name="LANDING_THROTTLE_PGAIN" value="600.0"/>
<define name="LANDING_THROTTLE_IGAIN" value="10.0"/>
<define name="LANDING_THROTTLE_MAX" value="0.65"/>
<define name="LANDING_DESIRED_SPEED" value="18" unit="m/s"/>
<define name="LANDING_PITCH_PGAIN" value="0.1"/>
<define name="LANDING_PITCH_IGAIN" value="0.1"/>
<define name="LANDING_PITCH_LIMITS" value="0.2" unit="rad"/>
<define name="LANDING_PITCH_FLARE" value="0.06"/>
<define name="LANDING_ALT_THROTTLE_KILL" value="15" unit="m"/>
<define name="LANDING_ALT_FLARE" value="5" unit="m"/>
</section>
<section name="HORIZONTAL CONTROL" prefix="H_CTL_">
<define name="COURSE_PGAIN" value="1.135"/>
<define name="COURSE_DGAIN" value="0.35"/>
<define name="ROLL_MAX_SETPOINT" value="0.6" unit="rad"/>
<define name="PITCH_MAX_SETPOINT" value="0.35" unit="rad"/>
<define name="PITCH_MIN_SETPOINT" value="-0.2" unit="rad"/>
<define name="PITCH_PGAIN" value="12900."/>
<define name="PITCH_DGAIN" value="1.5"/>
<define name="ROLL_ATTITUDE_GAIN" value="9000"/>
<define name="ROLL_RATE_GAIN" value="1600"/>
<define name="ELEVATOR_OF_ROLL" value="1250"/>
<define name="ROLL_SLEW" value="0.1"/>
</section>
<section name="AGGRESSIVE" prefix="AGR_">
<define name="BLEND_START" value="20"/> <!-- Altitude Error to Initiate Aggressive Climb CANNOT BE ZERO!!-->
<define name="BLEND_END" value="10"/> <!-- Altitude Error to Blend Aggressive to Regular Climb Modes CANNOT BE ZERO!!-->
<define name="CLIMB_THROTTLE" value="0.75"/> <!-- Throttle for Aggressive Climb -->
<define name="CLIMB_PITCH" value="0.13"/> <!-- Pitch for Aggressive Climb -->
<define name="DESCENT_THROTTLE" value="0.10"/> <!-- Throttle for Aggressive Decent -->
<define name="DESCENT_PITCH" value="-0.17"/> <!-- Pitch for Aggressive Decent in radians-->
<define name="CLIMB_NAV_RATIO" value="0.8"/> <!-- Percent Navigation for Altitude Error Equal to Start Altitude -->
<define name="DESCENT_NAV_RATIO" value="1.0"/>
</section>
<!-- Launcher Takeoff Configuration -->
<section name="Takeoff" prefix="Takeoff_">
<define name="Pitch" value="0.23" unit="rad"/>
<define name="Height" value="70" unit="m"/>
<define name="Speed" value="8" unit="m/s"/>
<define name="Distance" value="30" unit="m"/>
<define name="MinSpeed" value="5" unit="m/s"/>
</section>
<!-- Skid Landing Configuration -->
<section name="Landing" prefix="Landing_">
<define name="AFHeight" value="50" unit="m"/>
<define name="FinalHeight" value="50" unit="m"/>
<define name="FinalStageTime" value="10" unit="s"/>
</section>
<!-- Define Kill Position -->
<section name="FAILSAFE" prefix="FAILSAFE_">
<define name="DELAY_WITHOUT_GPS" value="5" unit="s"/>
<define name="DEFAULT_THROTTLE" value="0" unit="%"/>
<define name="DEFAULT_ROLL" value="0.3" unit="rad"/>
<define name="DEFAULT_PITCH" value="0.5" unit="rad"/>
</section>
<section name="SIMULATOR" prefix="NPS_">
<define name="JSBSIM_LAUNCHSPEED" value="25"/>
<define name="JSBSIM_MODEL" value="AGGIEAIR/minion" type="string"/>
<define name="SENSORS_PARAMS" value="nps_sensors_params_invariant.h" type="string"/>
<define name="JS_AXIS_THROTTLE" value="0"/>
<define name="JS_AXIS_THROTTLE_REVERSED" value="1"/>
<define name="JS_AXIS_ROLL" value="1"/>
<define name="JS_AXIS_PITCH" value="2"/>
<define name="JS_AXIS_PITCH_REVERSED" value="1"/>
<define name="JS_AXIS_YAW" value="3"/>
<define name="JS_AXIS_YAW_REVERSED" value="1"/>
<define name="JS_AXIS_FLAPS" value="5"/>
<define name="JS_AXIS_MODE" value="7"/>
<define name="JSBSIM_ROLL_TRIM" value="0.008"/>
<define name="JSBSIM_PITCH_TRIM" value="0.0375"/>
<define name="JSBSIM_YAW_TRIM" value="0.001"/>
</section>
<section name="IMU" prefix="IMU_">
<define name="BODY_TO_IMU_PHI" value="0." unit="deg"/>
<define name="BODY_TO_IMU_THETA" value="0." unit="deg"/>
<define name="BODY_TO_IMU_PSI" value="0." unit="deg"/>
<!-- Dummy Mag values for NPS -
replace with your own calibration -->
<define name="MAG_X_NEUTRAL" value="0"/>
<define name="MAG_Y_NEUTRAL" value="0"/>
<define name="MAG_Z_NEUTRAL" value="0"/>
</section>
<!-- **************************************************************** -->
<firmware name="fixedwing">
<target name="ap" board="umarim_lite_2.0"/>
<module name="radio_control" type="ppm"/>
<!-- NOTE: if you want to use extra_dl module for HITL
you have to set TELEMETRY_FREQUENCY to CONTROL_FREQUENCY -->
<configure name="PERIODIC_FREQUENCY" value="100"/>
<define name="CONTROL_FREQUENCY" value="100"/>
<configure name="TELEMETRY_FREQUENCY" value="100"/>
<define name="SERVO_HZ" value="100"/>
<target name="nps" board="pc">
<module name="fdm" type="jsbsim"/>
</target>
<target name="hitl" board="pc">
<module name="fdm" type="jsbsim"/>
<configure name="INS_DEV" value="/dev/ttyUSB1"/>
<configure name="INS_BAUD" value="B921600"/>
<configure name="AP_DEV" value="/dev/ttyUSB2"/>
<configure name="AP_BAUD" value="B921600"/>
</target>
<module name="control"/>
<module name="navigation"/>
<module name="telemetry" type="transparent">
<configure name="MODEM_PORT" value="UART1"/>
<configure name="MODEM_BAUD" value="B57600"/>
</module>
<module name="ins" type="vectornav">
<configure name="VN_PORT" value="UART0"/>
<configure name="VN_BAUD" value="B230400"/>
</module>
<define name="POLY_OSAM_HALF_SWEEP_ENABLED" value="FALSE"/>
<define name="GEOFENCE_DATALINK_LOST_TIME" value="45"/>
<!-- Extra Definitions -->
<define name="AGR_CLIMB" />
<define name="LOITER_TRIM" />
<define name="ALT_KALMAN" />
<define name="SixCellBatt"/>
<define name="SYS_TIME_LED" value="1"/>
<define name="TUNE_AGRESSIVE_CLIMB"/>
<define name="WIND_INFO"/>
<define name="WIND_INFO_RET"/>
<!-- Modules -->
<module name="nav" type="line"/>
<module name="nav" type="flower"/>
<module name="nav" type="survey_poly_osam"/>
<module name="nav" type="launcher"/>
<module name="nav" type="skid_landing"/>
<module name="extra_dl">
<configure name="EXTRA_DL_PORT" value="usb_serial"/>
<configure name="EXTRA_DL_BAUD" value="B921600"/>
</module>
<!-- Airspeed Sensor -->
<!--TODO: better to replace with air-data module and airspeed_ms45xx_i2c module-->
<module name="airspeed_adc">
<configure name="ADC_AIRSPEED" value="ADC_3"/>
<configure name="AIRSPEED_PIN" value="ADC_3"/>
<define name="AIRSPEED_ADC_SCALE" value="4.4083"/>
<define name="AIRSPEED_ADC_BIAS" value="740"/>
<define name="USE_AIRSPEED_ADC" value="TRUE"/>
</module>
<!-- Angle of Attack and Sideslip Angle -->
<!-- TODO: using AoA module only, not sure if we ever use sideslip anymore -->
<module name="AOA_adc">
<configure name="ADC_AOA" value="ADC_2"/>
<define name="AOA_OFFSET" value="0.0"/>
<define name="AOA_FILTER" value="0.0"/>
<define name="USE_AOA" value="TRUE"/>
</module>
<!-- I2C Payload -->
<!--load name="aggiecap2_i2c.xml">
<define name="I2C_SLAVE_ADDR" value="0x30"/>
<define name="I2C_BUF_LEN" value="256"/>
<define name="USE_I2C0_SLAVE"/>
</load-->
<!-- System Monitor -->
<module name="sys_mon"/>
</firmware>
</airframe>
@@ -81,7 +81,6 @@ AggieAir Atomic Tangerine
<define name="BATMON_TEMP_SENSITIVITY" value="10"/> <define name="BATMON_TEMP_SENSITIVITY" value="10"/>
</module> </module>
<module name="air_data"/> <module name="air_data"/>
</firmware> </firmware>
<!-- commands section --> <!-- commands section -->
@@ -79,7 +79,6 @@ AggieAir El Capitan
<define name="BATMON_TEMP_SENSITIVITY" value="10"/> <define name="BATMON_TEMP_SENSITIVITY" value="10"/>
</module> </module>
<module name="air_data"/> <module name="air_data"/>
</firmware> </firmware>
<!-- commands section --> <!-- commands section -->
@@ -6,6 +6,7 @@ AggieAir Minion Sim
<airframe name="AggieAir Minion Sim"> <airframe name="AggieAir Minion Sim">
<firmware name="fixedwing"> <firmware name="fixedwing">
<autopilot name="fixedwing_rusty.xml"/>
<target name="ap" board="lisa_mx_2.1_chibios"> <target name="ap" board="lisa_mx_2.1_chibios">
<module name="radio_control" type="sbus"> <module name="radio_control" type="sbus">
<configure name="SBUS_PORT" value="UART5"/> <configure name="SBUS_PORT" value="UART5"/>
@@ -54,6 +55,8 @@ AggieAir Minion Sim
<define name="POLY_OSAM_HALF_SWEEP_ENABLED" value="FALSE"/> <define name="POLY_OSAM_HALF_SWEEP_ENABLED" value="FALSE"/>
<define name="GEOFENCE_DATALINK_LOST_TIME" value="45"/> <define name="GEOFENCE_DATALINK_LOST_TIME" value="45"/>
<module name="rust_demo_module"/>
<module name="nav" type="line"/> <module name="nav" type="line"/>
<module name="nav" type="line_osam"/> <module name="nav" type="line_osam"/>
<module name="nav" type="flower"/> <module name="nav" type="flower"/>
@@ -79,7 +79,6 @@ AggieAir Minty Fresh
<define name="BATMON_TEMP_SENSITIVITY" value="10"/> <define name="BATMON_TEMP_SENSITIVITY" value="10"/>
</module> </module>
<module name="air_data"/> <module name="air_data"/>
</firmware> </firmware>
<!-- commands section --> <!-- commands section -->
+131
View File
@@ -0,0 +1,131 @@
<!DOCTYPE autopilot SYSTEM "autopilot.dtd">
<autopilot name="Corroded Fixed Wing Autopilot">
<state_machine name="ap" freq="CONTROL_FREQUENCY" gcs_mode="true" settings_mode="true">
<!-- Modules doesn't seem to work -->
<!--modules>
<load name="rust_demo_module"/>
</modules-->
<includes>
<include name="generated/airframe.h"/>
<include name="autopilot.h"/>
<include name="autopilot_rc_helpers.h"/>
<include name="inter_mcu.h"/>
<include name="nav.h"/>
<include name="guidance/guidance_common.h"/>
<include name="guidance/guidance_h.h"/>
<include name="stabilization/stabilization_attitude.h"/>
<include name="subsystems/gps.h"/>
<!-- We have to manually include the module's header files, so
we can use the provided functions -->
<include name ="modules/rust/demo_module/rust_demo_module.h"/>
</includes>
<control_block name="actuators_ap">
<call fun="PPRZ_MUTEX_LOCK(ap_state_mtx)"/>
<call fun="AP_COMMAND_SET_THROTTLE(v_ctl_throttle_slewed)"/>
<call fun="AP_COMMAND_SET_ROLL(-h_ctl_aileron_setpoint)"/>
<call fun="AP_COMMAND_SET_PITCH(h_ctl_elevator_setpoint)"/>
<call fun="AP_COMMAND_SET_YAW(h_ctl_rudder_setpoint)"/>
<call fun="AP_COMMAND_SET_CL(h_ctl_flaps_setpoint)"/>
<call fun="PPRZ_MUTEX_UNLOCK(ap_state_mtx)"/>
</control_block>
<control_block name="set_attitude_from_rc">
<call fun="PPRZ_MUTEX_LOCK(fbw_state_mtx)"/>
<call fun="AP_SETPOINT_ROLL(h_ctl_roll_setpoint, AUTO1_MAX_ROLL)"/>
<call fun="AP_SETPOINT_PITCH(h_ctl_pitch_setpoint, AUTO1_MAX_PITCH)"/>
<call fun="AP_SETPOINT_YAW_RATE(h_ctl_yaw_rate_setpoint, AUTO1_MAX_YAW_RATE)"/>
<call fun="AP_SETPOINT_THROTTLE(v_ctl_throttle_setpoint)"/>
<call fun="PPRZ_MUTEX_UNLOCK(fbw_state_mtx)"/>
</control_block>
<control_block name="attitude">
<call fun="h_ctl_attitude_loop()"/>
<call fun="v_ctl_throttle_slew()"/>
</control_block>
<control_block name="guidance">
<call fun="h_ctl_guidance_loop()"/>
<call fun="v_ctl_guidance_loop()"/>
</control_block>
<exceptions>
<exception cond="too_far_from_home && autopilot_in_flight()" deroute="HOME"/>
</exceptions>
<mode name="MANUAL" gcs_name="MANU">
<select cond="RCMode0()"/>
<control freq="4"> <!-- only for display -->
<call fun="common_nav_periodic_task_4Hz()"/>
<call fun="nav_periodic_task()"/>
</control>
<control> <!-- only for display -->
<call fun="v_ctl_throttle_slewed = imcu_get_radio(RADIO_THROTTLE)"/>
</control>
<exception cond="RCLost() && autopilot_in_flight()" deroute="HOME"/>
</mode>
<mode name="AUTO1">
<select cond="RCMode1()"/>
<control freq="4"> <!-- only for display -->
<call fun="common_nav_periodic_task_4Hz()"/>
<call fun="nav_periodic_task()"/>
<call fun="rust_periodic()"/>
</control>
<control>
<call_block name="set_attitude_from_rc"/>
<call_block name="attitude"/>
<call_block name="actuators_ap"/>
</control>
<exception cond="RCLost() && autopilot_in_flight()" deroute="HOME"/>
</mode>
<mode name="AUTO2">
<select cond="$DEFAULT_MODE"/>
<select cond="RCMode2()" exception="HOME"/>
<control freq="4">
<call fun="common_nav_periodic_task_4Hz()"/>
<call fun="nav_periodic_task()"/>
</control>
<control>
<call_block name="guidance"/>
<call_block name="attitude"/>
<call_block name="actuators_ap"/>
</control>
<exception cond="GpsIsLost() && autopilot_in_flight()" deroute="GPS_LOST"/>
</mode>
<mode name="HOME" settings="hide">
<control freq="4">
<call fun="common_nav_periodic_task_4Hz()"/>
<call fun="nav_home()"/>
</control>
<control>
<call_block name="guidance"/>
<call_block name="attitude"/>
<call_block name="actuators_ap"/>
</control>
<exception cond="GpsIsLost() && autopilot_in_flight()" deroute="GPS_LOST"/>
</mode>
<mode name="GPS_LOST" gcs_name="NOGPS" settings="hide">
<control freq="4">
<call fun="common_nav_periodic_task_4Hz()"/>
<call fun="nav_without_gps()"/>
</control>
<control>
<call_block name="guidance"/>
<call_block name="attitude"/>
<call_block name="actuators_ap"/>
</control>
<exception cond="!GpsIsLost()" deroute="$LAST_MODE"/>
</mode>
</state_machine>
</autopilot>
+3
View File
@@ -17,6 +17,9 @@ RTOS=chibios
## FPU on F4 ## FPU on F4
USE_FPU=hard USE_FPU=hard
# See list of supported Tier 3 architectures at: https://forge.rust-lang.org/platform-support.html
RUST_ARCH = thumbv7em-none-eabihf
$(TARGET).CFLAGS += -DSTM32F4 -DPPRZLINK_ENABLE_FD $(TARGET).CFLAGS += -DSTM32F4 -DPPRZLINK_ENABLE_FD
############################################################################## ##############################################################################
+8
View File
@@ -8,6 +8,14 @@ ARCH=sim
BOARD = pc BOARD = pc
BOARD_VERSION= BOARD_VERSION=
# specify host platform for Rust builds
UNAME = $(shell uname -s)
ifeq ("$(UNAME)","Darwin")
RUST_ARCH = x86_64-apple-darwin
else
RUST_ARCH = x86_64-unknown-linux-gnu
endif
BOARD_CFG = \"boards/pc_sim.h\" BOARD_CFG = \"boards/pc_sim.h\"
$(TARGET).ARCHDIR = $(ARCH) $(TARGET).ARCHDIR = $(ARCH)
+55
View File
@@ -0,0 +1,55 @@
<!DOCTYPE module SYSTEM "module.dtd">
<module name="rust_demo_module" dir="rust/demo_module">
<doc>
<description>
Simple rust module. It doesn't do much besides allocating a vector
and immediately freeying it afterwards.
Meant only as an example.
More info on Paparazzi wiki: https://wiki.paparazziuav.org/wiki/Rust
</description>
</doc>
<!--
We need a header file declaring the rust provided functions.
For simple cases, this can be done manually, but should eventually be
a part of the cargo/xargo build, preferably via `cbindgen` https://github.com/eqrion/cbindgen/
-->
<header>
<file name="rust_demo_module.h" />
</header>
<!--
Typical module functions. They are all void.
-->
<init fun="rust_function()"/>
<periodic fun="rust_periodic()" freq="1." autorun="TRUE"/>
<makefile target="ap">
<!-->
Additional defines needed by Rust's `alloc` crate
-->
<file name="pprz_syscalls.c" dir="."/>
</makefile>
<makefile target="ap|nps|hitl">
<!--
MODULE_PATH is where the module lives.
RUST_MODULES contains all Rust modules that should be built.
RUST_DIRS are paths to the module libraries, used by ChibiOS makefile.
RUST_LIBS are the actual libraries to be linked, used by ChibiOS makefile.
RUST_ARCH is board dependent.
Note - nothing is preventing name clashes, so make sure you name your
library appropriately.
-->
<raw>
MODULE_PATH = $(PAPARAZZI_SRC)/sw/airborne/modules/rust/demo_module
RUST_MODULES += $(MODULE_PATH)
RUST_DIRS += $(MODULE_PATH)/target/$(RUST_ARCH)/release
RUST_LIBS += -lrust_demo_module
</raw>
</makefile>
</module>
+1
View File
@@ -436,3 +436,4 @@
#endif /* _HALCONF_H_ */ #endif /* _HALCONF_H_ */
/** @} */ /** @} */
@@ -46,9 +46,13 @@ void rtos_mon_init_arch(void)
void rtos_mon_periodic_arch(void) void rtos_mon_periodic_arch(void)
{ {
int i; int i;
size_t total_fragments, total_fragmented_free_space, largest_free_block;
total_fragments = chHeapStatus(NULL, &total_fragmented_free_space, &largest_free_block);
rtos_mon.core_free_memory = chCoreGetStatusX(); rtos_mon.core_free_memory = chCoreGetStatusX();
rtos_mon.heap_free_memory = 0; rtos_mon.heap_fragments = total_fragments;
rtos_mon.heap_largest = largest_free_block;
rtos_mon.heap_free_memory = total_fragmented_free_space;
rtos_mon.thread_counter = 0; rtos_mon.thread_counter = 0;
// loop threads to find idle thread // loop threads to find idle thread
+2
View File
@@ -54,6 +54,8 @@ void periodic_report_sysmon(void)
&rtos_mon.cpu_load, &rtos_mon.cpu_load,
&rtos_mon.core_free_memory, &rtos_mon.core_free_memory,
&rtos_mon.heap_free_memory, &rtos_mon.heap_free_memory,
&rtos_mon.heap_fragments,
&rtos_mon.heap_largest,
&rtos_mon.cpu_time); &rtos_mon.cpu_time);
} }
+3 -1
View File
@@ -45,7 +45,9 @@
// RTOS structure // RTOS structure
struct rtos_monitoring { struct rtos_monitoring {
uint32_t core_free_memory; ///< core free memory in bytes uint32_t core_free_memory; ///< core free memory in bytes
uint32_t heap_free_memory; ///< heap free memory in bytes uint32_t heap_free_memory; ///< Total fragmented free memory in the heap
uint32_t heap_fragments; ///< Number of fragments in the heap
uint32_t heap_largest; ///< Largest free block in the heap
uint8_t cpu_load; ///< global CPU/MCU load in % uint8_t cpu_load; ///< global CPU/MCU load in %
uint8_t thread_counter; ///< number of threads uint8_t thread_counter; ///< number of threads
uint16_t thread_load[RTOS_MON_MAX_THREADS]; ///< individual thread load in centi-percent (10*%) uint16_t thread_load[RTOS_MON_MAX_THREADS]; ///< individual thread load in centi-percent (10*%)
@@ -0,0 +1,3 @@
/target
**/*.rs.bk
Cargo.lock
@@ -0,0 +1,30 @@
[package]
name = "rust_demo_module"
version = "0.1.0"
authors = ["Michal Podhradsky <mpodhradsky@galois.com>"]
edition = "2018"
[lib]
path = "src/lib.rs"
crate-type = ["staticlib"]
[features]
"use_std" = ["rust_alloc_sim"]
"not_std" = ["rust_alloc_chibios"]
default = []
[build-dependencies]
[build-dependencies.pprz_compat_build]
path = "../pprz_compat_build"
[dependencies.pprz_compat]
path = "../pprz_compat"
[dependencies.rust_alloc_chibios]
path = "../rust_alloc_chibios"
optional = true
[dependencies.rust_alloc_sim]
path = "../rust_alloc_sim"
optional = true
@@ -0,0 +1,5 @@
extern crate pprz_compat_build;
fn main() {
pprz_compat_build::generate_bindings();
}
@@ -0,0 +1,18 @@
/* Text to put at the beginning of the generated file. Probably a license. */
#ifndef RUST_RUST_DEMO_MODULE_H
#define RUST_RUST_DEMO_MODULE_H
/* Warning, this file is autogenerated by cbindgen. Don't modify this manually. */
#include <stdint.h>
#include <stdlib.h>
#include <stdbool.h>
void rust_function(void);
void rust_periodic(void);
#endif /* RUST_RUST_DEMO_MODULE_H */
/* Text to put at the end of the generated file */
@@ -0,0 +1,47 @@
#![no_std]
#![feature(alloc)]
#![feature(extern_crate_item_prelude)]
#![feature(lang_items)]
#![allow(non_upper_case_globals)]
#![allow(non_camel_case_types)]
#![allow(non_snake_case)]
include!(concat!(env!("OUT_DIR"), "/airframe.rs"));
extern crate alloc;
extern crate pprz_compat;
// Example of linking State and Actuators interfaces
use pprz_compat::actuators::actuators;
use pprz_compat::state::State;
#[cfg(feature = "use_std")]
extern crate rust_alloc_sim;
#[cfg(feature = "not_std")]
extern crate rust_alloc_chibios;
use alloc::vec::Vec;
#[no_mangle]
pub extern "C" fn rust_function() {
let mut v = Vec::new();
v.push(SERVO_AILERON_LEFT);
}
#[no_mangle]
pub extern "C" fn rust_periodic() {
let mut v = Vec::new();
v.push(1);
v.push(2);
v.pop();
}
#[cfg(test)]
mod tests {
#[test]
fn it_works() {
assert_eq!(2 + 2, 4);
}
}
@@ -0,0 +1,7 @@
[package]
name = "pprz_compat"
version = "0.1.0"
authors = ["Michal Podhradsky <mpodhradsky@galois.com>"]
edition = "2018"
[dependencies]
@@ -0,0 +1,16 @@
extern "C" {
#[link_name = "\u{1}actuators_delay_time"]
pub static mut actuators_delay_time: u32;
}
extern "C" {
#[link_name = "\u{1}actuators_delay_done"]
pub static mut actuators_delay_done: bool;
}
extern "C" {
#[link_name = "\u{1}actuators"]
pub static mut actuators: [i16; 6usize];
}
extern "C" {
#[link_name = "\u{1}actuators_pprz"]
pub static mut actuators_pprz: [i16; 6usize];
}
@@ -0,0 +1,3 @@
#![no_std]
pub mod actuators;
pub mod state;
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,9 @@
[package]
name = "pprz_compat_build"
version = "0.1.0"
authors = ["Michal Podhradsky <mpodhradsky@galois.com>"]
edition = "2018"
[dependencies]
bindgen = "0.42.2"
cbindgen = "0.6.7"
@@ -0,0 +1,106 @@
extern crate bindgen;
extern crate cbindgen;
use std::env;
use std::path::{Path, PathBuf};
use std::io::{BufReader, BufWriter, BufRead, Write};
use std::fs::File;
pub fn generate_bindings() {
let module_name = env::var("CARGO_PKG_NAME").unwrap();
//
// Bindings for Rust
//
let pprz_dir = env::var("PAPARAZZI_SRC").expect("PAPARAZZI_SRC not present");
let generated_dir = env::var("AC_GENERATED").expect("AC_GENERATED not present");
let pprz_path = Path::new(&pprz_dir);
let path_include = pprz_path.join("sw/include");
let path_airborne = pprz_path.join("sw/airborne/");
// Write the bindings to the $OUT_DIR/bindings.rs file.
let out_path = PathBuf::from(env::var("OUT_DIR").unwrap());
//
// Parse generated airframe.h and remove any includes to make live easier for bindgen
//
let file_path_in = generated_dir.clone() + "/airframe.h";
let path_in = Path::new(&file_path_in);
let airframe_h = BufReader::new(File::open(&path_in).unwrap());
let file_path_out = generated_dir.clone() + "/airframe_no_includes.h";
let path_out = Path::new(&file_path_out);
let mut airframe_no_includes_h = BufWriter::new(File::create(&path_out).unwrap());
for line in airframe_h.lines() {
if let Ok(line) = line {
if line.contains("#include") {
airframe_no_includes_h.write("// ".as_bytes()).unwrap();
}
airframe_no_includes_h.write(line.as_bytes()).unwrap();
airframe_no_includes_h.write("\n".as_bytes()).unwrap();
}
}
airframe_no_includes_h.flush().unwrap();
// Generate airframe.rs
let bindings_airframe = bindgen::Builder::default()
.header(generated_dir.clone() + "/airframe_no_includes.h")
.clang_arg(String::from("-I") + path_include.to_str().expect("path include problem"))
.clang_arg(String::from("-I") + path_airborne.to_str().expect("path airborne problem"))
.clang_arg(String::from("-I") + &generated_dir)
.layout_tests(false)
.use_core()
.generate()
.expect("Unable to generate airframe bindings");
bindings_airframe
.write_to_file(out_path.join("airframe.rs"))
.expect("Couldn't write airframe bindings!");
/*
// Generate state.rs
let bindings_state = bindgen::Builder::default()
.header(path_airborne.to_str().unwrap().to_owned() + "/state.h")
.clang_arg(String::from("-I") + path_include.to_str().expect("path include problem"))
.clang_arg(String::from("-I") + path_airborne.to_str().expect("path airborne problem"))
.clang_arg(String::from("-I") + &generated_dir)
.layout_tests(false)
.use_core()
.ignore_functions()
.generate()
.expect("Unable to generate state bindings");
bindings_state
.write_to_file(out_path.join("state.rs"))
.expect("Couldn't write state bindings!");
*/
//
// Bindings for paparazzi using cbindgen
//
let crate_dir = env::var("CARGO_MANIFEST_DIR").unwrap();
let builder_include_guard = String::from("RUST_") + &module_name.to_uppercase() + "_H";
let bindings_name = String::from(module_name) + ".h";
cbindgen::Builder::new()
// # An optional string of text to output at the beginning of the generated file
.with_header("/* Text to put at the beginning of the generated file. Probably a license. */")
// # An optional string of text to output at the end of the generated file
.with_trailer("/* Text to put at the end of the generated file */")
// # An optional string of text to output between major sections of the generated
// # file as a warning against manual editing
.with_autogen_warning("/* Warning, this file is autogenerated by cbindgen. Don't modify this manually. */")
// # An optional name to use as an include guard
.with_include_guard(builder_include_guard)
// # The language to output bindings in
.with_language(cbindgen::Language::C)
// # Whether to parse dependent crates and include their types in the generated
// # bindings
.with_parse_deps(false)
// # A black list of crate names that are not allowed to be parsed
.with_parse_exclude(&vec!["libc"])
.with_crate(crate_dir)
.generate()
.expect("Unable to generate bindings")
.write_to_file(bindings_name);
}
@@ -0,0 +1,3 @@
/target
**/*.rs.bk
Cargo.lock
@@ -0,0 +1,13 @@
[package]
name = "rust_alloc_chibios"
version = "0.1.0"
authors = ["Michal Podhradsky <mpodhradsky@galois.com>"]
edition = "2018"
[dependencies]
panic-halt = "0.2.0"
[features]
"arch32" = []
"arch16" = []
default = ["arch32"]
@@ -0,0 +1,57 @@
#![no_std]
#![feature(alloc)]
#![feature(extern_crate_item_prelude)]
#![feature(alloc_error_handler)]
#![feature(lang_items)]
#[allow(unused_extern_crates)] // NOTE(allow) bug rust-lang/rust#53964
extern crate panic_halt; // panic handler
extern crate alloc;
use core::alloc::{GlobalAlloc, Layout};
use core::ptr;
#[lang = "eh_personality"]
#[no_mangle]
pub extern "C" fn rust_eh_personality() {}
// See https://github.com/rust-lang/rust/issues/51540
#[alloc_error_handler]
fn foo(_: core::alloc::Layout) -> ! {
loop {}
}
extern "C" {
pub fn chHeapFree(p: *mut u8);
pub fn chHeapStatus(heapp: *mut u8, sizep: *mut usize, sizep2: *mut usize) -> usize;
/// Note: we have to call `chHeapAllocAligned` instead of `chHeapAlloc` because
/// paparazzi optimizes the `chHeapAlloc` call and doesn't export it.
/// As a result we have to guess the alignment. I am using a cfg feature
/// to distinguish between 32-bit and 16-bit targets
pub fn chHeapAllocAligned(heapp: *mut u8, size: usize, align: u8) -> *mut u8;
}
pub struct RustChibiOsAllocator;
unsafe impl GlobalAlloc for RustChibiOsAllocator {
unsafe fn alloc(&self, layout: Layout) -> *mut u8 {
#[cfg(feature = "arch32")]
{
chHeapAllocAligned(ptr::null_mut(), layout.size(), 8)
}
#[cfg(feature = "arch16")]
{
chHeapAllocAligned(ptr::null_mut(), layout.size(), 4)
}
}
unsafe fn dealloc(&self, ptr: *mut u8, _layout: Layout) {
chHeapFree(ptr)
}
}
#[global_allocator]
static GLOBAL: RustChibiOsAllocator = RustChibiOsAllocator;
@@ -0,0 +1,3 @@
/target
**/*.rs.bk
Cargo.lock
@@ -0,0 +1,7 @@
[package]
name = "rust_alloc_sim"
version = "0.1.0"
authors = ["Michal Podhradsky <mpodhradsky@galois.com>"]
edition = "2018"
[dependencies]
@@ -0,0 +1,41 @@
#![feature(lang_items, core_intrinsics)]
#![feature(start)]
#![feature(alloc)]
#![feature(alloc_system)]
#![feature(allocator_api)]
#![feature(extern_crate_item_prelude)]
#![feature(alloc_error_handler)]
#![no_std]
use core::panic::PanicInfo;
extern crate alloc;
extern crate alloc_system;
use alloc_system::System;
#[global_allocator]
static GLOBAL: System = System;
#[lang = "eh_personality"]
#[no_mangle]
pub extern "C" fn rust_eh_personality() {}
#[lang = "eh_unwind_resume"]
#[no_mangle]
pub extern "C" fn rust_eh_unwind_resume() {}
#[no_mangle]
#[allow(non_snake_case)]
pub extern "C" fn _Unwind_Resume() {}
#[panic_handler]
#[no_mangle]
pub extern fn panic(_info: &PanicInfo) -> ! {
loop{}
}
// See https://github.com/rust-lang/rust/issues/51540
#[alloc_error_handler]
fn foo(_: core::alloc::Layout) -> ! {
loop {}
}