Tutorials/beginner/topics

Gazebo communicates on TCP/IP sockets, which allows separate programs to interface with Gazebo. Boost ASIO is used by Gazebo to manage the communication layer, and Google Protobufs are used as the message passing and serialization library. Messages are sent on named channels called **topics** via **publishers**. On the other side of a topic are **subscribers**, which receive callbacks when messages arrive. In summary, to send messages one must publish messages using a publisher on a named topic, and to receive messages one must subscribe to a named topic using a subscriber.

The easiest way to communicate with Gazebo over TCP/IP sockets is to link against the Gazebo libraries, and use the provided functions.

All the built in messages are documented here].

The Gazebo transport system is documented [here.

A list of all the topics in use on a running system can be found with the following command (make sure Gazebo is running first):

gztopic list


 * 1) Example ###

This example assumes that you have a working a program that links against Gazebo.

Start by initializing the transport system

gazebo::transport::init;

Next creat a Node, which provides functions to create publishers and subscribers. gazebo::transport::NodePtr node(new gazebo::transport::Node); node->Init;

Create a subscriber on the world_stats topic. Gazebo publishes a stream of stats on this topic.

node->Subscribe("~/world_stats", &Class::Function, this);

You'll need to create a callback function, which we called Class::Function in the previous line.

void Class::Function(ConstWorldStatisticsPtr &_msg) {         std::cout << _msg->DebugString; }

Now run the transport system

gazebo::transport::run;

At this point you'll have to create a wait loop while messages come in, or do some other processing. Here is simple wait loop.

while (true) gazebo::common::Time::MSleep(100);

Once you're done, finalize the transport system

gazebo::transport::fini;