Ask Your Question
0

How to subscribe and publish to /points_map topic

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

crazyRan gravatar image

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

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.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

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

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

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.

crazyRan gravatar imagecrazyRan ( 2020-01-22 20:10:54 -0600 )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 imageJoe28965 ( 2020-01-23 02:25:35 -0600 )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

2 followers

Stats

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

Seen: 29 times

Last updated: Jan 22