ORB-SLAM3-UESTC/Workspace/Application/IMUDriver/IMUReader.h

65 lines
1.2 KiB
C
Raw Normal View History

2023-12-01 01:16:53 +08:00
#pragma once
#include <iostream>
#include <thread>
#include <chrono>
#include <string>
#include <boost/asio.hpp>
#include <boost/array.hpp>
2023-12-27 11:39:39 +08:00
#include <vector>
#include <opencv2/core/core.hpp>
using namespace std;
2023-12-01 01:16:53 +08:00
// 结构体定义 IMU 数据
struct IMUData {
2023-12-27 11:39:39 +08:00
cv::Point3f vAcc;
cv::Point3f vGyro;
double timestamp;
2023-12-01 01:16:53 +08:00
};
class IMUReader {
public:
// 构造函数
IMUReader(std::string ComNumber);
// 构造函数
IMUReader();
// 析构函数
~IMUReader();
// 初始化 IMU
void IMUInit(std::string ComNumber);
// 获取 IMU 数据状态
int ReadData(IMUData& data);
2023-12-27 11:39:39 +08:00
int IMUReadData();
std::vector<IMUData> imubuffer;
2023-12-01 01:16:53 +08:00
2023-12-27 11:39:39 +08:00
IMUData getdata() const{
std::unique_lock<std::mutex> lock(dataMutex);
return data;
};
2023-12-01 01:16:53 +08:00
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;
2023-12-27 11:39:39 +08:00
mutable std::mutex dataMutex;
2023-12-01 01:16:53 +08:00
// 读取 IMU 数据的循环
void IMUReadDataThread(void);
2023-12-27 11:39:39 +08:00
2023-12-01 01:16:53 +08:00
};