Skip to content

Commit

Permalink
Merge pull request #1520 from robotology/rgbd_fixes
Browse files Browse the repository at this point in the history
Some test is not running due to Travis problems, anyway a test for each OS is succesfull, so I merge
  • Loading branch information
Alberto Cardellino authored Jan 26, 2018
2 parents 9230883 + fb72e6b commit 9712fde
Show file tree
Hide file tree
Showing 12 changed files with 379 additions and 6 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
/packaging/windows/build/
/packaging/linux/build/
/bindings/build*/
/example/dev/build*/
/example/portmonitor/simple_dll/build*/
/bindings/check*/
/bindings/java/
/bindings/lua/
Expand Down
2 changes: 2 additions & 0 deletions example/dev/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,5 @@ target_link_libraries(simple_motor_client ${YARP_LIBRARIES})

add_executable(motortest motortest.cpp)
target_link_libraries(motortest ${YARP_LIBRARIES})

add_subdirectory(RGBD)
13 changes: 13 additions & 0 deletions example/dev/RGBD/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Copyright: (C) 2018 Istituto Italiano di Tecnologia (IIT) - iCub Facility
# Authors: Alberto Cardellino <[email protected]>
# CopyPolicy: Released under the terms of the LGPLv2.1 or later, see LGPL.TXT


add_executable(RGBD_test_1a RGBD_test_1a.cpp)
add_executable(RGBD_test_1b_server RGBD_test_1b_server.cpp)
add_executable(RGBD_test_1b_client RGBD_test_1b_client.cpp)

target_link_libraries(RGBD_test_1a ${YARP_LIBRARIES})
target_link_libraries(RGBD_test_1b_server ${YARP_LIBRARIES})
target_link_libraries(RGBD_test_1b_client ${YARP_LIBRARIES})

Binary file added example/dev/RGBD/ExpectedResult.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
137 changes: 137 additions & 0 deletions example/dev/RGBD/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
# Example of RGBD device usage


A user can interact with a YARP device driver directly inside the local application or via client/server paradigm through the network. Here are example for both cases.

## Smoke test

Let's run a quick test to see how YARP devices can run with a few simple commands. First we need to compile YARP repository, setting the following CMake flags to `true` in order to compile all required modules:

```
cmake .. -DCREATE_GUIS=true -DCREATE_OPTIONAL_CARRIERS=true -DENABLE_yarpcar_portmonitor=true -DENABLE_yarpcar_depthimage=true -DENABLE_yarpmod_fakeDepthCamera=true
```

To fully run the test, we need to open 5 terminals for command line input.

First we need to run the yarpserver and the device driver producing the images. In this example we will use a fake device, for testing purposes.

```
Terminal 1: yarpserver
Terminal 2: yarpdev --device RGBDSensorWrapper --name /server --subdevice fakeDepthCamera --mode ball
```
The parameters here means:
- device: The server we want to open
- name: name of the YARP port opened by the server will start with this prefix
- subdevice: the low-level device driver reading the images (fake device in this case)
- mode: this parameter is propagate to the fake device. It will produce an image showing a ball


Now we open 2 GUIs receiving the images produced by the fakeDevice:
```
Terminal 3: yarpview --name /view/rgb
Terminal 4: yarpview --name /view/depth
```

Finally we connect the producer to the viewer
```
Terminal 5: yarp connect /server/rgbImage:o /view/rgb udp
Terminal 5: yarp connect /server/depthImage:o /view/depth udp+recv.portmonitor+type.dll+file.depthimage
```

Expected result:

![Expected result](ExpectedResult.png)


## Local Application

This way of using a device driver is shown in file `RGBD_test_1a.cpp`.
In this example the dummy device called `fakeDepthCamera` is used, which is a software plugin emulating the features of a standard RGBD device. The `depthCamera` device shall be used instead, when operating with a real HW device.
In order to use it, we have to tell YARP framework we want to open a device called `fakeDepthCamera`.

``` c++
Property config;
config.put("device", "fakeDepthCamera"); // device producing (fake) data

PolyDriver dd;
dd.open(config);
```

The Polydriver class will load the required plugin and the makes it available to the user.
In order to access specific functionality offered by the driver, the user must access to the right YARP interface.
Polydriver offers the 'view' functionality which expose a particular interface (or view) of the device driver.

``` c++
yarp::dev::IRGBDSensor *RGBDInterface; // interface we want to use
dd.view(RGBDInterface);
```
Now, the user can easily access the device functionality by mean of the interface pointer:

``` c++
// Let's use the interface to get info from device
int rgbImageHeight = RGBDInterface->getRgbHeight();
int rgbImageWidth = RGBDInterface->getRgbWidth();
```

## Remote Application


The general procedure for instantiating devices does not change when using server/client paradigm, the only difference is the name of the device to be opened.

#### Server side:
The server side application will still open the device driver, but now it will also open the corresponding YARP server used to broadcast data over the network and reply to Remote Procedure Calls (RPC).
This way of using a device driver is shown in file `RGBD_test_1b_server.cpp`, the server class is called `RGBDSensorWrapper`:

