Comments (2)
Hi @BearrGod !
The issue you face is that the code does a "double free"
as both shared pointers that you created attempt to free/destruct the same underlying raw pointer.
Here is the corrected code:
#include <iostream>
#include <memory>
#include <opencv4/opencv2/highgui.hpp>
// Includes common necessary includes for development using depthai library
#include <depthai/depthai.hpp>
bool firstTs = false;
auto baseTs = std::chrono::time_point<std::chrono::steady_clock, std::chrono::steady_clock::duration>();
void imu_cb_dai(std::shared_ptr<dai::ADatatype> callback) {
using namespace std;
using namespace std::chrono;
auto imuData = std::dynamic_pointer_cast<dai::IMUData>(callback);
if(imuData) {
auto imuPackets = imuData->packets;
for(auto& imuPacket : imuPackets) {
auto& acceleroValues = imuPacket.acceleroMeter;
auto& gyroValues = imuPacket.gyroscope;
auto acceleroTs1 = acceleroValues.getTimestampDevice();
auto gyroTs1 = gyroValues.getTimestampDevice();
if(!firstTs) {
baseTs = std::min(acceleroTs1, gyroTs1);
firstTs = true;
}
auto acceleroTs = acceleroTs1 - baseTs;
auto gyroTs = gyroTs1 - baseTs;
printf("Accelerometer timestamp: %ld ms\n", static_cast<long>(duration_cast<milliseconds>(acceleroTs).count()));
// printf("Accelerometer [m/s^2]: x: %.3f y: %.3f z: %.3f \n", acceleroValues.x, acceleroValues.y, acceleroValues.z);
// printf("Gyroscope timestamp: %ld ms\n", static_cast<long>(duration_cast<milliseconds>(gyroTs).count()));
// printf("Gyroscope [rad/s]: x: %.3f y: %.3f z: %.3f \n", gyroValues.x, gyroValues.y, gyroValues.z);
}
} else
std::cout << "Imu ptr returned null \n";
}
int main() {
// Create pipeline
dai::Pipeline pipeline;
// Define sources and outputs
auto imu = pipeline.create<dai::node::IMU>();
auto xlinkOut = pipeline.create<dai::node::XLinkOut>();
xlinkOut->setStreamName("imu");
// enable ACCELEROMETER_RAW at 500 hz rate
imu->enableIMUSensor(dai::IMUSensor::ACCELEROMETER_RAW, 500);
// enable GYROSCOPE_RAW at 400 hz rate
imu->enableIMUSensor(dai::IMUSensor::GYROSCOPE_RAW, 400);
// it's recommended to set both setBatchReportThreshold and setMaxBatchReports to 20 when integrating in a pipeline with a lot of input/output connections
// above this threshold packets will be sent in batch of X, if the host is not blocked and USB bandwidth is available
imu->setBatchReportThreshold(1);
// maximum number of IMU packets in a batch, if it's reached device will block sending until host can receive it
// if lower or equal to batchReportThreshold then the sending is always blocking on device
// useful to reduce device's CPU load and number of lost packets, if CPU load is high on device side due to multiple nodes
imu->setMaxBatchReports(10);
// Link plugins IMU -> XLINK
imu->out.link(xlinkOut->input);
// Pipeline is defined, now we can connect to the device
dai::Device d(pipeline);
auto imuQueue = d.getOutputQueue("imu", 50, false);
baseTs = std::chrono::time_point<std::chrono::steady_clock, std::chrono::steady_clock::duration>();
imuQueue->addCallback(imu_cb_dai);
while(true) {
int key = cv::waitKey(1);
if(key == 'q') {
return 0;
}
}
return 0;
}
from depthai-core.
Hi @moratom . Thanks a lot for your help. I fixed my issue.
from depthai-core.
Related Issues (20)
- [Documentation] Use depthai-core library in Android HOT 1
- [BUG] Unable to access to 4 TOFs from 4 S5K33D through OAK-FFC-4P HOT 2
- [BUG] Where is this file XLink/XLinkTime.h ? HOT 1
- [Feature-Request] Add options to avoid installing some dependencies with Hunter HOT 8
- Feature Request: Add `maxSensitivityIso` to `setAutoExposureLimit()` HOT 5
- [Feature-Request] {Frame sync for OAK-T} HOT 1
- [Feature-Request] Live Update of ImageManip Mesh HOT 2
- Fatal error. Please report to developers. Log: 'Fatal error on MSS CPU: trap: 09, address: 80290064' '0' HOT 6
- [BUG] OAK-FFC-6P detects only 3 cameras at a time HOT 2
- [BUG] error: no member named 'numShaves' in 'dai::ToFProperties' HOT 3
- [BUG] Intermittent Issues with OAK-D W PoE Cameras Streaming Left Camera Data HOT 10
- [BUG] Will not generate ninja compile files with external compiled xlink directory HOT 1
- [BUG] depthai-core.dll will not link HOT 9
- [BUG] host get wrong message from outputQueue HOT 2
- [BUG] {Segfault using the same camera stream for two different xlink outs}
- [BUG] Pipeline crash when undistorting color image using Camera Node HOT 1
- [BUG] Not able to get video when using stereo pipeline HOT 1
- device->addLogCallback() doesn't work for bootloader warnings
- can't get factory bootloader version when running user bootloader
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from depthai-core.