-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample.cpp
130 lines (104 loc) · 4.24 KB
/
example.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
/*****************************************************************************
* EAI TOF LIDAR DRIVER *
* Copyright (C) 2018 EAI TEAM chushuifurong618@eaibot.com. *
* *
* This file is part of EAI TOF LIDAR DRIVER. *
* *
* @file example.cpp *
* @brief ETLidar Driver example *
* Details. *
* *
* @author Tony.Yang *
* @email chushuifurong618@eaibot.com *
* @version 1.0.0(版本号) *
* @date chushuifurong618@eaibot.com *
* *
* *
*----------------------------------------------------------------------------*
* Remark : Description *
*----------------------------------------------------------------------------*
* Change History : *
* <Date> | <Version> | <Author> | <Description> *
*----------------------------------------------------------------------------*
* 2018/08/09 | 1.0.0 | Tony.Yang | Create file *
*----------------------------------------------------------------------------*
* *
*****************************************************************************/
#include "ETLidarDriver.h"
#include <config.h>
#include "Console.h"
#include <iostream>
#include <iterator>
#include <algorithm>
#include <regex>
#if defined(_WIN32)
# pragma warning(disable: 4786)
# pragma comment(lib, "etlidar_driver.lib")
#endif
using namespace ydlidar;
int main(int argc, char **argv) {
std::string lidarIP;
std::string port;
ydlidar::init(argc, argv);
again:
printf("Please enter the lidar IP[192.168.0.11](yes):");
std::cin >> lidarIP;
regex reg("(\\d{1,3}).(\\d{1,3}).(\\d{1,3}).(\\d{1,3})");
smatch m;
if (!ydlidar::ok()) {
return 0;
}
if (lidarIP.find("yes") != std::string::npos) {
lidarIP = "192.168.0.11";
}
if (!regex_match(lidarIP, m, reg)) {
ydlidar::console.warning("ip address input error, please again.");
goto again;
}
ydlidar::ETLidarDriver lidar;
lidarConfig config;
if (!lidar.getScanCfg(config, lidarIP)) {
ydlidar::console.error("Failed to get Lidar Config. exit...");
return 0;
}
printf("Please enter the lidar port[%d](yes):", config.dataRecvPort);
std::cin >> port;
if (port.find("yes") == std::string::npos) {
config.dataRecvPort = atoi(port.c_str());
}
if (!ydlidar::ok()) {
return 0;
}
printf("Please enter the lidar scan frequency[%dHZ](yes):",
config.motor_rpm / 60);
std::cin >> port;
if (port.find("yes") == std::string::npos) {
config.motor_rpm = atoi(port.c_str()) * 60;
}
if (!ydlidar::ok()) {
return 0;
}
lidar.updateScanCfg(config);
ydlidar::console.message("SDK Version: %s", SDK_VERSION);
ydlidar::console.message("LIDAR Version: %s", EHLIDAR_VERSION);
result_t ans = lidar.connect(lidarIP, config.dataRecvPort);
if (!IS_OK(ans)) {
ydlidar::console.error("Failed to connecting lidar...");
return 0;
}
bool rs = lidar.turnOn();
while (rs && ydlidar::ok()) {
lidarData scan;
ans = lidar.grabScanData(scan);
if (IS_OK(ans)) {
ydlidar::console.message("scan recevied[%llu]: %d ranges [%f]hz",
scan.system_timestamp, scan.data.size(), 1e9 / scan.scan_time);
} else {
ydlidar::console.warning("Failed to get scan data");
}
}
lidar.turnOff();
lidar.disconnect();
ETLidarDriver::WSACleanUp();
return 0;
}