talker.cpp
Go to the documentation of this file.
00001 
00009 /*****************************************************************************
00010 ** Includes
00011 *****************************************************************************/
00012 
00013 #include <ros/ros.h>
00014 #include <string>
00015 #include "talker.hpp"
00016 #include <std_msgs/String.h>
00017 #include <sstream>
00018 
00019 /*****************************************************************************
00020 ** Implementation
00021 *****************************************************************************/
00022 
00023 Talker::Talker(int argc, char** argv ) :
00024         QNode(argc,argv,"qtalker")
00025         {}
00026 
00027 void Talker::ros_comms_init() {
00028     ros::NodeHandle n;
00029     chatter_publisher = n.advertise<std_msgs::String>("chatter", 1000);
00030 }
00031 
00032 void Talker::run() {
00033         ros::Rate loop_rate(1);
00034         int count = 0;
00035         while ( ros::ok() ) {
00036             std_msgs::String msg;
00037             std::stringstream ss;
00038                 ss << "hello world " << count;
00039                 msg.data = ss.str();
00040                 ROS_INFO("%s", msg.data.c_str());
00041 
00042                 this->logging.insertRows(0,1);
00043                 std::stringstream logging_msg;
00044                 logging_msg << "[ INFO] [" << ros::Time::now() << "]: " << msg.data;
00045                 QVariant new_row(QString(logging_msg.str().c_str()));
00046                 logging.setData(logging.index(0),new_row);
00047 
00048                 chatter_publisher.publish(msg);
00049                 ros::spinOnce();
00050                 loop_rate.sleep();
00051                 ++count;
00052         }
00053     std::cout << "Ros shutdown, proceeding to close the gui." << std::endl;
00054     Q_EMIT rosShutdown(); // used to signal the gui for a shutdown (useful to roslaunch)
00055 }


qt_tutorials
Author(s): Daniel Stonier
autogenerated on Fri Aug 28 2015 12:16:20