I m trying to make my Nodehandle global,below is my code.But I m unable to listen to subscribed topic.
I m trying to make my Nodehandle global,below is my code.But I m unable to listen to subscribed topic
#include<ros/ros.h>
#include<tf/transform_listener.h>
#include<std_msgs/Float32.h>
using namespace std;
class Node{
private:
ros::NodeHandle nh;
public:
Node(ros::NodeHandle &nh){
this->nh=nh;
}
ros::NodeHandle getnh(){
return this->nh;
}
};
void dataRecevied(const::std_msgs::Float32::ConstPtr &msg){
ROS_INFO("yes3");
ROS_INFO("Range is %f",msg->data);
}
void turn(Node n){
ros::NodeHandle nh=n.getnh();
ros::Subscriber sub;
ROS_INFO("yes2");
sub=nh.subscribe("test1",1,dataRecevied);
}
int main(int argv,char **argc){
ros::init(argv,argc,"tf_listener");
ros::NodeHandle nh;
Node pub(nh);
ROS_INFO("yes1");
turn(pub);
ros::spin();
}