From dfa5ca17104d1174d3e9aeeb3103d1cc592b1632 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20K=C3=A1kona?= Date: Wed, 29 Apr 2020 08:46:59 +0200 Subject: [PATCH] FlightGear simulator support (#14539) - Add flightgear_bridge submodule. - Add traget px4_sitl_nolockstep with disabled LOCKSTEP simulation. - Add flightgear viewer targets and startup scripts - Add a few possible vehicles plane (rascal), autogyro (tf-g1), and rover (tf-r1)) Co-authored-by: Vit Hanousek --- .gitmodules | 3 + ROMFS/px4fmu_common/init.d-posix/1033_rascal | 58 ++++++++++++ .../init.d-posix/1034_rascal-electric | 58 ++++++++++++ ROMFS/px4fmu_common/init.d-posix/1061_tf-r1 | 43 +++++++++ ROMFS/px4fmu_common/init.d-posix/17001_tf-g1 | 64 +++++++++++++ .../mixers-sitl/autogyro_sitl.main.mix | 37 ++++++++ Tools/flightgear_bridge | 1 + Tools/sitl_run.sh | 11 ++- boards/px4/sitl/nolockstep.cmake | 91 +++++++++++++++++++ platforms/posix/cmake/sitl_target.cmake | 47 ++++++++++ 10 files changed, 412 insertions(+), 1 deletion(-) create mode 100644 ROMFS/px4fmu_common/init.d-posix/1033_rascal create mode 100644 ROMFS/px4fmu_common/init.d-posix/1034_rascal-electric create mode 100644 ROMFS/px4fmu_common/init.d-posix/1061_tf-r1 create mode 100644 ROMFS/px4fmu_common/init.d-posix/17001_tf-g1 create mode 100644 ROMFS/px4fmu_common/mixers-sitl/autogyro_sitl.main.mix create mode 160000 Tools/flightgear_bridge create mode 100644 boards/px4/sitl/nolockstep.cmake diff --git a/.gitmodules b/.gitmodules index d590262a06..1ad5a3a9c2 100644 --- a/.gitmodules +++ b/.gitmodules @@ -45,3 +45,6 @@ [submodule "platforms/qurt/dspal"] path = platforms/qurt/dspal url = https://github.com/ATLFlight/dspal.git +[submodule "Tools/flightgear_bridge"] + path = Tools/flightgear_bridge + url = https://github.com/ThunderFly-aerospace/PX4-FlightGear-Bridge.git diff --git a/ROMFS/px4fmu_common/init.d-posix/1033_rascal b/ROMFS/px4fmu_common/init.d-posix/1033_rascal new file mode 100644 index 0000000000..05fd975438 --- /dev/null +++ b/ROMFS/px4fmu_common/init.d-posix/1033_rascal @@ -0,0 +1,58 @@ +#!/bin/sh +# +# @name Plane SITL +# + +sh /etc/init.d/rc.fw_defaults + +if [ $AUTOCNF = yes ] +then + param set EKF2_ARSP_THR 8 + param set EKF2_FUSE_BETA 1 + #param set EKF2_MAG_ACCLIM 0 + #param set EKF2_MAG_YAWLIM 0 + + param set FW_LND_AIRSPD_SC 1.1 + param set FW_LND_ANG 5 + param set FW_THR_LND_MAX 0 + param set FW_LND_HHDIST 30 + param set FW_LND_FL_PMIN 9.5 + param set FW_LND_FL_PMAX 20 + param set FW_LND_FLALT 5 + param set FW_LND_TLALT 15 + + param set FW_L1_PERIOD 25 + + param set FW_P_TC 0.4 + param set FW_PR_FF 0.40 + param set FW_PR_I 0.05 + param set FW_PR_P 0.05 + + param set FW_R_TC 0.45 + param set FW_RR_FF 0.40 + param set FW_RR_I 0.132 + param set FW_RR_P 0.085 + + param set FW_W_EN 1 + + param set MIS_LTRMIN_ALT 30 + param set MIS_TAKEOFF_ALT 20 + param set MIS_DIST_1WP 2500 + param set MIS_DIST_WPS 10000 + + param set NAV_ACC_RAD 15 + param set NAV_DLL_ACT 2 + param set NAV_LOITER_RAD 50 + + param set RWTO_TKOFF 1 + #param set FW_THR_SLEW_MAX 0.3 # fix takeoff failure for JSBsim in autonomous mission mode. + param set RWTO_MAX_PITCH 20 + param set RWTO_MAX_ROLL 10 + #param set RWTO_MAX_THR 0.6 # fix takeoff failure for JSBsim in autonomous mission mode. + param set RWTO_PSP 8 + param set RWTO_AIRSPD_SCL 1.8 + +fi + +set MIXER_FILE etc/mixers-sitl/plane_sitl.main.mix +set MIXER custom diff --git a/ROMFS/px4fmu_common/init.d-posix/1034_rascal-electric b/ROMFS/px4fmu_common/init.d-posix/1034_rascal-electric new file mode 100644 index 0000000000..05fd975438 --- /dev/null +++ b/ROMFS/px4fmu_common/init.d-posix/1034_rascal-electric @@ -0,0 +1,58 @@ +#!/bin/sh +# +# @name Plane SITL +# + +sh /etc/init.d/rc.fw_defaults + +if [ $AUTOCNF = yes ] +then + param set EKF2_ARSP_THR 8 + param set EKF2_FUSE_BETA 1 + #param set EKF2_MAG_ACCLIM 0 + #param set EKF2_MAG_YAWLIM 0 + + param set FW_LND_AIRSPD_SC 1.1 + param set FW_LND_ANG 5 + param set FW_THR_LND_MAX 0 + param set FW_LND_HHDIST 30 + param set FW_LND_FL_PMIN 9.5 + param set FW_LND_FL_PMAX 20 + param set FW_LND_FLALT 5 + param set FW_LND_TLALT 15 + + param set FW_L1_PERIOD 25 + + param set FW_P_TC 0.4 + param set FW_PR_FF 0.40 + param set FW_PR_I 0.05 + param set FW_PR_P 0.05 + + param set FW_R_TC 0.45 + param set FW_RR_FF 0.40 + param set FW_RR_I 0.132 + param set FW_RR_P 0.085 + + param set FW_W_EN 1 + + param set MIS_LTRMIN_ALT 30 + param set MIS_TAKEOFF_ALT 20 + param set MIS_DIST_1WP 2500 + param set MIS_DIST_WPS 10000 + + param set NAV_ACC_RAD 15 + param set NAV_DLL_ACT 2 + param set NAV_LOITER_RAD 50 + + param set RWTO_TKOFF 1 + #param set FW_THR_SLEW_MAX 0.3 # fix takeoff failure for JSBsim in autonomous mission mode. + param set RWTO_MAX_PITCH 20 + param set RWTO_MAX_ROLL 10 + #param set RWTO_MAX_THR 0.6 # fix takeoff failure for JSBsim in autonomous mission mode. + param set RWTO_PSP 8 + param set RWTO_AIRSPD_SCL 1.8 + +fi + +set MIXER_FILE etc/mixers-sitl/plane_sitl.main.mix +set MIXER custom diff --git a/ROMFS/px4fmu_common/init.d-posix/1061_tf-r1 b/ROMFS/px4fmu_common/init.d-posix/1061_tf-r1 new file mode 100644 index 0000000000..1de142b811 --- /dev/null +++ b/ROMFS/px4fmu_common/init.d-posix/1061_tf-r1 @@ -0,0 +1,43 @@ +#!/bin/sh +# +# @name ThunderFly TF-R1 UAV Rover +# @type Rover +# @class Rover +# +# @url https://github.com/ThunderFly-aerospace/TF-R1/ +# @maintainer ThunderFly s.r.o. +# + +sh /etc/init.d/rc.rover_defaults + +if [ $AUTOCNF = yes ] +then + param set GND_L1_DIST 5 + param set GND_SP_CTRL_MODE 1 + param set GND_SPEED_D 3 + param set GND_SPEED_I 0.001 + param set GND_SPEED_IMAX 0.125 + param set GND_SPEED_P 0.25 + param set GND_SPEED_THR_SC 1 + param set GND_SPEED_TRIM 15 + param set GND_SPEED_MAX 25 + param set GND_THR_CRUISE 0.3 + param set GND_THR_IDLE 0 + param set GND_THR_MAX 0.5 + param set GND_THR_MIN 0 + + param set MIS_LTRMIN_ALT 0.01 + param set MIS_TAKEOFF_ALT 0.01 + param set NAV_ACC_RAD 0.5 + param set NAV_LOITER_RAD 2 + + param set CBRK_AIRSPD_CHK 162128 + + param set GND_MAX_ANG 0.6 + param set GND_WHEEL_BASE 3.0 + +fi + +set MAV_TYPE 10 + +set MIXER_FILE etc/mixers-sitl/rover_sitl.main.mix diff --git a/ROMFS/px4fmu_common/init.d-posix/17001_tf-g1 b/ROMFS/px4fmu_common/init.d-posix/17001_tf-g1 new file mode 100644 index 0000000000..d60ccd9d6d --- /dev/null +++ b/ROMFS/px4fmu_common/init.d-posix/17001_tf-g1 @@ -0,0 +1,64 @@ +#!/bin/sh +# +# @name ThunderFly TF-G1 +# ThunderFly TF-G1 autogyro airframe. Only for FlightGear simulator +# +# @type Autogyro +# @class Autogyro +# +# @url https://github.com/ThunderFly-aerospace/TF-G1/ +# +# + +sh /etc/init.d/rc.fw_defaults + +if [ $AUTOCNF = yes ] +then + param set EKF2_ARSP_THR 8 + param set EKF2_FUSE_BETA 1 + param set ASPD_STALL 10.0 + + param set FW_P_RMAX_NEG 20.0 + param set FW_P_RMAX_POS 60.0 + param set FW_W_RMAX 10 + param set FW_W_EN 1 + + param set FW_PR_IMAX 0.4 + param set FW_R_TC 0.4 + param set FW_RR_FF 0.5 + param set FW_RR_I 0.1 + param set FW_RR_IMAX 0.2 + param set FW_RR_P 0.08 + + param set MIS_LTRMIN_ALT 50 + param set MIS_TAKEOFF_ALT 3 + + param set NAV_ACC_RAD 20 + param set NAV_DLL_ACT 2 + param set NAV_LOITER_RAD 100 + + param set RWTO_TKOFF 1 + param set MAV_BROADCAST 1 + + param set FW_ARSP_SCALE_EN 0 + + param set FW_AIRSPD_MAX 35 + param set FW_AIRSPD_MIN 7 + param set FW_AIRSPD_TRIM 15 + + param set FW_P_LIM_MAX 25 + param set FW_P_LIM_MIN -5 + param set FW_R_LIM 30 + + param set FW_MAN_P_MAX 30.0 + param set FW_MAN_R_MAX 30.0 + + param set FW_THR_CRUISE 0.8 + param set FW_THR_IDLE 0 + param set COM_DISARM_PRFLT 0 + +fi + + +set MIXER_FILE etc/mixers-sitl/autogyro_sitl.main.mix +set MIXER custom diff --git a/ROMFS/px4fmu_common/mixers-sitl/autogyro_sitl.main.mix b/ROMFS/px4fmu_common/mixers-sitl/autogyro_sitl.main.mix new file mode 100644 index 0000000000..2a9886cdee --- /dev/null +++ b/ROMFS/px4fmu_common/mixers-sitl/autogyro_sitl.main.mix @@ -0,0 +1,37 @@ +Mixer for SITL autogyro. +========================================================= + +# 0 mixer for the rudder (Rotor roll) +M: 1 +O: 10000 10000 0 -10000 10000 +S: 0 2 10000 10000 0 -10000 10000 + +# 1 mixer for the pusher/puller throttle +M: 1 +O: 10000 10000 0 -10000 10000 +S: 0 3 0 20000 -10000 -10000 10000 + +# 2 mixer for the aileron +M: 1 +O: 10000 10000 0 -10000 10000 +S: 0 0 -10000 -10000 0 -10000 10000 + +# 3 mixer for the elevator (Rotor pitch) +M: 1 +O: 10000 10000 0 -10000 10000 +S: 0 1 10000 10000 0 -10000 10000 + +# 4 mixer for the prerotator AUX1 +M: 1 +O: 10000 10000 0 -10000 10000 +S: 1 5 10000 10000 0 -10000 10000 + +# 5 mixer for the manual elevator AUX2 +M: 1 +O: 10000 10000 0 -10000 10000 +S: 1 6 10000 10000 0 -10000 10000 + +# 6 mixer for the release device AUX3 +M: 1 +O: 10000 10000 0 -10000 10000 +S: 1 7 10000 10000 0 -10000 10000 diff --git a/Tools/flightgear_bridge b/Tools/flightgear_bridge new file mode 160000 index 0000000000..f7eb676108 --- /dev/null +++ b/Tools/flightgear_bridge @@ -0,0 +1 @@ +Subproject commit f7eb676108c41edea5b9424f29a74a517a1dfd48 diff --git a/Tools/sitl_run.sh b/Tools/sitl_run.sh index 67da0ac215..f1f88715d5 100755 --- a/Tools/sitl_run.sh +++ b/Tools/sitl_run.sh @@ -9,7 +9,7 @@ fi if [[ -n "$DONT_RUN" ]]; then echo "Not running simulation (DONT_RUN is set)." - exit 0 + exit 0 fi sitl_bin="$1" @@ -121,6 +121,12 @@ elif [ "$program" == "gazebo" ] && [ ! -n "$no_sim" ]; then echo "You need to have gazebo simulator installed!" exit 1 fi +elif [ "$program" == "flightgear" ] && [ -z "$no_sim" ]; then + echo "FG setup" + cd "${src_path}/Tools/flightgear_bridge/" + "${src_path}/Tools/flightgear_bridge/FG_run.py" "models/"${model}".json" 0 + "${build_path}/build_flightgear_bridge/flightgear_bridge" 0 `./get_FGbridge_params.py "models/"${model}".json"` & + FG_BRIDGE_PID=`echo $!` fi pushd "$rootfs" >/dev/null @@ -171,4 +177,7 @@ elif [ "$program" == "gazebo" ]; then if [[ ! -n "$HEADLESS" ]]; then kill -9 $GUI_PID fi +elif [ "$program" == "flightgear" ]; then + kill $FG_BRIDGE_PID + kill -9 `cat /tmp/px4fgfspid_0` fi diff --git a/boards/px4/sitl/nolockstep.cmake b/boards/px4/sitl/nolockstep.cmake new file mode 100644 index 0000000000..174954e5ce --- /dev/null +++ b/boards/px4/sitl/nolockstep.cmake @@ -0,0 +1,91 @@ + +px4_add_board( + PLATFORM posix + VENDOR px4 + MODEL sitl + LABEL nolockstep + TESTING + DRIVERS + #barometer # all available barometer drivers + #batt_smbus + camera_capture + camera_trigger + #differential_pressure # all available differential pressure drivers + #distance_sensor # all available distance sensor drivers + gps + #imu # all available imu drivers + #magnetometer # all available magnetometer drivers + pwm_out_sim + #telemetry # all available telemetry drivers + tone_alarm + #uavcan + MODULES + airspeed_selector + attitude_estimator_q + camera_feedback + commander + dataman + ekf2 + events + fw_att_control + fw_pos_control_l1 + land_detector + landing_target_estimator + #load_mon + local_position_estimator + logger + mavlink + mc_att_control + mc_hover_thrust_estimator + mc_pos_control + mc_rate_control + navigator + rc_update + replay + rover_pos_control + sensors + #sih + simulator + temperature_compensation + vmount + vtol_att_control + uuv_att_control + + SYSTEMCMDS + #config + #dumpfile + dyn + esc_calib + led_control + mixer + motor_ramp + motor_test + #mtd + #nshterm + param + perf + pwm + reboot + sd_bench + shutdown + tests # tests and test runner + #top + topic_listener + tune_control + ver + work_queue + EXAMPLES + dyn_hello # dynamically loading modules example + fixedwing_control # Tutorial code from https://px4.io/dev/example_fixedwing_control + hello + #hwtest # Hardware test + #matlab_csv_serial + px4_mavlink_debug # Tutorial code from http://dev.px4.io/en/debug/debug_values.html + px4_simple_app # Tutorial code from http://dev.px4.io/en/apps/hello_sky.html + rover_steering_control # Rover example app + uuv_example_app + ) + +message(STATUS "Building without lockstep") +set(ENABLE_LOCKSTEP_SCHEDULER no) + diff --git a/platforms/posix/cmake/sitl_target.cmake b/platforms/posix/cmake/sitl_target.cmake index 558c1c811b..80aa0a3f1f 100644 --- a/platforms/posix/cmake/sitl_target.cmake +++ b/platforms/posix/cmake/sitl_target.cmake @@ -25,6 +25,7 @@ add_custom_target(run_config px4_add_git_submodule(TARGET git_gazebo PATH "${PX4_SOURCE_DIR}/Tools/sitl_gazebo") px4_add_git_submodule(TARGET git_jmavsim PATH "${PX4_SOURCE_DIR}/Tools/jMAVSim") +px4_add_git_submodule(TARGET git_flightgear_bridge PATH "${PX4_SOURCE_DIR}/Tools/flightgear_bridge") # Add support for external project building include(ExternalProject) @@ -57,6 +58,20 @@ ExternalProject_Add(mavsdk_tests BUILD_ALWAYS 1 ) +ExternalProject_Add(flightgear_bridge + SOURCE_DIR ${PX4_SOURCE_DIR}/Tools/flightgear_bridge + CMAKE_ARGS + -DCMAKE_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX} + BINARY_DIR ${PX4_BINARY_DIR}/build_flightgear_bridge + INSTALL_COMMAND "" + DEPENDS + git_flightgear_bridge + USES_TERMINAL_CONFIGURE true + USES_TERMINAL_BUILD true + EXCLUDE_FROM_ALL true + BUILD_ALWAYS 1 +) + # create targets for each viewer/model/debugger combination set(viewers none jmavsim gazebo) set(debuggers none ide gdb lldb ddd valgrind callgrind) @@ -146,6 +161,38 @@ foreach(viewer ${viewers}) endforeach() endforeach() +#add flighgear targets +if( ENABLE_LOCKSTEP_SCHEDULER STREQUAL "no") + set(models + rascal + rascal-electric + tf-g1 + tf-r1 + ) + set(all_posix_vmd_make_targets) + + foreach(model ${models}) + set(_targ_name "flightgear_${model}") + add_custom_target(${_targ_name} + COMMAND ${PX4_SOURCE_DIR}/Tools/sitl_run.sh + $ + none + flightgear + ${model} + none + ${PX4_SOURCE_DIR} + ${PX4_BINARY_DIR} + WORKING_DIRECTORY ${SITL_WORKING_DIR} + USES_TERMINAL + DEPENDS + logs_symlink + ) + + add_dependencies(${_targ_name} px4 flightgear_bridge) + list(APPEND all_posix_vmd_make_targets ${_targ_name}) + endforeach() +endif() + string(REPLACE ";" "," posix_vmd_make_target_list "${all_posix_vmd_make_targets}") add_custom_target(list_vmd_make_targets