参考论文:
①https://blog.csdn.net/WisdomXLH/article/details/80548293
②https://blog.csdn.net/WisdomXLH/article/details/80556795
③https://blog.csdn.net/sunyoop/article/details/78302090
此程序在在SDK中的rplidar_sdk-master\sdk\app\ultra_simple下进行修改,修改main.cpp文件。增加Target_orientation.cpp与Target_orientation.h文件。主要实现的功能是探测在固定的雷达扫面扇区内的目标物体的方位信息,距离信息,长度信息。
main.c文件:
//user header files
#include "Target_orientation.h"
#ifdef _WIN32
#include <Windows.h>
#define delay(x) ::Sleep(x)
#else
#include <unistd.h>
static inline void delay(_word_size_t ms){
while (ms>=1000){
usleep(1000*1000);
ms-=1000;
};
if (ms!=0)
usleep(ms*1000);
}
#endif
using namespace rp::standalone::rplidar;
bool checkRPLIDARHealth(RPlidarDriver * drv)
{
u_result op_result;
rplidar_response_device_health_t healthinfo;
op_result = drv->getHealth(healthinfo);
if (IS_OK(op_result)) { // the macro IS_OK is the preperred way to judge whether the operation is succeed.
printf("RPLidar health status : %d\n", healthinfo.status);
if (healthinfo.status == RPLIDAR_STATUS_ERROR) {
fprintf(stderr, "Error, rplidar internal error detected. Please reboot the device to retry.\n");
// enable the following code if you want rplidar to be reboot by software
// drv->reset();
return false;
} else {
return true;
}
} else {
fprintf(stderr, "Error, cannot retrieve the lidar health code: %x\n", op_result);
return false;
}
}
#include <signal.h>
bool ctrl_c_pressed;
void ctrlc(int)
{
ctrl_c_pressed = true;
}
int main(int argc, const char * argv[]) {
const char * opt_com_path = NULL;
_u32 baudrateArray[2] = {115200, 256000};
_u32 opt_com_baudrate = 0;
u_result op_result;
double target_slope = 0;
double target_length = 0;
target_information_t target_information;
bool useArgcBaudrate = false;
/*
printf("Ultra simple LIDAR data grabber for RPLIDAR.\n"
"Version: "RPLIDAR_SDK_VERSION"\n");
*/
printf("Ultra simple LIDAR data grabber for RPLIDAR.\n"
"Version: %s\n", RPLIDAR_SDK_VERSION);
// read serial port from the command line...
if (argc>1) opt_com_path = argv[1]; // or set to a fixed value: e.g. "com3"
// read baud rate from the command line if specified...
if (argc>2)
{
opt_com_baudrate = strtoul(argv[2], NULL, 10);
useArgcBaudrate = true;
}
if (!opt_com_path) {
#ifdef _WIN32
// use default com port
opt_com_path = "\\\\.\\com3";
#else
opt_com_path = "/dev/ttyUSB0";
#endif
}
// create the driver instance
RPlidarDriver * drv = RPlidarDriver::CreateDriver(DRIVER_TYPE_SERIALPORT);
if (!drv) {
fprintf(stderr, "insufficent memory, exit\n");
exit(-2);
}
rplidar_response_device_info_t devinfo;
bool connectSuccess = false;
// make connection...
if(useArgcBaudrate)
{
if(!d