imu_rotation_vector.cpp
Go to the documentation of this file.
1 
2 #include <cstdio>
3 #include <iostream>
4 
5 #include "utility.hpp"
6 
7 // Includes common necessary includes for development using depthai library
8 #include "depthai/depthai.hpp"
9 
10 int main() {
11  using namespace std;
12  using namespace std::chrono;
13 
14  // Create pipeline
15  dai::Pipeline pipeline;
16 
17  // Define sources and outputs
18  auto imu = pipeline.create<dai::node::IMU>();
19  auto xlinkOut = pipeline.create<dai::node::XLinkOut>();
20 
21  xlinkOut->setStreamName("imu");
22 
23  // enable ROTATION_VECTOR at 400 hz rate
25  // it's recommended to set both setBatchReportThreshold and setMaxBatchReports to 20 when integrating in a pipeline with a lot of input/output connections
26  // above this threshold packets will be sent in batch of X, if the host is not blocked and USB bandwidth is available
27  imu->setBatchReportThreshold(1);
28  // maximum number of IMU packets in a batch, if it's reached device will block sending until host can receive it
29  // if lower or equal to batchReportThreshold then the sending is always blocking on device
30  // useful to reduce device's CPU load and number of lost packets, if CPU load is high on device side due to multiple nodes
31  imu->setMaxBatchReports(10);
32 
33  // Link plugins IMU -> XLINK
34  imu->out.link(xlinkOut->input);
35 
36  dai::Device d(pipeline);
37 
38  auto imuQueue = d.getOutputQueue("imu", 50, false);
39  auto baseTs = steady_clock::now();
40 
41  while(true) {
42  auto imuData = imuQueue->get<dai::IMUData>();
43 
44  auto imuPackets = imuData->packets;
45  for(auto& imuPacket : imuPackets) {
46  auto& rVvalues = imuPacket.rotationVector;
47 
48  auto rvTs = rVvalues.getTimestampDevice() - baseTs;
49  printf("Rotation vector timestamp: %ld ms\n", static_cast<long>(duration_cast<milliseconds>(rvTs).count()));
50 
51  printf(
52  "Quaternion: i: %.3f j: %.3f k: %.3f real: %.3f\n"
53  "Accuracy (rad): %.3f \n",
54  rVvalues.i,
55  rVvalues.j,
56  rVvalues.k,
57  rVvalues.real,
58  rVvalues.rotationVectorAccuracy);
59  }
60 
61  int key = cv::waitKey(1);
62  if(key == 'q') {
63  return 0;
64  }
65  }
66 
67  return 0;
68 }
dai::node::XLinkOut
XLinkOut node. Sends messages over XLink.
Definition: XLinkOut.hpp:14
dai::Pipeline
Represents the pipeline, set of nodes and connections between them.
Definition: Pipeline.hpp:100
dai::IMUData
Definition: IMUData.hpp:14
dai::IMUSensor::ROTATION_VECTOR
@ ROTATION_VECTOR
dai::node::IMU
IMU node for BNO08X.
Definition: IMU.hpp:14
dai::Device::getOutputQueue
std::shared_ptr< DataOutputQueue > getOutputQueue(const std::string &name)
Definition: Device.cpp:86
depthai.hpp
main
int main()
Definition: imu_rotation_vector.cpp:10
dai::Pipeline::create
std::shared_ptr< N > create()
Definition: Pipeline.hpp:145
dai::node::IMU::enableIMUSensor
void enableIMUSensor(IMUSensorConfig sensorConfig)
Definition: IMU.cpp:14
dai::Device
Definition: Device.hpp:21
std
Definition: Node.hpp:366
dai::IMUData::packets
std::vector< IMUPacket > & packets
Detections.
Definition: IMUData.hpp:25
utility.hpp


depthai
Author(s): Martin Peterlin
autogenerated on Sat Mar 22 2025 02:58:19