YARP
Yet Another Robot Platform
 
Loading...
Searching...
No Matches
RgbdSensor_nwc_ros2.h
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2023 Istituto Italiano di Tecnologia (IIT)
3 * SPDX-License-Identifier: BSD-3-Clause
4 */
5
6#ifndef YARP_RGBDSENSOR_NWC_ROS2
7#define YARP_RGBDSENSOR_NWC_ROS2
8
9// c++ libraries
10#include <iostream>
11#include <cstring>
12#include <mutex>
13
14// yarp libraries
17#include <yarp/os/Property.h>
18#include <Ros2Spinner.h>
19#include <yarp/sig/all.h>
20#include <yarp/sig/Matrix.h>
21#include <yarp/os/Stamp.h>
24
25
26// ros libraries
27#include <rclcpp/rclcpp.hpp>
28#include <sensor_msgs/msg/image.hpp>
29#include <sensor_msgs/msg/camera_info.hpp>
30#include <Ros2Subscriber.h>
31
33
63
64
65
73 {
74 private:
75 // mutex for writing or retrieving images
76 std::mutex m_rgb_camera_info_mutex;
77 std::mutex m_rgb_image_mutex;
78 std::mutex m_depth_camera_info_mutex;
79 std::mutex m_depth_image_mutex;
80
81 // current depth and rgb images
82 yarp::os::Stamp m_current_depth_stamp;
83 depthImage m_current_depth_image;
84 std::string m_depth_image_frame;
85 yarp::sig::IntrinsicParams m_depth_params;
86 double m_max_depth_width;
87 double m_max_depth_height;
88
89 yarp::os::Stamp m_current_rgb_stamp;
90 flexImage m_current_rgb_image;
91 std::string m_rgb_image_frame;
92 yarp::sig::IntrinsicParams m_rgb_params;
93 double m_max_rgb_width;
94 double m_max_rgb_height;
95
96 bool m_depth_image_valid = false;
97 bool m_depth_stamp_valid = false;
98 bool m_rgb_image_valid = false;
99 bool m_rgb_stamp_valid = false;
100
101
102 // ros2 variables for topics and subscriptions
103 std::string m_topic_rgb_camera_info;
104 std::string m_topic_depth_camera_info;
105
106 // yarp variables
107 int m_verbose{2};
108
109 // Spinner
110 Ros2Spinner* m_spinner{nullptr};
111
112 //ros2 node and subscribers
115 rclcpp::Node::SharedPtr m_node;
116 //private functions
117 void saveIntrinsics(sensor_msgs::msg::CameraInfo::SharedPtr msg, yarp::sig::IntrinsicParams& params);
118
119 public:
123 RgbdSensor_nwc_ros2& operator=(const RgbdSensor_nwc_ros2&) = delete;
124 RgbdSensor_nwc_ros2& operator=(RgbdSensor_nwc_ros2&&) noexcept = delete;
125 ~RgbdSensor_nwc_ros2() override = default;
126
127 // DeviceDriver
128 bool open(yarp::os::Searchable& config) override;
129 bool close() override;
130
131 // IRGBDSensor
132 int getRgbHeight() override;
133 int getRgbWidth() override;
134 bool getRgbSupportedConfigurations(yarp::sig::VectorOf<yarp::dev::CameraConfig> &configurations) override;
135 bool getRgbResolution(int &width, int &height) override;
136 bool setRgbResolution(int width, int height) override;
137 bool getRgbFOV(double& horizontalFov, double& verticalFov) override;
138 bool setRgbFOV(double horizontalFov, double verticalFov) override;
139 bool getRgbMirroring(bool& mirror) override;
140 bool setRgbMirroring(bool mirror) override;
141
142 bool getRgbIntrinsicParam(yarp::os::Property& intrinsic) override;
143 int getDepthHeight() override;
144 int getDepthWidth() override;
145 bool setDepthResolution(int width, int height) override;
146 bool getDepthFOV(double& horizontalFov, double& verticalFov) override;
147 bool setDepthFOV(double horizontalFov, double verticalFov) override;
148 bool getDepthIntrinsicParam(yarp::os::Property& intrinsic) override;
149 double getDepthAccuracy() override;
150 bool setDepthAccuracy(double accuracy) override;
151 bool getDepthClipPlanes(double& nearPlane, double& farPlane) override;
152 bool setDepthClipPlanes(double nearPlane, double farPlane) override;
153 bool getDepthMirroring(bool& mirror) override;
154 bool setDepthMirroring(bool mirror) override;
155
156 bool getExtrinsicParam(yarp::sig::Matrix &extrinsic) override;
157
158 bool getRgbImage(yarp::sig::FlexImage& rgb_image, yarp::os::Stamp* rgb_image_stamp = NULL) override;
159 bool getDepthImage(depthImage& depth_image, yarp::os::Stamp* depth_image_stamp = nullptr) override;
160 bool getImages(yarp::sig::FlexImage& rgb_image, depthImage& depth_image, yarp::os::Stamp* rgb_image_stamp=nullptr, yarp::os::Stamp* depth_image_stamp=nullptr) override;
161
162 void callback(sensor_msgs::msg::CameraInfo::SharedPtr msg, std::string topic);
163 void callback(sensor_msgs::msg::Image::SharedPtr msg, std::string topic);
164
165 void depth_raw_callback(const sensor_msgs::msg::Image::SharedPtr msg);
166 void depth_info_callback(const sensor_msgs::msg::CameraInfo::SharedPtr msg);
167 void color_raw_callback(const sensor_msgs::msg::Image::SharedPtr msg);
168 void color_info_callback(const sensor_msgs::msg::CameraInfo::SharedPtr msg);
169
170 yarp::dev::IRGBDSensor::RGBDSensor_status getSensorStatus() override;
171 std::string getLastErrorMsg(yarp::os::Stamp* timeStamp = NULL) override;
172 };
173
174
175
176
177
178#endif // YARP_RGBDSENSOR_NWC_ROS2
contains the definition of a Matrix type
yarp::sig::FlexImage flexImage
This class is the parameters parser for class RgbdSensor_nwc_ros2.
This class implements an nwc for ros2 for an rgbd sensor.
bool getDepthMirroring(bool &mirror) override
Get the mirroring setting of the sensor.
bool getRgbSupportedConfigurations(yarp::sig::VectorOf< yarp::dev::CameraConfig > &configurations) override
Get the possible configurations of the camera.
int getDepthWidth() override
Return the height of each frame.
void color_info_callback(const sensor_msgs::msg::CameraInfo::SharedPtr msg)
std::string getLastErrorMsg(yarp::os::Stamp *timeStamp=NULL) override
Return an error message in case of error.
double getDepthAccuracy() override
Get the minimum detectable variation in distance [meter].
void depth_raw_callback(const sensor_msgs::msg::Image::SharedPtr msg)
bool getExtrinsicParam(yarp::sig::Matrix &extrinsic) override
Get the extrinsic parameters from the device.
bool close() override
Close the DeviceDriver.
bool setRgbMirroring(bool mirror) override
Set the mirroring setting of the sensor.
bool getRgbIntrinsicParam(yarp::os::Property &intrinsic) override
Get the intrinsic parameters of the rgb camera.
bool getRgbFOV(double &horizontalFov, double &verticalFov) override
Get the field of view (FOV) of the rgb camera.
bool setDepthAccuracy(double accuracy) override
Set the minimum detectable variation in distance [meter] when possible.
bool getDepthImage(depthImage &depth_image, yarp::os::Stamp *depth_image_stamp=nullptr) override
bool getRgbImage(yarp::sig::FlexImage &rgb_image, yarp::os::Stamp *rgb_image_stamp=NULL) override
Get the rgb frame from the device.
bool getDepthFOV(double &horizontalFov, double &verticalFov) override
Get the field of view (FOV) of the depth camera.
int getRgbWidth() override
Return the width of each frame.
int getRgbHeight() override
Return the height of each frame.
bool open(yarp::os::Searchable &config) override
Open the DeviceDriver.
void depth_info_callback(const sensor_msgs::msg::CameraInfo::SharedPtr msg)
bool getDepthClipPlanes(double &nearPlane, double &farPlane) override
Get the clipping planes of the sensor.
yarp::dev::IRGBDSensor::RGBDSensor_status getSensorStatus() override
Get the surrent status of the sensor, using enum type.
void color_raw_callback(const sensor_msgs::msg::Image::SharedPtr msg)
bool setDepthMirroring(bool mirror) override
Set the mirroring setting of the sensor.
bool getRgbResolution(int &width, int &height) override
Get the resolution of the rgb image from the camera.
bool setDepthResolution(int width, int height) override
Set the resolution of the depth image from the camera.
RgbdSensor_nwc_ros2(RgbdSensor_nwc_ros2 &&) noexcept=delete
bool setRgbResolution(int width, int height) override
Set the resolution of the rgb image from the camera.
bool getDepthIntrinsicParam(yarp::os::Property &intrinsic) override
Get the intrinsic parameters of the depth camera.
bool getImages(yarp::sig::FlexImage &rgb_image, depthImage &depth_image, yarp::os::Stamp *rgb_image_stamp=nullptr, yarp::os::Stamp *depth_image_stamp=nullptr) override
bool getRgbMirroring(bool &mirror) override
Get the mirroring setting of the sensor.
void callback(sensor_msgs::msg::CameraInfo::SharedPtr msg, std::string topic)
bool setDepthFOV(double horizontalFov, double verticalFov) override
Set the field of view (FOV) of the depth camera.
bool setDepthClipPlanes(double nearPlane, double farPlane) override
Set the clipping planes of the sensor.
bool setRgbFOV(double horizontalFov, double verticalFov) override
Set the field of view (FOV) of the rgb camera.
RgbdSensor_nwc_ros2(const RgbdSensor_nwc_ros2 &)=delete
int getDepthHeight() override
Return the height of each frame.
Interface implemented by all device drivers.
A generic interface for cameras that have both color camera as well as depth camera sensor,...
Definition IRGBDSensor.h:39
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
yarp::sig::ImageOf< yarp::sig::PixelFloat > depthImage
This class is an utility.
STL namespace.
The main, catch-all namespace for YARP.
Definition dirs.h:16
constexpr char accuracy[]
The IntrinsicParams struct to handle the intrinsic parameter of cameras(RGB and RGBD either).