Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gazebo Simulation Enablement #20319

Merged
merged 5 commits into from
Sep 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -218,10 +218,10 @@
"options": {
"cwd": "${workspaceFolder}",
"env": {
"IGN_GAZEBO_RESOURCE_PATH": "${workspaceFolder}/Tools/simulation/ignition/models",
"IGN_GAZEBO_RESOURCE_PATH": "${workspaceFolder}/Tools/simulation/gz/models",
}
},
"command": "ign gazebo -v 4 -r ${workspaceFolder}/Tools/simulation/ignition/worlds/${input:ignWorld}.sdf",
"command": "ign gazebo -v 4 -r ${workspaceFolder}/Tools/simulation/gz/worlds/${input:gzWorld}.sdf",
"isBackground": true,
"presentation": {
"echo": true,
Expand Down Expand Up @@ -342,8 +342,8 @@
"inputs": [
{
"type": "pickString",
"id": "ignWorld",
"description": "Ignition world",
"id": "gzWorld",
"description": "gz world",
"options": [
"default"
],
Expand Down
30 changes: 15 additions & 15 deletions ROMFS/px4fmu_common/init.d-posix/airframes/4001_x500
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
#!/bin/sh
#
# @name Ignition Gazebo X3
# @name Gazebo x500
#
# @type Quadrotor
#

. ${R}etc/init.d/rc.mc_defaults

PX4_SIMULATOR=${PX4_SIMULATOR:=ignition}
PX4_SIMULATOR=${PX4_SIMULATOR:=gz}
PX4_GZ_WORLD=${PX4_GZ_WORLD:=default}
PX4_SIM_MODEL=${PX4_SIM_MODEL:=x500}
PX4_SIM_WORLD=${PX4_SIM_WORLD:=default}

param set-default CA_AIRFRAME 0
param set-default CA_ROTOR_COUNT 4
Expand All @@ -30,19 +30,19 @@ param set-default CA_ROTOR3_PX -0.13
param set-default CA_ROTOR3_PY 0.20
param set-default CA_ROTOR3_KM -0.05

param set-default SIM_IGN_FUNC1 101
param set-default SIM_IGN_FUNC2 102
param set-default SIM_IGN_FUNC3 103
param set-default SIM_IGN_FUNC4 104
param set-default SIM_GZ_FUNC1 101
param set-default SIM_GZ_FUNC2 102
param set-default SIM_GZ_FUNC3 103
param set-default SIM_GZ_FUNC4 104

param set-default SIM_IGN_MIN1 150
param set-default SIM_IGN_MIN2 150
param set-default SIM_IGN_MIN3 150
param set-default SIM_IGN_MIN4 150
param set-default SIM_GZ_MIN1 150
param set-default SIM_GZ_MIN2 150
param set-default SIM_GZ_MIN3 150
param set-default SIM_GZ_MIN4 150

param set-default SIM_IGN_MAX1 1000
param set-default SIM_IGN_MAX2 1000
param set-default SIM_IGN_MAX3 1000
param set-default SIM_IGN_MAX4 1000
param set-default SIM_GZ_MAX1 1000
param set-default SIM_GZ_MAX2 1000
param set-default SIM_GZ_MAX3 1000
param set-default SIM_GZ_MAX4 1000

param set-default MPC_THR_HOVER 0.60
71 changes: 51 additions & 20 deletions ROMFS/px4fmu_common/init.d-posix/px4-rc.simulator
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ if [ "$PX4_SIMULATOR" = "sihsim" ] || [ "$(param show -q SYS_AUTOSTART)" -eq "0"
exit 1
fi

elif [ "$PX4_SIMULATOR" = "ignition" ]; then
elif [ "$PX4_SIMULATOR" = "gz" ]; then

# source generated gazebo_env.sh for IGN_GAZEBO_RESOURCE_PATH
if [ -f gazebo_env.sh ]; then
Expand All @@ -26,43 +26,71 @@ elif [ "$PX4_SIMULATOR" = "ignition" ]; then
. ../gazebo_env.sh
fi

ign_world=$( ign topic -l | grep -m 1 -e "/world/.*/clock" | sed 's/\/world\///g; s/\/clock//g' )
# shellcheck disable=SC2236
if [ ! -z $PX4_GZ_VERBOSE ]; then
if [ "$PX4_GZ_VERBOSE" -le "4" ] && [ "$PX4_GZ_VERBOSE" -ge "1" ]; then
gz_verbose=$PX4_GZ_VERBOSE
else
gz_verbose=4
echo "WARN [init] PX4_GZ_VERBOSE was passed: $PX4_GZ_VERBOSE, not in range [1,4], defaulting to: $gz_verbose."
fi
echo "INFO [init] PX4_GZ_VERBOSE set to $gz_verbose."
else
gz_verbose=1
echo "INFO [init] PX4_GZ_VERBOSE not explicitly set, defaulting to: $gz_verbose."
fi

if [ -z $ign_world ]; then
gz_world=$( ign topic -l | grep -m 1 -e "/world/.*/clock" | sed 's/\/world\///g; s/\/clock//g' )

# starting ign gazebo with ${PX4_SIM_WORLD} world
echo "INFO [init] starting ign gazebo"
if [ -z $gz_world ]; then

ign gazebo --verbose=1 -r -s "${PX4_IGN_GAZEBO_WORLDS}/${PX4_SIM_WORLD}.sdf" &
# starting ign gazebo with ${PX4_GZ_WORLD} world
echo "INFO [init] starting ign gazebo"
# shellcheck disable=SC2153
ign gazebo --verbose=$gz_verbose -r -s "${PX4_GZ_WORLDS}/${PX4_GZ_WORLD}.sdf" &

if [ -z $HEADLESS ]; then
# HEADLESS not set, starting ign gazebo gui
ign gazebo -g &
fi
else
echo "INFO [init] ign gazebo already running world: $ign_world"
PX4_SIM_WORLD=$ign_world
echo "INFO [init] ign gazebo already running world: $gz_world"
PX4_GZ_WORLD=$gz_world
fi

if [ -z $PX4_IGN_MODEL_POSE ]; then
# start ignition bridge without pose arg.
echo "WARN [init] PX4_IGN_MODEL_POSE not set, spawning at origin."
if simulator_ignition_bridge start -m "${PX4_SIM_MODEL}" -w "${PX4_SIM_WORLD}"; then
# shellcheck disable=SC2236
if [ ! -z $PX4_GZ_MODEL ] && [ -z $PX4_GZ_MODEL_NAME ]; then

# shellcheck disable=SC2236
if [ ! -z $PX4_GZ_MODEL_POSE ]; then
# Clean potential input line formatting.
model_pose="$( echo ${PX4_GZ_MODEL_POSE} | sed -e 's/^[ \t]*//; s/[ \t]*$//; s/,/ /g; s/ / /g; s/ /,/g' )"
echo "INFO [init] PX4_GZ_MODEL_POSE set, spawning at: ${model_pose}"
else
echo "WARN [init] PX4_GZ_MODEL_POSE not set, spawning at origin."
model_pose="0,0,0,0,0,0"
fi
# start gz bridge with pose arg.
if gz_bridge start -p "${model_pose}" -m "${PX4_GZ_MODEL}" -w "${PX4_GZ_WORLD}" -i "${px4_instance}"; then
sensor_baro_sim start
sensor_gps_sim start
sensor_mag_sim start
else
echo "ERROR [init] ign gazebo failed to start"
exit 1
fi
else

# Clean potential input line formatting.
model_pose="$( echo ${PX4_IGN_MODEL_POSE} | sed -e 's/^[ \t]*//; s/[ \t]*$//; s/,/ /g; s/ / /g; s/ /,/g' )"
echo "INFO [init] PX4_IGN_MODEL_POSE set, spawning at: ${model_pose}"

# start ignition bridge with pose arg.
if simulator_ignition_bridge start -p "${model_pose}" -m "${PX4_SIM_MODEL}" -w "${PX4_SIM_WORLD}"; then
elif [ ! -z $PX4_GZ_MODEL_NAME ] && [ -z $PX4_GZ_MODEL ]; then
if gz_bridge start -n "${PX4_GZ_MODEL_NAME}" -w "${PX4_GZ_WORLD}"; then
sensor_baro_sim start
sensor_gps_sim start
sensor_mag_sim start
else
echo "ERROR [init] ign gazebo failed to start"
exit 1
fi
elif [ ! -z $PX4_SIM_MODEL ] && [ -z $PX4_GZ_MODEL_NAME ] && [ -z $PX4_GZ_MODEL ]; then
echo "WARN [init] PX4_GZ_MODEL_NAME or PX4_GZ_MODEL not set using PX4_SIM_MODEL."
if gz_bridge start -m "${PX4_SIM_MODEL}" -w "${PX4_GZ_WORLD}" -i "${px4_instance}"; then
sensor_baro_sim start
sensor_gps_sim start
sensor_mag_sim start
Expand All @@ -71,6 +99,9 @@ elif [ "$PX4_SIMULATOR" = "ignition" ]; then
exit 1
fi

else
echo "ERROR [init] failed to pass only PX4_GZ_MODEL_NAME or PX4_GZ_MODEL"
exit 1
fi

else
Expand Down
11 changes: 10 additions & 1 deletion Tools/setup/ubuntu.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ set -e
INSTALL_NUTTX="true"
INSTALL_SIM="true"
INSTALL_ARCH=`uname -m`
INSTALL_SIM_JAMMY="false"

# Parse arguments
for arg in "$@"
Expand All @@ -28,6 +29,10 @@ do
INSTALL_SIM="false"
fi

if [[ $arg == "--sim_jammy" ]]; then
INSTALL_SIM_JAMMY="true"
fi

done

# detect if running in docker
Expand Down Expand Up @@ -67,6 +72,10 @@ elif [[ "${UBUNTU_RELEASE}" == "18.04" ]]; then
echo "Ubuntu 18.04"
elif [[ "${UBUNTU_RELEASE}" == "20.04" ]]; then
echo "Ubuntu 20.04"
elif [[ "${UBUNTU_RELEASE}" == "22.04" ]]; then
echo "Ubuntu 22.04, simulation build off by default."
echo "Use --sim_jammy to enable simulation build."
INSTALL_SIM=$INSTALL_SIM_JAMMY
fi


Expand Down Expand Up @@ -146,7 +155,7 @@ if [[ $INSTALL_NUTTX == "true" ]]; then
util-linux \
vim-common \
;
if [[ "${UBUNTU_RELEASE}" == "20.04" ]]; then
if [[ "${UBUNTU_RELEASE}" == "20.04" || "${UBUNTU_RELEASE}" == "22.04" ]]; then
sudo DEBIAN_FRONTEND=noninteractive apt-get -y --quiet --no-install-recommends install \
kconfig-frontends \
;
Expand Down
17 changes: 17 additions & 0 deletions Tools/simulation/gz/models/x500-Depth/model.sdf
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<sdf version='1.9'>
<model name='x500-Depth'>
<include merge='true'>
<uri>https://fuel.gazebosim.org/1.0/RudisLaboratories/models/x500-Base</uri>
</include>
<include merge='true'>
<uri>https://fuel.gazebosim.org/1.0/RudisLaboratories/models/OakD-Lite</uri>
<pose>.12 .03 .242 0 0 0</pose>
</include>
<joint name="CameraJoint" type="fixed">
<parent>base_link</parent>
<child>OakD-Lite/base_link</child>
<pose relative_to="base_link">.12 .03 .242 0 0 0</pose>
</joint>
</model>
</sdf>
8 changes: 8 additions & 0 deletions Tools/simulation/gz/models/x500/model.sdf
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<sdf version='1.9'>
<model name='x500'>
<include merge='true'>
<uri>https://fuel.gazebosim.org/1.0/RudisLaboratories/models/x500-Base</uri>
</include>
</model>
</sdf>
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading