$search
00001 00009 /***************************************************************************** 00010 ** Includes 00011 *****************************************************************************/ 00012 00013 #include <ros/ros.h> 00014 #include <string> 00015 #include <sstream> 00016 #include "qadd.hpp" 00017 #include <std_msgs/String.h> 00018 00019 /***************************************************************************** 00020 ** Implementation 00021 *****************************************************************************/ 00022 00023 QAdd::QAdd(int argc, char** argv ) : 00024 QNode(argc,argv,"qadd_server") 00025 {} 00026 00027 void QAdd::ros_comms_init() { 00028 ros::NodeHandle n; 00029 add_server = n.advertiseService("add_two_ints", &QAdd::add, this); 00030 } 00031 00032 bool QAdd::add(qt_tutorials::TwoInts::Request &req, qt_tutorials::TwoInts::Response &res) { 00033 res.sum = req.a + req.b; 00034 ROS_INFO_STREAM(req.a << " + " << req.b << " = " << res.sum); 00035 00036 logging.insertRows(0,1); 00037 std::stringstream logging_msg; 00038 logging_msg << "[ INFO] [" << ros::Time::now() << "]: " << req.a << " + " << req.b << " = " << res.sum; 00039 QVariant new_row(QString(logging_msg.str().c_str())); 00040 logging.setData(logging.index(0),new_row); 00041 00042 return true; 00043 } 00044 00045 void QAdd::run() { 00046 ros::spin(); 00047 std::cout << "Ros shutdown, proceeding to close the gui." << std::endl; 00048 Q_EMIT rosShutdown(); // used to signal the gui for a shutdown (useful to roslaunch) 00049 }