Ignition Sensors

API Reference

3.1.0
Manager.hh
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2017 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 IGNITION_SENSORS_MANAGER_HH_
18 #define IGNITION_SENSORS_MANAGER_HH_
19 
20 #include <memory>
21 #include <string>
22 #include <type_traits>
23 #include <vector>
24 #include <sdf/sdf.hh>
25 #include <ignition/common/Time.hh>
26 #include <ignition/common/Console.hh>
27 #include <ignition/sensors/config.hh>
28 #include <ignition/sensors/Export.hh>
30 
31 namespace ignition
32 {
33  namespace sensors
34  {
35  // Inline bracket to help doxygen filtering.
36  inline namespace IGNITION_SENSORS_VERSION_NAMESPACE {
37  // Forward declarations
38  class ManagerPrivate;
39 
51  class IGNITION_SENSORS_VISIBLE Manager
52  {
54  public: Manager();
55 
57  public: virtual ~Manager();
58 
61  public: bool Init();
62 
80  public: template<typename T>
81  T *CreateSensor(sdf::Sensor _sdf)
82  {
83  ignition::sensors::SensorId id = this->CreateSensor(_sdf);
84 
85  if (id != NO_SENSOR)
86  {
87  T *result = dynamic_cast<T*>(this->Sensor(id));
88 
89  if (!result)
90  ignerr << "SDF sensor type does not match template type\n";
91 
92  return result;
93  }
94 
95  ignerr << "Failed to create sensor of type["
96  << _sdf.TypeStr() << "]\n";
97  return nullptr;
98  }
99 
117  public: template<typename T>
118  T *CreateSensor(sdf::ElementPtr _sdf)
119  {
120  ignition::sensors::SensorId id = this->CreateSensor(_sdf);
121 
122  if (id != NO_SENSOR)
123  {
124  T *result = dynamic_cast<T*>(this->Sensor(id));
125 
126  if (nullptr == result)
127  {
128  ignerr << "Failed to create sensor [" << id << "] of type ["
129  << _sdf->Get<std::string>("type")
130  << "]. SDF sensor type does not match template type."
131  << std::endl;
132  }
133 
134  return result;
135  }
136 
137  ignerr << "Failed to create sensor of type ["
138  << _sdf->Get<std::string>("type") << "]\n";
139  return nullptr;
140  }
141 
159  public: ignition::sensors::SensorId CreateSensor(sdf::ElementPtr _sdf);
160 
178  public: ignition::sensors::SensorId CreateSensor(const sdf::Sensor &_sdf);
179 
180 
186 
190  public: bool Remove(const ignition::sensors::SensorId _id);
191 
196  public: void RunOnce(const ignition::common::Time &_time,
197  bool _force = false);
198 
200  public: void AddPluginPaths(const std::string &_path);
201 
205  private: ignition::sensors::SensorId LoadSensorPlugin(
206  const std::string &_filename, sdf::ElementPtr _sdf);
207 
209  private: std::unique_ptr<ManagerPrivate> dataPtr;
210  };
211  }
212  }
213 }
214 
215 #endif
T endl(T... args)
a base sensor class
Definition: Sensor.hh:50
STL class.
Loads and runs sensors.
Definition: Manager.hh:51
const SensorId NO_SENSOR
Definition: Sensor.hh:40
T * CreateSensor(sdf::Sensor _sdf)
Create a sensor from SDF with a known sensor type.
Definition: Manager.hh:81
T * CreateSensor(sdf::ElementPtr _sdf)
Create a sensor from SDF with a known sensor type.
Definition: Manager.hh:118
Definition: AirPressureSensor.hh:31