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

Revision history [back]

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 */
}