I want to add a new node handle in init.cpp, to do some caculations on tcp packages which uses this ros_comm
I added this class
class Rosperf {
public:
ros::NodeHandle node_;
ros::Subscriber sub_;
// ros::Publisher pub_;
Rosperf() {
init();
}
void init() {
sub_ = node_.subscribe("/perfswitcher", 1, &Rosperf::rosperfCallback, this);
std::cout << "sub to /perfswitcher" << std::endl;
// pub_ = node_.advertise<std_msgs::Bool>("/perfswitcher", 5);
// std::cout << "pub to /perfswitcher" << std::endl;
}
void rosperfCallback(const std_msgs::Bool::ConstPtr& switch_on) {
std::cout << "received switcher command" << std::endl;
if (switch_on) {
} else {
}
}
};
to init.cpp, and instanciate it at the end of init()
(after the g_initilize
becomes true). The node works well with a node handle publishing to /perfswitch
, but the rosperfCallback
had never been call by spin()
function of the node.
How can I make it work?