YDLIDAR SDK  V1.4.5
ydlidar_protocol.h
1 /*********************************************************************
2 * Software License Agreement (BSD License)
3 *
4 * Copyright (c) 2018, EAIBOT, Inc.
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 *
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above
14 * copyright notice, this list of conditions and the following
15 * disclaimer in the documentation and/or other materials provided
16 * with the distribution.
17 * * Neither the name of the Willow Garage nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32 * POSSIBILITY OF SUCH DAMAGE.
33 *********************************************************************/
34 #pragma once
35 #include "v8stdint.h"
36 #include <vector>
37 
38 #define PropertyBuilderByName(type, name, access_permission)\
39  access_permission:\
40  type m_##name;\
41  public:\
42  inline void set##name(type v) {\
43  m_##name = v;\
44  }\
45  inline type get##name() {\
46  return m_##name;\
47 }\
48 
49 
50 #if !defined(_countof)
51 #define _countof(_Array) (int)(sizeof(_Array) / sizeof(_Array[0]))
52 #endif
53 
54 #ifndef M_PI
55 #define M_PI 3.1415926
56 #endif
57 
58 #define SUNNOISEINTENSITY 0xff
59 #define GLASSNOISEINTENSITY 0xfe
60 
61 #define LIDAR_CMD_STOP 0x65
62 #define LIDAR_CMD_SCAN 0x60
63 #define LIDAR_CMD_FORCE_SCAN 0x61
64 #define LIDAR_CMD_RESET 0x80
65 #define LIDAR_CMD_FORCE_STOP 0x00
66 #define LIDAR_CMD_GET_EAI 0x55
67 #define LIDAR_CMD_GET_DEVICE_INFO 0x90
68 #define LIDAR_CMD_GET_DEVICE_HEALTH 0x92
69 #define LIDAR_ANS_TYPE_DEVINFO 0x4
70 #define LIDAR_ANS_TYPE_DEVHEALTH 0x6
71 #define LIDAR_CMD_SYNC_BYTE 0xA5
72 #define LIDAR_CMDFLAG_HAS_PAYLOAD 0x80
73 #define LIDAR_ANS_SYNC_BYTE1 0xA5
74 #define LIDAR_ANS_SYNC_BYTE2 0x5A
75 #define LIDAR_ANS_TYPE_MEASUREMENT 0x81
76 #define LIDAR_RESP_MEASUREMENT_SYNCBIT (0x1<<0)
77 #define LIDAR_RESP_MEASUREMENT_QUALITY_SHIFT 2
78 #define LIDAR_RESP_MEASUREMENT_CHECKBIT (0x1<<0)
79 #define LIDAR_RESP_MEASUREMENT_ANGLE_SHIFT 1
80 #define LIDAR_RESP_MEASUREMENT_DISTANCE_SHIFT 2
81 #define LIDAR_RESP_MEASUREMENT_ANGLE_SAMPLE_SHIFT 8
82 
83 #define LIDAR_CMD_RUN_POSITIVE 0x06
84 #define LIDAR_CMD_RUN_INVERSION 0x07
85 #define LIDAR_CMD_SET_AIMSPEED_ADDMIC 0x09
86 #define LIDAR_CMD_SET_AIMSPEED_DISMIC 0x0A
87 #define LIDAR_CMD_SET_AIMSPEED_ADD 0x0B
88 #define LIDAR_CMD_SET_AIMSPEED_DIS 0x0C
89 #define LIDAR_CMD_GET_AIMSPEED 0x0D
90 
91 #define LIDAR_CMD_SET_SAMPLING_RATE 0xD0
92 #define LIDAR_CMD_GET_SAMPLING_RATE 0xD1
93 #define LIDAR_STATUS_OK 0x0
94 #define LIDAR_STATUS_WARNING 0x1
95 #define LIDAR_STATUS_ERROR 0x2
96 
97 #define LIDAR_CMD_ENABLE_LOW_POWER 0x01
98 #define LIDAR_CMD_DISABLE_LOW_POWER 0x02
99 #define LIDAR_CMD_STATE_MODEL_MOTOR 0x05
100 #define LIDAR_CMD_ENABLE_CONST_FREQ 0x0E
101 #define LIDAR_CMD_DISABLE_CONST_FREQ 0x0F
102 
103 #define LIDAR_CMD_GET_OFFSET_ANGLE 0x93
104 #define LIDAR_CMD_SAVE_SET_EXPOSURE 0x94
105 #define LIDAR_CMD_SET_LOW_EXPOSURE 0x95
106 #define LIDAR_CMD_ADD_EXPOSURE 0x96
107 #define LIDAR_CMD_DIS_EXPOSURE 0x97
108 
109 
110 #define PackageSampleMaxLngth 0x100
111 typedef enum {
112  CT_Normal = 0,
113  CT_RingStart = 1,
114  CT_Tail,
115 } CT;
116 #define Node_Default_Quality (10)
117 #define Node_Sync 1
118 #define Node_NotSync 2
119 #define PackagePaidBytes 10
120 #define PH 0x55AA
121 #define NORMAL_PACKAGE_SIZE 90
122 #define INTENSITY_NORMAL_PACKAGE_SIZE 130
123 
124 
125 typedef enum {
126  TYPE_TOF = 0,
127  TYPE_TRIANGLE = 1,
128  TYPE_Tail,
129 } LidarTypeID;
130 
131 #if defined(_WIN32)
132 #pragma pack(1)
133 #endif
134 
135 struct node_info {
136  uint8_t sync_flag; //sync flag
137  uint16_t sync_quality;
138  uint16_t angle_q6_checkbit;
139  uint16_t distance_q2;
140  uint64_t stamp;
141  uint8_t scan_frequence;
142  uint8_t debug_info[12];
143  uint8_t index;
144 } __attribute__((packed)) ;
145 
146 struct PackageNode {
147  uint8_t PakageSampleQuality;
148  uint16_t PakageSampleDistance;
149 } __attribute__((packed));
150 
151 struct node_package {
152  uint16_t package_Head;
153  uint8_t package_CT;
154  uint8_t nowPackageNum;
155  uint16_t packageFirstSampleAngle;
156  uint16_t packageLastSampleAngle;
157  uint16_t checkSum;
158  PackageNode packageSample[PackageSampleMaxLngth];
159 } __attribute__((packed)) ;
160 
162  uint16_t package_Head;
163  uint8_t package_CT;
164  uint8_t nowPackageNum;
165  uint16_t packageFirstSampleAngle;
166  uint16_t packageLastSampleAngle;
167  uint16_t checkSum;
168  uint16_t packageSampleDistance[PackageSampleMaxLngth];
169 } __attribute__((packed)) ;
170 
171 
172 struct device_info {
173  uint8_t model;
174  uint16_t firmware_version;
176  uint8_t serialnum[16];
177 } __attribute__((packed)) ;
178 
180  uint8_t status;
181  uint16_t error_code;
182 } __attribute__((packed)) ;
183 
185  uint8_t rate;
186 } __attribute__((packed)) ;
187 
189  uint32_t frequency;
190 } __attribute__((packed)) ;
191 
193  uint8_t rotation;
194 } __attribute__((packed)) ;
195 
197  uint8_t exposure;
198 } __attribute__((packed)) ;
199 
201  uint8_t enable;
202 } __attribute__((packed));
203 
204 struct scan_points {
205  uint8_t flag;
206 } __attribute__((packed)) ;
207 
209  uint8_t state;
210 } __attribute__((packed)) ;
211 
212 struct offset_angle {
213  int32_t angle;
214 } __attribute__((packed)) ;
215 
216 struct cmd_packet {
217  uint8_t syncByte;
218  uint8_t cmd_flag;
219  uint8_t size;
220  uint8_t data;
221 } __attribute__((packed)) ;
222 
224  uint8_t syncByte1;
225  uint8_t syncByte2;
226  uint32_t size: 30;
227  uint32_t subType: 2;
228  uint8_t type;
229 } __attribute__((packed));
230 
231 #if defined(_WIN32)
232 #pragma pack()
233 #endif
234 
235 struct LaserPoint {
237  float angle;
239  float range;
241  float intensity;
242  LaserPoint &operator = (const LaserPoint &data) {
243  this->angle = data.angle;
244  this->range = data.range;
245  this->intensity = data.intensity;
246  return *this;
247  }
248 };
249 
250 struct LaserDebug {
251  uint8_t W3F4CusMajor_W4F0CusMinor;
252  uint8_t W4F3Model_W3F0DebugInfTranVer;
253  uint8_t W3F4HardwareVer_W4F0FirewareMajor;
254  uint8_t W3F4BoradHardVer_W4F0Moth;
255  uint8_t W2F5Output2K4K5K_W5F0Date;
256  uint8_t W1F6GNoise_W1F5SNoise_W1F4MotorCtl_W4F0SnYear;
257  uint8_t W7F0SnNumH;
258  uint8_t W7F0SnNumL;
259  uint8_t MaxDebugIndex;
260 };
261 
263 struct LaserConfig {
265  float min_angle;
267  float max_angle;
273  float scan_time;
275  float min_range;
277  float max_range;
278  LaserConfig &operator = (const LaserConfig &data) {
279  min_angle = data.min_angle;
280  max_angle = data.max_angle;
281  angle_increment = data.angle_increment;
282  time_increment = data.time_increment;
283  scan_time = data.scan_time;
284  min_range = data.min_range;
285  max_range = data.max_range;
286  return *this;
287  }
288 };
289 
290 
291 //struct LaserScan {
292 // //! Array of ranges
293 // std::vector<float> ranges;
294 // //! Array of intensities
295 // std::vector<float> intensities;
296 // //! System time when first range was measured in nanoseconds
297 // uint64_t system_time_stamp;
298 // //! Configuration of scan
299 // LaserConfig config;
300 // LaserScan &operator = (const LaserScan &data) {
301 // this->ranges = data.ranges;
302 // this->intensities = data.intensities;
303 // system_time_stamp = data.system_time_stamp;
304 // config = data.config;
305 // return *this;
306 // }
307 //};
308 
309 struct LaserScan {
311  uint64_t stamp;
313  std::vector<LaserPoint> points;
316  LaserScan &operator = (const LaserScan &data) {
317  this->points = data.points;
318  this->stamp = data.stamp;
319  this->config = data.config;
320  return *this;
321  }
322 
323 };
uint8_t rate
采样频率
Definition: ydlidar_protocol.h:185
uint8_t scan_frequence
时间戳
Definition: ydlidar_protocol.h:141
float min_angle
Start angle for the laser scan [rad]. 0 is forward and angles are measured clockwise when viewing YDL...
Definition: ydlidar_protocol.h:265
uint8_t status
健康状体
Definition: ydlidar_protocol.h:180
Definition: ydlidar_protocol.h:216
Definition: ydlidar_protocol.h:179
uint16_t error_code
错误代码
Definition: ydlidar_protocol.h:181
uint8_t debug_info[12]
特定版本此值才有效,无效值是0
Definition: ydlidar_protocol.h:142
Definition: ydlidar_protocol.h:223
Definition: ydlidar_protocol.h:235
A struct for returning configuration from the YDLIDAR.
Definition: ydlidar_protocol.h:263
Definition: ydlidar_protocol.h:309
Definition: ydlidar_protocol.h:151
Definition: ydlidar_protocol.h:200
uint8_t enable
掉电保护状态
Definition: ydlidar_protocol.h:201
Definition: ydlidar_protocol.h:250
uint64_t stamp
当前测距点距离
Definition: ydlidar_protocol.h:140
uint8_t exposure
低光功率模式
Definition: ydlidar_protocol.h:197
float range
lidar range
Definition: ydlidar_protocol.h:239
float intensity
lidar intensity
Definition: ydlidar_protocol.h:241
Definition: ydlidar_protocol.h:172
Definition: ydlidar_protocol.h:184
float time_increment
Scan resoltuion [s].
Definition: ydlidar_protocol.h:271
float scan_time
Time between scans.
Definition: ydlidar_protocol.h:273
Definition: ydlidar_protocol.h:212
float max_angle
Stop angle for the laser scan [rad]. 0 is forward and angles are measured clockwise when viewing YDLI...
Definition: ydlidar_protocol.h:267
float max_range
Maximum range [m].
Definition: ydlidar_protocol.h:277
std::vector< LaserPoint > points
Array of lidar points.
Definition: ydlidar_protocol.h:313
uint16_t firmware_version
固件版本号
Definition: ydlidar_protocol.h:174
uint16_t distance_q2
测距点角度
Definition: ydlidar_protocol.h:139
uint16_t angle_q6_checkbit
信号质量
Definition: ydlidar_protocol.h:138
Definition: ydlidar_protocol.h:196
uint8_t model
雷达型号
Definition: ydlidar_protocol.h:173
uint8_t hardware_version
硬件版本号
Definition: ydlidar_protocol.h:175
Definition: ydlidar_protocol.h:204
float min_range
Minimum range [m].
Definition: ydlidar_protocol.h:275
float angle
lidar angle
Definition: ydlidar_protocol.h:237
Definition: ydlidar_protocol.h:192
uint64_t stamp
System time when first range was measured in nanoseconds.
Definition: ydlidar_protocol.h:311
uint32_t frequency
扫描频率
Definition: ydlidar_protocol.h:189
LaserConfig config
Configuration of scan.
Definition: ydlidar_protocol.h:315
float angle_increment
angle resoltuion [rad]
Definition: ydlidar_protocol.h:269
Definition: ydlidar_protocol.h:135
Definition: ydlidar_protocol.h:188
Definition: ydlidar_protocol.h:146
Definition: ydlidar_protocol.h:208
Definition: ydlidar_protocol.h:161