ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

Revision history [back]

The build error is likely because you need to specify that your callbacks are member functions: n.subscribe("chatter", 1000, &EKF_node::chatterCallback, this);. I did not test that your code compiles with that type of change.

You don't get to your callbacks if ros::spin() is in main() because your subscribers are not member variables. They go out of scope as soon as you leave your constructor. When you put ros::spin() (which blocks) in your constructor you do not leave the constructor and the subscribers do not go out of scope. You should make your subscribers member variables and spin from main.

I normally see ros::init() in main also.

The build error is likely because you need to specify that your callbacks are member functions: n.subscribe("chatter", 1000, &EKF_node::chatterCallback, this);. I did not test that your code compiles with that type of change.

You don't get to your callbacks if ros::spin() is in main() because your subscribers are not member variables. They go out of scope as soon as you leave your constructor. When you put ros::spin() (which blocks) in your constructor you do not leave the constructor and the subscribers do not go out of scope. You should make your subscribers member variables and spin from main.

I normally see ros::init() in main also.

And you need to create an instance of your class in main, as answered by @Airuno2L.