Gazebo Sensors

API Reference

8.2.1
Lidar.hh
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2018 Open Source Robotics Foundation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16 */
17 #ifndef GZ_SENSORS_LIDAR_HH_
18 #define GZ_SENSORS_LIDAR_HH_
19 
20 #include <memory>
21 #include <string>
22 #include <vector>
23 
24 #include <gz/utils/SuppressWarning.hh>
25 #include <gz/common/Event.hh>
26 
27 #include "gz/sensors/lidar/Export.hh"
29 
30 namespace gz
31 {
32  namespace sensors
33  {
34  // Inline bracket to help doxygen filtering.
35  inline namespace GZ_SENSORS_VERSION_NAMESPACE {
36  //
38  class LidarPrivate;
39 
49  class GZ_SENSORS_LIDAR_VISIBLE Lidar : public RenderingSensor
50  {
52  public: Lidar();
53 
55  public: virtual ~Lidar();
56 
60  public: virtual bool Update(
61  const std::chrono::steady_clock::duration &_now) override;
62 
66  public: void ApplyNoise();
67 
71  public: virtual bool PublishLidarScan(
72  const std::chrono::steady_clock::duration &_now);
73 
77  public: virtual bool Load(const sdf::Sensor &_sdf) override;
78 
82  public: virtual bool Load(sdf::ElementPtr _sdf) override;
83 
86  public: virtual bool Init() override;
87 
90  public: void SetParent(const std::string &_parent) override;
91 
93  public: virtual bool CreateLidar();
94 
96  protected: virtual void Fini();
97 
100  public: gz::math::Angle AngleMin() const;
101 
104  public: void SetAngleMin(const double _angle);
105 
108  public: gz::math::Angle AngleMax() const;
109 
112  public: void SetAngleMax(const double _angle);
113 
116  public: double AngleResolution() const;
117 
120  public: double RangeMin() const;
121 
124  public: double RangeMax() const;
125 
133  public: double RangeResolution() const;
134 
137  public: unsigned int RayCount() const;
138 
141  public: unsigned int RangeCount() const;
142 
145  public: unsigned int VerticalRayCount() const;
146 
149  public: unsigned int VerticalRangeCount() const;
150 
153  public: gz::math::Angle VerticalAngleMin() const;
154 
157  public: void SetVerticalAngleMin(const double _angle);
158 
161  public: gz::math::Angle VerticalAngleMax() const;
162 
165  public: void SetVerticalAngleMax(const double _angle);
166 
169  public: double VerticalAngleResolution() const;
170 
180  public: double Range(const int _index) const;
181 
184  public: void Ranges(std::vector<double> &_ranges) const;
185 
195  public: double Retro(const int _index) const;
196 
206  public: int Fiducial(const unsigned int _index) const;
207 
210  public: bool IsHorizontal() const;
211 
218  public: double RayCountRatio() const;
219 
226  public: double RangeCountRatio() const;
227 
230  public: double HorzFOV() const;
231 
234  public: double VertFOV() const;
235 
236  // Documentation inherited
237  public: virtual bool IsActive() const;
238 
241  public: virtual bool HasConnections() const override;
242 
245  public: uint32_t VisibilityMask() const;
246 
252  private: double Clamp(double _range) const;
253 
254  GZ_UTILS_WARN_IGNORE__DLL_INTERFACE_MISSING
256  public: mutable std::mutex lidarMutex;
257  GZ_UTILS_WARN_RESUME__DLL_INTERFACE_MISSING
258 
260  public: float *laserBuffer = nullptr;
261 
263  public: bool initialized = false;
264 
272  public: virtual gz::common::ConnectionPtr ConnectNewLidarFrame(
273  std::function<void(const float *_scan, unsigned int _width,
274  unsigned int _heighti, unsigned int _channels,
275  const std::string &/*_format*/)> _subscriber);
276 
277  GZ_UTILS_WARN_IGNORE__DLL_INTERFACE_MISSING
280  private: std::unique_ptr<LidarPrivate> dataPtr;
281  GZ_UTILS_WARN_RESUME__DLL_INTERFACE_MISSING
282  };
283  }
284  }
285 }
286 
287 #endif