Robotics StackExchange | Archived questions

How to subscribe and publish to /points_map topic

Here's my code:

foreignTopic::foreignTopic() {
    chat_= n.advertise<sensor_msgs::PointCloud2>("multimaster/chatter", 1000);
}

void foreignTopic::callback(const sensor_msgs::PointCloud2::ConstPtr& msg){
    chat_.publish(msg);
}

void multimaster::init(ros::M_string remappings) {

    ros::Rate loop_rate(msgsFrequency_Hz);     
                 foreignTopic pc; 
    //Create subscribers in the host and connect them to the foreign topics 
    remappings["__master"] = host_master;
    ros::master::init(remappings);
    ros::Subscriber subscriberFeedback = nh.subscribe("/points_map", 1, &foreignTopic::callback, &pc);  
    remappings["__master"] =  foreign_master;
    ros::master::init(remappings);
    while(ros::ok() && ros::master::check()==true){
        ros::spinOnce(); 
        loop_rate.sleep();
    }

}

My problem here is that there's no message when i read the /multimaster/chatter topic.

Asked by crazyRan on 2020-01-22 02:25:49 UTC

Comments

Answers

Well first of all, you publish at /multimaster/chatter and you're saying you get nothing while listening to /multimaster_chatter which are in fact different topics.

Another problem could be that there is never anything published at /points_map so the callback function is never called.

The third option I can think of is that chat_ isn't properly defined in your class and is therefore not the same variable in your constructor as your callback function.

Asked by Joe28965 on 2020-01-22 10:11:22 UTC

Comments

Hi, thanks for you reply. I'm sorry my mistake, I'm also listening in /multimaster/chatter. But I can get the message in the callback function, the problem is that when I published the message to /multimaster/chatter topic.

Asked by crazyRan on 2020-01-22 21:10:54 UTC

okay, then there are a couple of options

First, what I originally said as the third option, where do you create the variable chat_

Also, in your class foreignTopic you use the nodehandle n where do you create that one? Do you initialise ROS in your class? Do you somewhere after that call `n = new ros::NodeHandle();' to make sure the nodehandle is actually properly connected to ROS?

If your callback function is getting called, I would suspect your nodehandle isn't working correctly, could you also post the header file of foreignTopic and anything else that happens in this class, if you need more help

Asked by Joe28965 on 2020-01-23 03:25:35 UTC

Hi, sorry for late reply. Thank you for your response. I fixed it already, but i didn't know what exactly the problem. Thank you so much!

Asked by crazyRan on 2020-02-18 21:19:54 UTC