Skip to content

T265 time sync: filter outliers - #5639

Merged
dorodnic merged 9 commits into
realsenseai:developmentfrom
cchen6:global_ts_base
Jan 22, 2020
Merged

dorodnic merged 9 commits into
realsenseai:developmentfrom
cchen6:global_ts_base

Conversation

@cchen6

@cchen6 cchen6 commented Jan 14, 2020 •

Copy link
Copy Markdown
Contributor

global timestamp will show deviation due to global timestamp base adjustment every 500ms. Issues found:

  1. big usb delay will cause big jump on base. Skip update if half usb delay > 250us
  2. Base change may happen between two mono images receiving. Adjust 2nd mono image timestamp to match 1st mono image timestamp.

@cchen6
cchen6 requested a review from ev-mp January 16, 2020 22:21
@radfordi
radfordi self-requested a review January 17, 2020 01:23

@radfordi radfordi left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Comment thread src/tm2/tm-device.h Outdated
bool manual_exposure = false;

std::atomic<int64_t> device_to_host_ns;
std::atomic<uint64_t> device_to_host_ns;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this needs to be signed as you don't know which is bigger.

Comment thread src/tm2/tm-device.cpp Outdated
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)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread src/backend.h Outdated
rs2_time_t get_time_ns() const override
{
return std::chrono::duration<double, std::nano>(std::chrono::system_clock::now().time_since_epoch()).count();
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we drop get_time_ns now that we are back to ms?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated

Comment thread src/mock/recorder.h Outdated
return _rec.get_time();
}

virtual rs2_time_t get_time_ns() const override

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Drop.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dropped

@cchen6
cchen6 requested a review from radfordi January 17, 2020 18:28
Comment thread src/tm2/tm-device.cpp Outdated

void tm2_sensor::time_sync()
{
device_to_host_ns = 0;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This initialization should be in class definition to avoid a race with the thread that use this.

Comment thread src/tm2/tm-device.cpp Outdated

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;

@radfordi radfordi Jan 17, 2020 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@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?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@radfordi radfordi left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the clean ups. Looks great, @cchen6.

@radfordi radfordi changed the title global ts base preecision and filtering T265 time sync: filter outliers Jan 21, 2020
@dorodnic
dorodnic merged commit 5190393 into realsenseai:development Jan 22, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants