Repository navigation
T265 time sync: filter outliers - #5639
Conversation
There was a problem hiding this comment.
I don't think there is an issue with precision when using doubles to represent ms. Here's an example of two ms times that are both on the order of 1 month but differ by 1ns.
std::chrono::duration<double, std::milli> x(2592000.000025),y(2592000.000026);
std::chrono::duration<double, std::nano> d = y - x;
std::cout << std::setprecision(15) << x.count() << " " << y.count() << " " << d.count() << "\n";and the output is what you would hope. Note the ns isn't exact, but it's still quite close after a month of running.
2592000.000025 2592000.000026 1.00024044513702
| bool manual_exposure = false; | ||
|
|
||
| std::atomic<int64_t> device_to_host_ns; | ||
| std::atomic<uint64_t> device_to_host_ns; |
There was a problem hiding this comment.
I think this needs to be signed as you don't know which is bigger.
| auto diff = duration<double, std::nano>(start + (finish - start)/2 - device); | ||
| device_to_host_ns = diff.count(); | ||
| //If usb response takes too long, skip update. 0.25ms is 5% of 200Hz | ||
| if ((finish.count() - start.count()) / 2 < 0.25) |
There was a problem hiding this comment.
I think it would be clearer if you used `std::chrono::milliseconds(0.25) instead of the bare constant. It would then be independent of the durations actual units.
There was a problem hiding this comment.
if you make this:
if ((finish.count() - start.count()) / 2 > 0.25)
continue;Then you don't have to indent/change the meat of the computation.
| rs2_time_t get_time_ns() const override | ||
| { | ||
| return std::chrono::duration<double, std::nano>(std::chrono::system_clock::now().time_since_epoch()).count(); | ||
| } |
There was a problem hiding this comment.
Can we drop get_time_ns now that we are back to ms?
| return _rec.get_time(); | ||
| } | ||
|
|
||
| virtual rs2_time_t get_time_ns() const override |
|
|
||
| void tm2_sensor::time_sync() | ||
| { | ||
| device_to_host_ns = 0; |
There was a problem hiding this comment.
This initialization should be in class definition to avoid a race with the thread that use this.
|
|
||
| if (std::abs((int64_t)(message->rawStreamHeader.llNanoseconds - last_hw_ts)) < (int64_t)allowed_delta) | ||
| { | ||
| global_ts = last_global_ts - last_hw_ts + message->rawStreamHeader.llNanoseconds; |
There was a problem hiding this comment.
@cchen6, at this point we have already applied device_to_host_ns in get_coordinated_timestamp. Why are you recreating it (or applying it again?) with last_global_ts - last_hw_ts?
There was a problem hiding this comment.
If device_to_host_ns is updated between two mono frames of stereo pair, the timestamp of two mono frames will be different causing mismatch while hw_ts is same for them. Adjust global_ts to be matched to hw_ts difference.
global timestamp will show deviation due to global timestamp base adjustment every 500ms. Issues found: