YARP
Yet Another Robot Platform
 
Loading...
Searching...
No Matches
RGBDSensor_nwc_yarp.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
8#include <yarp/os/Portable.h>
10#include <yarp/os/LogStream.h>
11
12using namespace yarp::os;
13using namespace yarp::sig;
14using namespace yarp::dev;
15
16YARP_LOG_COMPONENT(RGBDSENSOR_NWC_YARP, "yarp.devices.RGBDSensor_nwc_yarp")
17
18
23
29
31{
32 if (!parseParams(config)) { return false; }
33
34 bool ret = false;
35
36 // Opening Streaming ports
39
40 if (!ret)
41 {
42 yCError(RGBDSENSOR_NWC_YARP) << " cannot open local streaming ports: " << m_localImagePort << " or " << m_localDepthPort;
45 }
46
48 {
49 yCError(RGBDSENSOR_NWC_YARP) << m_colorFrame_StreamingPort.getName() << " cannot connect to remote port " << m_remoteImagePort << "with carrier " << m_ImageCarrier;
50 return false;
51 }
52
54 {
55 yCError(RGBDSENSOR_NWC_YARP) << m_depthFrame_StreamingPort.getName() << " cannot connect to remote port " << m_remoteDepthPort << "with carrier " << m_DepthCarrier;
56 return false;
57 }
58
59
60 // RPC port
62 if (!ret)
63 {
64 yCError(RGBDSENSOR_NWC_YARP) << " cannot open local RPC port " << m_localRpcPort;
68 }
69
71 {
72 yCError(RGBDSENSOR_NWC_YARP) << " cannot connect to port " << m_remoteRpcPort;
76 return false;
77 }
78
80 {
81 yCError(RGBDSENSOR_NWC_YARP, "Error! Cannot attach the port as a client");
85 return false;
86 }
87
88 // Check the protocol version
90 return false;
91 }
92
94
95 return true;
96}
97
105
106/*
107* IRGBDSensor specific interface methods
108*/
110{
111 std::lock_guard <std::mutex> lg(m_mutex);
113 extrinsic = r.matrix;
114 return r.ret;
115}
116
117
119{
120 std::lock_guard <std::mutex> lg(m_mutex);
122 status = r.status;
123 return r.ret;
124}
125
126
128{
129 std::lock_guard <std::mutex> lg(m_mutex);
131 mesg = r.errorMsg;
132 if (timeStamp) {
133 *timeStamp = r.stamp;
134 }
135 return r.ret;
136}
137
139{
140 //STREAMING IMPLEMENTATION, NO RPC
141 std::lock_guard <std::mutex> lg(m_mutex);
142
143 bool b = streamingReader->readRgb(rgbImage, timeStamp);
144 if (!b) {
145 return ReturnValue::return_code::return_value_error_not_ready;
146 }
147 return ReturnValue_ok;
148}
149
151{
152 //STREAMING IMPLEMENTATION, NO RPC
153 std::lock_guard <std::mutex> lg(m_mutex);
154
155 bool b = streamingReader->readDepth(depthImage, timeStamp);
156 if (!b) {
157 return ReturnValue::return_code::return_value_error_not_ready;
158 }
159 return ReturnValue_ok;
160}
161
163{
164 //STREAMING IMPLEMENTATION, NO RPC
165 std::lock_guard <std::mutex> lg(m_mutex);
166
167 bool b = streamingReader->read(rgbImage,
169 rgbStamp,
170 depthStamp);
171 if (!b) {
172 return ReturnValue::return_code::return_value_error_not_ready;
173 }
174 return ReturnValue_ok;
175}
176
177/*
178* IRgbVisualParams interface. Look at IVisualParams.h for documentation
179*/
181{
182 std::lock_guard <std::mutex> lg(m_mutex);
184 return r.height;
185}
186
188{
189 std::lock_guard <std::mutex> lg(m_mutex);
191 return r.width;
192}
193
194ReturnValue RGBDSensor_nwc_yarp::getRgbSupportedConfigurations(std::vector<CameraConfig> &configurations)
195{
196 std::lock_guard <std::mutex> lg(m_mutex);
198 configurations = r.configuration;
199 return r.ret;
200}
201
203{
204 std::lock_guard <std::mutex> lg(m_mutex);
206 height = r.height;
207 width = r.width;
208 return r.ret;
209}
210
212{
213 std::lock_guard <std::mutex> lg(m_mutex);
214 auto r = m_rgbdsensor_RPC.setRgbResolutionRPC(width, height);
215 return r;
216}
217
218ReturnValue RGBDSensor_nwc_yarp::getRgbFOV(double &horizontalFov, double &verticalFov)
219{
220 std::lock_guard <std::mutex> lg(m_mutex);
222 horizontalFov = r.horizontalFov;
223 verticalFov = r.verticalFOV;
224 return r.ret;
225}
226
227ReturnValue RGBDSensor_nwc_yarp::setRgbFOV(double horizontalFov, double verticalFov)
228{
229 std::lock_guard <std::mutex> lg(m_mutex);
230 auto r = m_rgbdsensor_RPC.setRgbFOVRPC(horizontalFov, verticalFov);
231 return r;
232}
233
235{
236 std::lock_guard <std::mutex> lg(m_mutex);
238 intrinsic = r.params;
239 return r.ret;
240}
241
243{
244 std::lock_guard <std::mutex> lg(m_mutex);
246 mirror = r.mirror;
247 return r.ret;
248}
249
251{
252 std::lock_guard <std::mutex> lg(m_mutex);
253 auto r = m_rgbdsensor_RPC.setRgbMirroringRPC(mirror);
254 return r;
255}
256
257/*
258* IDepthVisualParams interface. Look at IVisualParams.h for documentation
259*/
261{
262 std::lock_guard <std::mutex> lg(m_mutex);
264 return r.height;
265}
266
268{
269 std::lock_guard <std::mutex> lg(m_mutex);
271 return r.width;
272}
273
275{
276 std::lock_guard <std::mutex> lg(m_mutex);
278 height = r.height;
279 width = r.width;
280 return r.ret;
281}
282
284{
285 std::lock_guard<std::mutex> lg(m_mutex);
286 auto r = m_rgbdsensor_RPC.setDepthResolutionRPC(width, height);
287 return r;
288}
289
290ReturnValue RGBDSensor_nwc_yarp::getDepthFOV(double &horizontalFov, double &verticalFov)
291{
292 std::lock_guard<std::mutex> lg(m_mutex);
294 horizontalFov = r.horizontalFov;
295 verticalFov = r.verticalFOV;
296 return r.ret;
297}
298
299ReturnValue RGBDSensor_nwc_yarp::setDepthFOV(double horizontalFov, double verticalFov)
300{
301 std::lock_guard<std::mutex> lg(m_mutex);
302 auto r = m_rgbdsensor_RPC.setDepthFOVRPC(horizontalFov, verticalFov);
303 return r;
304}
305
307{
308 std::lock_guard<std::mutex> lg(m_mutex);
310 accuracy = r.accuracy;
311 return r.ret;
312}
313
315{
316 std::lock_guard<std::mutex> lg(m_mutex);
318 return r;
319}
320
321ReturnValue RGBDSensor_nwc_yarp::getDepthClipPlanes(double &nearPlane, double &farPlane)
322{
323 std::lock_guard<std::mutex> lg(m_mutex);
325 nearPlane = r.nearPlane;
326 farPlane = r.farPlane;
327 return r.ret;
328}
329
330ReturnValue RGBDSensor_nwc_yarp::setDepthClipPlanes(double nearPlane, double farPlane)
331{
332 std::lock_guard<std::mutex> lg(m_mutex);
333 auto r = m_rgbdsensor_RPC.setDepthClipPlanesRPC(nearPlane, farPlane);
334 return r;
335}
336
338{
339 std::lock_guard<std::mutex> lg(m_mutex);
341 intrinsic = r.params;
342 return r.ret;
343}
344
346{
347 std::lock_guard<std::mutex> lg(m_mutex);
349 mirror = r.mirror;
350 return r.ret;
351}
352
354{
355 std::lock_guard<std::mutex> lg(m_mutex);
356 auto r = m_rgbdsensor_RPC.setDepthMirroringRPC(mirror);
357 return r;
358}
359
360/*
361* IFrameGrabberControls specific interface methods
362*/
364{
365 std::lock_guard<std::mutex> lg(m_mutex);
367 camera.busType = r.camera.busType;
368 camera.deviceDescription = r.camera.deviceDescription;
369 return r.ret;
370}
371
373{
374 std::lock_guard<std::mutex> lg(m_mutex);
376 hasFeature = r.hasFeature;
377 return r.ret;
378}
379
381{
382 std::lock_guard<std::mutex> lg(m_mutex);
384 return r;
385}
386
388{
389 std::lock_guard<std::mutex> lg(m_mutex);
391 value = r.value;
392 return r.ret;
393}
394
396{
397 std::lock_guard<std::mutex> lg(m_mutex);
398 auto r = m_rgbdsensor_RPC.setFeature2RPC((int32_t)feature, value1, value2);
399 return r;
400}
401
403{
404 std::lock_guard<std::mutex> lg(m_mutex);
406 value1 = r.value1;
407 value2 = r.value2;
408 return r.ret;
409}
410
412{
413 std::lock_guard<std::mutex> lg(m_mutex);
415 HasOnOff = r.HasOnOff;
416 return r.ret;
417}
418
420{
421 std::lock_guard<std::mutex> lg(m_mutex);
423 return r;
424}
425
427{
428 std::lock_guard<std::mutex> lg(m_mutex);
430 isActive = r.isActive;
431 return r.ret;
432}
433
435{
436 std::lock_guard<std::mutex> lg(m_mutex);
438 hasAuto = r.hasAuto;
439 return r.ret;
440}
441
443{
444 std::lock_guard<std::mutex> lg(m_mutex);
446 hasManual = r.hasManual;
447 return r.ret;
448}
449
451{
452 std::lock_guard<std::mutex> lg(m_mutex);
454 hasOnePush = r.hasOnePush;
455 return r.ret;
456}
457
464
466{
467 std::lock_guard<std::mutex> lg(m_mutex);
469 mode = r.mode;
470 return r.ret;
471}
472
474{
475 std::lock_guard<std::mutex> lg(m_mutex);
477 return r;
478}
CameraDescriptor camera
FeatureMode mode
bool ret
const yarp::os::LogComponent & RGBDSENSOR_NWC_YARP()
#define ReturnValue_ok
Definition ReturnValue.h:80
virtual IFrameGrabberControlMsgs_return_getCameraDescription getCameraDescriptionRPC()
virtual IRGBDMsgs_return_getExtrinsic getExtrinsicParamRPC()
virtual IRGBVisualParamsMsgs_return_getRgbIntrinsicParam getRgbIntrinsicParamRPC()
virtual yarp::dev::ReturnValue setFeature2RPC(const std::int32_t feature, const double value1, const double value2)
virtual yarp::dev::ReturnValue setRgbResolutionRPC(const std::int32_t width, const std::int32_t height)
virtual IRGBDMsgs_return_getLastErrorMsg getLastErrorMsgRPC()
virtual yarp::dev::ReturnValue setRgbMirroringRPC(const bool mirror)
virtual IFrameGrabberControlMsgs_return_hasOnOff hasOnOffRPC(const std::int32_t feature)
virtual IDepthVisualParamsMsgs_return_getDepthHeight getDepthHeightRPC()
virtual IFrameGrabberControlMsgs_return_getMode getModeRPC(const std::int32_t feature)
virtual IDepthVisualParamsMsgs_return_getDepthWidth getDepthWidthRPC()
virtual yarp::dev::ReturnValue setRgbFOVRPC(const double horizontalFov, const double verticalFov)
virtual yarp::dev::ReturnValue setDepthClipPlanesRPC(const double nearPlane, const double farPlane)
virtual IRGBVisualParamsMsgs_return_getRgbSupportedCfg getRgbSupportedConfigurationsRPC()
virtual IFrameGrabberControlMsgs_return_getFeature1 getFeature1RPC(const std::int32_t feature)
virtual IDepthVisualParamsMsgs_return_getDepthClipPlanes getDepthClipPlanesRPC()
virtual IDepthVisualParamsMsgs_return_getDepthIntrinsicParam getDepthIntrinsicParamRPC()
virtual IRGBVisualParamsMsgs_return_getRgbMirroring getRgbMirroringRPC()
virtual IDepthVisualParamsMsgs_return_getDepthFOV getDepthFOVRPC()
virtual IRGBVisualParamsMsgs_return_getRgbFOV getRgbFOVRPC()
virtual IRGBVisualParamsMsgs_return_getRgbResolution getRgbResolutionRPC()
virtual IFrameGrabberControlMsgs_return_hasFeature hasFeatureRPC(const std::int32_t feature)
virtual yarp::dev::ReturnValue setOnePushRPC(const std::int32_t feature)
virtual IFrameGrabberControlMsgs_return_hasManual hasManualRPC(const std::int32_t feature)
virtual yarp::dev::ReturnValue setModeRPC(const std::int32_t feature, const yarp::dev::FeatureMode mode)
virtual yarp::dev::ReturnValue setFeature1RPC(const std::int32_t feature, const double value)
virtual IDepthVisualParamsMsgs_return_getDepthAccuracy getDepthAccuracyRPC()
virtual yarp::dev::ReturnValue setDepthFOVRPC(const double horizontalFov, const double verticalFov)
virtual yarp::dev::ReturnValue setDepthMirroringRPC(const bool mirror)
virtual yarp::dev::ReturnValue setActiveRPC(const std::int32_t feature, const bool onoff)
virtual IRGBVisualParamsMsgs_return_getRgbHeight getRgbHeightRPC()
virtual IFrameGrabberControlMsgs_return_getFeature2 getFeature2RPC(const std::int32_t feature)
virtual IDepthVisualParamsMsgs_return_getDepthResolution getDepthResolutionRPC()
virtual yarp::dev::ReturnValue setDepthResolutionRPC(const std::int32_t width, const std::int32_t height)
virtual yarp::dev::ReturnValue setDepthAccuracyRPC(const double accuracy)
virtual IDepthVisualParamsMsgs_return_getDepthMirroring getDepthMirroringRPC()
virtual IFrameGrabberControlMsgs_return_getActive getActiveRPC(const std::int32_t feature)
virtual bool checkProtocolVersion()
virtual IRGBVisualParamsMsgs_return_getRgbWidth getRgbWidthRPC()
virtual IFrameGrabberControlMsgs_return_hasAuto hasAutoRPC(const std::int32_t feature)
virtual IRGBDMsgs_return_getSensorStatus getSensorStatusRPC()
virtual IFrameGrabberControlMsgs_return_hasOnePush hasOnePushRPC(const std::int32_t feature)
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)
bool parseParams(const yarp::os::Searchable &config) override
Parse the DeviceDriver parameters.
RGBDSensor_nwc_yarp: A Network client to receive data from kinect-like devices.
RgbImageBufferedPort m_colorFrame_StreamingPort
yarp::os::Stamp depthStamp
FloatImageBufferedPort m_depthFrame_StreamingPort
bool close() override
Close the DeviceDriver.
yarp::dev::ReturnValue setRgbResolution(int width, int height) override
Set the resolution of the rgb image from the camera.
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 setDepthAccuracy(double accuracy) override
Set the minimum detectable variation in distance [meter] when possible.
yarp::dev::ReturnValue getActive(yarp::dev::cameraFeature_id_t feature, bool &isActive) override
Get the current status of the feature, on or off.
yarp::dev::ReturnValue setRgbFOV(double horizontalFov, double verticalFov) override
Set the field of view (FOV) of the rgb camera.
int getRgbHeight() override
Return the height of each frame.
yarp::dev::ReturnValue setActive(yarp::dev::cameraFeature_id_t feature, bool onoff) override
Set the requested feature on or off.
yarp::dev::ReturnValue hasOnePush(yarp::dev::cameraFeature_id_t feature, bool &hasOnePush) override
Check if the requested feature has the 'onePush' mode.
yarp::dev::ReturnValue getFeature(yarp::dev::cameraFeature_id_t feature, double &value) override
Get the current value for the requested feature.
yarp::dev::ReturnValue getDepthClipPlanes(double &near, double &far) override
Get the clipping planes of the sensor.
yarp::dev::ReturnValue hasManual(yarp::dev::cameraFeature_id_t feature, bool &hasManual) override
Check if the requested feature has the 'manual' mode.
yarp::dev::ReturnValue getDepthIntrinsicParam(yarp::os::Property &intrinsic) override
Get the intrinsic parameters of the depth camera.
yarp::dev::ReturnValue hasOnOff(yarp::dev::cameraFeature_id_t feature, bool &HasOnOff) override
Check if the camera has the ability to turn on/off the requested feature.
yarp::dev::ReturnValue getDepthFOV(double &horizontalFov, double &verticalFov) override
Get the field of view (FOV) of the depth camera.
int getDepthHeight() override
Return the height of each frame.
bool open(yarp::os::Searchable &config) override
Open the DeviceDriver.
yarp::dev::ReturnValue setFeature(yarp::dev::cameraFeature_id_t feature, double value) override
Set the requested feature to a value (saturation, brightness ... )
yarp::dev::ReturnValue getRgbIntrinsicParam(yarp::os::Property &intrinsic) override
Get the intrinsic parameters of the rgb camera.
int getDepthWidth() override
Return the height of each frame.
yarp::dev::ReturnValue hasAuto(yarp::dev::cameraFeature_id_t feature, bool &hasAuto) override
Check if the requested feature has the 'auto' mode.
yarp::dev::ReturnValue getExtrinsicParam(yarp::sig::Matrix &extrinsic) override
Get the extrinsic parameters from the device.
yarp::dev::ReturnValue getDepthMirroring(bool &mirror) override
Get the mirroring setting of the sensor.
yarp::dev::ReturnValue getDepthResolution(int &width, int &height) override
Get the resolution of the depth image from the camera.
yarp::dev::ReturnValue getRgbFOV(double &horizontalFov, double &verticalFov) override
Get the field of view (FOV) of the rgb camera.
yarp::dev::ReturnValue setMode(yarp::dev::cameraFeature_id_t feature, yarp::dev::FeatureMode mode) override
Set the requested mode for the feature.
yarp::dev::ReturnValue getCameraDescription(yarp::dev::CameraDescriptor &camera) override
Get a basic description of the camera hw.
yarp::dev::ReturnValue hasFeature(yarp::dev::cameraFeature_id_t feature, bool &hasFeature) override
Check if camera has the requested feature (saturation, brightness ... )
yarp::dev::ReturnValue getSensorStatus(IRGBDSensor::RGBDSensor_status &status) override
yarp::dev::ReturnValue getLastErrorMsg(std::string &message, yarp::os::Stamp *timeStamp=nullptr) override
Return an error message in case of error.
yarp::dev::ReturnValue setDepthResolution(int width, int height) override
Set the resolution of the depth image from the camera.
yarp::dev::ReturnValue getDepthAccuracy(double &accuracy) override
Get the minimum detectable variation in distance [meter].
RGBDSensorMsgs m_rgbdsensor_RPC
yarp::dev::ReturnValue getDepthImage(yarp::sig::ImageOf< yarp::sig::PixelFloat > &depthImage, yarp::os::Stamp *timeStamp=nullptr) override
Get the depth frame from the device.
yarp::dev::ReturnValue getRgbImage(yarp::sig::FlexImage &rgbImage, yarp::os::Stamp *timeStamp=nullptr) override
Get the rgb frame from the device.
yarp::dev::ReturnValue getRgbMirroring(bool &mirror) override
Get the mirroring setting of the sensor.
yarp::dev::ReturnValue setDepthFOV(double horizontalFov, double verticalFov) override
Set the field of view (FOV) of the depth camera.
yarp::dev::ReturnValue setOnePush(yarp::dev::cameraFeature_id_t feature) override
Set the requested feature to a value (saturation, brightness ... )
RGBDSensor_StreamingMsgParser * streamingReader
yarp::dev::ReturnValue getMode(yarp::dev::cameraFeature_id_t feature, yarp::dev::FeatureMode &mode) override
Get the current mode for the feature.
yarp::dev::ReturnValue 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.
int getRgbWidth() override
Return the width of each frame.
yarp::dev::ReturnValue setRgbMirroring(bool mirror) override
Set the mirroring setting of the sensor.
yarp::dev::ReturnValue setDepthMirroring(bool mirror) override
Set the mirroring setting of the sensor.
yarp::dev::ReturnValue setDepthClipPlanes(double near, double far) override
Set the clipping planes of the sensor.
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 addOutput(const std::string &name) override
Add an output connection to the specified port.
Definition Port.cpp:320
void close() override
Stop port activity.
Definition Port.cpp:330
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
yarp::os::WireLink & yarp()
Get YARP state associated with this object.
Definition Wire.h:28
Image class with user control of representation details.
Definition Image.h:361
Typed image class.
Definition Image.h:603
A class for a Matrix.
Definition Matrix.h:39
#define yCError(component,...)
#define YARP_LOG_COMPONENT(name,...)
For streams capable of holding different kinds of content, check what they actually have.
An interface to the operating system, including Port based communication.
constexpr char accuracy[]