Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <gazebo/transport/transport.hh>
- #include <gazebo/msgs/msgs.hh>
- #include <gazebo/gazebo_client.hh>
- #include "ros/ros.h"
- #include "sensor_msgs.msg.Image"
- #include <iostream>
- class readGazeboTopic
- {
- public:
- readGazeboTopic(arguments);
- virtual ~readGazeboTopic();
- void readGazeboTopic::cb(sensor_msgs::Image &img)
- {
- colorimage = *img;
- }
- sensor_msgs::Image readGazeboTopic::readImage()
- {
- return colorimage;
- }
- private:
- /* data */
- sensor_msgs::Image colorimage;
- };
- /////////////////////////////////////////////////
- // 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::client::setup(_argc, _argv);
- //Load ROS
- ros::init(argc, argv, "ImagePublisher");
- ros::NodeHandle n;
- // Create our node for communication
- gazebo::transport::NodePtr node(new gazebo::transport::Node());
- node->Init();
- //Create our class
- readGazeboTopic rGT;
- // Listen to Gazebo world_stats topic
- gazebo::transport::SubscriberPtr sub = node->Subscribe("~/world_stats", rGT::cb);
- // Ros publisher
- ros::Publisher ImagePub = n.advertise<sensor_msgs::Image>("color", 1000);
- ros::Rate loop_rate(10);
- // Busy wait loop...replace with your own code as needed.
- while (ros::ok()) {
- ImagePub.publish(rGT::readImage());
- ros::spinOnce();
- loop_rate.sleep();
- }
- // Make sure to shut everything down.
- gazebo::client::shutdown();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement