Skip to content

Commit

Permalink
gzclient: improve startup reliability (#3338)
Browse files Browse the repository at this point in the history
MainWindow: try getting scene info from the service,
which is more reliable than the request / response topics.
Fall back to using the request / response topics if the
service is not available or the call fails.

Signed-off-by: Steve Peters <[email protected]>
  • Loading branch information
scpeters authored Aug 14, 2023
1 parent fae595f commit af7d327
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 6 deletions.
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

0 comments on commit af7d327

Please sign in to comment.