Ask Your Question

How to subscribe and publish to /points_map topic

asked 2020-01-22 01:25:49 -0500

crazyRan gravatar image

updated 2020-01-22 19:59:31 -0500

Here's my code:

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

void foreignTopic::callback(const sensor_msgs::PointCloud2::ConstPtr& 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::Subscriber subscriberFeedback = nh.subscribe("/points_map", 1, &foreignTopic::callback, &pc);  
    remappings["__master"] =  foreign_master;
    while(ros::ok() && ros::master::check()==true){


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

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2020-01-22 09:11:22 -0500

Joe28965 gravatar image

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.

edit flag offensive delete link more


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.

crazyRan gravatar image crazyRan  ( 2020-01-22 20:10:54 -0500 )edit

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

Joe28965 gravatar image Joe28965  ( 2020-01-23 02:25:35 -0500 )edit

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!

crazyRan gravatar image crazyRan  ( 2020-02-18 20:19:54 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2020-01-22 01:25:49 -0500

Seen: 65 times

Last updated: Jan 22 '20