ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange |
1 | initial version |
This is a C++ problem.
Even though you have a ros::Subscriber gnssGGA_sub
and a ros::Publisher signal_pub
member in your class, you initialise your subscriber here:
ros::Publisher signal_pub = nh.advertise<..>(..);
and publisher like so:
ros::Subscriber gnssGGA_sub = nh.subscribe(..);
That makes signal_pub
and gnssGGA_sub
variables local to initPublishers(..)
and initSubscribers(..)
.
As those variables go out of scope at "the end" of those methods, the subscription and the publication will be destroyed, and your callback is "never called".
2 | No.2 Revision |
This is a C++ problem.
Even though you have a ros::Subscriber gnssGGA_sub
and a ros::Publisher signal_pub
member in your class, you initialise your subscriber here:
ros::Publisher signal_pub = nh.advertise<..>(..);
and publisher like so:
ros::Subscriber gnssGGA_sub = nh.subscribe(..);
That makes signal_pub
and gnssGGA_sub
variables local to initPublishers(..)
and initSubscribers(..)
. The specific terminology here is variable shadowing.
As those variables go out of scope at "the end" of those methods, the subscription and the publication will be destroyed, and your callback is "never called".
You'll want to do something like this:
signal_pub = nh.advertise<..>(..);
Note the absence of ros::Publisher
.
Note also that there are code styles where member variables are suffixed with an underscore (_
). That way, signal_pub
and signal_pub_
are two different things (well .. names .. but it's more obvious to a human reading the code what the intent is).