From 58060b23d9088ac9365f98df299dffaac8c59da4 Mon Sep 17 00:00:00 2001 From: JaeyoungLim Date: Tue, 20 Jul 2021 01:59:41 +0200 Subject: [PATCH] Add ignition gazebo support for PX4 Software-In-The-Loop simulations This commit adds SITL support for ignition gazebo. Ignition gazebo is a replacement for the "classic" gazebo for future applications. The simulation can be run as the following ``` make px4_sitl ignition ``` --- .gitmodules | 3 +++ Tools/setup_ignition.bash | 23 +++++++++++++++++++++++ Tools/simulation-ignition | 1 + Tools/sitl_run.sh | 4 ++++ platforms/posix/cmake/sitl_target.cmake | 17 +++++++++++++++++ 5 files changed, 48 insertions(+) create mode 100644 Tools/setup_ignition.bash create mode 160000 Tools/simulation-ignition diff --git a/.gitmodules b/.gitmodules index 131e3a40e1..e7fda61a65 100644 --- a/.gitmodules +++ b/.gitmodules @@ -63,3 +63,6 @@ [submodule "src/lib/events/libevents"] path = src/lib/events/libevents url = https://github.com/mavlink/libevents.git +[submodule "Tools/simulation-ignition"] + path = Tools/simulation-ignition + url = https://github.com/Auterion/px4-simulation-ignition.git \ No newline at end of file diff --git a/Tools/setup_ignition.bash b/Tools/setup_ignition.bash new file mode 100644 index 0000000000..7def58d358 --- /dev/null +++ b/Tools/setup_ignition.bash @@ -0,0 +1,23 @@ +#!/bin/bash +# +# Setup environment to make PX4 visible to Gazebo. +# +# Note, this is not necessary if using a ROS catkin workspace with the px4 +# package as the paths are exported. +# +# License: according to LICENSE.md in the root directory of the PX4 Firmware repository + +if [ "$#" != 2 ]; then + echo -e "usage: source setup_gazebo.bash src_dir build_dir\n" + return 1 +fi + +SRC_DIR=$1 +BUILD_DIR=$2 + +# setup Gazebo env and update package path +export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:${SRC_DIR}/build/px4_sitl_default/build_ign_gazebo +export IGN_GAZEBO_SYSTEM_PLUGIN_PATH=$IGN_GAZEBO_SYSTEM_PLUGIN_PATH:${SRC_DIR}/build/px4_sitl_default/build_ign_gazebo +export IGN_GAZEBO_RESOURCE_PATH=$IGN_GAZEBO_RESOURCE_PATH:${SRC_DIR}/Tools/simulation-ignition/models + +echo -e "LD_LIBRARY_PATH $LD_LIBRARY_PATH" diff --git a/Tools/simulation-ignition b/Tools/simulation-ignition new file mode 160000 index 0000000000..794a8dc505 --- /dev/null +++ b/Tools/simulation-ignition @@ -0,0 +1 @@ +Subproject commit 794a8dc50538e3476f6d874744d3d3ef24da594d diff --git a/Tools/sitl_run.sh b/Tools/sitl_run.sh index 9f36364ab2..5cd3e377b6 100755 --- a/Tools/sitl_run.sh +++ b/Tools/sitl_run.sh @@ -177,6 +177,10 @@ elif [ "$program" == "gazebo" ] && [ ! -n "$no_sim" ]; then echo "You need to have gazebo simulator installed!" exit 1 fi +elif [ "$program" == "ignition" ] && [ -z "$no_sim" ]; then + echo "Ignition Gazebo" + source "$src_path/Tools/setup_ignition.bash" "${src_path}" "${build_path}" + ign gazebo -r "${src_path}/Tools/simulation-ignition/worlds/ignition.world"& elif [ "$program" == "flightgear" ] && [ -z "$no_sim" ]; then echo "FG setup" cd "${src_path}/Tools/flightgear_bridge/" diff --git a/platforms/posix/cmake/sitl_target.cmake b/platforms/posix/cmake/sitl_target.cmake index 16392b2627..6c95482d69 100644 --- a/platforms/posix/cmake/sitl_target.cmake +++ b/platforms/posix/cmake/sitl_target.cmake @@ -48,6 +48,20 @@ ExternalProject_Add(sitl_gazebo BUILD_COMMAND ${CMAKE_COMMAND} --build -- -j ${build_cores} ) +px4_add_git_submodule(TARGET git_ign_gazebo PATH "${PX4_SOURCE_DIR}/Tools/simulation-ignition") +ExternalProject_Add(simulation-ignition + SOURCE_DIR ${PX4_SOURCE_DIR}/Tools/simulation-ignition + CMAKE_ARGS -DCMAKE_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX} + BINARY_DIR ${PX4_BINARY_DIR}/build_ign_gazebo + INSTALL_COMMAND "" + DEPENDS git_ign_gazebo + USES_TERMINAL_CONFIGURE true + USES_TERMINAL_BUILD true + EXCLUDE_FROM_ALL true + BUILD_ALWAYS 1 + BUILD_COMMAND ${CMAKE_COMMAND} --build -- -j ${build_cores} +) + ExternalProject_Add(mavsdk_tests SOURCE_DIR ${PX4_SOURCE_DIR}/test/mavsdk_tests CMAKE_ARGS -DCMAKE_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX} @@ -90,6 +104,7 @@ set(viewers none jmavsim gazebo + ignition ) set(debuggers @@ -179,6 +194,8 @@ foreach(viewer ${viewers}) add_dependencies(${_targ_name} px4 sitl_gazebo) elseif(viewer STREQUAL "jmavsim") add_dependencies(${_targ_name} px4 git_jmavsim) + elseif(viewer STREQUAL "ignition") + add_dependencies(${_targ_name} px4 simulation-ignition) endif() else() if(viewer STREQUAL "gazebo")