Sensor.hh
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2012 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 GAZEBO_SENSORS_SENSOR_HH_
18 #define GAZEBO_SENSORS_SENSOR_HH_
19 
20 #include <vector>
21 #include <memory>
22 #include <map>
23 #include <string>
24 
25 #include <sdf/sdf.hh>
26 #include <ignition/math/Pose3.hh>
27 #include <ignition/transport/Node.hh>
28 
32 
33 #include "gazebo/msgs/msgs.hh"
34 #include "gazebo/common/Events.hh"
35 #include "gazebo/common/Time.hh"
37 #include "gazebo/util/system.hh"
38 
39 namespace gazebo
40 {
41  namespace sensors
42  {
43  // Forward declare private data
44  class SensorPrivate;
45 
48 
51  class GZ_SENSORS_VISIBLE Sensor
52  : public std::enable_shared_from_this<Sensor>
53  {
56  public: explicit Sensor(SensorCategory _cat);
57 
59  public: virtual ~Sensor();
60 
64  public: virtual void Load(const std::string &_worldName,
65  sdf::ElementPtr _sdf);
66 
69  public: virtual void Load(const std::string &_worldName);
70 
72  public: virtual void Init();
73 
77  public: void SetParent(const std::string &_name, const uint32_t _id);
78 
82  public: std::string ParentName() const;
83 
86  public: virtual void Update(const bool _force);
87 
90  public: double UpdateRate() const;
91 
94  public: void SetUpdateRate(const double _hz);
95 
97  public: virtual void Fini();
98 
101  public: std::string Name() const;
102 
105  public: std::string ScopedName() const;
106 
110  public: virtual ignition::math::Pose3d Pose() const;
111 
115  public: virtual void SetPose(const ignition::math::Pose3d &_pose);
116 
119  public: virtual void SetActive(const bool _value);
120 
123  public: virtual bool IsActive() const;
124 
127  public: std::string Type() const;
128 
131  public: common::Time LastUpdateTime() const;
132 
136 
140  public: bool Visualize() const;
141 
144  public: virtual std::string Topic() const;
145 
148  public: void FillMsg(msgs::Sensor &_msg);
149 
152  public: std::string WorldName() const;
153 
160  std::function<void()> _subscriber);
161 
165  public: SensorCategory Category() const;
166 
168  public: virtual void ResetLastUpdateTime();
169 
172  public: uint32_t Id() const;
173 
176  public: uint32_t ParentId() const;
177 
182  public: NoisePtr Noise(const SensorNoiseType _type) const;
183 
186  public: virtual double NextRequiredTimestamp() const;
187 
190  public: bool StrictRate() const;
191 
198  protected: virtual bool UpdateImpl(const bool /*_force*/) {return false;}
199 
202  protected: virtual bool NeedsUpdate();
203 
206  private: void LoadPlugin(sdf::ElementPtr _sdf);
207 
213  protected: static bool useStrictRate;
214 
216  protected: bool active;
217 
219  protected: sdf::ElementPtr sdf;
220 
222  protected: ignition::math::Pose3d pose;
223 
225  protected: std::vector<event::ConnectionPtr> connections;
226 
229 
231  protected: std::string parentName;
232 
234  protected: uint32_t parentId;
235 
237  protected: std::vector<SensorPluginPtr> plugins;
238 
241 
244 
248 
251 
255 
257  protected: std::map<SensorNoiseType, NoisePtr> noises;
258 
260  protected: event::EventT<void()> updated;
261 
263  protected: ignition::transport::Node nodeIgn;
264 
267  private: std::unique_ptr<SensorPrivate> dataPtr;
268  };
270  }
271 }
272 #endif
sdf::ElementPtr sdf
Pointer the the SDF element for the sensor.
Definition: Sensor.hh:219
ignition::math::Pose3d pose
Pose of the sensor.
Definition: Sensor.hh:222
virtual bool NeedsUpdate()
Return true if the sensor needs to be updated.
std::vector< SensorPluginPtr > plugins
All the plugins for the sensor.
Definition: Sensor.hh:237
virtual void Fini()
Finalize the sensor.
Sensor(SensorCategory _cat)
Constructor.
transport::NodePtr node
Node for communication.
Definition: Sensor.hh:228
void SetUpdateRate(const double _hz)
Set the update rate of the sensor.
virtual bool UpdateImpl(const bool)
This gets overwritten by derived sensor types.
Definition: Sensor.hh:198
virtual void Load(const std::string &_worldName, sdf::ElementPtr _sdf)
Load the sensor with SDF parameters.
event::EventT< void()> updated
Event triggered when a sensor is updated.
Definition: Sensor.hh:260
virtual ~Sensor()
Destructor.
Forward declarations for the common classes.
Definition: Animation.hh:27
A Time class, can be used to hold wall- or sim-time.
Definition: Time.hh:48
uint32_t ParentId() const
Get the sensor's parent's ID.
void SetParent(const std::string &_name, const uint32_t _id)
Set the sensor's parent.
std::string parentName
Name of the parent.
Definition: Sensor.hh:231
virtual void Update(const bool _force)
Update the sensor.
void FillMsg(msgs::Sensor &_msg)
fills a msgs::Sensor message.
sensors
Definition: SensorManager.hh:37
common::Time LastMeasurementTime() const
Return last measurement time.
SensorCategory Category() const
Get the category of the sensor.
Forward declarations for transport.
common::Time LastUpdateTime() const
Return last update time.
bool active
True if sensor generation is active.
Definition: Sensor.hh:216
Forward declarations and typedefs for sensors.
std::vector< event::ConnectionPtr > connections
All event connections.
Definition: Sensor.hh:225
virtual void ResetLastUpdateTime()
Reset the lastUpdateTime to zero.
ignition::transport::Node nodeIgn
Ignition transport node.
Definition: Sensor.hh:263
virtual std::string Topic() const
Returns the topic name as set in SDF.
virtual double NextRequiredTimestamp() const
Get the next timestamp that will be used by the sensor.
default namespace for gazebo
boost::shared_ptr< Node > NodePtr
Definition: TransportTypes.hh:57
uint32_t parentId
The sensor's parent ID.
Definition: Sensor.hh:234
static bool useStrictRate
Whether to enforce strict sensor update rate, even if physics time has to slow down to wait for senso...
Definition: Sensor.hh:213
A class for event processing.
Definition: Event.hh:100
boost::shared_ptr< Scene > ScenePtr
Definition: RenderTypes.hh:82
std::string WorldName() const
Returns the name of the world the sensor is in.
bool Visualize() const
Return true if user requests the sensor to be visualized via tag: <visualize>true</visualize> in SDF.
virtual void Load(const std::string &_worldName)
Load the sensor with default parameters.
common::Time lastUpdateTime
Time of the last update.
Definition: Sensor.hh:250
std::string Name() const
Get name.
double UpdateRate() const
Get the update rate of the sensor.
event::ConnectionPtr ConnectUpdated(std::function< void()> _subscriber)
Connect a signal that is triggered when the sensor is updated.
gazebo::physics::WorldPtr world
Pointer to the world.
Definition: Sensor.hh:240
std::string Type() const
Get sensor type.
std::string ScopedName() const
Get fully scoped name of the sensor.
gazebo::rendering::ScenePtr scene
Pointer to the Scene.
Definition: Sensor.hh:243
bool StrictRate() const
Returns true if the sensor is to follow strict update rate.
boost::shared_ptr< Connection > ConnectionPtr
Definition: CommonTypes.hh:134
std::string ParentName() const
Returns the name of the sensor parent.
uint32_t Id() const
Get the sensor's ID.
virtual void SetActive(const bool _value)
Set whether the sensor is active or not.
virtual bool IsActive() const
Returns true if sensor generation is active.
SensorNoiseType
Definition: SensorTypes.hh:209
virtual void Init()
Initialize the sensor.
std::map< SensorNoiseType, NoisePtr > noises
Noise added to sensor data.
Definition: Sensor.hh:257
common::Time lastMeasurementTime
Stores last time that a sensor measurement was generated; this value must be updated within each sens...
Definition: Sensor.hh:254
Base class for sensors.
Definition: Sensor.hh:53
NoisePtr Noise(const SensorNoiseType _type) const
Get the sensor's noise model for a specified noise type.
virtual ignition::math::Pose3d Pose() const
Get the current pose.
boost::shared_ptr< World > WorldPtr
Definition: PhysicsTypes.hh:90
std::shared_ptr< Noise > NoisePtr
Definition: SensorTypes.hh:124
virtual void SetPose(const ignition::math::Pose3d &_pose)
Set the current pose.
SensorCategory
SensorCategory is used to categorize sensors.
Definition: SensorTypes.hh:309
common::Time updatePeriod
Desired time between updates, set indirectly by Sensor::SetUpdateRate.
Definition: Sensor.hh:247