YDLIDAR SDK  V1.4.5
CYdLidar.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 "utils.h"
36 #include "ydlidar_driver.h"
37 #include <math.h>
38 
39 using namespace ydlidar;
40 
41 class YDLIDAR_API CYdLidar {
42  PropertyBuilderByName(float, MaxRange,
43  private)
44  PropertyBuilderByName(float, MinRange,
45  private)
46  PropertyBuilderByName(float, MaxAngle,
47  private)
48  PropertyBuilderByName(float, MinAngle,
49  private)
50  PropertyBuilderByName(int, SampleRate,
51  private)
52  PropertyBuilderByName(float, ScanFrequency,
53  private)
54  PropertyBuilderByName(bool, FixedResolution,
55  private)
56  PropertyBuilderByName(bool, Reversion,
57  private)
58  PropertyBuilderByName(bool, Inverted,
59  private)
60  PropertyBuilderByName(bool, AutoReconnect,
61  private)
62  PropertyBuilderByName(int, SerialBaudrate,
63  private)
64  PropertyBuilderByName(int, AbnormalCheckCount,
65  private)
66  PropertyBuilderByName(std::string, SerialPort,
67  private)
68  PropertyBuilderByName(std::vector<float>, IgnoreArray,
69  private)
70  PropertyBuilderByName(float, OffsetTime,
71  private)
72  PropertyBuilderByName(bool, SingleChannel,
73  private)
74  PropertyBuilderByName(int, LidarType,
75  private)
76 
77 
78  public:
79  CYdLidar();
80  virtual ~CYdLidar();
81 
85  bool initialize();
86 
87  // Return true if laser data acquistion succeeds, If it's not
88  bool doProcessSimple(LaserScan &outscan,
89  bool &hardwareError);
90 
91  //Turn on the motor enable
92  bool turnOn();
93 
94  //Turn off the motor enable and close the scan
95  bool turnOff();
96 
97  //Turn off lidar connection
98  void disconnecting();
99 
100  //get zero angle offset value
101  float getAngleOffset() const;
102 
103  //Whether the zero offset angle is corrected?
104  bool isAngleOffetCorrected() const;
105 
107  std::string getSoftVersion() const;
108 
110  std::string getHardwareVersion() const;
111 
113  std::string getSerialNumber() const;
114 
115  protected:
120  bool checkCOMMs();
121 
125  bool checkStatus();
126 
130  bool checkHardware();
131 
133  bool getDeviceHealth();
134 
136  bool getDeviceInfo();
137 
141  void checkSampleRate();
142 
148  bool CalculateSampleRate(int count);
149 
151  bool checkScanFrequency();
152 
154  bool checkLidarAbnormal();
155 
160  void checkCalibrationAngle(const std::string &serialNumber);
161 
167  bool isRangeValid(double reading) const;
168 
174  bool isRangeIgnore(double angle) const;
175 
179  void handleSingleChannelDevice();
180 
186  void parsePackageNode(const node_info &node, LaserDebug &info);
187 
192  void handleDeviceInfoPackage(int count);
193 
198  void printfVersionInfo(const device_info &info);
199 
200  private:
201  bool isScanning;
202  int m_FixedSize ;
203  float m_AngleOffset;
204  bool m_isAngleOffsetCorrected;
205  float frequencyOffset;
206  int lidar_model;
207  uint8_t Major;
208  uint8_t Minjor;
209  YDlidarDriver *lidarPtr;
210  uint64_t m_PointTime;
211  uint64_t last_node_time;
212  node_info *global_nodes;
213  std::map<int, int> SampleRateMap;
214  bool m_ParseSuccess;
215  std::string m_lidarSoftVer;
216  std::string m_lidarHardVer;
217  std::string m_lidarSerialNum;
218 }; // End of class
219 
Definition: help_info.h:39
Definition: ydlidar_protocol.h:309
Definition: ydlidar_protocol.h:250
Definition: ydlidar_protocol.h:172
Definition: ydlidar_driver.h:75
Definition: CYdLidar.h:41
Definition: ydlidar_protocol.h:135