6#ifndef _USE_MATH_DEFINES
7#define _USE_MATH_DEFINES
24using namespace std::chrono_literals;
25using namespace std::placeholders;
94 if (topic == m_topic_rgb_camera_info) {
96 }
else if (topic == m_topic_depth_camera_info)
105 std::lock_guard<std::mutex> depth_image_guard(m_depth_image_mutex);
107 m_depth_image_valid =
true;
112 std::lock_guard<std::mutex> depth_camera_info_guard(m_depth_camera_info_mutex);
114 saveIntrinsics(msg, m_depth_params);
115 m_max_depth_height = msg->height;
116 m_max_depth_width = msg->width;
117 m_depth_stamp_valid =
true;
123 std::lock_guard<std::mutex> rgb_image_guard(m_rgb_image_mutex);
125 m_rgb_image_valid =
true;
130 std::lock_guard<std::mutex> rgb_camera_info_guard(m_rgb_camera_info_mutex);
132 saveIntrinsics(msg, m_rgb_params);
133 m_max_rgb_height = msg->height;
134 m_max_rgb_width = msg->width;
135 m_rgb_stamp_valid =
true;
146 if (msg->distortion_model==
"plumb_bob")
174 if (!m_rgb_image_valid)
return 0;
175 return m_current_rgb_image.
height();
180 if (!m_rgb_image_valid)
return 0;
181 return m_current_rgb_image.
width();
187 return ReturnValue::return_code::return_value_error_not_implemented_by_device;
192 if (!m_rgb_image_valid)
196 return ReturnValue::return_code::return_value_error_not_ready;
198 width = m_current_rgb_image.
width();
199 height = m_current_rgb_image.
height();
205 if (!m_rgb_image_valid)
209 return ReturnValue::return_code::return_value_error_not_ready;
211 width = m_current_depth_image.
width();
212 height = m_current_depth_image.
height();
219 return ReturnValue::return_code::return_value_error_not_implemented_by_device;
225 return ReturnValue::return_code::return_value_error_not_implemented_by_device;
231 return ReturnValue::return_code::return_value_error_not_implemented_by_device;
237 return ReturnValue::return_code::return_value_error_not_implemented_by_device;
243 return ReturnValue::return_code::return_value_error_not_implemented_by_device;
249 if (!m_rgb_image_valid && ! m_rgb_stamp_valid)
253 return ReturnValue::return_code::return_value_error_not_ready;
256 horizontalFov = 2 * atan(m_max_rgb_width / (2 * m_rgb_params.
focalLengthX)) * 180.0 /
M_PI;
257 verticalFov = 2 * atan(m_max_rgb_height / (2 * m_rgb_params.
focalLengthY)) * 180.0 /
M_PI;
265 return ReturnValue::return_code::return_value_error_not_implemented_by_device;
271 return ReturnValue::return_code::return_value_error_not_implemented_by_device;
276 if (m_rgb_stamp_valid)
279 m_rgb_params.toProperty(intrinsic);
282 return ReturnValue::return_code::return_value_error_not_ready;
287 if (!m_depth_image_valid)
return 0;
288 return m_current_depth_image.
height();
293 if (!m_depth_image_valid)
return 0;
294 return m_current_depth_image.
width();
299 if (!m_depth_image_valid && !m_depth_stamp_valid)
303 return ReturnValue::return_code::return_value_error_not_ready;
306 horizontalFov = 2 * atan(m_max_rgb_width / (2 * m_depth_params.
focalLengthX)) * 180.0 /
M_PI;
307 verticalFov = 2 * atan(m_max_rgb_height / (2 * m_depth_params.
focalLengthY)) * 180.0 /
M_PI;
313 if(m_depth_stamp_valid)
316 m_depth_params.toProperty(intrinsic);
319 return ReturnValue::return_code::return_value_error_not_ready;
325 return ReturnValue::return_code::return_value_error_not_implemented_by_device;
331 return ReturnValue::return_code::return_value_error_not_implemented_by_device;
337 return ReturnValue::return_code::return_value_error_not_implemented_by_device;
343 return ReturnValue::return_code::return_value_error_not_implemented_by_device;
349 return ReturnValue::return_code::return_value_error_not_implemented_by_device;
355 return ReturnValue::return_code::return_value_error_not_implemented_by_device;
364 std::lock_guard<std::mutex> guard_rgb_image(m_rgb_image_mutex);
365 std::lock_guard<std::mutex> guard_rgb_camera_info(m_rgb_camera_info_mutex);
367 if (m_rgb_image_valid)
369 if (m_rgb_stamp_valid)
371 if (rgb_image_stamp ==
nullptr)
374 rgb_image_stamp = &stamp;
391 return ReturnValue::return_code::return_value_error_not_ready;
399 std::lock_guard<std::mutex> guard_depth_image(m_depth_image_mutex);
400 std::lock_guard<std::mutex> guard_depth_camera_info(m_depth_camera_info_mutex);
401 bool depth_ok =
false;
403 if (m_depth_image_valid)
405 if (m_depth_stamp_valid)
407 if (depth_image_stamp ==
nullptr)
410 depth_image_stamp = &stamp;
428 return ReturnValue::return_code::return_value_error_not_ready;
435 bool rgb_ok, depth_ok;
440 return ReturnValue::return_code::return_value_error_not_ready;
454 message =
"get last error not yet implemented";
455 return ReturnValue::return_code::return_value_error_not_implemented_by_device;
const yarp::os::LogComponent & RGBDSENSOR_NWC_ROS2()
static rclcpp::Node::SharedPtr createNode(std::string name)
std::string m_depth_topic_name
bool parseParams(const yarp::os::Searchable &config) override
Parse the DeviceDriver parameters.
std::string m_color_topic_name
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.
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.
int getDepthHeight() override
Return the height of each frame.
void subscribe_to_topic(std::string topic_name)
A class for storing options and configuration information.
void clear()
Remove all associations.
A base class for nested structures that can be searched.
An abstraction for a time stamp and/or sequence number.
void update()
Set the timestamp to the current time, and increment the sequence number (wrapping to 0 if the sequen...
double getTime() const
Get the time stamp.
int getCount() const
Get the sequence number.
bool start()
Start the new thread running.
CameraDistortionType type
Image class with user control of representation details.
size_t width() const
Gets width of image in pixels.
size_t height() const
Gets height of image in pixels.
yarp::sig::DistortionModelData distortionModel
#define yCInfo(component,...)
#define yCError(component,...)
#define yCTrace(component,...)
#define yCWarning(component,...)
#define YARP_LOG_COMPONENT(name,...)
void deepCopyImageOf(const DepthImage &src, DepthImage &dest)
void updateStamp(sensor_msgs::msg::CameraInfo::SharedPtr ros_camera_info_src, std::string &frame_id_dest, yarp::os::Stamp &yarp_stamp)
void convertDepthImageRos2ToYarpImageOf(sensor_msgs::msg::Image::SharedPtr ros_image_src, yarp::sig::ImageOf< yarp::sig::PixelFloat > &dest)
void convertRGBImageRos2ToYarpFlexImage(sensor_msgs::msg::Image::SharedPtr ros_image_src, yarp::sig::FlexImage &dest)
void deepCopyFlexImage(const yarp::sig::FlexImage &src, yarp::sig::FlexImage &dest)
For streams capable of holding different kinds of content, check what they actually have.
constexpr char accuracy[]
The IntrinsicParams struct to handle the intrinsic parameter of cameras(RGB and RGBD either).