Sensor.hh
Go to the documentation of this file.
1 /*
2  * Copyright 2018 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 SDF_SENSOR_HH_
18 #define SDF_SENSOR_HH_
19 
20 #include <memory>
21 #include <string>
22 #include <gz/math/Pose3.hh>
23 #include <gz/utils/ImplPtr.hh>
24 #include "sdf/Element.hh"
25 #include "sdf/Plugin.hh"
26 #include "sdf/SemanticPose.hh"
27 #include "sdf/Types.hh"
28 #include "sdf/sdf_config.h"
29 #include "sdf/system_util.hh"
30 
31 namespace sdf
32 {
33  // Inline bracket to help doxygen filtering.
34  inline namespace SDF_VERSION_NAMESPACE {
35  //
36 
37  // Forward declarations.
38  class AirPressure;
39  class Altimeter;
40  class Camera;
41  class ForceTorque;
42  class Imu;
43  class Lidar;
44  class Magnetometer;
45  class NavSat;
46  struct PoseRelativeToGraph;
47  template <typename T> class ScopedGraph;
48 
51  // Developer note: Make sure to update sensorTypeStrs in the source file
52  // when changing this enum.
53  enum class SensorType
54  {
56  NONE = 0,
57 
59  ALTIMETER = 1,
60 
62  CAMERA = 2,
63 
65  CONTACT = 3,
66 
68  DEPTH_CAMERA = 4,
69 
71  FORCE_TORQUE = 5,
72 
74  GPS = 6,
75 
77  GPU_LIDAR = 7,
78 
80  IMU = 8,
81 
83  LOGICAL_CAMERA = 9,
84 
86  MAGNETOMETER = 10,
87 
89  MULTICAMERA = 11,
90 
92  LIDAR = 12,
93 
95  RFID = 13,
96 
98  RFIDTAG = 14,
99 
101  SONAR = 15,
102 
104  WIRELESS_RECEIVER = 16,
105 
108 
110  AIR_PRESSURE = 18,
111 
114  RGBD_CAMERA = 19,
115 
117  THERMAL_CAMERA = 20,
118 
120  NAVSAT = 21,
121 
123  SEGMENTATION_CAMERA = 22,
124 
126  BOUNDINGBOX_CAMERA = 23,
127 
129  CUSTOM = 24,
130 
132  WIDE_ANGLE_CAMERA = 25
133  };
134 
137  {
139  public: Sensor();
140 
147  public: Errors Load(ElementPtr _sdf);
148 
152  public: std::string Name() const;
153 
157  public: void SetName(const std::string &_name);
158 
161  public: std::string Topic() const;
162 
165  public: void SetTopic(const std::string &_topic);
166 
169  public: bool EnableMetrics() const;
170 
173  public: void SetEnableMetrics(bool _enableMetrics);
174 
180  public: const gz::math::Pose3d &RawPose() const;
181 
185  public: void SetRawPose(const gz::math::Pose3d &_pose);
186 
191  public: const std::string &PoseRelativeTo() const;
192 
197  public: void SetPoseRelativeTo(const std::string &_frame);
198 
203 
208  public: sdf::ElementPtr Element() const;
209 
215  public: sdf::ElementPtr ToElement() const;
216 
223  public: sdf::ElementPtr ToElement(sdf::Errors &_errors) const;
224 
227  public: SensorType Type() const;
228 
231  public: void SetType(const SensorType _type);
232 
239  public: bool SetType(const std::string &_typeStr);
240 
243  public: std::string TypeStr() const;
244 
249  public: double UpdateRate() const;
250 
255  public: void SetUpdateRate(double _hz);
256 
260  public: bool operator==(const Sensor &_sensor) const;
261 
266  public: bool operator!=(const Sensor &_sensor) const;
267 
273  public: const Magnetometer *MagnetometerSensor() const;
274 
281 
284  public: void SetMagnetometerSensor(const Magnetometer &_mag);
285 
291  public: const Altimeter *AltimeterSensor() const;
292 
299 
302  public: void SetAltimeterSensor(const Altimeter &_alt);
303 
309  public: const AirPressure *AirPressureSensor() const;
310 
317 
320  public: void SetAirPressureSensor(const AirPressure &_air);
321 
324  public: void SetCameraSensor(const Camera &_cam);
325 
331  public: const Camera *CameraSensor() const;
332 
338  public: Camera *CameraSensor();
339 
342  public: void SetNavSatSensor(const NavSat &_navsat);
343 
349  public: const NavSat *NavSatSensor() const;
350 
356  public: NavSat *NavSatSensor();
357 
360  public: void SetForceTorqueSensor(const ForceTorque &_ft);
361 
367  public: const ForceTorque *ForceTorqueSensor() const;
368 
375 
378  public: void SetImuSensor(const Imu &_imu);
379 
385  public: const Imu *ImuSensor() const;
386 
392  public: Imu *ImuSensor();
393 
399  public: const Lidar *LidarSensor() const;
400 
406  public: Lidar *LidarSensor();
407 
410  public: void SetLidarSensor(const Lidar &_lidar);
411 
415  public: const sdf::Plugins &Plugins() const;
416 
420  public: sdf::Plugins &Plugins();
421 
423  public: void ClearPlugins();
424 
427  public: void AddPlugin(const Plugin &_plugin);
428 
433  private: void SetXmlParentName(const std::string &_xmlParentName);
434 
439  private: void SetPoseRelativeToGraph(
441 
445  friend class Link;
449  friend class Joint;
450 
452  GZ_UTILS_IMPL_PTR(dataPtr)
453  };
454  }
455 }
456 #endif
AirPressure contains information about a general purpose fluid pressure sensor.
Definition: AirPressure.hh:35
Altimeter contains information about an altimeter sensor.
Definition: Altimeter.hh:34
Information about a monocular camera sensor.
Definition: Camera.hh:61
ForceTorque contains information about a force torque sensor.
Definition: ForceTorque.hh:65
Imu contains information about an imu sensor.
Definition: Imu.hh:34
Definition: Joint.hh:86
Lidar contains information about a Lidar sensor.
Definition: Lidar.hh:106
Magnetometer contains information about a magnetometer sensor.
Definition: Magnetometer.hh:35
NavSat contains information about a NavSat sensor.
Definition: NavSat.hh:76
Definition: Plugin.hh:46
Definition: Collision.hh:40
SemanticPose is a data structure that can be used by different DOM objects to resolve poses on a Pose...
Definition: SemanticPose.hh:55
Information about an SDF sensor.
Definition: Sensor.hh:137
void SetImuSensor(const Imu &_imu)
Set the IMU sensor.
const sdf::Plugins & Plugins() const
Get the plugins attached to this object.
void SetMagnetometerSensor(const Magnetometer &_mag)
Set the magnetometer sensor.
const Imu * ImuSensor() const
Get a pointer to an IMU sensor, or nullptr if the sensor does not contain an IMU sensor.
AirPressure * AirPressureSensor()
Get a mutable air pressure sensor, or nullptr if this sensor type is not an AirPressure sensor.
NavSat * NavSatSensor()
Get a mutable NAVSAT sensor, or nullptr if the sensor does not contain an NAVSAT sensor.
void SetName(const std::string &_name)
Set the name of the sensor.
bool operator!=(const Sensor &_sensor) const
Return true this Sensor object does not contain the same values as the passed in parameter.
void SetEnableMetrics(bool _enableMetrics)
Set flag to enable publishing performance metrics.
const ForceTorque * ForceTorqueSensor() const
Get a pointer to a force torque sensor, or nullptr if the sensor does not contain a force torque sens...
void SetPoseRelativeTo(const std::string &_frame)
Set the name of the coordinate frame relative to which this object's pose is expressed.
sdf::ElementPtr Element() const
Get a pointer to the SDF element that was used during load.
Lidar * LidarSensor()
Get a mutable lidar sensor, or nullptr if this sensor type is not a Lidar.
Camera * CameraSensor()
Get a mutable camera sensor, or nullptr if the sensor does not contain a camera sensor.
const Magnetometer * MagnetometerSensor() const
Get the magnetometer sensor, or nullptr if this sensor type is not a Magnetometer.
bool operator==(const Sensor &_sensor) const
Return true if both Sensor objects contain the same values.
void SetAirPressureSensor(const AirPressure &_air)
Set the air pressure sensor.
void SetNavSatSensor(const NavSat &_navsat)
Set the NAVSAT sensor.
Altimeter * AltimeterSensor()
Get a mutable altimeter sensor, or nullptr if this sensor type is not an Altimeter.
void SetCameraSensor(const Camera &_cam)
Set the camera sensor.
bool EnableMetrics() const
Get flag state for enabling performance metrics publication.
void AddPlugin(const Plugin &_plugin)
Add a plugin to this object.
sdf::Plugins & Plugins()
Get a mutable vector of plugins attached to this object.
const Camera * CameraSensor() const
Get a pointer to a camera sensor, or nullptr if the sensor does not contain a camera sensor.
void SetRawPose(const gz::math::Pose3d &_pose)
Set the pose of the sensor.
std::string Name() const
Get the name of the sensor.
const Lidar * LidarSensor() const
Get the lidar sensor, or nullptr if this sensor type is not a Lidar.
const AirPressure * AirPressureSensor() const
Get the air pressure sensor, or nullptr if this sensor type is not an AirPressure sensor.
void SetForceTorqueSensor(const ForceTorque &_ft)
Set the force torque sensor.
std::string TypeStr() const
Get the sensor type as a string.
Magnetometer * MagnetometerSensor()
Get a mutable magnetometer sensor, or nullptr if this sensor type is not a Magnetometer.
sdf::ElementPtr ToElement(sdf::Errors &_errors) const
Create and return an SDF element filled with data from this sensor.
void SetTopic(const std::string &_topic)
Set the topic on which sensor data should be published.
void SetType(const SensorType _type)
Set the sensor type.
std::string Topic() const
Get the topic on which sensor data should be published.
void SetAltimeterSensor(const Altimeter &_alt)
Set the altimeter sensor.
const std::string & PoseRelativeTo() const
Get the name of the coordinate frame relative to which this object's pose is expressed.
const Altimeter * AltimeterSensor() const
Get the altimeter sensor, or nullptr if this sensor type is not an Altimeter.
void SetUpdateRate(double _hz)
Set the update rate.
void SetLidarSensor(const Lidar &_lidar)
Set the lidar sensor.
Errors Load(ElementPtr _sdf)
Load the sensor based on a element pointer.
sdf::ElementPtr ToElement() const
Create and return an SDF element filled with data from this sensor.
const gz::math::Pose3d & RawPose() const
Get the pose of the sensor.
SensorType Type() const
Get the sensor type.
double UpdateRate() const
Get the update rate in Hz.
bool SetType(const std::string &_typeStr)
Set the sensor type from a string.
Sensor()
Default constructor.
ForceTorque * ForceTorqueSensor()
Get a mutable force torque sensor, or nullptr if the sensor does not contain a force torque sensor.
sdf::SemanticPose SemanticPose() const
Get SemanticPose object of this object to aid in resolving poses.
Imu * ImuSensor()
Get a mutable IMU sensor, or nullptr if the sensor does not contain an IMU sensor.
const NavSat * NavSatSensor() const
Get a pointer to a NAVSAT sensor, or nullptr if the sensor does not contain an NAVSAT sensor.
void ClearPlugins()
Remove all plugins.
std::vector< Plugin > Plugins
A vector of Plugin.
Definition: Plugin.hh:196
SensorType
The set of sensor types.
Definition: Sensor.hh:54
@ WIRELESS_TRANSMITTER
A wireless transmitter.
@ GPU_LIDAR
A GPU based lidar sensor.
@ NAVSAT
A NavSat sensor, such as GPS.
@ LOGICAL_CAMERA
A logical camera sensor.
@ WIRELESS_RECEIVER
A wireless receiver.
@ AIR_PRESSURE
An air pressure sensor.
@ THERMAL_CAMERA
A thermal camera sensor.
@ BOUNDINGBOX_CAMERA
A boundingbox camera sensor.
@ WIDE_ANGLE_CAMERA
A wide angle camera sensor.
@ RGBD_CAMERA
An RGBD sensor, which produces both a color image and a depth image.
@ SEGMENTATION_CAMERA
A segmentation camera sensor.
@ FORCE_TORQUE
A force-torque sensor.
@ NONE
An unspecified sensor type.
@ MULTICAMERA
A multicamera sensor.
@ MAGNETOMETER
A magnetometer sensor.
@ LIDAR
A CPU based lidar sensor.
@ CAMERA
A monocular camera sensor.
@ DEPTH_CAMERA
A depth camera sensor.
std::vector< Error > Errors
A vector of Error.
Definition: Types.hh:80
std::shared_ptr< Element > ElementPtr
Definition: Element.hh:54
namespace for Simulation Description Format parser
Definition: Actor.hh:35
#define SDFORMAT_VISIBLE
Use to represent "symbol visible" if supported.
Definition: system_util.hh:25