Ignition Sensors

API Reference

5.0.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/SuppressWarning.hh>
26 #include <ignition/common/Time.hh>
27 #include <ignition/common/Console.hh>
28 #include <ignition/sensors/config.hh>
29 #include <ignition/sensors/Export.hh>
31 
32 namespace ignition
33 {
34  namespace sensors
35  {
36  // Inline bracket to help doxygen filtering.
37  inline namespace IGNITION_SENSORS_VERSION_NAMESPACE {
38  // Forward declarations
39  class ManagerPrivate;
40 
52  class IGNITION_SENSORS_VISIBLE Manager
53  {
55  public: Manager();
56 
58  public: virtual ~Manager();
59 
62  public: bool Init();
63 
81  public: template<typename T>
82  T *CreateSensor(sdf::Sensor _sdf)
83  {
84  ignition::sensors::SensorId id = this->CreateSensor(_sdf);
85 
86  if (id != NO_SENSOR)
87  {
88  T *result = dynamic_cast<T*>(this->Sensor(id));
89 
90  if (!result)
91  ignerr << "SDF sensor type does not match template type\n";
92 
93  return result;
94  }
95 
96  ignerr << "Failed to create sensor of type["
97  << _sdf.TypeStr() << "]\n";
98  return nullptr;
99  }
100 
118  public: template<typename T>
119  T *CreateSensor(sdf::ElementPtr _sdf)
120  {
121  ignition::sensors::SensorId id = this->CreateSensor(_sdf);
122 
123  if (id != NO_SENSOR)
124  {
125  T *result = dynamic_cast<T*>(this->Sensor(id));
126 
127  if (nullptr == result)
128  {
129  ignerr << "Failed to create sensor [" << id << "] of type ["
130  << _sdf->Get<std::string>("type")
131  << "]. SDF sensor type does not match template type."
132  << std::endl;
133  }
134 
135  return result;
136  }
137 
138  ignerr << "Failed to create sensor of type ["
139  << _sdf->Get<std::string>("type") << "]\n";
140  return nullptr;
141  }
142 
160  public: ignition::sensors::SensorId CreateSensor(sdf::ElementPtr _sdf);
161 
179  public: ignition::sensors::SensorId CreateSensor(const sdf::Sensor &_sdf);
180 
181 
187 
191  public: bool Remove(const ignition::sensors::SensorId _id);
192 
197  public: void IGN_DEPRECATED(4) RunOnce(
198  const ignition::common::Time &_time, bool _force = false);
199 
204  public: void RunOnce(const std::chrono::steady_clock::duration &_time,
205  bool _force = false);
206 
208  public: void AddPluginPaths(const std::string &_path);
209 
213  private: ignition::sensors::SensorId LoadSensorPlugin(
214  const std::string &_filename, sdf::ElementPtr _sdf);
215 
216  IGN_COMMON_WARN_IGNORE__DLL_INTERFACE_MISSING
218  private: std::unique_ptr<ManagerPrivate> dataPtr;
219  IGN_COMMON_WARN_RESUME__DLL_INTERFACE_MISSING
220  };
221  }
222  }
223 }
224 
225 #endif
T endl(T... args)
a base sensor class
Definition: Sensor.hh:60
STL class.
Loads and runs sensors.
Definition: Manager.hh:52
const SensorId NO_SENSOR
Definition: Sensor.hh:50
T * CreateSensor(sdf::Sensor _sdf)
Create a sensor from SDF with a known sensor type.
Definition: Manager.hh:82
T * CreateSensor(sdf::ElementPtr _sdf)
Create a sensor from SDF with a known sensor type.
Definition: Manager.hh:119
Definition: AirPressureSensor.hh:32