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

ros::spinOnce and timeout

asked 2022-08-17 09:25:43 -0500

serhat gravatar image

Hello all,

I have a problem about ros::spinOnce. My main algorithm's frequency is 25 Hz. So, each iteration should last for 40 ms at most. But when I search the logs, I realized that the program spends for 30~40 ms to just passed the ros::spinOnce. I have only 4 callbacks/subscriptions and we don't make any expensive things in them. I didn't understand why we wait queries for that much? Is there any timeout parameter for preventing such situation.

[DEBUG] [ 01:47:10 .790449152]: New iteration
[DEBUG] [ 01:47:10 .830653549]: [Roboteq] The code is in imu_callback//IT PASSED 40 MS. WHY? 
[DEBUG] [ 01:47:10 .830864840]: [MotorDriver] cmd_vel.x = -0.300000
[DEBUG] [ 01:47:10 .830896443]: [MotorDriver] cmd_vel.th= -0.000000
[ INFO] [ 01:47:10 .841152961]: ser.avaliable() = 20
[ INFO] [ 01:47:10 .841399266]: ResultEncoder = C=47447:47386

As you can see, I spend 40 ms here before I start doing my actual stuff in the rest of the iteration. UBUNTU 16.04 - Kinetic - Ros1

Thanks in advance.

edit retag flag offensive close merge delete

Comments

1

You have not provided enough information. I suggest you show us the code for your ros node.

Mike Scheutzow gravatar image Mike Scheutzow  ( 2022-08-17 11:10:19 -0500 )edit

Hi Mike, thanks for the comment. Let me try to make it more clear:

void imu_Callback(std_msgs::Float64 input) //One of four callbacks. Others have similar pattern as well.(Not expensive at all)
{
    ROS_DEBUG("[Roboteq] The code is in imu_callback ") ;     
    th = input.data ; 
}

 SystemFrequency=25;
 ros::Rate r(SystemFrequency);  
 while(ros::ok())
 {
      ROS_DEBUG("New iteration") ; 
      ros::spinOnce() ; 

     "ser.avaliable() = 20" //shown in the main ticket
     "...."" 

      r.sleep() ; 
 }
serhat gravatar image serhat  ( 2022-08-17 13:17:21 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted
0

answered 2022-08-18 09:01:55 -0500

Mike Scheutzow gravatar image

In roscpp, the ros::spinOnce() is what invokes the subscribe callbacks. Since your code is calling spinOnce only once every 40 milliseconds, that is the fastest they fire. You may want to take a look at ros::AsyncSpinner(), but make sure you use proper thread mutexes if you do.

http://wiki.ros.org/roscpp/Overview/C...

edit flag offensive delete link more

Question Tools

2 followers

Stats

Asked: 2022-08-17 09:25:43 -0500

Seen: 231 times

Last updated: Aug 18 '22