ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

Nodelet Publisher

asked 2016-11-18 09:57:10 -0600

ROSfc gravatar image
 virtual void onInit()
{
    ros::NodeHandle & private_nh = getPrivateNodeHandle();
    pub = private_nh.advertise<nodelet_test::buff>("chatter2", 10);
    nodelet_test::buff buffer;
    buffer.buffer_data.push_back(20);
    while(ros::ok())
    {
        pub.publish(buffer);
    }

}

I have the example code above for nodelet publisher only. Since I do not use callbacks (no subscriber ), is the way its done ? adding while loop inside onInit () ?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
3

answered 2016-11-18 11:04:44 -0600

Dirk Thomas gravatar image

Reading the documentation of onInit it should not block. Basically it prevent the surrounding nodelet manager to continue initializing the other nodelets.

Instead you should create a timer in the onInit function and then publish your message in the triggered callback of the timer.

edit flag offensive delete link more

Comments

I would require 36Hz frequency of published messages, do you advice using a timer ? or do you see any problems arising ?

ROSfc gravatar image ROSfc  ( 2016-11-20 13:43:32 -0600 )edit

As you suggested I used createTimer and in that i could specify the frequency using ros::Duration

ROSfc gravatar image ROSfc  ( 2016-11-21 07:43:25 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2016-11-18 09:57:10 -0600

Seen: 936 times

Last updated: Nov 18 '16