Gazebo Sensors

API Reference

6.9.0
gz/sensors/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/common/SuppressWarning.hh>
25 #include <gz/common/Event.hh>
26 
27 #include "gz/sensors/lidar/Export.hh"
29 
30 namespace ignition
31 {
32  namespace sensors
33  {
34  // Inline bracket to help doxygen filtering.
35  inline namespace IGNITION_SENSORS_VERSION_NAMESPACE {
36  //
38  class LidarPrivate;
39 
49  class IGNITION_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 
242  public: bool HasConnections() const;
243 
246  public: uint32_t VisibilityMask() const;
247 
253  private: double Clamp(double _range) const;
254 
255  IGN_COMMON_WARN_IGNORE__DLL_INTERFACE_MISSING
257  public: mutable std::mutex lidarMutex;
258  IGN_COMMON_WARN_RESUME__DLL_INTERFACE_MISSING
259 
261  public: float *laserBuffer = nullptr;
262 
264  public: bool initialized = false;
265 
273  public: virtual gz::common::ConnectionPtr ConnectNewLidarFrame(
274  std::function<void(const float *_scan, unsigned int _width,
275  unsigned int _heighti, unsigned int _channels,
276  const std::string &/*_format*/)> _subscriber);
277 
278  IGN_COMMON_WARN_IGNORE__DLL_INTERFACE_MISSING
281  private: std::unique_ptr<LidarPrivate> dataPtr;
282  IGN_COMMON_WARN_RESUME__DLL_INTERFACE_MISSING
283  };
284  }
285  }
286 }
287 
288 #endif
Lidar Sensor Class.
Definition: gz/sensors/Lidar.hh:50
double Range(const int _index) const
Get detected range for a ray. Warning: If you are accessing all the ray data in a loop it's possible ...
double HorzFOV() const
Get the horizontal field of view of the laser sensor.
double RangeMax() const
Get the maximum range.
double VerticalAngleResolution() const
Get the vertical angle in radians between each range.
double VertFOV() const
Get the vertical field-of-view.
gz::math::Angle VerticalAngleMax() const
Get the vertical scan line top angle.
void SetAngleMax(const double _angle)
Set the scan maximum angle.
virtual void Fini()
Finalize the ray.
unsigned int VerticalRayCount() const
Get the vertical scan line count.
double RangeCountRatio() const
Return the ratio of horizontal range count to vertical range count.
gz::math::Angle AngleMax() const
Get the maximum angle.
double RangeMin() const
Get the minimum range.
gz::math::Angle VerticalAngleMin() const
Get the vertical scan bottom angle.
void SetVerticalAngleMax(const double _angle)
Set the vertical scan line top angle.
virtual ~Lidar()
destructor
double RangeResolution() const
Get the range resolution If RangeResolution is 1, the number of simulated rays is equal to the number...
virtual bool PublishLidarScan(const std::chrono::steady_clock::duration &_now)
Publish LaserScan message.
void ApplyNoise()
Apply noise to the laser buffer, if noise has been configured. This should be called before PublishLi...
unsigned int RangeCount() const
Get the range count.
double RayCountRatio() const
Return the ratio of horizontal ray count to vertical ray count.
virtual bool Load(sdf::ElementPtr _sdf) override
Load the sensor with SDF parameters.
void Ranges(std::vector< double > &_ranges) const
Get all the ranges.
virtual bool IsActive() const
virtual bool Load(const sdf::Sensor &_sdf) override
Load the sensor based on data from an sdf::Sensor object.
virtual gz::common::ConnectionPtr ConnectNewLidarFrame(std::function< void(const float *_scan, unsigned int _width, unsigned int _heighti, unsigned int _channels, const std::string &)> _subscriber)
Set a callback to be called when data is generated.
void SetParent(const std::string &_parent) override
Initialize values in the sensor.
double AngleResolution() const
Get radians between each range.
virtual bool Update(const std::chrono::steady_clock::duration &_now) override
Force the sensor to generate data.
virtual bool CreateLidar()
Create Lidar sensor.
double Retro(const int _index) const
Get detected retro (intensity) value for a ray. Warning: If you are accessing all the ray data in a l...
void SetAngleMin(const double _angle)
Set the scan minimum angle.
int Fiducial(const unsigned int _index) const
Get detected fiducial value for a ray. Warning: If you are accessing all the ray data in a loop it's ...
void SetVerticalAngleMin(const double _angle)
Set the vertical scan bottom angle.
bool IsHorizontal() const
Gets if sensor is horizontal.
std::mutex lidarMutex
Just a mutex for thread safety.
Definition: gz/sensors/Lidar.hh:257
virtual bool Init() override
Initialize values in the sensor.
uint32_t VisibilityMask() const
Get the visibility mask.
bool HasConnections() const
Check if there are any subscribers for sensor data.
unsigned int RayCount() const
Get the ray count.
gz::math::Angle AngleMin() const
Get the minimum angle.
unsigned int VerticalRangeCount() const
Get the vertical scan line count.
a rendering sensor class
Definition: gz/sensors/RenderingSensor.hh:54
Definition: gz/sensors/AirPressureSensor.hh:32