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

How to fix timing issue?

asked 2021-02-08 15:44:30 -0600

sh_ec_ks gravatar image

updated 2021-02-08 15:45:39 -0600

I'm having an issue calculating the change of time that corresponds with values being published by one of my nodes. My calculations of the delta are as follows and I run this function every loop of my subscriber.

void estimate::getTime(){
      now= ros::Time::now().toSec();
       if(last_update>0){
            dt=(now-last_update);
       }
       last_update=now;
}

I have noticed that as I add subscribers to the node i'm working on, I begin to get lots of errors in the delta t. is there some concept I'm missing that is causing this to happen?

Thanks for any help

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2021-02-09 07:36:28 -0600

miura gravatar image

Since last_update>0, (now-last_update) is calculated every time, and both now and last_update are updated in seconds, dt is usually set to 0 (zero).

dt=(now-last_update); itself should be done every time, but it is better to use ros::Time::now() instead of ros::Time::now().toSec().

For example, the following

ros::Time now;
ros::Time last_update;
ros::Duration dt;

void estimate::getTime(){
  now= ros::Time::now();
  dt=(now-last_update);
  last_update=now;
  /* dt.sec : Time difference in seconds */
  /* dt.nsec : Time difference in nanoseconds */
}
edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2021-02-08 15:44:30 -0600

Seen: 178 times

Last updated: Feb 09 '21