publisher.cpp
Go to the documentation of this file.
00001 #include <ros/ros.h>
00002 #include <ros/console.h>
00003 
00004 #include <std_msgs/String.h>
00005 #include <message_transport/message_transport.h>
00006 
00007 class StringPublisher {
00008         protected:
00009 
00010                 ros::NodeHandle n_;
00011                 message_transport::MessageTransport<std_msgs::String> it_;
00012                 message_transport::Publisher strmsg_pub_;
00013                 std_msgs::String text;
00014 
00015 
00016         public:
00017 
00018                 StringPublisher(ros::NodeHandle &n) : n_(n), 
00019                         it_(n_,"string_transport","std_msgs::String") {
00020                         strmsg_pub_ = it_.advertise("str_source",1);
00021 
00022                 }
00023 
00024                 ~StringPublisher()
00025                 {
00026                 }
00027 
00028                 int mainloop()
00029                 {
00030 
00031             ROS_INFO("Entering main loop");
00032                         ros::Rate loop_rate(3);
00033                         while (ros::ok())
00034                         {
00035                 text.data = "Hello";
00036                 ROS_INFO("Publishing '%s'",text.data.c_str());
00037                                 strmsg_pub_.publish(text);
00038                                 ros::spinOnce();
00039                                 loop_rate.sleep();
00040                         }
00041 
00042                         return 0;
00043                 }
00044 
00045 };
00046 
00047 void setDebugLevel(const std::string & logname) {
00048     log4cxx::LoggerPtr logger = log4cxx::Logger::getLogger(logname);
00049     logger->setLevel(log4cxx::Level::getDebug());
00050     ros::console::notifyLoggerLevelsChanged();
00051 }
00052 
00053 int main(int argc, char** argv)
00054 {
00055         ros::init(argc, argv, "test_publisher");
00056         ros::NodeHandle n;
00057         StringPublisher ic(n);
00058         ic.mainloop();
00059         return 0;
00060 }
00061 


string_transport
Author(s): Cedric Pradalier
autogenerated on Sun Oct 5 2014 23:49:31