listener.cpp
Go to the documentation of this file.
1 
9 /*****************************************************************************
10 ** Includes
11 *****************************************************************************/
12 
13 #include <ros/ros.h>
14 #include <string>
15 #include <sstream>
16 #include "listener.hpp"
17 #include <std_msgs/String.h>
18 
19 /*****************************************************************************
20 ** Implementation
21 *****************************************************************************/
22 
23 Listener::Listener(int argc, char** argv ) :
24  QNode(argc,argv,"qlistener")
25  {}
26 
29  chatter_subscriber = n.subscribe("chatter", 1000, &Listener::chatterCallback, this);
30 }
31 
32 void Listener::chatterCallback(const std_msgs::String::ConstPtr &msg) {
33  ROS_INFO("I heard: [%s]", msg->data.c_str());
34  logging.insertRows(0,1);
35  std::stringstream logging_msg;
36  logging_msg << "[ INFO] [" << ros::Time::now() << "]: I heard: " << msg->data;
37  QVariant new_row(QString(logging_msg.str().c_str()));
38  logging.setData(logging.index(0),new_row);
39 }
40 
41 void Listener::run() {
42  ros::spin();
43  std::cout << "Ros shutdown, proceeding to close the gui." << std::endl;
44  Q_EMIT rosShutdown(); // used to signal the gui for a shutdown (useful to roslaunch)
45 }
QStringListModel logging
Definition: qnode.hpp:54
Subscriber subscribe(const std::string &topic, uint32_t queue_size, void(T::*fp)(M), T *obj, const TransportHints &transport_hints=TransportHints())
Ros communication central!
void rosShutdown()
Listener(int argc, char **argv)
Definition: listener.cpp:23
void run()
Definition: listener.cpp:41
#define ROS_INFO(...)
ROSCPP_DECL void spin()
void ros_comms_init()
Definition: listener.cpp:27
Definition: qnode.hpp:31
ros::Subscriber chatter_subscriber
Definition: listener.hpp:40
void chatterCallback(const std_msgs::String::ConstPtr &msg)
Definition: listener.cpp:32
static Time now()


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