ydlidar_driver.h
#ifndef YDLIDAR_DRIVER_H
#define YDLIDAR_DRIVER_H
#include <stdlib.h>
#include <map>
#include "serial.h"
#include "locker.h"
#include "thread.h"
#include "ydlidar_protocol.h"
#if !defined(__cplusplus)
#ifndef __cplusplus
#error "The YDLIDAR SDK requires a C++ compiler to be built"
#endif
#endif
using namespace std;
using namespace serial;
namespace ydlidar {
class YDlidarDriver {
public:
YDlidarDriver();
virtual ~YDlidarDriver();
result_t connect(const char *port_path, uint32_t baudrate);
void disconnect();
static std::string getSDKVersion();
static std::map<std::string, std::string> lidarPortList();
bool isConnected() const;
bool isScanning() const;
uint32_t getPointTime() const;
void setAutoReconnect(const bool &enable);
result_t startScan(bool force = false, uint32_t timeout = DEFAULT_TIMEOUT) ;
result_t stop();
result_t grabScanData(node_info *nodebuffer, size_t &count,
uint32_t timeout = DEFAULT_TIMEOUT) ;
result_t ascendScanData(node_info *nodebuffer, size_t count);
result_t startMotor();
result_t stopMotor();
void flush();
protected:
result_t createThread();
result_t startAutoScan(bool force = false, uint32_t timeout = DEFAULT_TIMEOUT) ;
result_t waitPackage(node_info *node, uint32_t timeout = DEFAULT_TIMEOUT);
result_t waitScanData(node_info *nodebuffer, size_t &count,
uint32_t timeout = DEFAULT_TIMEOUT);
int cacheScanData();
result_t sendCommand(uint8_t cmd, const void *payload = NULL,
size_t payloadsize = 0);
result_t waitResponseHeader(lidar_ans_header *header,
uint32_t timeout = DEFAULT_TIMEOUT);
result_t waitForData(size_t data_count, uint32_t timeout = DEFAULT_TIMEOUT,
size_t *returned_size = NULL);
result_t getData(uint8_t *data, size_t size);
result_t sendData(const uint8_t *data, size_t size);
void disableDataGrabbing();
void setDTR();
void clearDTR();
public:
bool m_isConnected;
bool m_isScanning;
bool isAutoReconnect;
bool isAutoconnting;
enum {
DEFAULT_TIMEOUT = 2000,
DEFAULT_HEART_BEAT = 1000,
MAX_SCAN_NODES = 2048,
DEFAULT_TIMEOUT_COUNT = 3,
};
enum {
YDLIDAR_F4 = 1,
YDLIDAR_T1 = 2,
YDLIDAR_F2 = 3,
YDLIDAR_S4 = 4,
YDLIDAR_G4 = 5,
YDLIDAR_X4 = 6,
YDLIDAR_F4PRO = 6,
YDLIDAR_G4C = 9,
};
node_info scan_node_buf[2048];
size_t scan_node_count;
Event _dataEvent;
Locker _lock;
Locker _serial_lock;
Thread _thread;
private:
serial::Serial *_serial;
node_packages packages;
float IntervalSampleAngle;
float IntervalSampleAngle_LastPackage;
int PackageSampleBytes;
bool isSupportMotorCtrl;
bool CheckSumResult;
uint32_t m_baudrate;
uint32_t m_pointTime;
uint32_t trans_delay;
uint16_t package_Sample_Index;
uint16_t FirstSampleAngle;
uint16_t LastSampleAngle;
uint16_t CheckSum;
uint16_t CheckSumCal;
uint16_t SampleNumlAndCTCal;
uint16_t LastSampleAngleCal;
uint16_t Valu8Tou16;
std::string serial_port;
};
}
#endif // YDLIDAR_DRIVER_H
ydlidar::YDlidarDriver::scan_node_count
size_t scan_node_count
激光点数
Definition: ydlidar_driver.h:310
ydlidar
Definition: v8stdint.h:199
ydlidar::YDlidarDriver::_dataEvent
Event _dataEvent
数据同步事件
Definition: ydlidar_driver.h:311
Event
Definition: locker.h:167
ydlidar::YDlidarDriver::_thread
Thread _thread
线程id
Definition: ydlidar_driver.h:314
std
lidar_ans_header
Definition: ydlidar_protocol.h:97
ydlidar::YDlidarDriver::_lock
Locker _lock
线程锁
Definition: ydlidar_driver.h:312
ydlidar::YDlidarDriver::_serial_lock
Locker _serial_lock
串口锁
Definition: ydlidar_driver.h:313
Thread
Definition: thread.h:22
serial
Definition: serial.h:11
ydlidar::YDlidarDriver::m_isConnected
bool m_isConnected
串口连接状体
Definition: ydlidar_driver.h:286
ydlidar::YDlidarDriver::isAutoconnting
bool isAutoconnting
是否正在自动连接中
Definition: ydlidar_driver.h:289
ydlidar::YDlidarDriver::isAutoReconnect
bool isAutoReconnect
异常自动从新连接
Definition: ydlidar_driver.h:288
ydlidar::YDlidarDriver
Definition: ydlidar_driver.h:21
ydlidar::YDlidarDriver::m_isScanning
bool m_isScanning
扫图状态
Definition: ydlidar_driver.h:287
node_info
Definition: ydlidar_protocol.h:15
serial::Serial
Definition: serial.h:107
Locker
Definition: locker.h:20
node_packages
Definition: ydlidar_protocol.h:39