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 
141  public: virtual ignition::math::Pose3d Pose() const;
142 
149  public: void SetPose(const ignition::math::Pose3d &_pose);
150 
153  public: virtual void SetActive(bool _value);
154 
157  public: virtual bool IsActive();
158 
161  public: std::string GetType() const;
162 
165  public: common::Time GetLastUpdateTime();
166 
169  public: common::Time GetLastMeasurementTime();
170 
174  public: bool GetVisualize() const;
175 
178  public: virtual std::string GetTopic() const;
179 
182  public: void FillMsg(msgs::Sensor &_msg);
183 
186  public: std::string GetWorldName() const;
187 
193  public: template<typename T>
194  event::ConnectionPtr ConnectUpdated(T _subscriber)
195  {return this->updated.Connect(_subscriber);}
196 
201  {this->updated.Disconnect(_c);}
202 
206  public: SensorCategory GetCategory() const;
207 
209  public: void ResetLastUpdateTime();
210 
213  public: uint32_t GetId() const;
214 
217  public: uint32_t GetParentId() const;
218 
225  public: NoisePtr GetNoise(unsigned int _index = 0) const
226  GAZEBO_DEPRECATED(6.0);
227 
232  public: NoisePtr GetNoise(const SensorNoiseType _type) const;
233 
236  protected: bool NeedsUpdate();
237 
240  private: void LoadPlugin(sdf::ElementPtr _sdf);
241 
243  protected: bool active;
244 
246  protected: sdf::ElementPtr sdf;
247 
249  protected: ignition::math::Pose3d pose;
250 
252  protected: std::vector<event::ConnectionPtr> connections;
253 
255  protected: transport::NodePtr node;
256 
258  protected: transport::SubscriberPtr poseSub;
259 
261  protected: std::string parentName;
262 
264  protected: uint32_t parentId;
265 
267  protected: std::vector<SensorPluginPtr> plugins;
268 
270  protected: gazebo::physics::WorldPtr world;
271 
273  protected: gazebo::rendering::ScenePtr scene;
274 
277  protected: common::Time updatePeriod;
278 
280  protected: common::Time lastUpdateTime;
281 
284  protected: common::Time lastMeasurementTime;
285 
292  protected: std::map<int, NoisePtr> noises;
293 
295  private: boost::mutex mutexLastUpdateTime;
296 
298  private: event::EventT<void()> updated;
299 
301  private: transport::SubscriberPtr controlSub;
302 
304  private: transport::PublisherPtr sensorPub;
305 
307  private: SensorCategory category;
308 
310  private: common::Time updateDelay;
311 
313  private: uint32_t id;
314 
317  private: static sdf::ElementPtr sdfSensor;
318  };
320  }
321 }
322 #endif
boost::shared_ptr< Connection > ConnectionPtr
Definition: CommonTypes.hh:147
Definition: JointMaker.hh:41
Forward declarations for the common classes.
Definition: Animation.hh:33
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:200
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.
STL namespace.
#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
SensorNoiseType
Definition: SensorTypes.hh:202
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.
Definition: Animation.hh:24
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