Manual
16
Developer’s guide - C++, Urbi, Flex, Java - V2.0
robopec
This document is the property of Robopec. The information contained herein may not be used, reproduced or
communicated without its prior written consent.
An URBI module is a C++ library that will allow you to add instructions understood by the URBI
server. Instructions can be of two types:
- variables
- functions
7.1 Create a URBI module
Declare a class as URBI module
For a class to be loaded and interpreted by a module URBI, you must do as follow when creating it:
- Includes library urbi/uobject.hh (in /usr/share/gostai/includes) :
o #include <urbi/uobject.hh>
- Inherits your class from UObject :
o class ma_classe: public urbi::UObject{
- Create a public function init taking as arguments those you would use in traditional
constructor (returning 1 on fail, 0 on success):
o int init() ;
- Your real constructor must bind the function init and use UObject constructor:
ma_classe::ma_classe(const string &n):UObject(n)
{
UBindFunction(ma_classe, init);
}
- Declare your class to URBI server
o UStart(ma_classe);
Declare a variable
You can declare in C++ code variables understandable by URBI:
- Create a variable UVar :
o UVar something;
- Declare this variable to the server :
o UBindVar(ma_classe, something);
If your variable changes in your program, it will also change in the interpreter URBI. UObject class
includes in particular a useful function: UNotifyChange. This function creates a callback on any
changes in the value of the variable.
Call : UNotifyChange(something, &ma_classe::somethingChange);
When something changes, function somethingChange is called:
Prototype : int ma_classe::somethingChange(UVar& var)
7 C++ URBI modules