ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange |
1 | initial version |
Your problem has nothing to do with ROS, but rather C++. From your code, your subscription is not failing, but the object you're instantiating within each "case" statement is going out of scope straight after you instantiate the object.
Try the following:
Add ros::Subscriber splitcmd_sub;
just below ros::Subscriber h_sub = ...
and then change your "case" statements to only have splitcmd_sub = n.subscribe(...);
.
That will solve your problem. :-)