talker.cpp
Go to the documentation of this file.
1 
9 /*****************************************************************************
10 ** Includes
11 *****************************************************************************/
12 
13 #include <ros/ros.h>
14 #include <string>
15 #include "talker.hpp"
16 #include <std_msgs/String.h>
17 #include <sstream>
18 
19 /*****************************************************************************
20 ** Implementation
21 *****************************************************************************/
22 
23 Talker::Talker(int argc, char** argv ) :
24  QNode(argc,argv,"qtalker")
25  {}
26 
29  chatter_publisher = n.advertise<std_msgs::String>("chatter", 1000);
30 }
31 
32 void Talker::run() {
33  ros::Rate loop_rate(1);
34  int count = 0;
35  while ( ros::ok() ) {
36  std_msgs::String msg;
37  std::stringstream ss;
38  ss << "hello world " << count;
39  msg.data = ss.str();
40  ROS_INFO("%s", msg.data.c_str());
41 
42  this->logging.insertRows(0,1);
43  std::stringstream logging_msg;
44  logging_msg << "[ INFO] [" << ros::Time::now() << "]: " << msg.data;
45  QVariant new_row(QString(logging_msg.str().c_str()));
46  logging.setData(logging.index(0),new_row);
47 
49  ros::spinOnce();
50  loop_rate.sleep();
51  ++count;
52  }
53  std::cout << "Ros shutdown, proceeding to close the gui." << std::endl;
54  Q_EMIT rosShutdown(); // used to signal the gui for a shutdown (useful to roslaunch)
55 }
ros::Publisher chatter_publisher
Definition: talker.hpp:38
void run()
Definition: talker.cpp:32
void publish(const boost::shared_ptr< M > &message) const
QStringListModel logging
Definition: qnode.hpp:54
void rosShutdown()
#define ROS_INFO(...)
Ros communication central!
ROSCPP_DECL bool ok()
void ros_comms_init()
Definition: talker.cpp:27
Publisher advertise(const std::string &topic, uint32_t queue_size, bool latch=false)
bool sleep()
Definition: qnode.hpp:31
Talker(int argc, char **argv)
Definition: talker.cpp:23
static Time now()
ROSCPP_DECL void spinOnce()


qt_tutorials
Author(s): Daniel Stonier
autogenerated on Wed Mar 11 2020 03:12:20