YARP
Yet Another Robot Platform
 
Loading...
Searching...
No Matches
RGBDSensorClient.cpp
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2006-2021 Istituto Italiano di Tecnologia (IIT)
3 * SPDX-License-Identifier: BSD-3-Clause
4 */
5
6#include "RGBDSensorClient.h"
8#include <yarp/os/Portable.h>
10#include <yarp/os/LogStream.h>
12
13using namespace yarp::os;
14using namespace yarp::sig;
15using namespace yarp::dev;
16
17#define RGBD_INTERFACE_PROTOCOL_VERSION_MAJOR 1
18#define RGBD_INTERFACE_PROTOCOL_VERSION_MINOR 0
19
20YARP_LOG_COMPONENT(RGBDSENSORCLIENT, "yarp.devices.RGBDSensorClient")
21
22
24 yarp::proto::framegrabber::FrameGrabberControls_Forwarder(rpcPort),
25 RgbMsgSender(new yarp::proto::framegrabber::RgbVisualParams_Forwarder(rpcPort)),
26 DepthMsgSender(new yarp::proto::framegrabber::DepthVisualParams_Forwarder(rpcPort)),
27 streamingReader(new RGBDSensor_StreamingMsgParser)
28{
29}
30
32{
33 close();
34 delete RgbMsgSender;
35 delete DepthMsgSender;
36 delete streamingReader;
37}
38
40{
41 if (!parseParams(config)) { return false; }
42
43 bool ret = false;
44
45 // Opening Streaming ports
48
49 if (!ret)
50 {
51 yCError(RGBDSENSORCLIENT) << " cannot open local streaming ports: " << m_localImagePort << " or " << m_localDepthPort;
54 }
55
57 {
58 yCError(RGBDSENSORCLIENT) << colorFrame_StreamingPort.getName() << " cannot connect to remote port " << m_remoteImagePort << "with carrier " << m_ImageCarrier;
59 return false;
60 }
61
63 {
64 yCError(RGBDSENSORCLIENT) << depthFrame_StreamingPort.getName() << " cannot connect to remote port " << m_remoteDepthPort << "with carrier " << m_DepthCarrier;
65 return false;
66 }
67
68
69 // Single RPC port
71
72 if (!ret)
73 {
74 yCError(RGBDSENSORCLIENT) << " cannot open local RPC port " << m_localRpcPort;
77 rpcPort.close();
78 }
79
81 {
82 yCError(RGBDSENSORCLIENT) << " cannot connect to port " << m_remoteRpcPort;
85 rpcPort.close();
86 return false;
87 }
88
89 // Check protocol version
91 yarp::os::Bottle response;
95 rpcPort.write(cmd, response);
96 int major = response.get(3).asInt32();
97 int minor = response.get(4).asInt32();
98
100 {
101 yCError(RGBDSENSORCLIENT) << "Major protocol number does not match, please verify client and server are updated. \
102 Expected: " << RGBD_INTERFACE_PROTOCOL_VERSION_MAJOR << " received: " << major;
103 return false;
104 }
105
106
108 {
109 yCWarning(RGBDSENSORCLIENT) << "Minor protocol number does not match, please verify client and server are updated.\
110 Expected: " << RGBD_INTERFACE_PROTOCOL_VERSION_MINOR << " received: " << minor;
111 }
112
114
115 return true;
116}
117
125
126/*
127 * IDepthVisualParams interface. Look at IVisualParams.h for documentation
128 *
129 * Implemented by DepthVisualParams_Forwarder
130 */
131
132/*
133 * IDepthVisualParams interface. Look at IVisualParams.h for documentation
134 *
135 * Implemented by DepthVisualParams_Forwarder
136 */
137
138
139/*
140 * IRGBDSensor specific interface methods
141 */
142
144{
146 yarp::os::Bottle response;
150 rpcPort.write(cmd, response);
151
152 // Minimal check on response, we suppose the response is always correctly formatted
153 if((response.get(0).asVocab32()) == VOCAB_FAILED)
154 {
155 extrinsic.zero();
156 return false;
157 }
158
159 return Property::copyPortable(response.get(3), extrinsic); // will it really work??
160}
161
162
173
174
176{
178 yarp::os::Bottle response;
182 rpcPort.write(cmd, response);
183 return response.get(3).asString();
184}
185
190
195
203
204//
205// IFrame Grabber Control 2 interface is implemented by FrameGrabberControls2_Forwarder
206//
207
208//
209// Rgb
210//
212{
213 return RgbMsgSender->getRgbHeight();
214}
215
217{
218 return RgbMsgSender->getRgbWidth();
219}
220
222{
223 return RgbMsgSender->getRgbSupportedConfigurations(configurations);
224}
225
226bool RGBDSensorClient::getRgbResolution(int &width, int &height)
227{
228 return RgbMsgSender->getRgbResolution(width, height);
229}
230
231bool RGBDSensorClient::setRgbResolution(int width, int height)
232{
233 return RgbMsgSender->setRgbResolution(width, height);
234}
235
236bool RGBDSensorClient::getRgbFOV(double &horizontalFov, double &verticalFov)
237{
238 return RgbMsgSender->getRgbFOV(horizontalFov, verticalFov);
239}
240
241bool RGBDSensorClient::setRgbFOV(double horizontalFov, double verticalFov)
242{
243 return RgbMsgSender->getRgbFOV(horizontalFov, verticalFov);
244}
245
247{
248 return RgbMsgSender->getRgbIntrinsicParam(intrinsic);
249}
250
252{
253 return RgbMsgSender->getRgbMirroring(mirror);
254}
255
257{
258 return RgbMsgSender->setRgbMirroring(mirror);
259}
260
261//
262// Depth
263//
265{
266 return DepthMsgSender->getDepthHeight();
267}
268
270{
271 return DepthMsgSender->getDepthWidth();
272}
273
274bool RGBDSensorClient::setDepthResolution(int width, int height)
275{
276 return DepthMsgSender->setDepthResolution(width, height);
277}
278
279bool RGBDSensorClient::getDepthFOV(double &horizontalFov, double &verticalFov)
280{
281 return DepthMsgSender->getDepthFOV(horizontalFov, verticalFov);
282}
283
284bool RGBDSensorClient::setDepthFOV(double horizontalFov, double verticalFov)
285{
286 return DepthMsgSender->setDepthFOV(horizontalFov, verticalFov);
287}
288
290{
291 return DepthMsgSender->getDepthAccuracy();
292}
293
295{
296 return DepthMsgSender->setDepthAccuracy(accuracy);
297}
298
300{
301 return DepthMsgSender->getDepthClipPlanes(nearPlane, farPlane);
302}
303
305{
306 return DepthMsgSender->setDepthClipPlanes(nearPlane, farPlane);
307}
308
310{
311 return DepthMsgSender->getDepthIntrinsicParam(intrinsic);
312}
313
315{
316 return DepthMsgSender->getDepthMirroring(mirror);
317}
318
320{
321 return DepthMsgSender->setDepthMirroring(mirror);
322}
constexpr yarp::conf::vocab32_t VOCAB_RGBD_SENSOR
constexpr yarp::conf::vocab32_t VOCAB_EXTRINSIC_PARAM
constexpr yarp::conf::vocab32_t VOCAB_RGBD_PROTOCOL_VERSION
constexpr yarp::conf::vocab32_t VOCAB_STATUS
constexpr yarp::conf::vocab32_t VOCAB_ERROR_MSG
constexpr yarp::conf::vocab32_t VOCAB_GET
constexpr yarp::conf::vocab32_t VOCAB_FAILED
bool ret
const yarp::os::LogComponent & RGBDSENSORCLIENT()
#define RGBD_INTERFACE_PROTOCOL_VERSION_MINOR
#define RGBD_INTERFACE_PROTOCOL_VERSION_MAJOR
bool parseParams(const yarp::os::Searchable &config) override
Parse the DeviceDriver parameters.
RGBDSensorClient: A Network client to receive data from kinect-like devices. This device will read fr...
bool getRgbResolution(int &width, int &height) override
Get the resolution of the rgb image from the camera.
bool setRgbFOV(double horizontalFov, double verticalFov) override
Set the field of view (FOV) of the rgb camera.
int getDepthWidth() override
Return the height of each frame.
bool getRgbMirroring(bool &mirror) override
Get the mirroring setting of the sensor.
RgbImageBufferedPort colorFrame_StreamingPort
bool setDepthMirroring(bool mirror) override
Set the mirroring setting of the sensor.
std::string getLastErrorMsg(yarp::os::Stamp *timeStamp=nullptr) override
Return an error message in case of error.
bool getDepthClipPlanes(double &near, double &far) override
Get the clipping planes of the sensor.
bool setRgbResolution(int width, int height) override
Set the resolution of the rgb image from the camera.
bool setDepthAccuracy(double accuracy) override
Set the minimum detectable variation in distance [meter] when possible.
bool getRgbSupportedConfigurations(yarp::sig::VectorOf< yarp::dev::CameraConfig > &configurations) override
Get the possible configurations of the camera.
int getRgbWidth() override
Return the width of each frame.
bool setDepthResolution(int width, int height) override
Set the resolution of the depth image from the camera.
bool getDepthIntrinsicParam(yarp::os::Property &intrinsic) override
Get the intrinsic parameters of the depth camera.
bool getDepthFOV(double &horizontalFov, double &verticalFov) override
Get the field of view (FOV) of the depth camera.
bool getImages(yarp::sig::FlexImage &colorFrame, yarp::sig::ImageOf< yarp::sig::PixelFloat > &depthFrame, yarp::os::Stamp *colorStamp=nullptr, yarp::os::Stamp *depthStamp=nullptr) override
Get the both the color and depth frame in a single call.
bool setDepthClipPlanes(double near, double far) override
Set the clipping planes of the sensor.
bool getDepthMirroring(bool &mirror) override
Get the mirroring setting of the sensor.
bool getDepthImage(yarp::sig::ImageOf< yarp::sig::PixelFloat > &depthImage, yarp::os::Stamp *timeStamp=nullptr) override
Get the depth frame from the device.
bool getRgbFOV(double &horizontalFov, double &verticalFov) override
Get the field of view (FOV) of the rgb camera.
~RGBDSensorClient() override
bool close() override
Close the DeviceDriver.
double getDepthAccuracy() override
Get the minimum detectable variation in distance [meter].
bool getRgbImage(yarp::sig::FlexImage &rgbImage, yarp::os::Stamp *timeStamp=nullptr) override
Get the rgb frame from the device.
yarp::os::Port rpcPort
RGBDSensor_StreamingMsgParser * streamingReader
bool setDepthFOV(double horizontalFov, double verticalFov) override
Set the field of view (FOV) of the depth camera.
bool getExtrinsicParam(yarp::sig::Matrix &extrinsic) override
Get the extrinsic parameters from the device.
int getDepthHeight() override
Return the height of each frame.
IRGBDSensor::RGBDSensor_status getSensorStatus() override
Get the surrent status of the sensor, using enum type.
bool getRgbIntrinsicParam(yarp::os::Property &intrinsic) override
Get the intrinsic parameters of the rgb camera.
bool open(yarp::os::Searchable &config) override
Create and configure a device, by name.
int getRgbHeight() override
Return the height of each frame.
bool setRgbMirroring(bool mirror) override
Set the mirroring setting of the sensor.
FloatImageBufferedPort depthFrame_StreamingPort
yarp::os::Stamp depthStamp
bool read(yarp::sig::FlexImage &rgbImage, yarp::sig::ImageOf< yarp::sig::PixelFloat > &depthImage, yarp::os::Stamp *rgbStamp=nullptr, yarp::os::Stamp *depthStamp=nullptr)
void attach(RgbImageBufferedPort *_port_rgb, FloatImageBufferedPort *_port_depth)
bool readDepth(yarp::sig::ImageOf< yarp::sig::PixelFloat > &data, yarp::os::Stamp *timeStamp=nullptr)
bool readRgb(yarp::sig::FlexImage &data, yarp::os::Stamp *timeStamp=nullptr)
A simple collection of objects that can be described and transmitted in a portable way.
Definition Bottle.h:64
void addVocab32(yarp::conf::vocab32_t x)
Places a vocabulary item in the bottle, at the end of the list.
Definition Bottle.cpp:164
Value & get(size_type index) const
Reads a Value v from a certain part of the list.
Definition Bottle.cpp:246
A mini-server for performing network communication in the background.
std::string getName() const override
Get name of port.
void close() override
Stop port activity.
bool open(const std::string &name) override
Start port operation, with a specific name, with automatically-chosen network parameters.
static bool connect(const std::string &src, const std::string &dest, const std::string &carrier="", bool quiet=true)
Request that an output port connect to an input port.
Definition Network.cpp:682
bool write(const PortWriter &writer, const PortWriter *callback=nullptr) const override
Write an object to the port.
Definition Port.cpp:436
bool addOutput(const std::string &name) override
Add an output connection to the specified port.
Definition Port.cpp:353
void close() override
Stop port activity.
Definition Port.cpp:363
bool open(const std::string &name) override
Start port operation, with a specific name, with automatically-chosen network parameters.
Definition Port.cpp:79
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
virtual yarp::conf::vocab32_t asVocab32() const
Get vocabulary identifier as an integer.
Definition Value.cpp:228
virtual std::int32_t asInt32() const
Get 32-bit integer value.
Definition Value.cpp:204
virtual std::string asString() const
Get string value.
Definition Value.cpp:234
bool setDepthMirroring(bool mirror) override
Set the mirroring setting of the sensor.
bool setDepthFOV(double horizontalFov, double verticalFov) override
Set the field of view (FOV) of the depth camera.
bool getDepthClipPlanes(double &nearPlane, double &farPlane) override
Get the clipping planes of the sensor.
bool setDepthClipPlanes(double nearPlane, double farPlane) override
Set the clipping planes of the sensor.
int getDepthWidth() override
Return the height of each frame.
bool getDepthMirroring(bool &mirror) override
Get the mirroring setting of the sensor.
bool setDepthResolution(int width, int height) override
Set the resolution of the depth image from the camera.
double getDepthAccuracy() override
Get the minimum detectable variation in distance [meter].
bool getDepthFOV(double &horizontalFov, double &verticalFov) override
Get the field of view (FOV) of the depth camera.
bool setDepthAccuracy(double accuracy) override
Set the minimum detectable variation in distance [meter] when possible.
bool getDepthIntrinsicParam(yarp::os::Property &intrinsic) override
Get the intrinsic parameters of the depth camera.
int getDepthHeight() override
Return the height of each frame.
bool getRgbSupportedConfigurations(yarp::sig::VectorOf< yarp::dev::CameraConfig > &configurations) override
Get the possible configurations of the camera.
bool getRgbMirroring(bool &mirror) override
Get the mirroring setting of the sensor.
bool setRgbResolution(int width, int height) override
Set the resolution of the rgb image from the camera.
int getRgbHeight() override
Return the height of each frame.
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.
int getRgbWidth() override
Return the width of each frame.
bool getRgbResolution(int &width, int &height) override
Get the resolution of the rgb image from the camera.
bool setRgbMirroring(bool mirror) override
Set the mirroring setting of the sensor.
Image class with user control of representation details.
Definition Image.h:374
Typed image class.
Definition Image.h:616
A class for a Matrix.
Definition Matrix.h:39
#define yCError(component,...)
#define yCWarning(component,...)
#define YARP_LOG_COMPONENT(name,...)
For streams capable of holding different kinds of content, check what they actually have.
Definition jointData.cpp:13
An interface to the operating system, including Port based communication.
The main, catch-all namespace for YARP.
Definition dirs.h:16
constexpr char accuracy[]