Problem to subscrib with class
Hello,
I am currently in an internship and Im working on ROS with GAZEBO simulator. I made my own package but now im facing a problem. I have 10 pioneer3AT with a hokuyo laser on each, the plugin for the laser is working well, and I have a topic called "/hokuyo_laser" and I am trying to make my own plugin, using a C++ class, here is my code :
class ListenerPlugin : public ModelPlugin
{
private:
ros::NodeHandle n;
ros::Subscriber sub
public:
ListenerPlugin() {}
void scanCallback(const sensor_msgs::LaserScan::ConstPtr& scan){
ROS_INFO("VALEUR SCAN: [%s]", scan->ranges);
}
virtual void Load(physics::ModelPtr _model, sdf::ElementPtr _sdf){
std::cerr << "Le plugin listener a ete attache a[" << _model->GetName() << "]\n";
sub = n.subscribe("hokuyo_laser", 1, &ListenerPlugin::scanCallback, this);
std::cerr << sub;
}
};
GZ_REGISTER_MODEL_PLUGIN(ListenerPlugin)
And my problem is that my programm is never going in scanCallback, when I use std::cerr to display my Subscriber, there is only "0x1" that is showing.
Here is the result of the command "rostopic list -v" while simulator is running :
Published topics:
* /hokuyo_laser [sensor_msgs/LaserScan] 1 publisher
* /gazebo/link_states [gazebo_msgs/LinkStates] 1 publisher
* /rosout [rosgraph_msgs/Log] 1 publisher
* /rosout_agg [rosgraph_msgs/Log] 1 publisher
* /gazebo/model_states [gazebo_msgs/ModelStates] 1 publisher
* /clock [rosgraph_msgs/Clock] 1 publisher
* /gazebo/parameter_descriptions [dynamic_reconfigure/ConfigDescription] 1 publisher
* /gazebo/parameter_updates [dynamic_reconfigure/Config] 1 publisher
Subscribed topics:
* /clock [rosgraph_msgs/Clock] 1 subscriber
* /gazebo/set_model_state [gazebo_msgs/ModelState] 1 subscriber
* /rosout [rosgraph_msgs/Log] 1 subscriber
* /gazebo/set_link_state [gazebo_msgs/LinkState] 1 subscriber
I am using ros kinetic by the way, and I am sorry if my mistake is stupid, I litteraly can't find anything working on the Internet. Thank you for answering me !
It's surprising if u can compile it, you have a syntax error here. A ; is missing after your subscribe definition. Furthermore make sure instant of the nodehandle is initialized properly..
Hello, i must have had a problem while recopying but the ";" is in the code. After your commentary I searched how does node initialise, and I just switch it on public and now it's working, thank you so much, i've been stuck on that for hours