Before creating your own UObject (low level module) you must know basic uobject terms:

  • UVar - type of internal Urbi variables,
  • UBindVar - registers UVar into Urbi (without UVar registration, UVar can not be used in urbiscript),
  • UBindFunction - register method into Urbi (withoud method registration, method can not be called in urbiscript),
  • UNotifyAccess - set callback method at access to UVar (useful for updating UVars only when they are used via urbiscript),
  • UNotifyChange - set callback method at changing UVar value (useful for sending new UVars values to external devices/algorithms when they were changed in urbiscript).

More information about creating UObjects you can find in the URBI documentation LINK.

As an example of simple C++ uobject we will use UBoard which is interface to simple development board with diodes, button, potentiometer and servo. 

Download UBoard VS2008 solution to see the whole definition of simple UObject LINK.

Following listing presents main parts of UObject class definition (it is not a complete code, it will not compile correctly).

    //every uobject needs uobject.hh header
#include <urbi/uobject.hh> 
   //some other includes
using namespace std;
  //we are using urbi namespace
using namespace urbi; 
   //uobject class must inherit UObject
class UBoard: public UObject
       //you must define constructor with const string& parameter
       UBoard(const string& str);
       //every uobject must have init method. If you want to pass some parameters 
       // during creating your uobject in urbiscript, you should pas this parameters
       //  throught init method  
       void init(); 
       //here should be functions for serial communication
       //method for sending RGB colors
       bool setColor(int red, int green, int blue);
       //UVars, which after registration will be accesible from urbiscript
       UVar led1;
       UVar led2;
       UVar led3;
       UVar servo;
       UVar potentiometer;
       UVar button;
       //here should be some atributtes needed by serial driver
       //callback method for sending the new state (of leds and servo) to development board
       bool setState();
       //callback methods for reading the state of potentiometer and button from development board
       bool getPotentiometer();
       bool getButton();
       //local variables, which will be send by setColor function
       int mRed, mGreen, mBlue, mServo;
//Be always initialize urbi::UObject with constructor parameter.
UBoard::UBoard(const string& s) : urbi::UObject(s)
    //Usually only thing we do in constructor is binding init method to urbiscript.
    UBindFunction(UBoard, init); 
//In init method we initialize our variables, bind atributes and methoda and set callback methods for access and and change.
void UBoard::init() 
    mRed = mGreen = mBlue = 0; //initialization of module variables
    //Binding setColor method to Urbi. Thanks to it we can write in urbiscript: uboard.setColor(100,200,0);
    UBindFunction(UBoard, setColor);
    //Binding variables to urbi. Thanks to it we can use them in urbiscript (read and write)
    UBindVar(UBoard, led1);
    UBindVar(UBoard, led2);
    UBindVar(UBoard, led3);
    UBindVar(UBoard, servo);
    UBindVar(UBoard, potentiometer);
    UBindVar(UBoard, button);
    //Seting call back method for changes of UVars.
    //Thanks to it we can write in urbiscript: uboard.led1 =1;
    //and this will cause call of setState method, which will send new led1 value to development board
    UNotifyChange(led1, &UBoard::setState);
    UNotifyChange(led2, &UBoard::setState);
    UNotifyChange(led3, &UBoard::setState);
    UNotifyChange(servo, &UBoard::setState);
    //Seting call back method for accesing UVars.
    //Thanks to it we can write in urbiscript: echo(uboard.potentiometer);
    //and this will cause call of getPotentiometer method, which will update UVar to
    //accual measured on develompend board and in urbiscript we will get updated value
    UNotifyAccess(potentiometer, &UBoard::getPotentiometer);
    UNotifyAccess(button, &UBoard::getButton);
//here should be definitions of communication functions 
//the uobject ends with calling UStart method which registers uobject to urbi durin loading of the module

Following listing presents usage of created uobject in urbiscript

   // loads the module, it calls UStart(UBoard) function and registers module to Urbi. It also calls the uobject constructor.
   // in case of more complex uobjects with parametric construcotors you shoul call, param2, ...);
   // here should be some function for establishing transmisson between board and PC
   // creates new instance of uobject. It calls constructor and init method
var board =;
   // changing the value of UVar will call the callback method setState, which will send new board state and light first led
board.led1 = 1;
   // changing the value of UVar will call the callback method setState, which will send new board state and move servo to new position
board.servo = 90;
   // reading the value of UVarr will call the callback method getPotentiometer which will update the UVar value to real value measuered on development board
echo (board.potentiometer);
   // we call setColor method bound to Urbi, which will send new RGB diode state to development board




EMYS and FLASH are Open Source and distributed according to the GPL v2.0 © Rev. 1.0, 04.04.2018

FLASH Documentation