Sensor.hh
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2012-2016 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 
31 
32 #include "gazebo/msgs/msgs.hh"
33 #include "gazebo/common/Events.hh"
34 #include "gazebo/common/Time.hh"
36 #include "gazebo/util/system.hh"
37 
38 namespace gazebo
39 {
40  namespace sensors
41  {
42  // Forward declare private data
43  class SensorPrivate;
44 
47 
50  class GAZEBO_VISIBLE Sensor : public std::enable_shared_from_this<Sensor>
51  {
54  public: explicit Sensor(SensorCategory _cat);
55 
57  public: virtual ~Sensor();
58 
62  public: virtual void Load(const std::string &_worldName,
63  sdf::ElementPtr _sdf);
64 
67  public: virtual void Load(const std::string &_worldName);
68 
70  public: virtual void Init();
71 
75  public: void SetParent(const std::string &_name, const uint32_t _id);
76 
81  public: std::string GetParentName() const
82  GAZEBO_DEPRECATED(7.0);
83 
87  public: std::string ParentName() const;
88 
91  public: void Update(const bool _force);
92 
96  public: double GetUpdateRate() GAZEBO_DEPRECATED(7.0);
97 
100  public: double UpdateRate() const;
101 
104  public: void SetUpdateRate(const double _hz);
105 
107  public: virtual void Fini();
108 
112  public: std::string GetName() const GAZEBO_DEPRECATED(7.0);
113 
116  public: std::string Name() const;
117 
121  public: std::string GetScopedName() const GAZEBO_DEPRECATED(7.0);
122 
125  public: std::string ScopedName() const;
126 
130  public: virtual ignition::math::Pose3d Pose() const;
131 
135  public: virtual void SetPose(const ignition::math::Pose3d &_pose);
136 
139  public: virtual void SetActive(const bool _value);
140 
143  public: virtual bool IsActive() const;
144 
148  public: std::string GetType() const GAZEBO_DEPRECATED(7.0);
149 
152  public: std::string Type() const;
153 
157  public: common::Time GetLastUpdateTime() GAZEBO_DEPRECATED(7.0);
158 
161  public: common::Time LastUpdateTime() const;
162 
166  public: common::Time GetLastMeasurementTime() GAZEBO_DEPRECATED(7.0);
167 
171  public: common::Time LastMeasurementTime() const;
172 
177  public: bool GetVisualize() const GAZEBO_DEPRECATED(7.0);
178 
182  public: bool Visualize() const;
183 
187  public: virtual std::string GetTopic() const GAZEBO_DEPRECATED(7.0);
188 
191  public: virtual std::string Topic() const;
192 
195  public: void FillMsg(msgs::Sensor &_msg);
196 
200  public: std::string GetWorldName() const GAZEBO_DEPRECATED(7.0);
201 
204  public: std::string WorldName() const;
205 
211  public: event::ConnectionPtr ConnectUpdated(
212  std::function<void()> _subscriber);
213 
217  public: void DisconnectUpdated(event::ConnectionPtr &_c);
218 
223  public: SensorCategory GetCategory() const GAZEBO_DEPRECATED(7.0);
224 
228  public: SensorCategory Category() const;
229 
231  public: void ResetLastUpdateTime();
232 
236  public: uint32_t GetId() const GAZEBO_DEPRECATED(7.0);
237 
240  public: uint32_t Id() const;
241 
245  public: uint32_t GetParentId() const GAZEBO_DEPRECATED(7.0);
246 
249  public: uint32_t ParentId() const;
250 
256  public: NoisePtr GetNoise(const SensorNoiseType _type) const
257  GAZEBO_DEPRECATED(7.0);
258 
263  public: NoisePtr Noise(const SensorNoiseType _type) const;
264 
271  protected: virtual bool UpdateImpl(const bool /*_force*/) {return false;}
272 
275  protected: bool NeedsUpdate();
276 
279  private: void LoadPlugin(sdf::ElementPtr _sdf);
280 
282  protected: bool active;
283 
285  protected: sdf::ElementPtr sdf;
286 
288  protected: ignition::math::Pose3d pose;
289 
291  protected: std::vector<event::ConnectionPtr> connections;
292 
295 
297  protected: std::string parentName;
298 
300  protected: uint32_t parentId;
301 
303  protected: std::vector<SensorPluginPtr> plugins;
304 
307 
310 
314 
317 
321 
323  protected: std::map<SensorNoiseType, NoisePtr> noises;
324 
327  private: std::unique_ptr<SensorPrivate> dataPtr;
328  };
330  }
331 }
332 #endif
virtual bool UpdateImpl(const bool)
This gets overwritten by derived sensor types.
Definition: Sensor.hh:271
boost::shared_ptr< Connection > ConnectionPtr
Definition: CommonTypes.hh:153
std::vector< SensorPluginPtr > plugins
All the plugins for the sensor.
Definition: Sensor.hh:303
uint32_t parentId
The sensor's parent ID.
Definition: Sensor.hh:300
common::Time updatePeriod
Desired time between updates, set indirectly by Sensor::SetUpdateRate.
Definition: Sensor.hh:313
gazebo::rendering::ScenePtr scene
Pointer to the Scene.
Definition: Sensor.hh:309
gazebo::physics::WorldPtr world
Pointer to the world.
Definition: Sensor.hh:306
Forward declarations for transport.
#define GAZEBO_DEPRECATED(version)
Definition: CommonTypes.hh:48
common::Time lastUpdateTime
Time of the last update.
Definition: Sensor.hh:316
default namespace for gazebo
common::Time lastMeasurementTime
Stores last time that a sensor measurement was generated; this value must be updated within each sens...
Definition: Sensor.hh:320
std::shared_ptr< Noise > NoisePtr
Definition: SensorTypes.hh:119
std::string parentName
Name of the parent.
Definition: Sensor.hh:297
std::map< SensorNoiseType, NoisePtr > noises
Noise added to sensor data.
Definition: Sensor.hh:323
boost::shared_ptr< World > WorldPtr
Definition: PhysicsTypes.hh:84
SensorCategory
SensorCategory is used to categorize sensors.
Definition: SensorTypes.hh:303
ignition::math::Pose3d pose
Pose of the sensor.
Definition: Sensor.hh:288
sdf::ElementPtr sdf
Pointer the the SDF element for the sensor.
Definition: Sensor.hh:285
boost::shared_ptr< Node > NodePtr
Definition: TransportTypes.hh:57
boost::shared_ptr< Scene > ScenePtr
Definition: RenderTypes.hh:80
bool active
True if sensor generation is active.
Definition: Sensor.hh:282
GAZEBO_VISIBLE void Init(google::protobuf::Message &_message, const std::string &_id="")
Initialize a message.
Forward declarations and typedefs for sensors.
SensorNoiseType
Definition: SensorTypes.hh:203
std::vector< event::ConnectionPtr > connections
All event connections.
Definition: Sensor.hh:291
Base class for sensors.
Definition: Sensor.hh:50
#define GAZEBO_VISIBLE
Use to represent "symbol visible" if supported.
Definition: system.hh:59
transport::NodePtr node
Node for communication.
Definition: Sensor.hh:294
A Time class, can be used to hold wall- or sim-time.
Definition: Time.hh:44
Noise models for sensor output signals.
Definition: Noise.hh:55