forked from PX4/PX4-Autopilot
-
Notifications
You must be signed in to change notification settings - Fork 13
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
Support for running simulation with gz sim in hitl mode #729
Merged
+138
−0
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -91,3 +91,6 @@ | |
[submodule "boards/ssrc/saluki-nxp93"] | ||
path = boards/ssrc/saluki-nxp93 | ||
url = [email protected]:tiiuae/saluki-nxp93.git | ||
[submodule "Tools/simulation/gz/plugins/px4-gzsim-plugins"] | ||
path = Tools/simulation/gz/plugins/px4-gzsim-plugins | ||
url = https://github.com/tiiuae/px4-gzsim-plugins.git |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
#!/bin/bash | ||
|
||
#example for run | ||
#./Tools/simulation/gz/hitl_run.sh x500/model_hitl.sdf | ||
|
||
MODEL_PATH=$1 | ||
|
||
if [ -z $MODEL_PATH ]; then | ||
echo "You should specify a path to the using model" | ||
echo "./Tools/simulation/gz/hitl_run.sh x500/model_hitl.sdf" | ||
exit | ||
fi | ||
|
||
if [ ! -f $(pwd)/build/px4_sitl_default/rootfs/gz_env.sh ]; then | ||
echo "You should build px4_sitl_default" | ||
echo "make px4_sitl_default" | ||
exit | ||
fi | ||
|
||
source $(pwd)/build/px4_sitl_default/rootfs/gz_env.sh | ||
|
||
if [ ! -f $GZ_SIM_SYSTEM_PLUGIN_PATH/libmavlink_hitl_gazebosim.so ]; then | ||
echo "You should build gz-sim" | ||
echo "make px4_sitl gz-sim" | ||
exit | ||
fi | ||
|
||
spawn_model() { | ||
sleep 5 | ||
MODEL=${PX4_GZ_MODELS}/${MODEL_PATH} | ||
NAME="HITL_Drone" | ||
REQUEST="sdf_filename: \"${MODEL}\", name: \"${NAME}\" pose: {position: {x: 1.01, y: 0.98, z: 0.83}}" | ||
gz service -s /world/default/create \ | ||
--reqtype gz.msgs.EntityFactory \ | ||
--reptype gz.msgs.Boolean \ | ||
--timeout 1000 \ | ||
--req "`echo $REQUEST`" | ||
} | ||
|
||
spawn_model & | ||
|
||
WORD_PATH="${PX4_GZ_WORLDS}/default.sdf" | ||
gz sim ${WORD_PATH} -r |
18 changes: 18 additions & 0 deletions
18
Tools/simulation/gz/models/ssrc_holybro_x500/model_hitl.sdf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<sdf version='1.9'> | ||
<model name='ssrc_holybro_x500_hitl'> | ||
<include merge='true'> | ||
<uri>model://ssrc_holybro_x500</uri> | ||
</include> | ||
<plugin filename="libmavlink_hitl_gazebosim.so" name="mavlink_interface::GazeboMavlinkInterface"> | ||
<robotNamespace/> | ||
<imuSubTopic>/link/base_link/sensor/imu_sensor/imu</imuSubTopic> | ||
<poseSubTopic>/pose/info</poseSubTopic> | ||
<mavlink_addr>192.168.200.101</mavlink_addr> | ||
<mavlink_udp_local_port>14542</mavlink_udp_local_port> | ||
<mavlink_udp_remote_port>14543</mavlink_udp_remote_port> | ||
<mavlink_tcp_port>4560</mavlink_tcp_port> | ||
<use_tcp>0</use_tcp> | ||
</plugin> | ||
</model> | ||
</sdf> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<sdf version='1.9'> | ||
<model name='x500_hitl'> | ||
<include merge='true'> | ||
<uri>model://x500</uri> | ||
</include> | ||
<plugin filename="libmavlink_hitl_gazebosim.so" name="mavlink_interface::GazeboMavlinkInterface"> | ||
<robotNamespace/> | ||
<imuSubTopic>/link/base_link/sensor/imu_sensor/imu</imuSubTopic> | ||
<poseSubTopic>/pose/info</poseSubTopic> | ||
<mavlink_addr>192.168.0.3</mavlink_addr> | ||
<mavlink_udp_local_port>14542</mavlink_udp_local_port> | ||
<mavlink_udp_remote_port>14543</mavlink_udp_remote_port> | ||
<mavlink_tcp_port>4560</mavlink_tcp_port> | ||
<use_tcp>0</use_tcp> | ||
</plugin> | ||
</model> | ||
</sdf> |
Submodule px4-gzsim-plugins
added at
f2da22
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
src/modules/simulation/simulator_mavlink/sitl_targets_gz-sim.cmake
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
set(GAZEBO_VERSION 8) | ||
|
||
find_package(gz-sim8 QUIET) | ||
|
||
if(gz-sim8_FOUND) | ||
|
||
# Estimate an appropriate number of parallel jobs | ||
cmake_host_system_information(RESULT AVAILABLE_PHYSICAL_MEMORY QUERY AVAILABLE_PHYSICAL_MEMORY) | ||
cmake_host_system_information(RESULT NUMBER_OF_LOGICAL_CORES QUERY NUMBER_OF_LOGICAL_CORES) | ||
|
||
set(parallel_jobs 1) | ||
|
||
if(NOT NUMBER_OF_LOGICAL_CORES) | ||
include(ProcessorCount) | ||
ProcessorCount(NUMBER_OF_LOGICAL_CORES) | ||
endif() | ||
|
||
if(NOT AVAILABLE_PHYSICAL_MEMORY AND NUMBER_OF_LOGICAL_CORES GREATER_EQUAL 4) | ||
# Memory estimate unavailable, use N-2 jobs | ||
math(EXPR parallel_jobs "${NUMBER_OF_LOGICAL_CORES} - 2") | ||
endif() | ||
|
||
if(AVAILABLE_PHYSICAL_MEMORY) | ||
# Allow an additional job for every 1.5GB of available physical memory | ||
math(EXPR parallel_jobs "${AVAILABLE_PHYSICAL_MEMORY}/(3*1024/2)") | ||
else() | ||
set(AVAILABLE_PHYSICAL_MEMORY "?") | ||
endif() | ||
|
||
if(parallel_jobs GREATER NUMBER_OF_LOGICAL_CORES) | ||
set(parallel_jobs ${NUMBER_OF_LOGICAL_CORES}) | ||
endif() | ||
|
||
if(parallel_jobs LESS 1) | ||
set(parallel_jobs 1) | ||
endif() | ||
|
||
include(ExternalProject) | ||
|
||
ExternalProject_Add(gz-sim | ||
SOURCE_DIR ${PX4_SOURCE_DIR}/Tools/simulation/gz/plugins/px4-gzsim-plugins/ | ||
BINARY_DIR ${PX4_BINARY_DIR}/build_gz-sim_plugins | ||
INSTALL_COMMAND "" | ||
DEPENDS mavlink_c_generate | ||
USES_TERMINAL_CONFIGURE true | ||
USES_TERMINAL_BUILD true | ||
EXCLUDE_FROM_ALL true | ||
BUILD_ALWAYS 1 | ||
BUILD_COMMAND ${CMAKE_COMMAND} --build <BINARY_DIR> -- -j ${parallel_jobs} | ||
) | ||
endif() | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are these mavlink instances (addr and ports) defined some script to start udp mavlink automatically? Or is it meant to be so that mavlink instance is configured manually via parameters or started from command line?
There are some SD-card scripts in px4-firmware/ssrc_config folder to configure HITL mavlink instance to start automatically.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, there are. For example this is for salukiV2 https://github.com/tiiuae/saluki-v2/blob/42cbe653acda38e66acd6e4ee7c6da7ca38930f4/init/rc.board_mavlink
There is same for salukiV3
https://github.com/tiiuae/saluki-v3/blob/a0cd5b9119e392e7d9c910a48df91ce05cbc6f36/init/rc.board_mavlink