Gazebo Sensors

API Reference

6.9.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/math/Pose3.hh>
36 #include <gz/sensors/config.hh>
37 #include <gz/sensors/Export.hh>
38 #include <sdf/sdf.hh>
39 
40 namespace ignition
41 {
42  namespace sensors
43  {
44  // Inline bracket to help doxygen filtering.
45  inline namespace IGNITION_SENSORS_VERSION_NAMESPACE {
46  //
49  const SensorId NO_SENSOR = 0;
50 
52  class SensorPrivate;
53 
59  class IGNITION_SENSORS_VISIBLE Sensor
60  {
62  protected: Sensor();
63 
65  public: virtual ~Sensor();
66 
70  public: virtual bool Load(const sdf::Sensor &_sdf);
71 
75  public: virtual bool Load(sdf::ElementPtr _sdf);
76 
81  public: virtual bool Init();
82 
96  public: virtual bool Update(
97  const std::chrono::steady_clock::duration &_now) = 0;
98 
100  public: std::chrono::steady_clock::duration NextDataUpdateTime() const;
101 
115  public: bool Update(
116  const std::chrono::steady_clock::duration &_now, const bool _force);
117 
123  public: double UpdateRate() const;
124 
129  public: void SetUpdateRate(const double _hz);
130 
133  public: gz::math::Pose3d Pose() const;
134 
136  public: void SetPose(const gz::math::Pose3d &_pose);
137 
139  public: virtual void SetParent(const std::string &_parent);
140 
143  public: std::string Name() const;
144 
147  public: std::string FrameId() const;
148 
151  public: void SetFrameId(const std::string &_frameId);
152 
155  public: std::string Topic() const;
156 
160  public: bool SetTopic(const std::string &_topic);
161 
164  public: bool EnableMetrics() const;
165 
168  public: void SetEnableMetrics(bool _enableMetrics);
169 
172  public: std::string Parent() const;
173 
176  public: SensorId Id() const;
177 
181  public: sdf::ElementPtr SDF() const;
182 
201  public: void AddSequence(gz::msgs::Header *_msg,
202  const std::string &_seqKey = "default");
203 
207  public: void PublishMetrics(
208  const std::chrono::duration<double> &_now);
209 
213  public: bool IsActive() const;
214 
221  public: void SetActive(bool _active);
222 
223  IGN_COMMON_WARN_IGNORE__DLL_INTERFACE_MISSING
226  private: std::unique_ptr<SensorPrivate> dataPtr;
227  IGN_COMMON_WARN_RESUME__DLL_INTERFACE_MISSING
228  };
229  }
230  }
231 }
232 #endif
a base sensor class
Definition: gz/sensors/Sensor.hh:60
void PublishMetrics(const std::chrono::duration< double > &_now)
Publishes information about the performance of the sensor. This method is called by Update().
double UpdateRate() const
Get the update rate of the sensor.
virtual bool Update(const std::chrono::steady_clock::duration &_now)=0
Force the sensor to generate data.
virtual void SetParent(const std::string &_parent)
Set the parent of the sensor.
void SetActive(bool _active)
Enable or disable the sensor. Disabled sensors will not generate or publish data unless Update is cal...
bool SetTopic(const std::string &_topic)
Set topic where sensor data is published.
std::string Name() const
Get name.
std::string Parent() const
Get parent link of the sensor.
virtual ~Sensor()
destructor
std::string Topic() const
Get topic where sensor data is published.
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...
bool Update(const std::chrono::steady_clock::duration &_now, const bool _force)
Update the sensor.
SensorId Id() const
Get the sensor's ID.
void SetEnableMetrics(bool _enableMetrics)
Set flag to enable publishing performance metrics.
std::chrono::steady_clock::duration NextDataUpdateTime() const
Return the next time the sensor will generate data.
virtual bool Load(sdf::ElementPtr _sdf)
Load the sensor with SDF parameters.
std::string FrameId() const
FrameId.
sdf::ElementPtr SDF() const
Get the SDF used to load this sensor.
virtual bool Load(const sdf::Sensor &_sdf)
Load the sensor based on data from an sdf::Sensor object.
bool IsActive() const
Get whether the sensor is enabled or not.
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...
void SetFrameId(const std::string &_frameId)
Set Frame ID of the sensor.
void SetPose(const gz::math::Pose3d &_pose)
Update the pose of the sensor.
gz::math::Pose3d Pose() const
Get the current pose.
bool EnableMetrics() const
Get flag state for enabling performance metrics publication.
virtual bool Init()
Initialize values in the sensor This will set the next update time to zero. This is particularly usef...
const SensorId NO_SENSOR
Definition: gz/sensors/Sensor.hh:49
Definition: gz/sensors/AirPressureSensor.hh:32