rosserial: time syncronization across multiple sensor, connected to same ros master
Hello,
I have an imu, and odometry sensor, connected to ros master tru rosserial_tivac. Occasionally I get warnings like:
Timestamps of odometry and imu are x seconds apart
from robot_pose_ekf, which indicates that timestamps of the sensor messages that are received differ more than 1 second.
I have looked at the source code of node_handle.h and I see that, as long as spinOnce() is called, the rosserial system sycronizes the clocks.
/* occasionally sync time */
if (configured_ && ((c_time - last_sync_time) > (SYNC_SECONDS * 500))) {
requestSyncTime();
last_sync_time = c_time;
}
- How can I make sure that timeStamps across my sensors are syncronized?
- Is there a way to force the rosserial into syncronization?
- Provided both microcontrollers (running the sensors) were syncronized at some point, how can the time difference between them differ by 1 seconds in such a short amount of time?
I have done further code reading and found out this is how rosserial sycronizes time. There is a systick generator, that counts the time since the program has started in milliseconds. This is accomplished by the systick interrupt handler, and is connected to internal clock, well not even a clock, just a crystal at 80mhz, and of course its frequency will vary with temperature.
void setNow(Time & new_now){
uint32_t ms = hardware_.time();
sec_offset = new_now.sec - ms / 1000 - 1;
nsec_offset = new_now.nsec - (ms % 1000) * 1000000UL + 1000000000UL;
normalizeSecNSec(sec_offset, nsec_offset); }
So it just records offsets, and when time is requested, it will report time taking sec_offset
and nsec_offset
How can I improve this? I could modify my hardware to add a RTC? or maybe I could force time sync updates?
Any ideas/recomendations/solutions greatly appreciated.
Best Regards, Can