forked from logzhan/ORB-SLAM3-UESTC
65 lines
1.2 KiB
C++
65 lines
1.2 KiB
C++
#pragma once
|
|
|
|
#include <iostream>
|
|
#include <thread>
|
|
#include <chrono>
|
|
#include <string>
|
|
#include <boost/asio.hpp>
|
|
#include <boost/array.hpp>
|
|
#include <vector>
|
|
#include <opencv2/core/core.hpp>
|
|
|
|
|
|
using namespace std;
|
|
|
|
// 结构体定义 IMU 数据
|
|
struct IMUData {
|
|
|
|
cv::Point3f vAcc;
|
|
cv::Point3f vGyro;
|
|
double timestamp;
|
|
|
|
|
|
};
|
|
|
|
class IMUReader {
|
|
public:
|
|
// 构造函数
|
|
IMUReader(std::string ComNumber);
|
|
|
|
// 构造函数
|
|
IMUReader();
|
|
|
|
// 析构函数
|
|
~IMUReader();
|
|
|
|
// 初始化 IMU
|
|
void IMUInit(std::string ComNumber);
|
|
|
|
// 获取 IMU 数据状态
|
|
int ReadData(IMUData& data);
|
|
int IMUReadData();
|
|
std::vector<IMUData> imubuffer;
|
|
|
|
IMUData getdata() const{
|
|
std::unique_lock<std::mutex> lock(dataMutex);
|
|
return data;
|
|
};
|
|
private:
|
|
boost::asio::io_service io;
|
|
boost::asio::serial_port* serial;
|
|
// boost::asio::serial_port serial(io, "/dev/ttyUSB0"); // 替换成你的串口设备路径
|
|
|
|
bool isRunning; // 控制是否退出循环的标志变量
|
|
std::thread dataThread; // 数据读取线程
|
|
IMUData data;
|
|
mutable std::mutex dataMutex;
|
|
|
|
|
|
// 读取 IMU 数据的循环
|
|
|
|
void IMUReadDataThread(void);
|
|
|
|
|
|
};
|