All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
SensorManager.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 _SENSORMANAGER_HH_
18 #define _SENSORMANAGER_HH_
19 
20 #include <boost/thread.hpp>
21 #include <string>
22 #include <vector>
23 #include <list>
24 
25 #include <sdf/sdf.hh>
26 
31 #include "gazebo/util/system.hh"
32 
33 namespace gazebo
34 {
37  namespace sensors
38  {
41  class GAZEBO_VISIBLE SimTimeEvent
42  {
44  public: common::Time time;
45 
47  public: boost::condition_variable *condition;
48  };
49 
52  class GAZEBO_VISIBLE SimTimeEventHandler
53  {
55  public: SimTimeEventHandler();
56 
58  public: virtual ~SimTimeEventHandler();
59 
65  public: void AddRelativeEvent(const common::Time &_time,
66  boost::condition_variable *_var);
67 
70  private: void OnUpdate(const common::UpdateInfo &_info);
71 
73  private: boost::mutex mutex;
74 
76  private: std::list<SimTimeEvent*> events;
77 
79  private: event::ConnectionPtr updateConnection;
80  };
82 
87  class GAZEBO_VISIBLE SensorManager : public SingletonT<SensorManager>
88  {
91  private: SensorManager();
92 
94  private: virtual ~SensorManager();
95 
101  public: void Update(bool _force = false);
102 
104  public: void Init();
105 
108  public: void RunThreads();
109 
111  public: void Stop();
112 
114  public: void Fini();
115 
118  public: void GetSensorTypes(std::vector<std::string> &_types) const;
119 
127  public: std::string CreateSensor(sdf::ElementPtr _elem,
128  const std::string &_worldName,
129  const std::string &_parentName,
130  uint32_t _parentId);
131 
135  public: SensorPtr GetSensor(const std::string &_name) const;
136 
139  public: Sensor_V GetSensors() const;
140 
143  public: void RemoveSensor(const std::string &_name);
144 
146  public: void RemoveSensors();
147 
150  public: bool SensorsInitialized();
151 
153  public: void ResetLastUpdateTimes();
154 
157  private: void AddSensor(SensorPtr _sensor);
158 
165  private: class SensorContainer
166  {
168  public: SensorContainer();
169 
171  public: virtual ~SensorContainer();
172 
174  public: void Init();
175 
177  public: void Fini();
178 
180  public: void Run();
181 
183  public: void Stop();
184 
188  public: virtual void Update(bool _force = false);
189 
192  public: void AddSensor(SensorPtr _sensor);
193 
199  public: SensorPtr GetSensor(const std::string &_name,
200  bool _useLeafName = false) const;
201 
205  public: bool RemoveSensor(const std::string &_name);
206 
208  public: void RemoveSensors();
209 
211  public: void ResetLastUpdateTimes();
212 
215  private: void RunLoop();
216 
218  public: Sensor_V sensors;
219 
221  private: bool stop;
222 
225  private: bool initialized;
226 
228  private: boost::thread *runThread;
229 
231  private: mutable boost::recursive_mutex mutex;
232 
235  private: boost::condition_variable runCondition;
236  };
238 
242  private: class ImageSensorContainer : public SensorContainer
243  {
247  public: virtual void Update(bool _force = false);
248  };
250 
253  private: bool initialized;
254 
256  private: bool removeAllSensors;
257 
259  private: mutable boost::recursive_mutex mutex;
260 
262  private: Sensor_V initSensors;
263 
265  private: std::vector<std::string> removeSensors;
266 
268  private: typedef std::vector<SensorContainer*> SensorContainer_V;
269 
271  private: SensorContainer_V sensorContainers;
272 
274  private: friend class SingletonT<SensorManager>;
275 
277  private: friend class SensorContainer;
278 
280  private: SimTimeEventHandler *simTimeEventHandler;
281  };
283  }
284 }
285 #endif
boost::shared_ptr< Connection > ConnectionPtr
Definition: CommonTypes.hh:144
std::vector< SensorPtr > Sensor_V
Definition: SensorTypes.hh:131
Singleton template class.
Definition: SingletonT.hh:33
default namespace for gazebo
Class to manage and update all sensors.
Definition: SensorManager.hh:87
GAZEBO_VISIBLE void stop()
Stop the sensor generation loop.
GAZEBO_VISIBLE void Init(google::protobuf::Message &_message, const std::string &_id="")
Initialize a message.
Forward declarations and typedefs for sensors.
boost::shared_ptr< Sensor > SensorPtr
Definition: SensorTypes.hh:55
#define GAZEBO_VISIBLE
Use to represent "symbol visible" if supported.
Definition: system.hh:48