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 GAZEBO_VISIBLE Sensor : public std::enable_shared_from_this<Sensor>
52  {
55  public: explicit Sensor(SensorCategory _cat);
56 
58  public: virtual ~Sensor();
59 
63  public: virtual void Load(const std::string &_worldName,
64  sdf::ElementPtr _sdf);
65 
68  public: virtual void Load(const std::string &_worldName);
69 
71  public: virtual void Init();
72 
76  public: void SetParent(const std::string &_name, const uint32_t _id);
77 
81  public: std::string ParentName() const;
82 
85  public: void Update(const bool _force);
86 
89  public: double UpdateRate() const;
90 
93  public: void SetUpdateRate(const double _hz);
94 
96  public: virtual void Fini();
97 
100  public: std::string Name() const;
101 
104  public: std::string ScopedName() const;
105 
109  public: virtual ignition::math::Pose3d Pose() const;
110 
114  public: virtual void SetPose(const ignition::math::Pose3d &_pose);
115 
118  public: virtual void SetActive(const bool _value);
119 
122  public: virtual bool IsActive() const;
123 
126  public: std::string Type() const;
127 
130  public: common::Time LastUpdateTime() const;
131 
134  public: common::Time LastMeasurementTime() const;
135 
139  public: bool Visualize() const;
140 
143  public: virtual std::string Topic() const;
144 
147  public: void FillMsg(msgs::Sensor &_msg);
148 
151  public: std::string WorldName() const;
152 
158  public: event::ConnectionPtr ConnectUpdated(
159  std::function<void()> _subscriber);
160 
164  public: SensorCategory Category() const;
165 
167  public: void ResetLastUpdateTime();
168 
171  public: uint32_t Id() const;
172 
175  public: uint32_t ParentId() const;
176 
181  public: NoisePtr Noise(const SensorNoiseType _type) const;
182 
189  protected: virtual bool UpdateImpl(const bool /*_force*/) {return false;}
190 
193  protected: bool NeedsUpdate();
194 
197  private: void LoadPlugin(sdf::ElementPtr _sdf);
198 
200  protected: bool active;
201 
203  protected: sdf::ElementPtr sdf;
204 
206  protected: ignition::math::Pose3d pose;
207 
209  protected: std::vector<event::ConnectionPtr> connections;
210 
213 
215  protected: std::string parentName;
216 
218  protected: uint32_t parentId;
219 
221  protected: std::vector<SensorPluginPtr> plugins;
222 
225 
228 
232 
235 
239 
241  protected: std::map<SensorNoiseType, NoisePtr> noises;
242 
244  protected: ignition::transport::Node nodeIgn;
245 
248  private: std::unique_ptr<SensorPrivate> dataPtr;
249  };
251  }
252 }
253 #endif
SensorCategory
SensorCategory is used to categorize sensors.
Definition: SensorTypes.hh:308
std::shared_ptr< Noise > NoisePtr
Definition: SensorTypes.hh:124
boost::shared_ptr< World > WorldPtr
Definition: PhysicsTypes.hh:89
bool active
True if sensor generation is active.
Definition: Sensor.hh:200
Forward declarations for the common classes.
Definition: Animation.hh:33
sdf::ElementPtr sdf
Pointer the the SDF element for the sensor.
Definition: Sensor.hh:203
uint32_t parentId
The sensor&#39;s parent ID.
Definition: Sensor.hh:218
Forward declarations for transport.
std::string parentName
Name of the parent.
Definition: Sensor.hh:215
std::vector< event::ConnectionPtr > connections
All event connections.
Definition: Sensor.hh:209
common::Time lastMeasurementTime
Stores last time that a sensor measurement was generated; this value must be updated within each sens...
Definition: Sensor.hh:238
boost::shared_ptr< Node > NodePtr
Definition: TransportTypes.hh:57
common::Time updatePeriod
Desired time between updates, set indirectly by Sensor::SetUpdateRate.
Definition: Sensor.hh:231
default namespace for gazebo
common::Time lastUpdateTime
Time of the last update.
Definition: Sensor.hh:234
boost::shared_ptr< Scene > ScenePtr
Definition: RenderTypes.hh:81
ignition::math::Pose3d pose
Pose of the sensor.
Definition: Sensor.hh:206
transport::NodePtr node
Node for communication.
Definition: Sensor.hh:212
gazebo::rendering::ScenePtr scene
Pointer to the Scene.
Definition: Sensor.hh:227
virtual bool UpdateImpl(const bool)
This gets overwritten by derived sensor types.
Definition: Sensor.hh:189
boost::shared_ptr< Connection > ConnectionPtr
Definition: CommonTypes.hh:134
gazebo::physics::WorldPtr world
Pointer to the world.
Definition: Sensor.hh:224
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:208
std::map< SensorNoiseType, NoisePtr > noises
Noise added to sensor data.
Definition: Sensor.hh:241
Base class for sensors.
Definition: Sensor.hh:51
#define GAZEBO_VISIBLE
Use to represent "symbol visible" if supported.
Definition: system.hh:58
ignition::transport::Node nodeIgn
Ignition transport node.
Definition: Sensor.hh:244
std::vector< SensorPluginPtr > plugins
All the plugins for the sensor.
Definition: Sensor.hh:221
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