Skip to content

Commit

Permalink
Merge pull request #934 from luxonis/xlinkin_timestamps
Browse files Browse the repository at this point in the history
XLinkIn timestamps
  • Loading branch information
moratom authored Dec 11, 2023
2 parents b40465e + c9fd406 commit 0cae1b0
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 4 deletions.
2 changes: 1 addition & 1 deletion cmake/Depthai/DepthaiDeviceSideConfig.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
set(DEPTHAI_DEVICE_SIDE_MATURITY "snapshot")

# "full commit hash of device side binary"
set(DEPTHAI_DEVICE_SIDE_COMMIT "549315be3f2e2af09e6301c5b131b77ceedb0391")
set(DEPTHAI_DEVICE_SIDE_COMMIT "afcf303d4bee6a0e313fc763ecb390fcf1a4886e")

# "version if applicable"
set(DEPTHAI_DEVICE_SIDE_VERSION "")
4 changes: 2 additions & 2 deletions cmake/Hunter/config.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ hunter_config(
hunter_config(
XLink
VERSION "luxonis-2021.4.2-xlink-linkid-race-fix"
URL "https://github.com/luxonis/XLink/archive/6bf33bb51100f6a5aa159d025159fa22eb4f15b7.tar.gz"
SHA1 "e54effec01d0fa7403fcc34ebebf784370256a29"
URL "https://github.com/luxonis/XLink/archive/14d4056d9d9dc21de2c6089a4648ddb9e981f418.tar.gz"
SHA1 "14613474368971d67c520f6f911cf88fb6384506"
CMAKE_ARGS
XLINK_ENABLE_LIBUSB=${DEPTHAI_ENABLE_LIBUSB}
)
Expand Down
1 change: 1 addition & 0 deletions examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -374,3 +374,4 @@ dai_add_example(crash_report CrashReport/crash_report.cpp OFF)
dai_add_example(sync_scripts Sync/sync_scripts.cpp ON)
dai_add_example(demux_message_group Sync/demux_message_group.cpp ON)
dai_add_example(depth_video_synced Sync/depth_video_synced.cpp ON)
dai_add_example(imu_video_synced Sync/imu_video_synced.cpp ON)
74 changes: 74 additions & 0 deletions examples/Sync/imu_video_synced.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
#include <iostream>
#include <opencv2/opencv.hpp>

#include "depthai/depthai.hpp"

int main() {
dai::Device device;

auto imuType = device.getConnectedIMU();
auto imuFirmwareVersion = device.getIMUFirmwareVersion();
std::cout << "IMU type: " << imuType << ", firmware version: " << imuFirmwareVersion << std::endl;

if(imuType != "BNO086") {
std::cout << "Rotation vector output is supported only by BNO086!" << std::endl;
return 1;
}

dai::Pipeline pipeline;

auto colorCamera = pipeline.create<dai::node::ColorCamera>();
auto imu = pipeline.create<dai::node::IMU>();
auto sync = pipeline.create<dai::node::Sync>();
auto xoutGroup = pipeline.create<dai::node::XLinkOut>();

xoutGroup->setStreamName("xout");

colorCamera->setCamera("color");

imu->enableIMUSensor(dai::IMUSensor::ROTATION_VECTOR, 120);
imu->setBatchReportThreshold(1);
imu->setMaxBatchReports(10);

sync->setSyncThreshold(std::chrono::milliseconds(10));
sync->setSyncAttempts(-1); // Infinite attempts

colorCamera->video.link(sync->inputs["video"]);
imu->out.link(sync->inputs["imu"]);

sync->out.link(xoutGroup->input);

device.startPipeline(pipeline);

auto groupQueue = device.getOutputQueue("xout", 3, false);

while(true) {
auto groupMessage = groupQueue->get<dai::MessageGroup>();
auto imuData = groupMessage->get<dai::IMUData>("imu");
auto colorData = groupMessage->get<dai::ImgFrame>("video");
auto timeDifference = imuData->getTimestampDevice() - colorData->getTimestampDevice();
auto timeDifferenceUs = std::chrono::duration_cast<std::chrono::microseconds>(timeDifference).count();

std::cout << "Time difference between messages is: " << std::abs(timeDifferenceUs / 1000.0) << " ms" << std::endl;

for(auto& packet : imuData->packets) {
auto& rv = packet.rotationVector;

printf(
"Quaternion: i: %.3f j: %.3f k: %.3f real: %.3f\n"
"Accuracy (rad): %.3f \n",
rv.i,
rv.j,
rv.k,
rv.real,
rv.rotationVectorAccuracy);
}

cv::imshow("Color", colorData->getCvFrame());
if(cv::waitKey(1) == 'q') {
break;
}
}

return 0;
}
2 changes: 1 addition & 1 deletion shared/depthai-shared

0 comments on commit 0cae1b0

Please sign in to comment.