ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange |
1 | initial version |
Yes, you can call a non-class callback from a subscriber that's within another class, so I suspect your problem is elsewhere. As a minimal example, something like this works:
#include "ros/ros.h"
#include "std_msgs/Empty.h"
void emptyCallback(const std_msgs::Empty::ConstPtr& msg) {
ROS_INFO("Got empty message!");
}
class Listener {
ros::NodeHandle nh_;
ros::Subscriber sub_;
public:
Listener(): nh_("") {
sub_ = nh_.subscribe("empty_msg", 1000, emptyCallback);
ROS_INFO("done constructing Listener!");
};
~Listener() {};
};
int main(int argc, char ** argv) {
ros::init(argc, argv, "test_cb_node");
Listener my_listener = Listener();
ros::spin();
return 0;
}
2 | No.2 Revision |
Yes, you can call a non-class callback from a subscriber that's within another class, so I suspect your problem is elsewhere. class. As a minimal example, something like this works:
#include "ros/ros.h"
#include "std_msgs/Empty.h"
void emptyCallback(const std_msgs::Empty::ConstPtr& msg) {
ROS_INFO("Got empty message!");
}
class Listener {
ros::NodeHandle nh_;
ros::Subscriber sub_;
public:
Listener(): nh_("") {
sub_ = nh_.subscribe("empty_msg", 1000, emptyCallback);
&emptyCallback);
ROS_INFO("done constructing Listener!");
};
~Listener() {};
};
int main(int argc, char ** argv) {
ros::init(argc, argv, "test_cb_node");
Listener my_listener = Listener();
ros::spin();
return 0;
}