All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties 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 #ifndef _SENSOR_HH_
18 #define _SENSOR_HH_
19 
20 #include <boost/enable_shared_from_this.hpp>
21 #include <boost/thread/mutex.hpp>
22 #include <vector>
23 #include <string>
24 
25 #include <sdf/sdf.hh>
26 
30 
31 #include "gazebo/msgs/msgs.hh"
32 #include "gazebo/common/Events.hh"
33 #include "gazebo/common/Time.hh"
34 #include "gazebo/math/Pose.hh"
36 #include "gazebo/util/system.hh"
37 
38 namespace gazebo
39 {
40  namespace sensors
41  {
45  {
46  // IMAGE must be the first element, and it must start with 0. Do not
47  // change this! See SensorManager::sensorContainers for reference.
50  IMAGE = 0,
51 
53  RAY = 1,
54 
56  OTHER = 2,
57 
60  };
61 
64 
67  class GAZEBO_VISIBLE Sensor : public boost::enable_shared_from_this<Sensor>
68  {
71  public: explicit Sensor(SensorCategory _cat);
72 
74  public: virtual ~Sensor();
75 
79  public: virtual void Load(const std::string &_worldName,
80  sdf::ElementPtr _sdf);
81 
84  public: virtual void Load(const std::string &_worldName);
85 
87  public: virtual void Init();
88 
92  public: void SetParent(const std::string &_name, uint32_t _id);
93 
97  public: std::string GetParentName() const;
98 
101  public: void Update(bool _force);
102 
109  protected: virtual bool UpdateImpl(bool /*_force*/) {return false;}
110 
113  public: double GetUpdateRate();
114 
117  public: void SetUpdateRate(double _hz);
118 
120  public: virtual void Fini();
121 
124  public: std::string GetName() const;
125 
128  public: std::string GetScopedName() const;
129 
132  public: virtual math::Pose GetPose() const;
133 
136  public: virtual void SetActive(bool _value);
137 
140  public: virtual bool IsActive();
141 
144  public: std::string GetType() const;
145 
148  public: common::Time GetLastUpdateTime();
149 
152  public: common::Time GetLastMeasurementTime();
153 
157  public: bool GetVisualize() const;
158 
161  public: virtual std::string GetTopic() const;
162 
165  public: void FillMsg(msgs::Sensor &_msg);
166 
169  public: std::string GetWorldName() const;
170 
176  public: template<typename T>
178  {return this->updated.Connect(_subscriber);}
179 
184  {this->updated.Disconnect(_c);}
185 
189  public: SensorCategory GetCategory() const;
190 
192  public: void ResetLastUpdateTime();
193 
196  public: uint32_t GetId() const;
197 
200  public: uint32_t GetParentId() const;
201 
206  public: NoisePtr GetNoise(unsigned int _index = 0) const;
207 
210  protected: bool NeedsUpdate();
211 
214  private: void LoadPlugin(sdf::ElementPtr _sdf);
215 
217  protected: bool active;
218 
220  protected: sdf::ElementPtr sdf;
221 
223  protected: math::Pose pose;
224 
226  protected: std::vector<event::ConnectionPtr> connections;
227 
230 
233 
235  protected: std::string parentName;
236 
238  protected: uint32_t parentId;
239 
241  protected: std::vector<SensorPluginPtr> plugins;
242 
245 
248 
252 
255 
259 
261  protected: std::vector<NoisePtr> noises;
262 
264  private: boost::mutex mutexLastUpdateTime;
265 
267  private: event::EventT<void()> updated;
268 
270  private: transport::SubscriberPtr controlSub;
271 
273  private: transport::PublisherPtr sensorPub;
274 
276  private: SensorCategory category;
277 
279  private: common::Time updateDelay;
280 
282  private: uint32_t id;
283 
286  private: static sdf::ElementPtr sdfSensor;
287  };
289  }
290 }
291 #endif
transport::SubscriberPtr poseSub
Subscribe to pose updates.
Definition: Sensor.hh:232
boost::shared_ptr< Connection > ConnectionPtr
Definition: CommonTypes.hh:144
boost::shared_ptr< Noise > NoisePtr
Definition: SensorTypes.hh:107
virtual bool UpdateImpl(bool)
This gets overwritten by derived sensor types.
Definition: Sensor.hh:109
std::vector< SensorPluginPtr > plugins
All the plugins for the sensor.
Definition: Sensor.hh:241
void DisconnectUpdated(event::ConnectionPtr &_c)
Disconnect from a the updated signal.
Definition: Sensor.hh:183
Encapsulates a position and rotation in three space.
Definition: Pose.hh:40
Number of Sensor Categories.
Definition: Sensor.hh:59
boost::shared_ptr< Subscriber > SubscriberPtr
Definition: TransportTypes.hh:48
uint32_t parentId
The sensor's parent ID.
Definition: Sensor.hh:238
A type of sensor is not a RAY or IMAGE sensor.
Definition: Sensor.hh:56
common::Time updatePeriod
Desired time between updates, set indirectly by Sensor::SetUpdateRate.
Definition: Sensor.hh:251
gazebo::rendering::ScenePtr scene
Pointer to the Scene.
Definition: Sensor.hh:247
gazebo::physics::WorldPtr world
Pointer to the world.
Definition: Sensor.hh:244
Forward declarations for transport.
event::ConnectionPtr ConnectUpdated(T _subscriber)
Connect a signal that is triggered when the sensor is updated.
Definition: Sensor.hh:177
common::Time lastUpdateTime
Time of the last update.
Definition: Sensor.hh:254
std::vector< NoisePtr > noises
Noise added to sensor data.
Definition: Sensor.hh:261
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:258
math::Pose pose
Pose of the sensor.
Definition: Sensor.hh:223
std::string parentName
Name of the parent.
Definition: Sensor.hh:235
boost::shared_ptr< World > WorldPtr
Definition: PhysicsTypes.hh:78
SensorCategory
SensorClass is used to categorize sensors.
Definition: Sensor.hh:44
sdf::ElementPtr sdf
Pointer the the SDF element for the sensor.
Definition: Sensor.hh:220
boost::shared_ptr< Node > NodePtr
Definition: TransportTypes.hh:52
boost::shared_ptr< Scene > ScenePtr
Definition: RenderTypes.hh:72
bool active
True if sensor generation is active.
Definition: Sensor.hh:217
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:226
Ray based sensor class.
Definition: Sensor.hh:53
Base class for sensors.
Definition: Sensor.hh:67
#define GAZEBO_VISIBLE
Use to represent "symbol visible" if supported.
Definition: system.hh:48
Image based sensor class.
Definition: Sensor.hh:50
transport::NodePtr node
Node for communication.
Definition: Sensor.hh:229
A Time class, can be used to hold wall- or sim-time.
Definition: Time.hh:43