How Timer Callback Function Does the Timing?
I want to know how accurate ROS timer is. So for example, I create the timer as follows:
timer1=n.createTimer(ros::Rate(500),&HWController::Timer1_Process,this);
There is a callback function here HWController::Timer1_Process
, which takes an argument of C++ class ros::TimerEvent
. There are several member variables in this class, one of which is current_expected_
. I want to know when current_expected_
is calculated. In ROS documentation, the explanation of this variable is
In a perfect world, this is when the current callback should be happening.
However, no further information is given. I want this accurate value because I need to calculate the time error as shown below.
void HWController::Timer1_Process(const ros::TimerEvent &e)
{
ros::Duration time_err = e.current_real_ - e.current_expected_;
.....
}
So, to be more specific, is current_expected_
calculated after this callback function exits (i.e. after the '}' symbol) where it adds the timer period (in this case, 0.0002s) to the current ROS time upon exiting the function? Or is it calculated at the beginning of the function? Actually I prefer to the first explanation because it should not take into account the execution time of this function. I hope someone could clarify this by providing some source codes of its implementation rather than random guessing. I tried to find its implementation but failed. :(