From ae4cb2410001f0921b94ab7e608d5fedae72483a Mon Sep 17 00:00:00 2001 From: Daniel Agar Date: Wed, 4 Jan 2023 20:22:04 -0500 Subject: [PATCH] SITL flightgear make airframes simulator specific --- ...ectric => 1034_flightgear_rascal-electric} | 0 .../{1062_tf-r1 => 1062_flightgear_tf-r1} | 0 .../{17001_tf-g1 => 17001_flightgear_tf-g1} | 0 .../{17002_tf-g2 => 17002_flightgear_tf-g2} | 0 .../init.d-posix/airframes/CMakeLists.txt | 7 +- Tools/simulation/flightgear/sitl_run.sh | 2 +- .../sitl_targets_flightgear.cmake | 105 ++++++++++++------ 7 files changed, 78 insertions(+), 36 deletions(-) rename ROMFS/px4fmu_common/init.d-posix/airframes/{1034_rascal-electric => 1034_flightgear_rascal-electric} (100%) rename ROMFS/px4fmu_common/init.d-posix/airframes/{1062_tf-r1 => 1062_flightgear_tf-r1} (100%) rename ROMFS/px4fmu_common/init.d-posix/airframes/{17001_tf-g1 => 17001_flightgear_tf-g1} (100%) rename ROMFS/px4fmu_common/init.d-posix/airframes/{17002_tf-g2 => 17002_flightgear_tf-g2} (100%) diff --git a/ROMFS/px4fmu_common/init.d-posix/airframes/1034_rascal-electric b/ROMFS/px4fmu_common/init.d-posix/airframes/1034_flightgear_rascal-electric similarity index 100% rename from ROMFS/px4fmu_common/init.d-posix/airframes/1034_rascal-electric rename to ROMFS/px4fmu_common/init.d-posix/airframes/1034_flightgear_rascal-electric diff --git a/ROMFS/px4fmu_common/init.d-posix/airframes/1062_tf-r1 b/ROMFS/px4fmu_common/init.d-posix/airframes/1062_flightgear_tf-r1 similarity index 100% rename from ROMFS/px4fmu_common/init.d-posix/airframes/1062_tf-r1 rename to ROMFS/px4fmu_common/init.d-posix/airframes/1062_flightgear_tf-r1 diff --git a/ROMFS/px4fmu_common/init.d-posix/airframes/17001_tf-g1 b/ROMFS/px4fmu_common/init.d-posix/airframes/17001_flightgear_tf-g1 similarity index 100% rename from ROMFS/px4fmu_common/init.d-posix/airframes/17001_tf-g1 rename to ROMFS/px4fmu_common/init.d-posix/airframes/17001_flightgear_tf-g1 diff --git a/ROMFS/px4fmu_common/init.d-posix/airframes/17002_tf-g2 b/ROMFS/px4fmu_common/init.d-posix/airframes/17002_flightgear_tf-g2 similarity index 100% rename from ROMFS/px4fmu_common/init.d-posix/airframes/17002_tf-g2 rename to ROMFS/px4fmu_common/init.d-posix/airframes/17002_flightgear_tf-g2 diff --git a/ROMFS/px4fmu_common/init.d-posix/airframes/CMakeLists.txt b/ROMFS/px4fmu_common/init.d-posix/airframes/CMakeLists.txt index 09cc2126c1..102780e874 100644 --- a/ROMFS/px4fmu_common/init.d-posix/airframes/CMakeLists.txt +++ b/ROMFS/px4fmu_common/init.d-posix/airframes/CMakeLists.txt @@ -54,6 +54,7 @@ px4_add_romfs_files( 1031_plane_cam 1032_plane_catapult 1033_jsbsim_rascal + 1034_flightgear_rascal-electric 1035_techpod 1036_jsbsim_malolo 1037_believer @@ -66,7 +67,6 @@ px4_add_romfs_files( 1044_plane_lidar 1060_rover 1061_r1_rover - 1062_tf-r1 1070_boat 3010_jsbsim_quadrotor_x @@ -74,8 +74,6 @@ px4_add_romfs_files( 4001_x500 - 17001_tf-g1 - 17002_tf-g2 2507_cloudship 6011_typhoon_h480 @@ -84,4 +82,7 @@ px4_add_romfs_files( 10040_sihsim_quadx 10041_sihsim_airplane 10042_sihsim_xvert + + 17001_flightgear_tf-g1 + 17002_flightgear_tf-g2 ) diff --git a/Tools/simulation/flightgear/sitl_run.sh b/Tools/simulation/flightgear/sitl_run.sh index 5dc75c36c7..efed15d19d 100755 --- a/Tools/simulation/flightgear/sitl_run.sh +++ b/Tools/simulation/flightgear/sitl_run.sh @@ -22,7 +22,7 @@ echo build_path: $build_path rootfs="$build_path/rootfs" # this is the working directory mkdir -p "$rootfs" -export PX4_SIM_MODEL=${model} +export PX4_SIM_MODEL=flightgear_${model} echo "FG setup" cd "${src_path}/Tools/simulation/flightgear/flightgear_bridge/" diff --git a/src/modules/simulation/simulator_mavlink/sitl_targets_flightgear.cmake b/src/modules/simulation/simulator_mavlink/sitl_targets_flightgear.cmake index 9c5f09aeaf..809a988fb9 100644 --- a/src/modules/simulation/simulator_mavlink/sitl_targets_flightgear.cmake +++ b/src/modules/simulation/simulator_mavlink/sitl_targets_flightgear.cmake @@ -1,43 +1,84 @@ if(ENABLE_LOCKSTEP_SCHEDULER STREQUAL "no") - px4_add_git_submodule(TARGET git_flightgear_bridge PATH "${PX4_SOURCE_DIR}/Tools/simulation/flightgear/flightgear_bridge") + find_program(FGFS_PATH "fgfs") - include(ExternalProject) - ExternalProject_Add(flightgear_bridge - SOURCE_DIR ${PX4_SOURCE_DIR}/Tools/simulation/flightgear/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 - ) + if(FGFS_PATH) - # flighgear targets - set(models - rascal - rascal-electric - tf-g1 - tf-g2 - tf-r1 - ) + px4_add_git_submodule(TARGET git_flightgear_bridge PATH "${PX4_SOURCE_DIR}/Tools/simulation/flightgear/flightgear_bridge") - # default flightgear target - add_custom_target(flightgear - COMMAND ${PX4_SOURCE_DIR}/Tools/simulation/flightgear/sitl_run.sh $ "rascal" ${PX4_SOURCE_DIR} ${PX4_BINARY_DIR} - WORKING_DIRECTORY ${SITL_WORKING_DIR} - USES_TERMINAL - DEPENDS px4 flightgear_bridge - ) + include(ExternalProject) + ExternalProject_Add(flightgear_bridge + SOURCE_DIR ${PX4_SOURCE_DIR}/Tools/simulation/flightgear/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 + ) - foreach(model ${models}) - add_custom_target(flightgear_${model} - COMMAND ${PX4_SOURCE_DIR}/Tools/simulation/flightgear/sitl_run.sh $ ${model} ${PX4_SOURCE_DIR} ${PX4_BINARY_DIR} + # flighgear targets + set(models + rascal + rascal-electric + tf-g1 + tf-g2 + tf-r1 + ) + + # find corresponding airframes + file(GLOB flightgear_airframes + RELATIVE ${PX4_SOURCE_DIR}/ROMFS/px4fmu_common/init.d-posix/airframes + ${PX4_SOURCE_DIR}/ROMFS/px4fmu_common/init.d-posix/airframes/*_flightgear_* + ) + + # remove any .post files + foreach(flightgear_airframe IN LISTS flightgear_airframes) + if(flightgear_airframe MATCHES ".post") + list(REMOVE_ITEM flightgear_airframes ${flightgear_airframe}) + endif() + endforeach() + list(REMOVE_DUPLICATES flightgear_airframes) + + # default flightgear target + add_custom_target(flightgear + COMMAND ${PX4_SOURCE_DIR}/Tools/simulation/flightgear/sitl_run.sh $ "rascal" ${PX4_SOURCE_DIR} ${PX4_BINARY_DIR} WORKING_DIRECTORY ${SITL_WORKING_DIR} USES_TERMINAL DEPENDS px4 flightgear_bridge ) - endforeach() + + foreach(model ${models}) + + # match model to airframe + set(airframe_model_only) + set(airframe_sys_autostart) + set(flightgear_airframe_found) + foreach(flightgear_airframe IN LISTS flightgear_airframes) + + string(REGEX REPLACE ".*_flightgear_" "" airframe_model_only ${flightgear_airframe}) + string(REGEX REPLACE "_flightgear_.*" "" airframe_sys_autostart ${flightgear_airframe}) + + if(model STREQUAL ${airframe_model_only}) + set(flightgear_airframe_found ${flightgear_airframe}) + break() + endif() + endforeach() + + if(flightgear_airframe_found) + #message(STATUS "flightgear model: ${model} (${airframe_model_only}), airframe: ${flightgear_airframe_found}, SYS_AUTOSTART: ${airframe_sys_autostart}") + else() + message(WARNING "flightgear missing model: ${model} (${airframe_model_only}), airframe: ${flightgear_airframe_found}, SYS_AUTOSTART: ${airframe_sys_autostart}") + endif() + + add_custom_target(flightgear_${model} + COMMAND ${PX4_SOURCE_DIR}/Tools/simulation/flightgear/sitl_run.sh $ ${model} ${PX4_SOURCE_DIR} ${PX4_BINARY_DIR} + WORKING_DIRECTORY ${SITL_WORKING_DIR} + USES_TERMINAL + DEPENDS px4 flightgear_bridge + ) + endforeach() + endif() endif()