All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
SensorManager.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 /*
18  * Desc: Class to manager all sensors
19  * Author: Nate Koenig
20  * Date: 18 Dec 2009
21  */
22 
23 #ifndef _SENSORMANAGER_HH_
24 #define _SENSORMANAGER_HH_
25 
26 #include <boost/thread.hpp>
27 #include <string>
28 #include <vector>
29 #include <list>
30 
31 #include <sdf/sdf.hh>
32 
37 
38 namespace gazebo
39 {
42  namespace sensors
43  {
47  {
49  public: common::Time time;
50 
52  public: boost::condition_variable *condition;
53  };
54 
58  {
60  public: SimTimeEventHandler();
61 
63  public: virtual ~SimTimeEventHandler();
64 
70  public: void AddRelativeEvent(const common::Time &_time,
71  boost::condition_variable *_var);
72 
75  private: void OnUpdate(const common::UpdateInfo &_info);
76 
78  private: boost::mutex mutex;
79 
81  private: std::list<SimTimeEvent*> events;
82 
84  private: event::ConnectionPtr updateConnection;
85  };
87 
92  class SensorManager : public SingletonT<SensorManager>
93  {
96  private: SensorManager();
97 
99  private: virtual ~SensorManager();
100 
106  public: void Update(bool _force = false);
107 
109  public: void Init();
110 
113  public: void Run() GAZEBO_DEPRECATED(1.5);
114 
117  public: void RunThreads();
118 
120  public: void Stop();
121 
123  public: void Fini();
124 
127  public: void GetSensorTypes(std::vector<std::string> &_types) const;
128 
136  public: std::string CreateSensor(sdf::ElementPtr _elem,
137  const std::string &_worldName,
138  const std::string &_parentName);
139 
143  public: SensorPtr GetSensor(const std::string &_name) const;
144 
147  public: Sensor_V GetSensors() const;
148 
151  public: void RemoveSensor(const std::string &_name);
152 
154  public: void RemoveSensors();
155 
158  public: bool SensorsInitialized();
159 
161  public: void ResetLastUpdateTimes();
162 
165  private: void AddSensor(SensorPtr _sensor);
166 
173  private: class SensorContainer
174  {
176  public: SensorContainer();
177 
179  public: virtual ~SensorContainer();
180 
182  public: void Init();
183 
185  public: void Fini();
186 
188  public: void Run();
189 
191  public: void Stop();
192 
196  public: virtual void Update(bool _force = false);
197 
200  public: void AddSensor(SensorPtr _sensor);
201 
207  public: SensorPtr GetSensor(const std::string &_name,
208  bool _useLeafName = false) const;
209 
213  public: bool RemoveSensor(const std::string &_name);
214 
216  public: void RemoveSensors();
217 
219  public: void ResetLastUpdateTimes();
220 
223  private: void RunLoop();
224 
226  public: Sensor_V sensors;
227 
229  private: bool stop;
230 
233  private: bool initialized;
234 
236  private: boost::thread *runThread;
237 
239  private: mutable boost::recursive_mutex mutex;
240 
243  private: boost::condition_variable runCondition;
244  };
246 
250  private: class ImageSensorContainer : public SensorContainer
251  {
255  public: virtual void Update(bool _force = false);
256  };
258 
261  private: bool initialized;
262 
264  private: bool removeAllSensors;
265 
267  private: mutable boost::recursive_mutex mutex;
268 
270  private: Sensor_V initSensors;
271 
273  private: Sensor_V removeSensors;
274 
276  private: typedef std::vector<SensorContainer*> SensorContainer_V;
277 
279  private: SensorContainer_V sensorContainers;
280 
282  private: friend class SingletonT<SensorManager>;
283 
285  private: friend class SensorContainer;
286 
288  private: SimTimeEventHandler *simTimeEventHandler;
289  };
291  }
292 }
293 #endif