Sensor.hh
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2012-2015 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_SENSOR_HH_
18 #define _GAZEBO_SENSOR_HH_
19 
20 #include <boost/enable_shared_from_this.hpp>
21 #include <boost/thread/mutex.hpp>
22 #include <vector>
23 #include <map>
24 #include <string>
25 
26 #include <sdf/sdf.hh>
27 #include <ignition/math/Pose3.hh>
28 
32 
33 #include "gazebo/msgs/msgs.hh"
34 #include "gazebo/common/Events.hh"
35 #include "gazebo/common/Time.hh"
36 #include "gazebo/math/Pose.hh"
38 #include "gazebo/util/system.hh"
39 
40 namespace gazebo
41 {
42  namespace sensors
43  {
47  {
48  // IMAGE must be the first element, and it must start with 0. Do not
49  // change this! See SensorManager::sensorContainers for reference.
52  IMAGE = 0,
53 
55  RAY = 1,
56 
58  OTHER = 2,
59 
62  };
63 
66 
69  class GAZEBO_VISIBLE Sensor : public boost::enable_shared_from_this<Sensor>
70  {
73  public: explicit Sensor(SensorCategory _cat);
74 
76  public: virtual ~Sensor();
77 
81  public: virtual void Load(const std::string &_worldName,
82  sdf::ElementPtr _sdf);
83 
86  public: virtual void Load(const std::string &_worldName);
87 
89  public: virtual void Init();
90 
94  public: void SetParent(const std::string &_name, uint32_t _id);
95 
99  public: std::string GetParentName() const;
100 
103  public: void Update(bool _force);
104 
111  protected: virtual bool UpdateImpl(bool /*_force*/) {return false;}
112 
115  public: double GetUpdateRate();
116 
119  public: void SetUpdateRate(double _hz);
120 
122  public: virtual void Fini();
123 
126  public: std::string GetName() const;
127 
130  public: std::string GetScopedName() const;
131 
136  public: virtual math::Pose GetPose() const GAZEBO_DEPRECATED(6.0);
137 
140  public: virtual ignition::math::Pose3d Pose() const;
141 
144  public: virtual void SetActive(bool _value);
145 
148  public: virtual bool IsActive();
149 
152  public: std::string GetType() const;
153 
156  public: common::Time GetLastUpdateTime();
157 
160  public: common::Time GetLastMeasurementTime();
161 
165  public: bool GetVisualize() const;
166 
169  public: virtual std::string GetTopic() const;
170 
173  public: void FillMsg(msgs::Sensor &_msg);
174 
177  public: std::string GetWorldName() const;
178 
184  public: template<typename T>
185  event::ConnectionPtr ConnectUpdated(T _subscriber)
186  {return this->updated.Connect(_subscriber);}
187 
192  {this->updated.Disconnect(_c);}
193 
197  public: SensorCategory GetCategory() const;
198 
200  public: void ResetLastUpdateTime();
201 
204  public: uint32_t GetId() const;
205 
208  public: uint32_t GetParentId() const;
209 
216  public: NoisePtr GetNoise(unsigned int _index = 0) const
217  GAZEBO_DEPRECATED(6.0);
218 
223  public: NoisePtr GetNoise(const SensorNoiseType _type) const;
224 
227  protected: bool NeedsUpdate();
228 
231  private: void LoadPlugin(sdf::ElementPtr _sdf);
232 
234  protected: bool active;
235 
237  protected: sdf::ElementPtr sdf;
238 
240  protected: ignition::math::Pose3d pose;
241 
243  protected: std::vector<event::ConnectionPtr> connections;
244 
246  protected: transport::NodePtr node;
247 
249  protected: transport::SubscriberPtr poseSub;
250 
252  protected: std::string parentName;
253 
255  protected: uint32_t parentId;
256 
258  protected: std::vector<SensorPluginPtr> plugins;
259 
261  protected: gazebo::physics::WorldPtr world;
262 
264  protected: gazebo::rendering::ScenePtr scene;
265 
268  protected: common::Time updatePeriod;
269 
271  protected: common::Time lastUpdateTime;
272 
275  protected: common::Time lastMeasurementTime;
276 
283  protected: std::map<int, NoisePtr> noises;
284 
286  private: boost::mutex mutexLastUpdateTime;
287 
289  private: event::EventT<void()> updated;
290 
292  private: transport::SubscriberPtr controlSub;
293 
295  private: transport::PublisherPtr sensorPub;
296 
298  private: SensorCategory category;
299 
301  private: common::Time updateDelay;
302 
304  private: uint32_t id;
305 
308  private: static sdf::ElementPtr sdfSensor;
309  };
311  }
312 }
313 #endif
boost::shared_ptr< Connection > ConnectionPtr
Definition: CommonTypes.hh:147
boost::shared_ptr< Noise > NoisePtr
Definition: SensorTypes.hh:118
virtual bool UpdateImpl(bool)
This gets overwritten by derived sensor types.
Definition: Sensor.hh:111
void DisconnectUpdated(event::ConnectionPtr &_c)
Disconnect from a the updated signal.
Definition: Sensor.hh:191
Encapsulates a position and rotation in three space.
Definition: Pose.hh:37
Number of Sensor Categories.
Definition: Sensor.hh:61
boost::shared_ptr< Subscriber > SubscriberPtr
Definition: TransportTypes.hh:53
A type of sensor is not a RAY or IMAGE sensor.
Definition: Sensor.hh:58
Forward declarations for transport.
#define GAZEBO_DEPRECATED(version)
Definition: CommonTypes.hh:47
default namespace for gazebo
boost::shared_ptr< SensorPlugin > SensorPluginPtr
Definition: CommonTypes.hh:76
boost::shared_ptr< World > WorldPtr
Definition: PhysicsTypes.hh:80
SensorCategory
SensorClass is used to categorize sensors.
Definition: Sensor.hh:46
boost::shared_ptr< Node > NodePtr
Definition: TransportTypes.hh:57
boost::shared_ptr< Scene > ScenePtr
Definition: RenderTypes.hh:79
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:202
boost::shared_ptr< Publisher > PublisherPtr
Definition: TransportTypes.hh:49
Ray based sensor class.
Definition: Sensor.hh:55
Base class for sensors.
Definition: Sensor.hh:69
#define GAZEBO_VISIBLE
Use to represent "symbol visible" if supported.
Definition: system.hh:66
Image based sensor class.
Definition: Sensor.hh:52