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

gzclient: improve startup reliability #3338

Merged
merged 1 commit into from
Aug 14, 2023
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
36 changes: 30 additions & 6 deletions gazebo/gui/MainWindow.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include <functional>

#include <ignition/math/Pose3.hh>
#include <ignition/transport/Node.hh>
#include <sdf/sdf.hh>
#include <boost/algorithm/string.hpp>

Expand Down Expand Up @@ -362,8 +363,19 @@ void MainWindow::Init()
"/gazebo/world/modify",
&MainWindow::OnWorldModify, this);

this->dataPtr->requestMsg = msgs::CreateRequest("scene_info");
this->dataPtr->requestPub->Publish(*this->dataPtr->requestMsg);
// Get scene info from physics::World with ignition transport service
ignition::transport::Node node;
const std::string serviceName = "/scene_info";
std::vector<ignition::transport::ServicePublisher> publishers;
if (!node.ServiceInfo(serviceName, publishers) ||
!node.Request(serviceName, &MainWindow::OnSceneInfo, this))
{
gzwarn << "Ignition transport [" << serviceName << "] service call failed,"
<< " falling back to gazebo transport [scene_info] request."
<< std::endl;
this->dataPtr->requestMsg = msgs::CreateRequest("scene_info");
this->dataPtr->requestPub->Publish(*this->dataPtr->requestMsg);
}

gui::Events::mainWindowReady();
}
Expand Down Expand Up @@ -2150,8 +2162,19 @@ void MainWindow::OnResponse(ConstResponsePtr &_msg)

if (_msg->has_type() && _msg->type() == sceneMsg.GetTypeName())
{
sceneMsg.ParseFromString(_msg->serialized_data());
bool parseResult = sceneMsg.ParseFromString(_msg->serialized_data());
this->OnSceneInfo(sceneMsg, parseResult);
}

delete this->dataPtr->requestMsg;
this->dataPtr->requestMsg = nullptr;
}

/////////////////////////////////////////////////
void MainWindow::OnSceneInfo(const msgs::Scene &sceneMsg, const bool _result)
{
if (_result)
{
for (int i = 0; i < sceneMsg.model_size(); ++i)
{
this->dataPtr->entities[sceneMsg.model(i).name()] =
Expand All @@ -2177,9 +2200,10 @@ void MainWindow::OnResponse(ConstResponsePtr &_msg)
gui::Events::lightUpdate(sceneMsg.light(i));
}
}

delete this->dataPtr->requestMsg;
this->dataPtr->requestMsg = nullptr;
else
{
gzerr << "Error when requesting scene_info" << std::endl;
}
}

/////////////////////////////////////////////////
Expand Down
6 changes: 6 additions & 0 deletions gazebo/gui/MainWindow.hh
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,12 @@ namespace gazebo
/// \param[in] _msg Pointer to the light message.
private: void OnLight(ConstLightPtr &_msg);

/// \brief Called when the scene info service replies with the scene
/// message.
/// \param[in] _msg The message.
/// \param[in] _result Flag indicating if service call succeeded.
private: void OnSceneInfo(const msgs::Scene &_msg, const bool _result);

private: void OnResponse(ConstResponsePtr &_msg);
private: void OnWorldModify(ConstWorldModifyPtr &_msg);
private: void OnManipMode(const std::string &_mode);
Expand Down
Loading