##

SensorManager.hh
Go to the documentation of this file.
/*
* Copyright (C) 2012 Open Source Robotics Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
#ifndef _GAZEBO_SENSORMANAGER_HH_
#define _GAZEBO_SENSORMANAGER_HH_
#include <boost/thread.hpp>
#include <string>
#include <vector>
#include <list>
#include <map>
#include <sdf/sdf.hh>
#include "gazebo/physics/PhysicsTypes.hh"
#include "gazebo/common/SingletonT.hh"
#include "gazebo/common/UpdateInfo.hh"
#include "gazebo/sensors/SensorTypes.hh"
#include "gazebo/util/system.hh"
GZ_SINGLETON_DECLARE(GZ_SENSORS_VISIBLE, gazebo, sensors, SensorManager)
namespace gazebo
{
namespace sensors
{
class GZ_SENSORS_VISIBLE SimTimeEvent
{
public: common::Time time;
public: boost::condition_variable *condition;
};
class GZ_SENSORS_VISIBLE SimTimeEventHandler
{
public: SimTimeEventHandler();
public: virtual ~SimTimeEventHandler();
public: void AddRelativeEvent(const common::Time &_time,
boost::condition_variable *_var);
private: void OnUpdate(const common::UpdateInfo &_info);
private: boost::mutex mutex;
private: std::list<SimTimeEvent*> events;
private: event::ConnectionPtr updateConnection;
};
class GZ_SENSORS_VISIBLE SensorManager : public SingletonT<SensorManager>
{
private: SensorManager();
private: virtual ~SensorManager();
public: void Update(bool _force = false);
public: void Init();
public: void RunThreads();
public: void Stop();
public: void Fini();
public: bool Running() const;
public: void GetSensorTypes(std::vector<std::string> &_types) const;
public: std::string CreateSensor(sdf::ElementPtr _elem,
const std::string &_worldName,
const std::string &_parentName,
uint32_t _parentId);
public: void OnCreateSensor(sdf::ElementPtr _elem,
const std::string &_worldName,
const std::string &_parentName,
const uint32_t _parentId);
public: SensorPtr GetSensor(const std::string &_name) const;
public: Sensor_V GetSensors() const;
public: void RemoveSensor(const std::string &_name);
public: void RemoveSensors();
public: bool SensorsInitialized();
public: void ResetLastUpdateTimes();
private: void AddSensor(SensorPtr _sensor);
private: class SensorContainer
{
public: SensorContainer();
public: virtual ~SensorContainer();
public: void Init();
public: void Fini();
public: void Run();
public: void Stop();
public: bool Running() const;
public: virtual void Update(bool _force = false);
public: void AddSensor(SensorPtr _sensor);
public: SensorPtr GetSensor(const std::string &_name,
bool _useLeafName = false) const;
public: bool RemoveSensor(const std::string &_name);
public: void RemoveSensors();
public: void ResetLastUpdateTimes();
private: void RunLoop();
public: Sensor_V sensors;
private: bool stop;
private: bool initialized;
private: boost::thread *runThread;
private: mutable boost::recursive_mutex mutex;
private: boost::condition_variable runCondition;
};
private: class ImageSensorContainer : public SensorContainer
{
public: virtual void Update(bool _force = false);
};
private: bool initialized;
private: bool removeAllSensors;
private: mutable boost::recursive_mutex mutex;
private: Sensor_V initSensors;
private: std::vector<std::string> removeSensors;
private: typedef std::vector<SensorContainer*> SensorContainer_V;
private: SensorContainer_V sensorContainers;
private: friend class SingletonT<SensorManager>;
private: friend class SensorContainer;
private: SimTimeEventHandler *simTimeEventHandler;
private: std::map<std::string, physics::WorldPtr> worlds;
private: event::ConnectionPtr timeResetConnection;
private: event::ConnectionPtr createSensorConnection;
private: event::ConnectionPtr removeSensorConnection;
};
}
}
#endif
gazebo::sensors::SensorManager
Class to manage and update all sensors.
Definition: SensorManager.hh:91
gazebo::sensors::SensorPtr
std::shared_ptr< Sensor > SensorPtr
Definition: SensorTypes.hh:64
UpdateInfo.hh
gazebo
Forward declarations for the common classes.
Definition: Animation.hh:26
SingletonT
Singleton template class.
Definition: SingletonT.hh:33
sensors
sensors
Definition: SensorManager.hh:35
gazebo::sensors::Sensor_V
std::vector< SensorPtr > Sensor_V
Definition: SensorTypes.hh:152
SensorTypes.hh
Forward declarations and typedefs for sensors.
system.hh
PhysicsTypes.hh
default namespace for gazebo
gazebo::event::ConnectionPtr
boost::shared_ptr< Connection > ConnectionPtr
Definition: CommonTypes.hh:134
gazebo::msgs::Init
GAZEBO_VISIBLE void Init(google::protobuf::Message &_message, const std::string &_id="")
Initialize a message.
gazebo
gazebo
Definition: SensorManager.hh:35
GZ_SINGLETON_DECLARE
#define GZ_SINGLETON_DECLARE(visibility, n1, n2, singletonType)
Helper to declare typed SingletonT.
Definition: SingletonT.hh:61
gazebo::sensors::stop
void stop()
Stop the sensor generation loop.
SingletonT.hh
gazebo::gui::stop
void stop()