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 <vector>
27 #include <string>
28 
29 #include "gazebo/sdf/sdf.hh"
30 
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 
39 namespace gazebo
40 {
41  namespace sensors
42  {
45 
48  class Sensor : public boost::enable_shared_from_this<Sensor>
49  {
51  public: Sensor();
52 
54  public: virtual ~Sensor();
55 
59  public: virtual void Load(const std::string &_worldName,
60  sdf::ElementPtr _sdf);
61 
64  public: virtual void Load(const std::string &_worldName);
65 
67  public: virtual void Init();
68 
71  public: virtual void SetParent(const std::string &_name);
72 
76  public: std::string GetParentName() const;
77 
80  public: void Update(bool _force);
81 
87  protected: virtual void UpdateImpl(bool /*_force*/) {}
88 
91  public: double GetUpdateRate();
92 
95  public: void SetUpdateRate(double _hz);
96 
98  public: virtual void Fini();
99 
102  public: std::string GetName() const;
103 
106  public: std::string GetScopedName() const;
107 
110  public: virtual math::Pose GetPose() const;
111 
114  public: virtual void SetActive(bool _value);
115 
118  public: virtual bool IsActive();
119 
122  public: std::string GetType() const;
123 
127 
131 
135  public: bool GetVisualize() const;
136 
139  public: virtual std::string GetTopic() const;
140 
143  public: void FillMsg(msgs::Sensor &_msg);
144 
147  public: std::string GetWorldName() const;
148 
154  public: template<typename T>
156  {return this->updated.Connect(_subscriber);}
157 
162  {this->updated.Disconnect(_c);}
163 
166  private: void LoadPlugin(sdf::ElementPtr _sdf);
167 
170  private: void OnControl(ConstWorldControlPtr &_data);
171 
173  protected: bool active;
174 
176  protected: sdf::ElementPtr sdf;
177 
179  protected: math::Pose pose;
180 
182  protected: std::vector<event::ConnectionPtr> connections;
183 
186 
189 
191  private: event::EventT<void()> updated;
192 
194  private: transport::SubscriberPtr controlSub;
195 
197  private: transport::PublisherPtr sensorPub;
198 
200  protected: std::string parentName;
201 
203  protected: std::vector<SensorPluginPtr> plugins;
204 
207 
211 
214 
218  };
220  }
221 }
222 #endif