From eef6da16d62c2e6b872230465d6a1419a4f2d909 Mon Sep 17 00:00:00 2001 From: Balduin Date: Mon, 3 Mar 2025 10:21:57 +0100 Subject: [PATCH] move platform to own world in Tools/simulation/gz submodule. for now I am pointing it to the PR branch moving_platform_world which contains the moving_platform world. The world contains the platform so we remove the platform definition and the code that added it dynamically. Also the env var GZ_MOVING_PLATFORM is now gone -- world name can be set with existing env var PX4_GZ_WORLD. --- .gitmodules | 2 +- Tools/simulation/gz | 2 +- src/modules/simulation/gz_bridge/GZBridge.cpp | 106 +----------------- 3 files changed, 4 insertions(+), 106 deletions(-) diff --git a/.gitmodules b/.gitmodules index 1ebafcf5a4..eb419cfb1b 100644 --- a/.gitmodules +++ b/.gitmodules @@ -75,7 +75,7 @@ [submodule "Tools/simulation/gz"] path = Tools/simulation/gz url = https://github.com/PX4/PX4-gazebo-models.git - branch = main + branch = moving_platform_world [submodule "boards/modalai/voxl2/libfc-sensor-api"] path = boards/modalai/voxl2/libfc-sensor-api url = https://gitlab.com/voxl-public/voxl-sdk/core-libs/libfc-sensor-api.git diff --git a/Tools/simulation/gz b/Tools/simulation/gz index 183cbee9e2..f9204722ea 160000 --- a/Tools/simulation/gz +++ b/Tools/simulation/gz @@ -1 +1 @@ -Subproject commit 183cbee9e2250d1ca5517cd76c5d9a7e47cc0b7a +Subproject commit f9204722eaaa5b95dbe99e32723653731fe46434 diff --git a/src/modules/simulation/gz_bridge/GZBridge.cpp b/src/modules/simulation/gz_bridge/GZBridge.cpp index 3e54674e41..13a1729839 100644 --- a/src/modules/simulation/gz_bridge/GZBridge.cpp +++ b/src/modules/simulation/gz_bridge/GZBridge.cpp @@ -69,8 +69,8 @@ GZBridge::~GZBridge() int GZBridge::init() { // TODO document this somehow - const char *moving_platform = std::getenv("GZ_MOVING_PLATFORM"); - _has_platform = ((moving_platform != nullptr) && (std::strcmp(moving_platform, "1") == 0)); + // const char *moving_platform = std::getenv("GZ_MOVING_PLATFORM"); + _has_platform = 0 == _world_name.compare("moving_platform"); if (!_model_sim.empty()) { @@ -184,10 +184,6 @@ int GZBridge::init() if (_has_platform) { - if (!createMovingPlatform()) { - return PX4_ERROR; - } - // Initialise publisher for setPlatformVelocity // TODO less hardcoding of these topic strings std::string cmd_vel_topic = "/model/flat_platform/link/platform_link/cmd_vel"; @@ -321,104 +317,6 @@ void GZBridge::setPlatformVelocity(float vx, float vy, float vz) // TODO unified error handling? PX4_ERR at the lowest level or return success bool? } -bool GZBridge::createMovingPlatform() -{ - - // moving platform to launch & land from. - - gz::msgs::EntityFactory req{}; - - // https://gazebosim.org/api/gazebo/6/entity_creation.html - // This just as a first hacky quick solution. - // Ultimately we should probably put this in the PX4-gazebo-models repo - std::string platform_sdf = R""""( - - - - - - - - - - 5 5 0.1 - - - - 0.3 0.3 0.3 1 - 0.3 0.3 0.3 1 - 0.1 0.1 0.1 1 - - - - - - - - 5 5 0.1 - shit - - - - - - 1 - - 1 - 1 - 1 - - - - - - 1 - 30 - - - - - - - platform_link - - - - - )""""; - - - req.set_sdf(platform_sdf); - - // base dir: Tools/simulation/gz/models - // req.set_sdf_filename("platform.sdf"); - - req.set_allow_renaming(false); - - // Set position & orientation. Origin hardcoded -- adapt to model pose? - gz::msgs::Pose *p = req.mutable_pose(); - gz::msgs::Vector3d *position = p->mutable_position(); - position->set_x(0.); - position->set_y(0.); - position->set_z(0.05); - - gz::msgs::Quaternion *orientation = p->mutable_orientation(); - orientation->set_x(0.); - orientation->set_y(0.); - orientation->set_z(0.); - orientation->set_w(1.); - - std::string create_service = "/world/" + _world_name + "/create"; - - if (!callEntityFactoryService(create_service, req)) { - PX4_ERR("EntityFactory service call failed (platform)"); - return false; - } - - return true; -} bool GZBridge::setPlatformPose(gz::msgs::Pose &pose) {