YARP
Yet Another Robot Platform
 
Loading...
Searching...
No Matches
realsense2Driver.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2006-2020 Istituto Italiano di Tecnologia (IIT)
3 * All rights reserved.
4 *
5 * This software may be modified and distributed under the terms of the
6 * BSD-3-Clause license. See the accompanying LICENSE file for details.
7 */
8
9#ifndef REALSENSE2_DRIVER_H
10#define REALSENSE2_DRIVER_H
11
12#include <iostream>
13#include <cstring>
14#include <map>
15#include <mutex>
16
21#include <yarp/sig/all.h>
22#include <yarp/sig/Matrix.h>
23#include <yarp/os/Stamp.h>
26#include <librealsense2/rs.hpp>
27
28
34{
35private:
37 typedef yarp::os::Stamp Stamp;
40
41
42public:
44 ~realsense2Driver() override = default;
45
46 // DeviceDriver
47 bool open(yarp::os::Searchable& config) override;
48 bool close() override;
49
50 // IRGBDSensor
51 int getRgbHeight() override;
52 int getRgbWidth() override;
54 bool getRgbResolution(int &width, int &height) override;
55 bool setRgbResolution(int width, int height) override;
56 bool getRgbFOV(double& horizontalFov, double& verticalFov) override;
57 bool setRgbFOV(double horizontalFov, double verticalFov) override;
58 bool getRgbMirroring(bool& mirror) override;
59 bool setRgbMirroring(bool mirror) override;
60
61 bool getRgbIntrinsicParam(Property& intrinsic) override;
62 int getDepthHeight() override;
63 int getDepthWidth() override;
64 bool setDepthResolution(int width, int height) override;
65 bool getDepthFOV(double& horizontalFov, double& verticalFov) override;
66 bool setDepthFOV(double horizontalFov, double verticalFov) override;
67 bool getDepthIntrinsicParam(Property& intrinsic) override;
68 double getDepthAccuracy() override;
69 bool setDepthAccuracy(double accuracy) override;
70 bool getDepthClipPlanes(double& nearPlane, double& farPlane) override;
71 bool setDepthClipPlanes(double nearPlane, double farPlane) override;
72 bool getDepthMirroring(bool& mirror) override;
73 bool setDepthMirroring(bool mirror) override;
74
75
76 bool getExtrinsicParam(yarp::sig::Matrix &extrinsic) override;
77 bool getRgbImage(FlexImage& rgbImage, Stamp* timeStamp = nullptr) override;
78 bool getDepthImage(depthImage& depthImage, Stamp* timeStamp = nullptr) override;
79 bool getImages(FlexImage& colorFrame, depthImage& depthFrame, Stamp* colorStamp=NULL, Stamp* depthStamp=NULL) override;
80
82 std::string getLastErrorMsg(Stamp* timeStamp = NULL) override;
83
84 //IFrameGrabberControls
85 bool getCameraDescription(CameraDescriptor *camera) override;
86 bool hasFeature(int feature, bool* hasFeature) override;
87 bool setFeature(int feature, double value) override;
88 bool getFeature(int feature, double* value) override;
89 bool setFeature(int feature, double value1, double value2) override;
90 bool getFeature(int feature, double* value1, double* value2) override;
91 bool hasOnOff( int feature, bool* HasOnOff) override;
92 bool setActive( int feature, bool onoff) override;
93 bool getActive( int feature, bool* isActive) override;
94 bool hasAuto( int feature, bool* hasAuto) override;
95 bool hasManual( int feature, bool* hasManual) override;
96 bool hasOnePush(int feature, bool* hasOnePush) override;
97 bool setMode( int feature, FeatureMode mode) override;
98 bool getMode( int feature, FeatureMode *mode) override;
99 bool setOnePush(int feature) override;
100
101 //IFrameGrabberImageRaw
103 int height() const override;
104 int width() const override;
105
106protected:
107 //method
108 inline bool initializeRealsenseDevice();
109 inline bool setParams();
110
111 bool getImage(FlexImage& Frame, Stamp* timeStamp, rs2::frameset& sourceFrame);
112 bool getImage(depthImage& Frame, Stamp* timeStamp, const rs2::frameset& sourceFrame);
114 bool pipelineStartup();
115 bool pipelineShutdown();
116 bool pipelineRestart();
117 bool setFramerate(const int _fps);
118 void fallback();
119
120
121 // realsense classes
122 mutable std::mutex m_mutex;
123 rs2::context m_ctx;
124 rs2::config m_cfg;
125 rs2::pipeline m_pipeline;
126 rs2::pipeline_profile m_profile;
127 rs2::device m_device;
128 std::vector<rs2::sensor> m_sensors;
129 rs2::sensor* m_depth_sensor;
130 rs2::sensor* m_color_sensor;
133 rs2_stream m_alignment_stream{RS2_STREAM_COLOR};
134
135
136 // Data quantization related parameters
139
142 mutable std::string m_lastError;
148 int m_fps;
149 float m_scale;
150 bool m_rotateImage180{false};
151 std::vector<cameraFeature_id_t> m_supportedFeatures;
152};
153#endif
contains the definition of a Matrix type
yarp::os::Stamp m_depth_stamp
rs2::pipeline m_pipeline
bool setActive(int feature, bool onoff) override
Set the requested feature on or off.
bool setDepthClipPlanes(double nearPlane, double farPlane) override
Set the clipping planes of the sensor.
rs2_intrinsics m_infrared_intrin
RGBDSensor_status getSensorStatus() override
Get the surrent status of the sensor, using enum type.
bool hasManual(int feature, bool *hasManual) override
Check if the requested feature has the 'manual' mode.
rs2_intrinsics m_color_intrin
bool getRgbMirroring(bool &mirror) override
Get the mirroring setting of the sensor.
bool getDepthImage(depthImage &depthImage, Stamp *timeStamp=nullptr) override
rs2::sensor * m_depth_sensor
bool getActive(int feature, bool *isActive) override
Get the current status of the feature, on or off.
std::vector< cameraFeature_id_t > m_supportedFeatures
bool close() override
Close the DeviceDriver.
bool setFramerate(const int _fps)
bool hasAuto(int feature, bool *hasAuto) override
Check if the requested feature has the 'auto' mode.
int height() const override
Return the height of each frame.
bool setDepthFOV(double horizontalFov, double verticalFov) override
Set the field of view (FOV) of the depth camera.
bool hasFeature(int feature, bool *hasFeature) override
Check if camera has the requested feature (saturation, brightness ... )
bool getCameraDescription(CameraDescriptor *camera) override
Get a basic description of the camera hw.
bool getRgbSupportedConfigurations(yarp::sig::VectorOf< yarp::dev::CameraConfig > &configurations) override
Get the possible configurations of the camera.
bool getMode(int feature, FeatureMode *mode) override
Get the current mode for the feature.
bool setDepthResolution(int width, int height) override
Set the resolution of the depth image from the camera.
bool setRgbFOV(double horizontalFov, double verticalFov) override
Set the field of view (FOV) of the rgb camera.
rs2::pipeline_profile m_profile
rs2_intrinsics m_depth_intrin
rs2_stream m_alignment_stream
int getDepthHeight() override
Return the height of each frame.
bool setRgbMirroring(bool mirror) override
Set the mirroring setting of the sensor.
bool open(yarp::os::Searchable &config) override
Open the DeviceDriver.
rs2_extrinsics m_depth_to_color
double getDepthAccuracy() override
Get the minimum detectable variation in distance [meter].
bool setDepthMirroring(bool mirror) override
Set the mirroring setting of the sensor.
bool hasOnOff(int feature, bool *HasOnOff) override
Check if the camera has the ability to turn on/off the requested feature.
~realsense2Driver() override=default
bool hasOnePush(int feature, bool *hasOnePush) override
Check if the requested feature has the 'onePush' mode.
std::string getLastErrorMsg(Stamp *timeStamp=NULL) override
Return an error message in case of error.
int getDepthWidth() override
Return the height of each frame.
bool getRgbResolution(int &width, int &height) override
Get the resolution of the rgb image from the camera.
bool getDepthFOV(double &horizontalFov, double &verticalFov) override
Get the field of view (FOV) of the depth camera.
bool setFeature(int feature, double value) override
Set the requested feature to a value (saturation, brightness ... )
bool setOnePush(int feature) override
Set the requested feature to a value (saturation, brightness ... )
bool setDepthAccuracy(double accuracy) override
Set the minimum detectable variation in distance [meter] when possible.
rs2::sensor * m_color_sensor
bool getRgbFOV(double &horizontalFov, double &verticalFov) override
Get the field of view (FOV) of the rgb camera.
bool getRgbImage(FlexImage &rgbImage, Stamp *timeStamp=nullptr) override
Get the rgb frame from the device.
rs2_extrinsics m_color_to_depth
bool getImages(FlexImage &colorFrame, depthImage &depthFrame, Stamp *colorStamp=NULL, Stamp *depthStamp=NULL) override
yarp::os::Stamp m_rgb_stamp
bool getExtrinsicParam(yarp::sig::Matrix &extrinsic) override
Get the extrinsic parameters from the device.
bool getRgbIntrinsicParam(Property &intrinsic) override
Get the intrinsic parameters of the rgb camera.
int getRgbHeight() override
Return the height of each frame.
bool getDepthIntrinsicParam(Property &intrinsic) override
Get the intrinsic parameters of the depth camera.
bool getImage(yarp::sig::ImageOf< yarp::sig::PixelMono > &image) override
Get an image from the frame grabber.
int width() const override
Return the width of each frame.
int getRgbWidth() override
Return the width of each frame.
yarp::dev::RGBDSensorParamParser m_paramParser
bool setMode(int feature, FeatureMode mode) override
Set the requested mode for the feature.
std::vector< rs2::sensor > m_sensors
bool getFeature(int feature, double *value) override
Get the current value for the requested feature.
std::string m_lastError
bool setRgbResolution(int width, int height) override
Set the resolution of the rgb image from the camera.
bool getDepthClipPlanes(double &nearPlane, double &farPlane) override
Get the clipping planes of the sensor.
bool getDepthMirroring(bool &mirror) override
Get the mirroring setting of the sensor.
Interface implemented by all device drivers.
Control interface for frame grabber devices.
A generic interface for cameras that have both color camera as well as depth camera sensor,...
Definition IRGBDSensor.h:39
The RGBDSensorParamParser class.
A class for storing options and configuration information.
Definition Property.h:33
A base class for nested structures that can be searched.
Definition Searchable.h:31
An abstraction for a time stamp and/or sequence number.
Definition Stamp.h:21
Image class with user control of representation details.
Definition Image.h:363
Typed image class.
Definition Image.h:605
A class for a Matrix.
Definition Matrix.h:39
constexpr char accuracy[]