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>
23
24
25// ros libraries
26#include <rclcpp/rclcpp.hpp>
27#include <sensor_msgs/msg/image.hpp>
28#include <sensor_msgs/msg/camera_info.hpp>
29#include <Ros2Subscriber.h>
30
32
62
63
64
72 {
73 private:
74 // mutex for writing or retrieving images
75 std::mutex m_rgb_camera_info_mutex;
76 std::mutex m_rgb_image_mutex;
77 std::mutex m_depth_camera_info_mutex;
78 std::mutex m_depth_image_mutex;
79
80 // current depth and rgb images
81 yarp::os::Stamp m_current_depth_stamp;
82 depthImage m_current_depth_image;
83 std::string m_depth_image_frame;
84 yarp::sig::IntrinsicParams m_depth_params;
85 double m_max_depth_width;
86 double m_max_depth_height;
87
88 yarp::os::Stamp m_current_rgb_stamp;
89 flexImage m_current_rgb_image;
90 std::string m_rgb_image_frame;
91 yarp::sig::IntrinsicParams m_rgb_params;
92 double m_max_rgb_width;
93 double m_max_rgb_height;
94
95 bool m_depth_image_valid = false;
96 bool m_depth_stamp_valid = false;
97 bool m_rgb_image_valid = false;
98 bool m_rgb_stamp_valid = false;
99
100
101 // ros2 variables for topics and subscriptions
102 std::string m_topic_rgb_camera_info;
103 std::string m_topic_depth_camera_info;
104
105 // yarp variables
106 int m_verbose{2};
107
108 // Spinner
109 Ros2Spinner* m_spinner{nullptr};
110
111 //ros2 node and subscribers
114 rclcpp::Node::SharedPtr m_node;
115 //private functions
116 void saveIntrinsics(sensor_msgs::msg::CameraInfo::SharedPtr msg, yarp::sig::IntrinsicParams& params);
117
118 public:
122 RgbdSensor_nwc_ros2& operator=(const RgbdSensor_nwc_ros2&) = delete;
123 RgbdSensor_nwc_ros2& operator=(RgbdSensor_nwc_ros2&&) noexcept = delete;
124 ~RgbdSensor_nwc_ros2() override = default;
125
126 // DeviceDriver
127 bool open(yarp::os::Searchable& config) override;
128 bool close() override;
129
130 // IRGBDSensor
131 int getRgbHeight() override;
132 int getRgbWidth() override;
133 yarp::dev::ReturnValue getRgbSupportedConfigurations(std::vector<yarp::dev::CameraConfig> &configurations) override;
134 yarp::dev::ReturnValue getRgbResolution(int &width, int &height) override;
135 yarp::dev::ReturnValue setRgbResolution(int width, int height) override;
136 yarp::dev::ReturnValue getRgbFOV(double& horizontalFov, double& verticalFov) override;
137 yarp::dev::ReturnValue setRgbFOV(double horizontalFov, double verticalFov) override;
138 yarp::dev::ReturnValue getRgbMirroring(bool& mirror) override;
139 yarp::dev::ReturnValue setRgbMirroring(bool mirror) override;
140
141 yarp::dev::ReturnValue getRgbIntrinsicParam(yarp::os::Property& intrinsic) override;
142 int getDepthHeight() override;
143 int getDepthWidth() override;
144 yarp::dev::ReturnValue getDepthResolution(int& width, int& height) override;
145 yarp::dev::ReturnValue setDepthResolution(int width, int height) override;
146 yarp::dev::ReturnValue getDepthFOV(double& horizontalFov, double& verticalFov) override;
147 yarp::dev::ReturnValue setDepthFOV(double horizontalFov, double verticalFov) override;
148 yarp::dev::ReturnValue getDepthIntrinsicParam(yarp::os::Property& intrinsic) override;
149 yarp::dev::ReturnValue getDepthAccuracy(double& accuracy) override;
150 yarp::dev::ReturnValue setDepthAccuracy(double accuracy) override;
151 yarp::dev::ReturnValue getDepthClipPlanes(double& nearPlane, double& farPlane) override;
152 yarp::dev::ReturnValue setDepthClipPlanes(double nearPlane, double farPlane) override;
153 yarp::dev::ReturnValue getDepthMirroring(bool& mirror) override;
154 yarp::dev::ReturnValue setDepthMirroring(bool mirror) override;
155
156 yarp::dev::ReturnValue getExtrinsicParam(yarp::sig::Matrix &extrinsic) override;
157
158 yarp::dev::ReturnValue getRgbImage(yarp::sig::FlexImage& rgb_image, yarp::os::Stamp* rgb_image_stamp = NULL) override;
159 yarp::dev::ReturnValue getDepthImage(depthImage& depth_image, yarp::os::Stamp* depth_image_stamp = nullptr) override;
160 yarp::dev::ReturnValue 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::ReturnValue getSensorStatus(yarp::dev::IRGBDSensor::RGBDSensor_status& status) override;
171 yarp::dev::ReturnValue getLastErrorMsg(std::string& message, 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.
yarp::dev::ReturnValue getExtrinsicParam(yarp::sig::Matrix &extrinsic) override
Get the extrinsic parameters from the device.
int getDepthWidth() override
Return the height of each frame.
yarp::dev::ReturnValue getRgbResolution(int &width, int &height) override
Get the resolution of the rgb image from the camera.
yarp::dev::ReturnValue getRgbSupportedConfigurations(std::vector< yarp::dev::CameraConfig > &configurations) override
Get the possible configurations of the camera.
yarp::dev::ReturnValue getDepthClipPlanes(double &nearPlane, double &farPlane) override
Get the clipping planes of the sensor.
void color_info_callback(const sensor_msgs::msg::CameraInfo::SharedPtr msg)
yarp::dev::ReturnValue setDepthMirroring(bool mirror) override
Set the mirroring setting of the sensor.
void depth_raw_callback(const sensor_msgs::msg::Image::SharedPtr msg)
yarp::dev::ReturnValue getDepthAccuracy(double &accuracy) override
Get the minimum detectable variation in distance [meter].
yarp::dev::ReturnValue getDepthImage(depthImage &depth_image, yarp::os::Stamp *depth_image_stamp=nullptr) override
yarp::dev::ReturnValue 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 close() override
Close the DeviceDriver.
yarp::dev::ReturnValue getLastErrorMsg(std::string &message, yarp::os::Stamp *timeStamp=NULL) override
Return an error message in case of error.
yarp::dev::ReturnValue getDepthIntrinsicParam(yarp::os::Property &intrinsic) override
yarp::dev::ReturnValue getRgbFOV(double &horizontalFov, double &verticalFov) override
Get the field of view (FOV) of the rgb camera.
yarp::dev::ReturnValue getSensorStatus(yarp::dev::IRGBDSensor::RGBDSensor_status &status) override
Get the current status of the sensor, using enum type.
yarp::dev::ReturnValue getDepthFOV(double &horizontalFov, double &verticalFov) override
Get the field of view (FOV) of the depth camera.
yarp::dev::ReturnValue getRgbMirroring(bool &mirror) override
Get the mirroring setting of the sensor.
yarp::dev::ReturnValue getRgbImage(yarp::sig::FlexImage &rgb_image, yarp::os::Stamp *rgb_image_stamp=NULL) override
Get the rgb frame from the device.
int getRgbWidth() override
Return the width of each frame.
int getRgbHeight() override
Return the height of each frame.
yarp::dev::ReturnValue getRgbIntrinsicParam(yarp::os::Property &intrinsic) override
bool open(yarp::os::Searchable &config) override
Open the DeviceDriver.
yarp::dev::ReturnValue setDepthFOV(double horizontalFov, double verticalFov) override
Set the field of view (FOV) of the depth camera.
yarp::dev::ReturnValue setDepthClipPlanes(double nearPlane, double farPlane) override
Set the clipping planes of the sensor.
void depth_info_callback(const sensor_msgs::msg::CameraInfo::SharedPtr msg)
yarp::dev::ReturnValue setRgbResolution(int width, int height) override
Set the resolution of the rgb image from the camera.
void color_raw_callback(const sensor_msgs::msg::Image::SharedPtr msg)
yarp::dev::ReturnValue getDepthMirroring(bool &mirror) override
Get the mirroring setting of the sensor.
yarp::dev::ReturnValue setDepthAccuracy(double accuracy) override
Set the minimum detectable variation in distance [meter] when possible.
RgbdSensor_nwc_ros2(RgbdSensor_nwc_ros2 &&) noexcept=delete
yarp::dev::ReturnValue setRgbMirroring(bool mirror) override
Set the mirroring setting of the sensor.
yarp::dev::ReturnValue setRgbFOV(double horizontalFov, double verticalFov) override
Set the field of view (FOV) of the rgb camera.
void callback(sensor_msgs::msg::CameraInfo::SharedPtr msg, std::string topic)
yarp::dev::ReturnValue setDepthResolution(int width, int height) override
Set the resolution of the depth image from the camera.
yarp::dev::ReturnValue getDepthResolution(int &width, int &height) override
Get the resolution of the depth image from the 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:18
Image class with user control of representation details.
Definition Image.h:361
Typed image class.
Definition Image.h:603
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).