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 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 /* 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 
34 
35 #include "gazebo/msgs/msgs.hh"
36 #include "gazebo/common/Events.hh"
37 #include "gazebo/common/Time.hh"
38 #include "gazebo/math/Pose.hh"
40 
41 namespace gazebo
42 {
43  namespace sensors
44  {
48  {
49  // IMAGE must be the first element, and it must start with 0. Do not
50  // change this! See SensorManager::sensorContainers for reference.
53  IMAGE = 0,
54 
56  RAY = 1,
57 
59  OTHER = 2,
60 
63  };
64 
67 
70  class Sensor : public boost::enable_shared_from_this<Sensor>
71  {
74  public: explicit Sensor(SensorCategory _cat);
75 
77  public: virtual ~Sensor();
78 
82  public: virtual void Load(const std::string &_worldName,
83  sdf::ElementPtr _sdf);
84 
87  public: virtual void Load(const std::string &_worldName);
88 
90  public: virtual void Init();
91 
94  public: virtual void SetParent(const std::string &_name)
95  GAZEBO_DEPRECATED(1.10);
96 
100  public: void SetParent(const std::string &_name, uint32_t _id);
101 
105  public: std::string GetParentName() const;
106 
109  public: void Update(bool _force);
110 
116  protected: virtual void UpdateImpl(bool /*_force*/) {}
117 
120  public: double GetUpdateRate();
121 
124  public: void SetUpdateRate(double _hz);
125 
127  public: virtual void Fini();
128 
131  public: std::string GetName() const;
132 
135  public: std::string GetScopedName() const;
136 
139  public: virtual math::Pose GetPose() const;
140 
143  public: virtual void SetActive(bool _value);
144 
147  public: virtual bool IsActive();
148 
151  public: std::string GetType() const;
152 
156 
160 
164  public: bool GetVisualize() const;
165 
168  public: virtual std::string GetTopic() const;
169 
172  public: void FillMsg(msgs::Sensor &_msg);
173 
176  public: std::string GetWorldName() const;
177 
183  public: template<typename T>
185  {return this->updated.Connect(_subscriber);}
186 
191  {this->updated.Disconnect(_c);}
192 
196  public: SensorCategory GetCategory() const;
197 
199  public: void ResetLastUpdateTime();
200 
203  public: uint32_t GetId() const;
204 
207  public: uint32_t GetParentId() const;
208 
211  private: void LoadPlugin(sdf::ElementPtr _sdf);
212 
214  protected: bool active;
215 
217  protected: sdf::ElementPtr sdf;
218 
220  protected: math::Pose pose;
221 
223  protected: std::vector<event::ConnectionPtr> connections;
224 
227 
230 
232  protected: std::string parentName;
233 
235  protected: uint32_t parentId;
236 
238  protected: std::vector<SensorPluginPtr> plugins;
239 
242 
245 
249 
252 
254  protected: boost::mutex mutexLastUpdateTime;
255 
259 
261  private: event::EventT<void()> updated;
262 
264  private: transport::SubscriberPtr controlSub;
265 
267  private: transport::PublisherPtr sensorPub;
268 
270  private: SensorCategory category;
271 
273  private: common::Time updateDelay;
274 
276  private: uint32_t id;
277 
280  private: static sdf::ElementPtr sdfSensor;
281  };
283  }
284 }
285 #endif