Gazebo | Ignition | Community
Ask Your Question

What is the topic ~/world_stats?

asked 2015-03-11 19:58:14 -0500

winston gravatar image

I am following this tutorial . It teaches me to write a program to listen on the topic ~/worldstats. I did and it worked. However, when I run $ gz topic -l, I cannot find a topic named ~/worldstats. So what is ~/world_stats? and what does the tilde '~' mean here? And what is 'ConstWorldStatisticsPtr'?

The following is the listener.cpp files for your reference:

#include <gazebo/transport/transport.hh>
#include <gazebo/msgs/msgs.hh>
#include <gazebo/gazebo.hh>

#include <iostream>

// Function is called everytime a message is received.
void cb(ConstWorldStatisticsPtr &_msg)
  // Dump the message contents to stdout.
  std::cout << _msg->DebugString();

int main(int _argc, char **_argv)
  // Load gazebo
  gazebo::setupClient(_argc, _argv);

  // Create our node for communication
  gazebo::transport::NodePtr node(new gazebo::transport::Node());

  // Listen to Gazebo world_stats topic
  gazebo::transport::SubscriberPtr sub = node->Subscribe("~/world_stats", cb);

  // Busy wait loop...replace with your own code as needed.
  while (true)

  // Make sure to shut everything down.
edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2015-03-21 12:57:01 -0500

chapulina gravatar image

~/world_stats gives you statistics about the world, such as the time elapsed and the paused state.

  • The type of the messages being published is gazebo::msgs::WorldStatistics. Here you can see all the message fields. ConstWorldStatisticsPtr is the same as boost::shared_ptr<const gazebo::msgs::WorldStatistics>.

  • The tilde ~ is shorthand for the default world. If you're running the default world, when you do $ gz topic -l, you'll see a list of topics all starting with /gazebo/default and one of them is /gazebo/default/world_stats, which corresponds to the ~/world_stats you're subscribing to.

  • You can run $ gz topic -e /gazebo/default/world_stats, to see all fields of the message printed out as the simulation is running.

edit flag offensive delete link more


great! but who publish the ~/world_stats? i did not find it in the source code. thanks

Lays gravatar imageLays ( 2019-08-18 22:03:06 -0500 )edit

Question Tools


Asked: 2015-03-11 19:58:14 -0500

Seen: 1,645 times

Last updated: Mar 21 '15