All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules 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
transport::SubscriberPtr poseSub
Subscribe to pose updates.
Definition: Sensor.hh:242
boost::shared_ptr< Connection > ConnectionPtr
Definition: CommonTypes.hh:144
Forward declarations for the common classes.
Definition: Animation.hh:24
boost::shared_ptr< Noise > NoisePtr
Definition: SensorTypes.hh:107
virtual bool UpdateImpl(bool)
This gets overwritten by derived sensor types.
Definition: Sensor.hh:119
std::vector< SensorPluginPtr > plugins
All the plugins for the sensor.
Definition: Sensor.hh:251
void DisconnectUpdated(event::ConnectionPtr &_c)
Disconnect from a the updated signal.
Definition: Sensor.hh:193
Encapsulates a position and rotation in three space.
Definition: Pose.hh:40
Number of Sensor Categories.
Definition: Sensor.hh:64
boost::shared_ptr< Subscriber > SubscriberPtr
Definition: TransportTypes.hh:48
uint32_t parentId
The sensor's parent ID.
Definition: Sensor.hh:248
A type of sensor is not a RAY or IMAGE sensor.
Definition: Sensor.hh:61
common::Time updatePeriod
Desired time between updates, set indirectly by Sensor::SetUpdateRate.
Definition: Sensor.hh:261
gazebo::rendering::ScenePtr scene
Pointer to the Scene.
Definition: Sensor.hh:257
gazebo::physics::WorldPtr world
Pointer to the world.
Definition: Sensor.hh:254
Forward declarations for transport.
#define GAZEBO_DEPRECATED(version)
Definition: CommonTypes.hh:44
event::ConnectionPtr ConnectUpdated(T _subscriber)
Connect a signal that is triggered when the sensor is updated.
Definition: Sensor.hh:187
common::Time lastUpdateTime
Time of the last update.
Definition: Sensor.hh:264
std::vector< NoisePtr > noises
Noise added to sensor data.
Definition: Sensor.hh:271
default namespace for gazebo
common::Time lastMeasurementTime
Stores last time that a sensor measurement was generated; this value must be updated within each sens...
Definition: Sensor.hh:268
math::Pose pose
Pose of the sensor.
Definition: Sensor.hh:233
std::string parentName
Name of the parent.
Definition: Sensor.hh:245
boost::shared_ptr< World > WorldPtr
Definition: PhysicsTypes.hh:77
SensorCategory
SensorClass is used to categorize sensors.
Definition: Sensor.hh:49
sdf::ElementPtr sdf
Pointer the the SDF element for the sensor.
Definition: Sensor.hh:230
boost::shared_ptr< Node > NodePtr
Definition: TransportTypes.hh:52
boost::shared_ptr< Scene > ScenePtr
Definition: RenderTypes.hh:67
bool active
True if sensor generation is active.
Definition: Sensor.hh:227
GAZEBO_VISIBLE void Init(google::protobuf::Message &_message, const std::string &_id="")
Initialize a message.
Forward declarations and typedefs for sensors.
boost::shared_ptr< Publisher > PublisherPtr
Definition: TransportTypes.hh:44
std::vector< event::ConnectionPtr > connections
All event connections.
Definition: Sensor.hh:236
Ray based sensor class.
Definition: Sensor.hh:58
Base class for sensors.
Definition: Sensor.hh:72
#define GAZEBO_VISIBLE
Use to represent "symbol visible" if supported.
Definition: system.hh:48
Image based sensor class.
Definition: Sensor.hh:55
transport::NodePtr node
Node for communication.
Definition: Sensor.hh:239
A Time class, can be used to hold wall- or sim-time.
Definition: Time.hh:43