All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Sensor.hh
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2012-2014 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 /* Desc: Base class for all sensors
18  * Author: Nathan Koenig
19  * Date: 25 May 2007
20  */
21 
22 #ifndef _SENSOR_HH_
23 #define _SENSOR_HH_
24 
25 #include <boost/enable_shared_from_this.hpp>
26 #include <boost/thread/mutex.hpp>
27 #include <vector>
28 #include <string>
29 
30 #include <sdf/sdf.hh>
31 
35 
36 #include "gazebo/msgs/msgs.hh"
37 #include "gazebo/common/Events.hh"
38 #include "gazebo/common/Time.hh"
39 #include "gazebo/math/Pose.hh"
41 #include "gazebo/util/system.hh"
42 
43 namespace gazebo
44 {
45  namespace sensors
46  {
50  {
51  // IMAGE must be the first element, and it must start with 0. Do not
52  // change this! See SensorManager::sensorContainers for reference.
55  IMAGE = 0,
56 
58  RAY = 1,
59 
61  OTHER = 2,
62 
65  };
66 
69 
72  class GAZEBO_VISIBLE Sensor : public boost::enable_shared_from_this<Sensor>
73  {
76  public: explicit Sensor(SensorCategory _cat);
77 
79  public: virtual ~Sensor();
80 
84  public: virtual void Load(const std::string &_worldName,
85  sdf::ElementPtr _sdf);
86 
89  public: virtual void Load(const std::string &_worldName);
90 
92  public: virtual void Init();
93 
96  public: virtual void SetParent(const std::string &_name)
97  GAZEBO_DEPRECATED(2.0);
98 
102  public: void SetParent(const std::string &_name, uint32_t _id);
103 
107  public: std::string GetParentName() const;
108 
111  public: void Update(bool _force);
112 
119  protected: virtual bool UpdateImpl(bool /*_force*/) {return false;}
120 
123  public: double GetUpdateRate();
124 
127  public: void SetUpdateRate(double _hz);
128 
130  public: virtual void Fini();
131 
134  public: std::string GetName() const;
135 
138  public: std::string GetScopedName() const;
139 
142  public: virtual math::Pose GetPose() const;
143 
146  public: virtual void SetActive(bool _value);
147 
150  public: virtual bool IsActive();
151 
154  public: std::string GetType() const;
155 
158  public: common::Time GetLastUpdateTime();
159 
162  public: common::Time GetLastMeasurementTime();
163 
167  public: bool GetVisualize() const;
168 
171  public: virtual std::string GetTopic() const;
172 
175  public: void FillMsg(msgs::Sensor &_msg);
176 
179  public: std::string GetWorldName() const;
180 
186  public: template<typename T>
188  {return this->updated.Connect(_subscriber);}
189 
194  {this->updated.Disconnect(_c);}
195 
199  public: SensorCategory GetCategory() const;
200 
202  public: void ResetLastUpdateTime();
203 
206  public: uint32_t GetId() const;
207 
210  public: uint32_t GetParentId() const;
211 
216  public: NoisePtr GetNoise(unsigned int _index = 0) const;
217 
220  protected: bool NeedsUpdate();
221 
224  private: void LoadPlugin(sdf::ElementPtr _sdf);
225 
227  protected: bool active;
228 
230  protected: sdf::ElementPtr sdf;
231 
233  protected: math::Pose pose;
234 
236  protected: std::vector<event::ConnectionPtr> connections;
237 
240 
243 
245  protected: std::string parentName;
246 
248  protected: uint32_t parentId;
249 
251  protected: std::vector<SensorPluginPtr> plugins;
252 
255 
258 
262 
265 
269 
271  protected: std::vector<NoisePtr> noises;
272 
274  private: boost::mutex mutexLastUpdateTime;
275 
277  private: event::EventT<void()> updated;
278 
280  private: transport::SubscriberPtr controlSub;
281 
283  private: transport::PublisherPtr sensorPub;
284 
286  private: SensorCategory category;
287 
289  private: common::Time updateDelay;
290 
292  private: uint32_t id;
293 
296  private: static sdf::ElementPtr sdfSensor;
297  };
299  }
300 }
301 #endif