``` c++
PolyDriver wrapperDriver;
Property wrapperConfig;

// Wrapper config
wrapperConfig.put("device", "RGBDSensorWrapper"); // Network server broadcasting data through network
wrapperConfig.put("name", "/server"); // Prefix for port names opened by the YARP server

// Instantiating RGBD server
wrapperDriver.open(wrapperConfig);
```

The `fakeDepthCamera` device driver is opened in the very same way as before. After we open the device, we can couple server and device driver by calling the `attach` function:

```
yarp::dev::IWrapper *wrapperInterface;
wrapperDriver.view(wrapperInterface);
wrapperInterface->attach(&rgbdDriver); // Bind the wrapper with the actual device
```

#### Client side:

The client needs to know hot to reach the server, therefore we need to provide port names as additional information.
List of parameters is explained here: [http://www.yarp.it/classyarp_1_1dev_1_1RGBDSensorClient.html](url).

This way of using a device driver is shown in file `RGBD_test_1b_client.cpp`.

``` C++
PolyDriver clientDriver;
Property clientConfig;

// client configuration
clientConfig.put("device", "RGBDSensorClient"); // Network client receiving data from YARP network
clientConfig.put(<paramName>, <paramValue>);

// Instantiating RGBD client
clientDriver.open(clientConfig);
```


As in the local application, the user has to get the `view` of the required interface to operate on:

``` C++
yarp::dev::IRGBDSensor *RGBDInterface; // interface we want to use
clientDriver.view(RGBDInterface); // wanted device interface

// Let's use the interface to get info from device
int rgbImageHeight = RGBDInterface->getRgbHeight();
int rgbImageWidth = RGBDInterface->getRgbWidth();

<...>
clientDriver.close();
```
64 changes: 64 additions & 0 deletions example/dev/RGBD/RGBD_test_1a.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/*
* Copyright (C) 2018 Istituto Italiano di Tecnologia (IIT)
* Author: Alberto Cardellino <[email protected]>
* CopyPolicy: Released under the terms of the LGPLv2.1 or later, see LGPL.TXT
*/


#include <stdio.h>
#include <stdlib.h>
#include <yarp/os/Time.h>
#include <yarp/dev/Drivers.h>
#include <yarp/dev/PolyDriver.h>
#include <yarp/dev/IRGBDSensor.h>

using namespace yarp::os;
using namespace yarp::sig;
using namespace yarp::dev;

int main(int argc, char *argv[])
{
Network yarp; // Initialize yarp framework

// use YARP to create and configure an instance of fakeDepthCamera
Property config;
config.put("device", "fakeDepthCamera"); // device producing (fake) data
config.put("mode", "ball"); // fake data type to be produced

PolyDriver dd;
dd.open(config);
if (!dd.isValid())
{
yError("Failed to create and configure a the fake device\n");
return 1;
}

yarp::dev::IRGBDSensor *RGBDInterface; // interface we want to use
if (!dd.view(RGBDInterface)) // grab wanted device interface
{
yError("Failed to get RGBDInterface device interface\n");
return 1;
}

// Let's use the interface to get info from device
int rgbImageHeight = RGBDInterface->getRgbHeight();
int rgbImageWidth = RGBDInterface->getRgbWidth();
int depthImageHeight = RGBDInterface->getDepthHeight();
int depthImageWidth = RGBDInterface->getDepthWidth();

FlexImage rgbImage;
ImageOf<PixelFloat> depthImage;
bool gotImage = RGBDInterface->getImages(rgbImage, depthImage);

if(gotImage)
yInfo("Succesfully retieved an image");
else
yError("Failed retieving images");

yarp::os::Property intrinsic;
RGBDInterface->getRgbIntrinsicParam(intrinsic);
yInfo("RGB intrinsic parameters: \n%s", intrinsic.toString().c_str());
dd.close();

return 0;
}
76 changes: 76 additions & 0 deletions example/dev/RGBD/RGBD_test_1b_client.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/*
* Copyright (C) 2018 Istituto Italiano di Tecnologia (IIT)
* Author: Alberto Cardellino <[email protected]>
* CopyPolicy: Released under the terms of the LGPLv2.1 or later, see LGPL.TXT
*/


#include <stdio.h>
#include <stdlib.h>
#include <yarp/os/Time.h>
#include <yarp/dev/Wrapper.h>
#include <yarp/dev/Drivers.h>
#include <yarp/os/LogStream.h>
#include <yarp/dev/PolyDriver.h>
#include <yarp/dev/IRGBDSensor.h>

using namespace yarp::os;
using namespace yarp::sig;
using namespace yarp::dev;

int main(int argc, char *argv[])
{
Network yarp;
PolyDriver clientDriver;
Property clientConfig;

// Keyword 'device' is used by YARP framework

// client config
clientConfig.put("device", "RGBDSensorClient"); // Network client receiving data from YARP network
clientConfig.put("localImagePort", "/client/rgbInput:i"); // Name of the rgb input port opened by the client
clientConfig.put("localDepthPort", "/client/depthInput:i"); // Name of the depth input port opened by the client
clientConfig.put("remoteImagePort", "/server/rgbImage:o"); // Name of the server port broadcasting rgb image
clientConfig.put("remoteDepthPort", "/server/depthImage:o"); // Name of the server port broadcasting depth image
clientConfig.put("localRpcPort", "/client/rpc"); // Name of the client RPC port
clientConfig.put("remoteRpcPort", "/server/rpc:i"); // Name of the server RPC port

yInfo() << "Opening client";
// Instantiating RGBD client
clientDriver.open(clientConfig);
if (!clientDriver.isValid())
{
yError("Failed to create and configure the client device\n");
return 1;
}

yarp::dev::IRGBDSensor *RGBDInterface; // interface we want to use
if (!clientDriver.view(RGBDInterface)) // wanted device interface
{
yError("Failed to get RGBDInterface device interface\n");
return 1;
}

// Let's use the interface to get info from device
int rgbImageHeight = RGBDInterface->getRgbHeight();
int rgbImageWidth = RGBDInterface->getRgbWidth();
int depthImageHeight = RGBDInterface->getDepthHeight();
int depthImageWidth = RGBDInterface->getDepthWidth();

Time::delay(0.1); // wait for first data to arrive
FlexImage rgbImage;
ImageOf<PixelFloat> depthImage;
bool gotImage = RGBDInterface->getImages(rgbImage, depthImage);

if(gotImage)
yInfo("Succesfully retieved an image");
else
yError("Failed retieving images");

yarp::os::Property intrinsic;
RGBDInterface->getRgbIntrinsicParam(intrinsic);
yInfo("RGB intrinsic parameters: \n%s", intrinsic.toString().c_str());
clientDriver.close();

return 0;
}
66 changes: 66 additions & 0 deletions example/dev/RGBD/RGBD_test_1b_server.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/*
* Copyright (C) 2018 Istituto Italiano di Tecnologia (IIT)
* Author: Alberto Cardellino <[email protected]>
* CopyPolicy: Released under the terms of the LGPLv2.1 or later, see LGPL.TXT
*/


#include <stdio.h>
#include <stdlib.h>
#include <yarp/os/Time.h>
#include <yarp/dev/Wrapper.h>
#include <yarp/dev/Drivers.h>
#include <yarp/os/LogStream.h>
#include <yarp/dev/PolyDriver.h>
#include <yarp/dev/IRGBDSensor.h>

using namespace yarp::os;
using namespace yarp::sig;
using namespace yarp::dev;

int main(int argc, char *argv[])
{
Network yarp;
PolyDriver wrapperDriver, rgbdDriver;
Property wrapperConfig, rgbdConfig;

// Keyword 'device' is used by YARP framework

// Wrapper config
wrapperConfig.put("device", "RGBDSensorWrapper"); // Network server broadcasting data through YARP network
wrapperConfig.put("name", "/server"); // Prefix for port names opened by the YARP server

// Device driver config
rgbdConfig.put("device", "fakeDepthCamera"); // Device producing (fake) data
rgbdConfig.put("mode", "ball"); // (fake) data type to be produced

yInfo() << "Opening server";
// Instantiating RGBD server
wrapperDriver.open(wrapperConfig);
if (!wrapperDriver.isValid())
{
yError("Failed to create and configure the RGBD server\n");
return 1;
}

yInfo() << "Opening fake device";
// Instantiating RGBD device
rgbdDriver.open(rgbdConfig);
if (!rgbdDriver.isValid())
{
yError("Failed to create and configure the fake device\n");
return 1;
}

yInfo() << "Attaching server to device";
yarp::dev::IWrapper *wrapperInterface;
wrapperDriver.view(wrapperInterface);
wrapperInterface->attach(&rgbdDriver); // Bind the wrapper with the actual device

// Stay up some time waiting for the client to do its work
yarp::os::Time::delay(10);
wrapperDriver.close();
rgbdDriver.close();

return 0;
}
7 changes: 3 additions & 4 deletions src/devices/depthCamera/depthCameraDriver.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,13 @@ namespace yarp


/**
* @ingroup dev_impl
*
* @ingroup dev_impl_media
*
*
* This device is a YARP plugin for OpenNI2 compatible devices, and exposes the IRGBDSensor and IFrameGrabberControls2
* interfaces to read the images and operate on available settings.
* interfaces to read the images and operate on the available settings.
*
* See they documentation for more details about each interface.
* See the documentation for more details about each interface.
*
* This device is paired with its server called RGBDSensorWrapper to stream the images and perform remote operations.
*
Expand Down
1 change: 1 addition & 0 deletions src/devices/fakeDepthCamera/fakeDepthCamera.ini
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
type device
name fakeDepthCamera
library yarp_fakeDepthCamera
wrapper RGBDSensorWrapper
Loading

0 comments on commit 9712fde

Please sign in to comment.