mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-07-14 06:20:36 +08:00
Standalone px4 stable (#22467)
simulation gazebo: move the gazebo models to submodule, allow for operation with external gazebo instance, independent of startup order. Allows drag an drop of models from gazebo fuel. * rolled back updates Signed-off-by: frederik <frederik@auterion.com> * fixing empy Signed-off-by: frederik <frederik@auterion.com> * Update GZBridge.cpp to lower drop position Dropping from 1m leads to movement in the rc_cessna. Dropping from 0.5m leads to no movement. * Update STANDALONE env variable. * Update STANDALONE env_variable on GZBridge * Update src/modules/simulation/gz_bridge/GZBridge.cpp Co-authored-by: Daniel Agar <daniel@agar.ca> * test removal of x500 Signed-off-by: frederik <frederik.anilmarkus@gmail.com> * removed all models and reworked logic Signed-off-by: frederik <frederik.anilmarkus@gmail.com> * remove model path in set_sdf_filename Signed-off-by: frederik <frederik.anilmarkus@gmail.com> * filter resource path for world sdf Signed-off-by: frederik <frederik.anilmarkus@gmail.com> * updated structure to keep old make px4_sitl Signed-off-by: frederik <frederik.anilmarkus@gmail.com> * remove gz tools Signed-off-by: frederik <frederik.anilmarkus@gmail.com> * import gz as submodule and reverse rc simulator logic Signed-off-by: frederik <frederik.anilmarkus@gmail.com> * [gz-sim]: source GZ_SIM_RESOURCE_PATH only if PX4 starts gz server Signed-off-by: Beniamino Pozzan <beniamino.pozzan@gmail.com> * Typo fix --------- Signed-off-by: frederik <frederik@auterion.com> Signed-off-by: frederik <frederik.anilmarkus@gmail.com> Signed-off-by: Beniamino Pozzan <beniamino.pozzan@gmail.com> Co-authored-by: Daniel Agar <daniel@agar.ca> Co-authored-by: Beniamino Pozzan <beniamino.pozzan@gmail.com>
This commit is contained in:
@@ -72,14 +72,24 @@ if(gz-transport_FOUND)
|
||||
module.yaml
|
||||
)
|
||||
|
||||
file(GLOB gz_models
|
||||
LIST_DIRECTORIES true
|
||||
RELATIVE ${PX4_SOURCE_DIR}/Tools/simulation/gz/models
|
||||
${PX4_SOURCE_DIR}/Tools/simulation/gz/models/*
|
||||
px4_add_git_submodule(TARGET git_gz PATH "${PX4_SOURCE_DIR}/Tools/simulation/gz")
|
||||
include(ExternalProject)
|
||||
ExternalProject_Add(gz
|
||||
SOURCE_DIR ${PX4_SOURCE_DIR}/Tools/simulation/gz
|
||||
CMAKE_ARGS -DCMAKE_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX}
|
||||
BINARY_DIR ${PX4_BINARY_DIR}/build_gz
|
||||
INSTALL_COMMAND ""
|
||||
DEPENDS git_gz
|
||||
USES_TERMINAL_CONFIGURE true
|
||||
USES_TERMINAL_BUILD true
|
||||
EXCLUDE_FROM_ALL true
|
||||
BUILD_ALWAYS 1
|
||||
)
|
||||
|
||||
file(GLOB gz_worlds
|
||||
${PX4_SOURCE_DIR}/Tools/simulation/gz/worlds/*.sdf
|
||||
set(gz_worlds
|
||||
default
|
||||
windy
|
||||
baylands
|
||||
)
|
||||
|
||||
# find corresponding airframes
|
||||
@@ -100,56 +110,20 @@ if(gz-transport_FOUND)
|
||||
set(model_only)
|
||||
string(REGEX REPLACE ".*_gz_" "" model_only ${gz_airframe})
|
||||
|
||||
if(EXISTS "${PX4_SOURCE_DIR}/Tools/simulation/gz/models/${model_only}")
|
||||
|
||||
if((EXISTS "${PX4_SOURCE_DIR}/Tools/simulation/gz/models/${model_only}/model.sdf"))
|
||||
#message(STATUS "Ignition SDF file found for ${model_only}")
|
||||
else()
|
||||
message(WARNING "Ignition no SDF file found for ${model_only}")
|
||||
endif()
|
||||
|
||||
else()
|
||||
message(WARNING "model directory ${PX4_SOURCE_DIR}/Tools/simulation/gz/models/${model_only} not found")
|
||||
endif()
|
||||
endforeach()
|
||||
|
||||
foreach(model ${gz_models})
|
||||
|
||||
# match model to airframe
|
||||
set(airframe_model_only)
|
||||
set(airframe_sys_autostart)
|
||||
set(gz_airframe_found)
|
||||
foreach(gz_airframe IN LISTS gz_airframes)
|
||||
|
||||
string(REGEX REPLACE ".*_gz_" "" airframe_model_only ${gz_airframe})
|
||||
string(REGEX REPLACE "_gz_.*" "" airframe_sys_autostart ${gz_airframe})
|
||||
|
||||
if(model STREQUAL ${airframe_model_only})
|
||||
set(gz_airframe_found ${gz_airframe})
|
||||
break()
|
||||
endif()
|
||||
endforeach()
|
||||
|
||||
if(gz_airframe_found)
|
||||
#message(STATUS "gz model: ${model} (${airframe_model_only}), airframe: ${gz_airframe_found}, SYS_AUTOSTART: ${airframe_sys_autostart}")
|
||||
else()
|
||||
message(WARNING "gz missing model: ${model} (${airframe_model_only}), airframe: ${gz_airframe_found}, SYS_AUTOSTART: ${airframe_sys_autostart}")
|
||||
endif()
|
||||
|
||||
foreach(world ${gz_worlds})
|
||||
|
||||
get_filename_component("world_name" ${world} NAME_WE)
|
||||
|
||||
if(world_name STREQUAL "default")
|
||||
add_custom_target(gz_${model}
|
||||
COMMAND ${CMAKE_COMMAND} -E env PX4_SIM_MODEL=gz_${model} $<TARGET_FILE:px4>
|
||||
add_custom_target(gz_${model_only}
|
||||
COMMAND ${CMAKE_COMMAND} -E env PX4_SIM_MODEL=gz_${model_only} $<TARGET_FILE:px4>
|
||||
WORKING_DIRECTORY ${SITL_WORKING_DIR}
|
||||
USES_TERMINAL
|
||||
DEPENDS px4
|
||||
)
|
||||
else()
|
||||
add_custom_target(gz_${model}_${world_name}
|
||||
COMMAND ${CMAKE_COMMAND} -E env PX4_SIM_MODEL=gz_${model} PX4_GZ_WORLD=${world_name} $<TARGET_FILE:px4>
|
||||
add_custom_target(gz_${model_only}_${world_name}
|
||||
COMMAND ${CMAKE_COMMAND} -E env PX4_SIM_MODEL=gz_${model_only} PX4_GZ_WORLD=${world_name} $<TARGET_FILE:px4>
|
||||
WORKING_DIRECTORY ${SITL_WORKING_DIR}
|
||||
USES_TERMINAL
|
||||
DEPENDS px4
|
||||
@@ -157,7 +131,6 @@ if(gz-transport_FOUND)
|
||||
endif()
|
||||
endforeach()
|
||||
endforeach()
|
||||
|
||||
# PX4_GZ_MODELS, PX4_GZ_WORLDS, GZ_SIM_RESOURCE_PATH
|
||||
configure_file(gz_env.sh.in ${PX4_BINARY_DIR}/rootfs/gz_env.sh)
|
||||
|
||||
|
||||
@@ -98,7 +98,7 @@ int GZBridge::init()
|
||||
// If model position z is less equal than 0, move above floor to prevent floor glitching
|
||||
if (model_pose_v[2] <= 0.0) {
|
||||
PX4_INFO("Model position z is less or equal 0.0, moving upwards");
|
||||
model_pose_v[2] = 1.0;
|
||||
model_pose_v[2] = 0.5;
|
||||
}
|
||||
|
||||
gz::msgs::Pose *p = req.mutable_pose();
|
||||
@@ -122,15 +122,44 @@ int GZBridge::init()
|
||||
bool result;
|
||||
std::string create_service = "/world/" + _world_name + "/create";
|
||||
|
||||
if (_node.Request(create_service, req, 1000, rep, result)) {
|
||||
if (!rep.data() || !result) {
|
||||
PX4_ERR("EntityFactory service call failed");
|
||||
bool gz_called = false;
|
||||
// Check if PX4_GZ_STANDALONE has been set.
|
||||
char *standalone_val = std::getenv("PX4_GZ_STANDALONE");
|
||||
|
||||
if ((standalone_val != nullptr) && (std::strcmp(standalone_val, "1") == 0)) {
|
||||
// Check if Gazebo has been called and if not attempt to reconnect.
|
||||
while (gz_called == false) {
|
||||
if (_node.Request(create_service, req, 1000, rep, result)) {
|
||||
if (!rep.data() || !result) {
|
||||
PX4_ERR("EntityFactory service call failed");
|
||||
return PX4_ERROR;
|
||||
|
||||
} else {
|
||||
gz_called = true;
|
||||
}
|
||||
}
|
||||
|
||||
// If Gazebo has not been called, wait 2 seconds and try again.
|
||||
else {
|
||||
PX4_WARN("Service call timed out as Gazebo has not been detected.");
|
||||
system_usleep(2000000);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// If PX4_GZ_STANDALONE has been set, you can try to connect but GZ_SIM_RESOURCE_PATH needs to be set correctly to work.
|
||||
else {
|
||||
if (_node.Request(create_service, req, 1000, rep, result)) {
|
||||
if (!rep.data() || !result) {
|
||||
PX4_ERR("EntityFactory service call failed.");
|
||||
return PX4_ERROR;
|
||||
}
|
||||
|
||||
} else {
|
||||
PX4_ERR("Service call timed out. Check GZ_SIM_RESOURCE_PATH is set correctly.");
|
||||
return PX4_ERROR;
|
||||
}
|
||||
|
||||
} else {
|
||||
PX4_ERR("Service call timed out");
|
||||
return PX4_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user