Gazebo | Ignition | Community
Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Hello,

This snippet of code shows how to subscribe to a camera topic generated by Gazebo using gazebo::Transport::node

In the callback function void cb(ConstImageStampedPtr &_msg) you can handle the data from the image:

gazebo::transport::NodePtr gz_node;

// Function is called everytime a message is received.
void cb(ConstImageStampedPtr &_msg)
{
}

/////////////////////////////////////////////////
int main(int argc, char ** argv)
{
  // Load gazebo
  gazebo::client::setup(argc, argv);

  // Gazebo transport
  gz_node = gazebo::transport::NodePtr(new gazebo::transport::Node());
  gz_node->Init();

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

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

  // Make sure to shut everything down.
  gazebo::client::shutdown();
}