-
Notifications
You must be signed in to change notification settings - Fork 4
/
ydlidar_protocol.h
323 lines (283 loc) · 9.84 KB
/
ydlidar_protocol.h
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
/*********************************************************************
* Software License Agreement (BSD License)
*
* Copyright (c) 2018, EAIBOT, Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* * Neither the name of the Willow Garage nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*********************************************************************/
#pragma once
#include "v8stdint.h"
#include <vector>
#define PropertyBuilderByName(type, name, access_permission)\
access_permission:\
type m_##name;\
public:\
inline void set##name(type v) {\
m_##name = v;\
}\
inline type get##name() {\
return m_##name;\
}\
#if !defined(_countof)
#define _countof(_Array) (int)(sizeof(_Array) / sizeof(_Array[0]))
#endif
#ifndef M_PI
#define M_PI 3.1415926
#endif
#define SUNNOISEINTENSITY 0xff
#define GLASSNOISEINTENSITY 0xfe
#define LIDAR_CMD_STOP 0x65
#define LIDAR_CMD_SCAN 0x60
#define LIDAR_CMD_FORCE_SCAN 0x61
#define LIDAR_CMD_RESET 0x80
#define LIDAR_CMD_FORCE_STOP 0x00
#define LIDAR_CMD_GET_EAI 0x55
#define LIDAR_CMD_GET_DEVICE_INFO 0x90
#define LIDAR_CMD_GET_DEVICE_HEALTH 0x92
#define LIDAR_ANS_TYPE_DEVINFO 0x4
#define LIDAR_ANS_TYPE_DEVHEALTH 0x6
#define LIDAR_CMD_SYNC_BYTE 0xA5
#define LIDAR_CMDFLAG_HAS_PAYLOAD 0x80
#define LIDAR_ANS_SYNC_BYTE1 0xA5
#define LIDAR_ANS_SYNC_BYTE2 0x5A
#define LIDAR_ANS_TYPE_MEASUREMENT 0x81
#define LIDAR_RESP_MEASUREMENT_SYNCBIT (0x1<<0)
#define LIDAR_RESP_MEASUREMENT_QUALITY_SHIFT 2
#define LIDAR_RESP_MEASUREMENT_CHECKBIT (0x1<<0)
#define LIDAR_RESP_MEASUREMENT_ANGLE_SHIFT 1
#define LIDAR_RESP_MEASUREMENT_DISTANCE_SHIFT 2
#define LIDAR_RESP_MEASUREMENT_ANGLE_SAMPLE_SHIFT 8
#define LIDAR_CMD_RUN_POSITIVE 0x06
#define LIDAR_CMD_RUN_INVERSION 0x07
#define LIDAR_CMD_SET_AIMSPEED_ADDMIC 0x09
#define LIDAR_CMD_SET_AIMSPEED_DISMIC 0x0A
#define LIDAR_CMD_SET_AIMSPEED_ADD 0x0B
#define LIDAR_CMD_SET_AIMSPEED_DIS 0x0C
#define LIDAR_CMD_GET_AIMSPEED 0x0D
#define LIDAR_CMD_SET_SAMPLING_RATE 0xD0
#define LIDAR_CMD_GET_SAMPLING_RATE 0xD1
#define LIDAR_STATUS_OK 0x0
#define LIDAR_STATUS_WARNING 0x1
#define LIDAR_STATUS_ERROR 0x2
#define LIDAR_CMD_ENABLE_LOW_POWER 0x01
#define LIDAR_CMD_DISABLE_LOW_POWER 0x02
#define LIDAR_CMD_STATE_MODEL_MOTOR 0x05
#define LIDAR_CMD_ENABLE_CONST_FREQ 0x0E
#define LIDAR_CMD_DISABLE_CONST_FREQ 0x0F
#define LIDAR_CMD_GET_OFFSET_ANGLE 0x93
#define LIDAR_CMD_SAVE_SET_EXPOSURE 0x94
#define LIDAR_CMD_SET_LOW_EXPOSURE 0x95
#define LIDAR_CMD_ADD_EXPOSURE 0x96
#define LIDAR_CMD_DIS_EXPOSURE 0x97
#define PackageSampleMaxLngth 0x100
typedef enum {
CT_Normal = 0,
CT_RingStart = 1,
CT_Tail,
} CT;
#define Node_Default_Quality (10)
#define Node_Sync 1
#define Node_NotSync 2
#define PackagePaidBytes 10
#define PH 0x55AA
#define NORMAL_PACKAGE_SIZE 90
#define INTENSITY_NORMAL_PACKAGE_SIZE 130
typedef enum {
TYPE_TOF = 0,
TYPE_TRIANGLE = 1,
TYPE_Tail,
} LidarTypeID;
#if defined(_WIN32)
#pragma pack(1)
#endif
struct node_info {
uint8_t sync_flag; //sync flag
uint16_t sync_quality;//!信号质量
uint16_t angle_q6_checkbit; //!测距点角度
uint16_t distance_q2; //! 当前测距点距离
uint64_t stamp; //! 时间戳
uint8_t scan_frequence;//! 特定版本此值才有效,无效值是0
uint8_t debug_info[12];
uint8_t index;
} __attribute__((packed)) ;
struct PackageNode {
uint8_t PakageSampleQuality;
uint16_t PakageSampleDistance;
} __attribute__((packed));
struct node_package {
uint16_t package_Head;
uint8_t package_CT;
uint8_t nowPackageNum;
uint16_t packageFirstSampleAngle;
uint16_t packageLastSampleAngle;
uint16_t checkSum;
PackageNode packageSample[PackageSampleMaxLngth];
} __attribute__((packed)) ;
struct node_packages {
uint16_t package_Head;
uint8_t package_CT;
uint8_t nowPackageNum;
uint16_t packageFirstSampleAngle;
uint16_t packageLastSampleAngle;
uint16_t checkSum;
uint16_t packageSampleDistance[PackageSampleMaxLngth];
} __attribute__((packed)) ;
struct device_info {
uint8_t model; ///< 雷达型号
uint16_t firmware_version; ///< 固件版本号
uint8_t hardware_version; ///< 硬件版本号
uint8_t serialnum[16]; ///< 系列号
} __attribute__((packed)) ;
struct device_health {
uint8_t status; ///< 健康状体
uint16_t error_code; ///< 错误代码
} __attribute__((packed)) ;
struct sampling_rate {
uint8_t rate; ///< 采样频率
} __attribute__((packed)) ;
struct scan_frequency {
uint32_t frequency; ///< 扫描频率
} __attribute__((packed)) ;
struct scan_rotation {
uint8_t rotation;
} __attribute__((packed)) ;
struct scan_exposure {
uint8_t exposure; ///< 低光功率模式
} __attribute__((packed)) ;
struct scan_heart_beat {
uint8_t enable; ///< 掉电保护状态
} __attribute__((packed));
struct scan_points {
uint8_t flag;
} __attribute__((packed)) ;
struct function_state {
uint8_t state;
} __attribute__((packed)) ;
struct offset_angle {
int32_t angle;
} __attribute__((packed)) ;
struct cmd_packet {
uint8_t syncByte;
uint8_t cmd_flag;
uint8_t size;
uint8_t data;
} __attribute__((packed)) ;
struct lidar_ans_header {
uint8_t syncByte1;
uint8_t syncByte2;
uint32_t size: 30;
uint32_t subType: 2;
uint8_t type;
} __attribute__((packed));
#if defined(_WIN32)
#pragma pack()
#endif
struct LaserPoint {
//! lidar angle [rad]
float angle;
//! lidar range [m]
float range;
//! lidar intensity
float intensity;
LaserPoint &operator = (const LaserPoint &data) {
this->angle = data.angle;
this->range = data.range;
this->intensity = data.intensity;
return *this;
}
};
struct LaserDebug {
uint8_t W3F4CusMajor_W4F0CusMinor;
uint8_t W4F3Model_W3F0DebugInfTranVer;
uint8_t W3F4HardwareVer_W4F0FirewareMajor;
uint8_t W3F4BoradHardVer_W4F0Moth;
uint8_t W2F5Output2K4K5K_W5F0Date;
uint8_t W1F6GNoise_W1F5SNoise_W1F4MotorCtl_W4F0SnYear;
uint8_t W7F0SnNumH;
uint8_t W7F0SnNumL;
uint8_t MaxDebugIndex;
};
//! A struct for returning configuration from the YDLIDAR
struct LaserConfig {
//! Start angle for the laser scan [rad]. 0 is forward and angles are measured clockwise when viewing YDLIDAR from the top.
float min_angle;
//! Stop angle for the laser scan [rad]. 0 is forward and angles are measured clockwise when viewing YDLIDAR from the top.
float max_angle;
//! angle resoltuion [rad]
float angle_increment;
//! Scan resoltuion [s]
float time_increment;
//! Time between scans
float scan_time;
//! Minimum range [m]
float min_range;
//! Maximum range [m]
float max_range;
LaserConfig &operator = (const LaserConfig &data) {
min_angle = data.min_angle;
max_angle = data.max_angle;
angle_increment = data.angle_increment;
time_increment = data.time_increment;
scan_time = data.scan_time;
min_range = data.min_range;
max_range = data.max_range;
return *this;
}
};
//struct LaserScan {
// //! Array of ranges
// std::vector<float> ranges;
// //! Array of intensities
// std::vector<float> intensities;
// //! System time when first range was measured in nanoseconds
// uint64_t system_time_stamp;
// //! Configuration of scan
// LaserConfig config;
// LaserScan &operator = (const LaserScan &data) {
// this->ranges = data.ranges;
// this->intensities = data.intensities;
// system_time_stamp = data.system_time_stamp;
// config = data.config;
// return *this;
// }
//};
struct LaserScan {
//! System time when first range was measured in nanoseconds
uint64_t stamp;
//! Array of lidar points
std::vector<LaserPoint> points;
//! Configuration of scan
LaserConfig config;
LaserScan &operator = (const LaserScan &data) {
this->points = data.points;
this->stamp = data.stamp;
this->config = data.config;
return *this;
}
};