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 AirSpeed;
40  class Altimeter;
41  class Camera;
42  class ForceTorque;
43  class Imu;
44  class Lidar;
45  class Magnetometer;
46  class NavSat;
47  struct PoseRelativeToGraph;
48  template <typename T> class ScopedGraph;
49 
52  // Developer note: Make sure to update kSensorTypeStrs in the source file
53  // when changing this enum.
54  enum class SensorType
55  {
57  NONE = 0,
58 
60  ALTIMETER = 1,
61 
63  CAMERA = 2,
64 
66  CONTACT = 3,
67 
69  DEPTH_CAMERA = 4,
70 
72  FORCE_TORQUE = 5,
73 
75  GPS = 6,
76 
78  GPU_LIDAR = 7,
79 
81  IMU = 8,
82 
84  LOGICAL_CAMERA = 9,
85 
87  MAGNETOMETER = 10,
88 
90  MULTICAMERA = 11,
91 
93  LIDAR = 12,
94 
96  RFID = 13,
97 
99  RFIDTAG = 14,
100 
102  SONAR = 15,
103 
105  WIRELESS_RECEIVER = 16,
106 
109 
111  AIR_PRESSURE = 18,
112 
115  RGBD_CAMERA = 19,
116 
118  THERMAL_CAMERA = 20,
119 
121  NAVSAT = 21,
122 
124  SEGMENTATION_CAMERA = 22,
125 
127  BOUNDINGBOX_CAMERA = 23,
128 
130  CUSTOM = 24,
131 
133  WIDE_ANGLE_CAMERA = 25,
134 
136  AIR_SPEED = 26,
137  };
138 
141  {
143  public: Sensor();
144 
151  public: Errors Load(ElementPtr _sdf);
152 
156  public: std::string Name() const;
157 
161  public: void SetName(const std::string &_name);
162 
165  public: std::string Topic() const;
166 
169  public: void SetTopic(const std::string &_topic);
170 
173  public: bool EnableMetrics() const;
174 
177  public: void SetEnableMetrics(bool _enableMetrics);
178 
184  public: const gz::math::Pose3d &RawPose() const;
185 
189  public: void SetRawPose(const gz::math::Pose3d &_pose);
190 
195  public: const std::string &PoseRelativeTo() const;
196 
201  public: void SetPoseRelativeTo(const std::string &_frame);
202 
207 
212  public: sdf::ElementPtr Element() const;
213 
219  public: sdf::ElementPtr ToElement() const;
220 
227  public: sdf::ElementPtr ToElement(sdf::Errors &_errors) const;
228 
231  public: SensorType Type() const;
232 
235  public: void SetType(const SensorType _type);
236 
243  public: bool SetType(const std::string &_typeStr);
244 
247  public: std::string TypeStr() const;
248 
253  public: double UpdateRate() const;
254 
259  public: void SetUpdateRate(double _hz);
260 
264  public: bool operator==(const Sensor &_sensor) const;
265 
270  public: bool operator!=(const Sensor &_sensor) const;
271 
277  public: const Magnetometer *MagnetometerSensor() const;
278 
285 
288  public: void SetMagnetometerSensor(const Magnetometer &_mag);
289 
295  public: const Altimeter *AltimeterSensor() const;
296 
303 
306  public: void SetAltimeterSensor(const Altimeter &_alt);
307 
313  public: const AirPressure *AirPressureSensor() const;
314 
321 
324  public: void SetAirPressureSensor(const AirPressure &_air);
325 
331  public: const AirSpeed *AirSpeedSensor() const;
332 
339 
342  public: void SetAirSpeedSensor(const AirSpeed &_air);
343 
346  public: void SetCameraSensor(const Camera &_cam);
347 
353  public: const Camera *CameraSensor() const;
354 
360  public: Camera *CameraSensor();
361 
364  public: void SetNavSatSensor(const NavSat &_navsat);
365 
371  public: const NavSat *NavSatSensor() const;
372 
378  public: NavSat *NavSatSensor();
379 
382  public: void SetForceTorqueSensor(const ForceTorque &_ft);
383 
389  public: const ForceTorque *ForceTorqueSensor() const;
390 
397 
400  public: void SetImuSensor(const Imu &_imu);
401 
407  public: const Imu *ImuSensor() const;
408 
414  public: Imu *ImuSensor();
415 
421  public: const Lidar *LidarSensor() const;
422 
428  public: Lidar *LidarSensor();
429 
432  public: void SetLidarSensor(const Lidar &_lidar);
433 
437  public: const sdf::Plugins &Plugins() const;
438 
442  public: sdf::Plugins &Plugins();
443 
445  public: void ClearPlugins();
446 
449  public: void AddPlugin(const Plugin &_plugin);
450 
455  private: void SetXmlParentName(const std::string &_xmlParentName);
456 
461  private: void SetPoseRelativeToGraph(
463 
467  friend class Link;
471  friend class Joint;
472 
474  GZ_UTILS_IMPL_PTR(dataPtr)
475  };
476  }
477 }
478 #endif
AirPressure contains information about a general purpose fluid pressure sensor.
Definition: AirPressure.hh:35
AirSpeed contains information about a general purpose air speed sensor.
Definition: AirSpeed.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:44
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:141
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.
AirSpeed * AirSpeedSensor()
Get a mutable air speed sensor, or nullptr if this sensor type is not an AirSpeed sensor.
const AirSpeed * AirSpeedSensor() const
Get the air speed sensor, or nullptr if this sensor type is not an AirSpeed sensor.
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.
void SetAirSpeedSensor(const AirSpeed &_air)
Set the air pressure 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:245
SensorType
The set of sensor types.
Definition: Sensor.hh:55
@ 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:95
std::shared_ptr< Element > ElementPtr
Definition: Element.hh:55
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