Synchronous operations

The derived class USyncClient implements methods to synchronously get the result of URBI commands. You must be aware that these functions are less efficient, and that they will not work in the OPEN-R version of the liburbi, for instance. As a general programming rule with robots, synchronous programming should be avoided.

Synchronous read of a device value

To get the value of a device object (with a val attribute), you can use the method syncGetDevice. The first parameter is the name of the device (for instance, "neck"), the second is a double that is filled with the received value:

double neckVal;
syncClient->syncGetDevice("neck", neckVal);

Getting an image synchronously

You can use the method syncGetImage to synchronously get an image. The method will send the appropriate command, and wait for the result, thus blocking your thread until the image is received.

client->send("camera.resolution = 0;camera.gain = 2;");
int width, height;
client->syncGetImage("camera", myBuffer, myBufferSize,
                            URBI_RGB, URBI_TRANSMIT_JPEG, width, height);

The first parameter is the name of the camera device. The second is the buffer which will be filled with the image data. The third must be an integer variable equal to the size of the buffer. The function will set this variable to the size of the data. If the buffer is too small, data will be truncated .

The fourth parameter is the format in which you want to receive the image data. Possible values are URBI_RGB for a raw RGB 24 bit per pixel image, URBI_PPM for a PPM file, URBI_YCbCr for raw YCbCr data, and URBI_JPEG for a jpeg-compressed file.

The fifth parameter can be either URBI_TRANSMIT_JPEG or URBI_TRANSMIT_YCbCr and specifies how the image will be transmitted between the robot and the client. Transmitting JPEG images increases the frame rate and should be used for better performances.

Finally the width and height parameters are filled with the with and height of the image on return.

Getting sound synchronously

The method syncGetSound can be used to get a sound sample of any length from the server.

client->syncGetSound("micro", duration, sound);

The first parameter is the name of the device from which to request sound, the second is the duration requested, in milliseconds. Sound is a USound structure) that will be filled with the recorded sound on output.