-
Notifications
You must be signed in to change notification settings - Fork 5
[RSDK-13174] Fixing spammy color and depth timsteamps differ logs #62
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -213,6 +213,18 @@ std::string formatError(Args&&... args) { | |
| return buffer.str(); | ||
| } | ||
|
|
||
| // Get the best available timestamp for a frame (Global > System) | ||
| uint64_t getBestTimestampUs(std::shared_ptr<ob::Frame> frame) { | ||
| if (frame == nullptr) { | ||
| return 0; | ||
| } | ||
| uint64_t ts = frame->getGlobalTimeStampUs(); | ||
| if (ts > 0) { | ||
| return ts; | ||
| } | ||
| return frame->getSystemTimeStampUs(); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. according to your description, it sounds like we shouldn't use system timestamp bc it's unreliable why are we still using it as a fallback when somehow also, how can could it happen when global timestamp is not enabled on the system?
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should we log a single, not noisy warning that color-depth timestamp comparisons are not supported when global timestamp isn't available? Instead of falling back to the unreliable system timestamp?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. hmmm, another option would be to support system timestamp and put a threshold of perhaps 400ms between frames. My thinking is that it may be better to have that rough measurement than nothing, but totally open to discuss it. |
||
| } | ||
|
|
||
| // Validate color frame format and timestamp | ||
| void validateColorFrame(std::shared_ptr<ob::Frame> color, | ||
| const std::optional<DeviceFormat>& device_format_opt, | ||
|
|
@@ -234,7 +246,7 @@ void validateColorFrame(std::shared_ptr<ob::Frame> color, | |
|
|
||
| // Timestamp validation | ||
| uint64_t nowUs = getNowUs(); | ||
| uint64_t diff = timeSinceFrameUs(nowUs, color->getSystemTimeStampUs()); | ||
| uint64_t diff = timeSinceFrameUs(nowUs, getBestTimestampUs(color)); | ||
| if (diff > maxFrameAgeUs) { | ||
| throw std::runtime_error(formatError("no recent color frame: check connection, diff: ", diff, "us")); | ||
| } | ||
|
|
@@ -271,7 +283,7 @@ void validateDepthFrame(std::shared_ptr<ob::Frame> depth, | |
|
|
||
| // Timestamp validation | ||
| uint64_t nowUs = getNowUs(); | ||
| uint64_t diff = timeSinceFrameUs(nowUs, depth->getSystemTimeStampUs()); | ||
| uint64_t diff = timeSinceFrameUs(nowUs, getBestTimestampUs(depth)); | ||
| if (diff > maxFrameAgeUs) { | ||
| throw std::runtime_error(formatError("no recent depth frame: check connection, diff: ", diff, "us")); | ||
| } | ||
|
|
@@ -654,33 +666,33 @@ auto frameCallback(const std::string& serialNumber) { | |
|
|
||
| std::lock_guard<std::mutex> lock(frame_set_by_serial_mu()); | ||
| uint64_t nowUs = getNowUs(); | ||
| uint64_t diff = timeSinceFrameUs(nowUs, color->getSystemTimeStampUs()); | ||
| uint64_t diff = timeSinceFrameUs(nowUs, getBestTimestampUs(color)); | ||
| if (diff > maxFrameAgeUs) { | ||
| std::cerr << "color frame is " << diff << "us older than now, nowUs: " << nowUs << " frameTimeUs " | ||
| << color->getSystemTimeStampUs() << "\n"; | ||
| std::cerr << "color frame is " << diff << "us older than now, nowUs: " << nowUs << " frameTimeUs " << getBestTimestampUs(color) | ||
| << "\n"; | ||
| } | ||
| diff = timeSinceFrameUs(nowUs, depth->getSystemTimeStampUs()); | ||
| diff = timeSinceFrameUs(nowUs, getBestTimestampUs(depth)); | ||
| if (diff > maxFrameAgeUs) { | ||
| std::cerr << "depth frame is " << diff << "us older than now, nowUs: " << nowUs << " frameTimeUs " | ||
| << depth->getSystemTimeStampUs() << "\n"; | ||
| std::cerr << "depth frame is " << diff << "us older than now, nowUs: " << nowUs << " frameTimeUs " << getBestTimestampUs(depth) | ||
| << "\n"; | ||
| } | ||
|
|
||
| auto it = frame_set_by_serial().find(serialNumber); | ||
| if (it != frame_set_by_serial().end()) { | ||
| std::shared_ptr<ob::Frame> prevColor = it->second->getFrame(OB_FRAME_COLOR); | ||
| std::shared_ptr<ob::Frame> prevDepth = it->second->getFrame(OB_FRAME_DEPTH); | ||
| if (prevColor != nullptr && prevDepth != nullptr) { | ||
| diff = timeSinceFrameUs(color->getSystemTimeStampUs(), prevColor->getSystemTimeStampUs()); | ||
| diff = timeSinceFrameUs(getBestTimestampUs(color), getBestTimestampUs(prevColor)); | ||
| if (diff > maxFrameAgeUs) { | ||
| std::cerr << "previous color frame is " << diff | ||
| << "us older than current color frame. previousUs: " << prevColor->getSystemTimeStampUs() | ||
| << " currentUs: " << color->getSystemTimeStampUs() << "\n"; | ||
| << "us older than current color frame. previousUs: " << getBestTimestampUs(prevColor) | ||
| << " currentUs: " << getBestTimestampUs(color) << "\n"; | ||
| } | ||
| diff = timeSinceFrameUs(depth->getSystemTimeStampUs(), prevDepth->getSystemTimeStampUs()); | ||
| diff = timeSinceFrameUs(getBestTimestampUs(depth), getBestTimestampUs(prevDepth)); | ||
| if (diff > maxFrameAgeUs) { | ||
| std::cerr << "previous depth frame is " << diff | ||
| << "us older than current depth frame. previousUs: " << prevDepth->getSystemTimeStampUs() | ||
| << " currentUs: " << depth->getSystemTimeStampUs() << "\n"; | ||
| << "us older than current depth frame. previousUs: " << getBestTimestampUs(prevDepth) | ||
| << " currentUs: " << getBestTimestampUs(depth) << "\n"; | ||
| } | ||
| } | ||
| } | ||
|
|
@@ -700,6 +712,14 @@ void configureDevice(std::string serialNumber, OrbbecModelConfig const& modelCon | |
|
|
||
| std::unique_ptr<ViamOBDevice>& my_dev = search->second; | ||
|
|
||
| // Enable global timestamp if supported | ||
| if (my_dev->device->isGlobalTimestampSupported()) { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Given that GlobalTimstamps are supported on the orbecc module we care about, can we remove the system backup? |
||
| my_dev->device->enableGlobalTimestamp(true); | ||
| VIAM_SDK_LOG(info) << "[configureDevice] Global timestamp enabled for device " << serialNumber; | ||
| } else { | ||
| VIAM_SDK_LOG(info) << "[configureDevice] Global timestamp not supported for device " << serialNumber; | ||
| } | ||
|
|
||
| // Initialize fields if not already set | ||
| if (!my_dev->pipe) { | ||
| my_dev->pipe = std::make_shared<ob::Pipeline>(my_dev->device); | ||
|
|
@@ -1341,8 +1361,8 @@ vsdk::Camera::image_collection Orbbec::get_images(std::vector<std::string> filte | |
| return response; | ||
| } | ||
|
|
||
| uint64_t colorTS = color ? color->getSystemTimeStampUs() : 0; | ||
| uint64_t depthTS = depth ? depth->getSystemTimeStampUs() : 0; | ||
| uint64_t colorTS = color ? getBestTimestampUs(color) : 0; | ||
| uint64_t depthTS = depth ? getBestTimestampUs(depth) : 0; | ||
| uint64_t timestamp = 0; | ||
|
|
||
| if (colorTS > 0 && depthTS > 0) { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[maybe nit] Should we pass in as const ref here so we do not increment/decrement the shared_pt every time the helper is called?