Gazebo Sensors

API Reference

3.6.0
gz/sensors/Sensor.hh
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2017 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_SENSOR_HH_
18 #define GZ_SENSORS_SENSOR_HH_
19 
20 #ifdef _WIN32
21 #pragma warning(push)
22 #pragma warning(disable: 4005)
23 #pragma warning(disable: 4251)
24 #endif
25 #include <gz/msgs/header.pb.h>
26 #ifdef _WIN32
27 #pragma warning(pop)
28 #endif
29 
30 #include <chrono>
31 #include <memory>
32 #include <string>
33 
34 #include <gz/common/SuppressWarning.hh>
35 #include <gz/common/Time.hh>
36 #include <gz/math/Pose3.hh>
37 #include <gz/sensors/config.hh>
38 #include <gz/sensors/Export.hh>
39 #include <sdf/sdf.hh>
40 
41 namespace ignition
42 {
43  namespace sensors
44  {
45  // Inline bracket to help doxygen filtering.
46  inline namespace IGNITION_SENSORS_VERSION_NAMESPACE {
47  //
50  const SensorId NO_SENSOR = 0;
51 
53  class SensorPrivate;
54 
60  class IGNITION_SENSORS_VISIBLE Sensor
61  {
63  protected: Sensor();
64 
66  public: virtual ~Sensor();
67 
71  public: virtual bool Load(const sdf::Sensor &_sdf);
72 
76  public: virtual bool Load(sdf::ElementPtr _sdf);
77 
79  public: virtual bool Init();
80 
94  public: virtual bool Update(const common::Time &_now) = 0;
95 
97  public: common::Time NextUpdateTime() const;
98 
112  public: bool Update(const common::Time &_now, const bool _force);
113 
119  public: double UpdateRate() const;
120 
125  public: void SetUpdateRate(const double _hz);
126 
129  public: gz::math::Pose3d Pose() const;
130 
132  public: void SetPose(const gz::math::Pose3d &_pose);
133 
135  public: virtual void SetParent(const std::string &_parent);
136 
139  public: std::string Name() const;
140 
143  public: std::string FrameId() const;
144 
147  public: void SetFrameId(const std::string &_frameId);
148 
151  public: std::string Topic() const;
152 
156  public: bool SetTopic(const std::string &_topic);
157 
160  public: bool EnableMetrics() const;
161 
164  public: void SetEnableMetrics(bool _enableMetrics);
165 
168  public: std::string Parent() const;
169 
172  public: SensorId Id() const;
173 
177  public: sdf::ElementPtr SDF() const;
178 
197  public: void AddSequence(gz::msgs::Header *_msg,
198  const std::string &_seqKey = "default");
199 
203  public: void PublishMetrics(
204  const std::chrono::duration<double> &_now);
205 
206  IGN_COMMON_WARN_IGNORE__DLL_INTERFACE_MISSING
209  private: std::unique_ptr<SensorPrivate> dataPtr;
210  IGN_COMMON_WARN_RESUME__DLL_INTERFACE_MISSING
211  };
212  }
213  }
214 }
215 
216 #endif
gz::math::Pose3d Pose() const
Get the current pose.
Definition: gz/sensors/AirPressureSensor.hh:32
STL class.
double UpdateRate() const
Get the update rate of the sensor.
void SetEnableMetrics(bool _enableMetrics)
Set flag to enable publishing performance metrics.
std::string FrameId() const
FrameId.
void PublishMetrics(const std::chrono::duration< double > &_now)
Publishes information about the performance of the sensor. This method is called by Update().
sdf::ElementPtr SDF() const
Get the SDF used to load this sensor.
virtual void SetParent(const std::string &_parent)
Set the parent of the sensor.
virtual bool Update(const common::Time &_now)=0
Force the sensor to generate data.
void SetPose(const gz::math::Pose3d &_pose)
Update the pose of the sensor.
void SetFrameId(const std::string &_frameId)
Set Frame ID of the sensor.
const SensorId NO_SENSOR
Definition: gz/sensors/Sensor.hh:50
common::Time NextUpdateTime() const
Return the next time the sensor will generate data.
std::string Parent() const
Get parent link of the sensor.
virtual bool Load(const sdf::Sensor &_sdf)
Load the sensor based on data from an sdf::Sensor object.
bool SetTopic(const std::string &_topic)
Set topic where sensor data is published.
virtual bool Init()
Initialize values in the sensor.
std::string Topic() const
Get topic where sensor data is published.
std::string Name() const
Get name.
bool EnableMetrics() const
Get flag state for enabling performance metrics publication.
void SetUpdateRate(const double _hz)
Set the update rate of the sensor. An update rate of zero means that the sensor is updated every cycl...
a base sensor class
Definition: gz/sensors/Sensor.hh:60
SensorId Id() const
Get the sensor's ID.
void AddSequence(gz::msgs::Header *_msg, const std::string &_seqKey="default")
Add a sequence number to an gz::msgs::Header. This function can be called by a sensor that wants to a...
virtual ~Sensor()
destructor