mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-11-24 13:36:37 +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:
co-authored by
Daniel Agar
Beniamino Pozzan
parent
6ffc5a9eae
commit
65e53286b6
@@ -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