25
1/25 [email protected] m First URBI Workshop, March 2006 - Tutorial Universal Real-time Behavior Interface Jean-Christophe Baillie ENSTA / Gostai URBI Tutorial URBI Tutorial Aldebaran Aldebaran Robotics Robotics

[email protected] First URBI Workshop, March 2006 - Tutorial 1/25 Universal Real-time Behavior Interface Jean-Christophe Baillie ENSTA / Gostai URBI

Embed Size (px)

Citation preview

Page 1: Contact@urbiforge.com First URBI Workshop, March 2006 - Tutorial 1/25 Universal Real-time Behavior Interface Jean-Christophe Baillie ENSTA / Gostai URBI

1/[email protected] First URBI Workshop, March 2006 - Tutorial

Universal Real-time Behavior Interface

Jean-Christophe BaillieENSTA / Gostai

URBI TutorialURBI TutorialURBI TutorialURBI Tutorial

AldebaranAldebaranRoboticsRobotics

Page 2: Contact@urbiforge.com First URBI Workshop, March 2006 - Tutorial 1/25 Universal Real-time Behavior Interface Jean-Christophe Baillie ENSTA / Gostai URBI

2/[email protected] First URBI Workshop, March 2006 - Tutorial

WHAT IS URBI?WHAT IS URBI?WHAT IS URBI?WHAT IS URBI?

Page 3: Contact@urbiforge.com First URBI Workshop, March 2006 - Tutorial 1/25 Universal Real-time Behavior Interface Jean-Christophe Baillie ENSTA / Gostai URBI

3/[email protected] First URBI Workshop, March 2006 - Tutorial

URBI is a complete solution to URBI is a complete solution to control robotscontrol robots. . The base of the system is a The base of the system is a new new Interface LanguageInterface Language..

FlexibilityFlexibility

Independent of the robot, OS, platform, interfaced with many languages (C++, Java, Matlab…), Client/Server architecture.

ParallelismParallelism

Parallel processing of commands, concurrent variable access policies, event based programming, task scheduling, … many new powerful concepts

oriented towards parallel programming and Artificial Intelligence

SimplicitySimplicity

Easy to understand, but with extremely advanced capabilities for demanding applications. URBI is used as well by Research Labs and by 12 years old kids as a hobby.

ModularityModularity

Software devices can be transparently plugged in the language to extend it, as internal new functions or external modules running on different computers (DOM: Distributed Object Management).

URBI Key Features

Page 4: Contact@urbiforge.com First URBI Workshop, March 2006 - Tutorial 1/25 Universal Real-time Behavior Interface Jean-Christophe Baillie ENSTA / Gostai URBI

4/[email protected] First URBI Workshop, March 2006 - Tutorial

URBI Engine

URBIEngine

URBImodules

(remote)

super calculator

or, simply onboard

Windows, Linux, …

Mac OSX, Intel or standard

commands

messages

URBI Module

(plugin)

Page 5: Contact@urbiforge.com First URBI Workshop, March 2006 - Tutorial 1/25 Universal Real-time Behavior Interface Jean-Christophe Baillie ENSTA / Gostai URBI

5/[email protected] First URBI Workshop, March 2006 - Tutorial

TECHNICAL PARTTECHNICAL PART

Inside URBIInside URBI

TECHNICAL PARTTECHNICAL PART

Inside URBIInside URBI

Page 6: Contact@urbiforge.com First URBI Workshop, March 2006 - Tutorial 1/25 Universal Real-time Behavior Interface Jean-Christophe Baillie ENSTA / Gostai URBI

6/[email protected] First URBI Workshop, March 2006 - Tutorial

Objects to control hardware

Every sensor, motor, camera or physical hardware in the

robot is an object.micro

gripL

legR3

legRF3

headPan

micro

An URBI object is similar to a C++ object: it has methods and properties.

The val property is related to the device value

(telnet session, port 54000, with Aibo ERS7)

headPan = 15; // or headPan.val = 15headPan;[136901543:notag] 15.1030265089 accelX;[136901543:notag] 0.002938829104

(telnet session, port 54000, with Aibo ERS7)

headPan = 15; // or headPan.val = 15headPan;[136901543:notag] 15.1030265089 accelX;[136901543:notag] 0.002938829104

camera;[145879854:notag] BIN 5347 jpeg 208 160############# 5347 bytes ###########

speaker = bin 54112 wav 2 16000 16;####### 54112 bytes #####

camera;[145879854:notag] BIN 5347 jpeg 208 160############# 5347 bytes ###########

speaker = bin 54112 wav 2 16000 16;####### 54112 bytes #####

Page 7: Contact@urbiforge.com First URBI Workshop, March 2006 - Tutorial 1/25 Universal Real-time Behavior Interface Jean-Christophe Baillie ENSTA / Gostai URBI

7/[email protected] First URBI Workshop, March 2006 - Tutorial

Messages and tags

headTilt;[136901543:notag] 15.1030265089headTilt;[136901543:notag] 15.1030265089

Time stamp (ms) Command tag Message content

mytag: headTilt;[136901543:mytag] 15.1030265089mytag: headTilt;[136901543:mytag] 15.1030265089

custom tag: useful to know who is sending what and to control running commands.Any command or group of commands can be prefixed by a tag.This is one of the most powerful features in URBI, crucial to handle parallelism properly

All messages from the server are composed with the same standard structure:

the command to the server:

the message from the server:

Page 8: Contact@urbiforge.com First URBI Workshop, March 2006 - Tutorial 1/25 Universal Real-time Behavior Interface Jean-Christophe Baillie ENSTA / Gostai URBI

8/[email protected] First URBI Workshop, March 2006 - Tutorial

Advanced Tagging

mytag: { command1; if (distance < 50) sometag: command2;

while (index < 10) { ping; index++; }; ...};

mytag: { command1; if (distance < 50) sometag: command2;

while (index < 10) { ping; index++; }; ...};

stop / block / freeze

stop mytag;

block mytag; unblock mytag;

freeze mytag; unfreeze mytag;

Stops the commandsStops the commands

kills any new command with tag "mytag"kills any new command with tag "mytag"

freezes any running or new commandfreezes any running or new command

From another client or from

other commands running in

parallel

Page 9: Contact@urbiforge.com First URBI Workshop, March 2006 - Tutorial 1/25 Universal Real-time Behavior Interface Jean-Christophe Baillie ENSTA / Gostai URBI

9/[email protected] First URBI Workshop, March 2006 - Tutorial

Commands can be executed in serial or parallel mode:

Set headPan to 15 and neck to 30 at the same time

Set headPan to 15 and after, set neck to 30.

A B

A

B

A B

A

B

A | BB.Start == A.end

A & BB.Start == A.start

A ; BB.Start >= A.end

A , BB.Start >= A.start

Operators , and ; are also available and have a semantics identical to & and | except that they have looser constraints:

gap

gap

headPan = 15 & neck = 30;headPan = 15 & neck = 30;

headPan = 15 | neck = 30;headPan = 15 | neck = 30;

NB: Brackets can be used to group commands, like in C:

{ headPan = 15 | headTilt = 23 time:1000 } & neck = 10;{ headPan = 15 | headTilt = 23 time:1000 } & neck = 10;

Parallelism

Page 10: Contact@urbiforge.com First URBI Workshop, March 2006 - Tutorial 1/25 Universal Real-time Behavior Interface Jean-Christophe Baillie ENSTA / Gostai URBI

10/[email protected] First URBI Workshop, March 2006 - Tutorial

Complex Assignments

Numerical assignments can be specified via “modifiers”

Simple assignment:

headPan = -2;headPan = -2;

headPan = 15 time:5s;headPan = 15 time:5s;

5000ms

-2

15

headPan = 15 speed:0.34;headPan = 15 speed:0.34;

speed = 0.34 unit/s-2

15

headPan = 15 accel:0.02;headPan = 15 accel:0.02;

accel = 0.02 unit/s²

-2

15

headPan = -2 sin:1s ampli:3,headPan = -2 sin:1s ampli:3,

1000ms

-2

6 units

This command never terminates

Any function can be assigned as time parameterized trajectory with the function modifier (v2.0):

headPan = function(t):sqr(t)+sin(3*t+pi);headPan = function(t):sqr(t)+sin(3*t+pi);

put the command in background

Page 11: Contact@urbiforge.com First URBI Workshop, March 2006 - Tutorial 1/25 Universal Real-time Behavior Interface Jean-Christophe Baillie ENSTA / Gostai URBI

11/[email protected] First URBI Workshop, March 2006 - Tutorial

NB: this is also true for sound devices => simple multiplexer

Blending modes

Conflicting assignments can occur from several clients or inside the same program.How to handle it?

neck.val->blend = add; neck.val->blend = add; Each assignment occurs at the same time and is added to the others=> Used to superimpose sinuses in Fourier decomposition

neck.val->blend = mix; neck.val->blend = mix; Like add, but they are averaged instead of added

neck.val->blend = queue; neck.val->blend = queue; Each assignement occurs only when the others are finished

neck.val->blend = discard; neck.val->blend = discard;

Each conflicting assignment is ignored

neck.val->blend = cancel; neck.val->blend = cancel;

Each new assignment terminate any other pending assignment

neck.val->blend = normal; neck.val->blend = normal;

The latest assignment has the focus, be the others run in background

Blending modes:

variable->blend = …

variable "property"

Page 12: Contact@urbiforge.com First URBI Workshop, March 2006 - Tutorial 1/25 Universal Real-time Behavior Interface Jean-Christophe Baillie ENSTA / Gostai URBI

12/[email protected] First URBI Workshop, March 2006 - Tutorial

Objects: OOP and broadcasting

Usual OOP features are available:

class motor { var val; function switchon(); event overheat;};

legRF1 = new motor("xx24");legRF2 = new motor("xx27");legRF3 = new motor("xx789");

// broadcast groupinggroup legRF { legRF1, legRF2, legRF3};

Usual OOP features are available (1.0 only)motor

legRF

head

legs

tail legRF1 legRF2 legRF3

URBI multiple parallel launch going downward:broadcasting.

function motor.switchon() { echo “on “+val;};

legRF.switchon(); broadcast switchon() gets motor.switchon()

legRF1.switchon() &legRF2.switchon() &legRF3.switchon();

Usual virtual method search going upward

function motor.switchon() { echo “on “+val;};

legRF2.switchon(); gets motor.switchon

subclassing and multiple inheritance possible

Page 13: Contact@urbiforge.com First URBI Workshop, March 2006 - Tutorial 1/25 Universal Real-time Behavior Interface Jean-Christophe Baillie ENSTA / Gostai URBI

13/[email protected] First URBI Workshop, March 2006 - Tutorial

C-like Features

Function definition

Functions can be defined on devices or virtual devices:

Control structures:

Standard control structures are available andsome more specific to URBI:

function robot.walk (x,y) { … /* walk code*/

};

function add (x,y) { return x+y};

function fibo(n) { if (n<2) return 1 else { a = fibo(n-1); b = fibo(n-2); return a+b }};

function robot.walk (x,y) { … /* walk code*/

};

function add (x,y) { return x+y};

function fibo(n) { if (n<2) return 1 else { a = fibo(n-1); b = fibo(n-2); return a+b }};

usage:

robot.walk (14,255);myresult = fibo(10);robot.process_mystring("bonjour");

robot.walk (14,255);myresult = fibo(10);robot.process_mystring("bonjour");

no semicolon

// the classical for loopfor (i=0;i<10;i++) echo i;

// soft tests : must be true for 3mswhile (headsensor > 0) {

instructions…}

// loop 10 timesloopn (10) legLF1 = legRF1;

// Funny average calculation with for& avg = 0;avg->blend = mix;for& (i=0;i<10;i++) avg = tab[i];

// the classical for loopfor (i=0;i<10;i++) echo i;

// soft tests : must be true for 3mswhile (headsensor > 0) {

instructions…}

// loop 10 timesloopn (10) legLF1 = legRF1;

// Funny average calculation with for& avg = 0;avg->blend = mix;for& (i=0;i<10;i++) avg = tab[i];

Page 14: Contact@urbiforge.com First URBI Workshop, March 2006 - Tutorial 1/25 Universal Real-time Behavior Interface Jean-Christophe Baillie ENSTA / Gostai URBI

14/[email protected] First URBI Workshop, March 2006 - Tutorial

test = true;

test = false;

Instruction A

Instruction B

Event catching

Several event catching mechanisms are available:

at (test) { at (test) { instructionsA; instructionsA;}; }

onleave { instructionsB;};

at (test) { at (test) { instructionsA; instructionsA;}; }

onleave { instructionsB;};

whenever (test) { whenever (test) { instructionsA; instructionsA;}; }

else { instructionsB;};

whenever (test) { whenever (test) { instructionsA; instructionsA;}; }

else { instructionsB;};

waituntil (test); waituntil (test); Terminates only when test becomes true.=> If given a number, the wait command pauses for this nb of ms.

usage: waituntil (test) | instructions… waituntil (test) | instructions…

test = true;

test = false;

Instruction A

Instruction B

Page 15: Contact@urbiforge.com First URBI Workshop, March 2006 - Tutorial 1/25 Universal Real-time Behavior Interface Jean-Christophe Baillie ENSTA / Gostai URBI

15/[email protected] First URBI Workshop, March 2006 - Tutorial

Event catching (2)

You can control the lifespan of a command:

timeout (time) command;

//exampletimeout(10s) robot.walk();

timeout (time) command;

//exampletimeout(10s) robot.walk();

command will be executed until time is over.

This command runs in the background.

stopif (test) command;

//examplestopif(headSensor) loop legRF1 = legLF1;

stopif (test) command;

//examplestopif(headSensor) loop legRF1 = legLF1;

command will be executed until the test becomes true.

This command runs in the background.

freezeif (test) command;

//examplefreezeif(!ball.visible) balltracking();

freezeif (test) command;

//examplefreezeif(!ball.visible) balltracking();

command will be executed until the test becomes true, then it is freezed. When test becomes false again, it is unfreezed.

Also runs in the background.

Page 16: Contact@urbiforge.com First URBI Workshop, March 2006 - Tutorial 1/25 Universal Real-time Behavior Interface Jean-Christophe Baillie ENSTA / Gostai URBI

16/[email protected] First URBI Workshop, March 2006 - Tutorial

Event catching(3)

You can emit your own events with the emit function:

emit myevent;

emit myevent (1,"hello");

emit myevent;

emit myevent (1,"hello");

This creates an spiking event with or without parameters.

at (myevent) ...

whenever (myevent (x,y)) echo x+y;

at (myevent (1,s)) echo s;...

at (myevent) ...

whenever (myevent (x,y)) echo x+y;

at (myevent (1,s)) echo s;...

You can catch events with a simple test. If there are parameters, you get them together with the event and you can filter on the base of those parameters value.

emit(2s) myevent;

emit() myevent (1,"hello");

emit(2s) myevent;

emit() myevent (1,"hello");

This will add a duration to then event. Possibly, no time limit.

every(2s) commands;

every(2s) emit myevent;

every(2s) commands;

every(2s) emit myevent;

The every command starts the command at given time intervals. It can be used to create « pulsing events »

Page 17: Contact@urbiforge.com First URBI Workshop, March 2006 - Tutorial 1/25 Universal Real-time Behavior Interface Jean-Christophe Baillie ENSTA / Gostai URBI

17/[email protected] First URBI Workshop, March 2006 - Tutorial

Multicore Integration

Netw

ork Layer

URBICode

Client2

URBICode

Client1

URBICode

Client3…

URBICommands

=Micro-threads

(logical thread)

CoreCore22

CoreCore22

CoreCore11

CoreCore11

CoreCore33

CoreCore33

PhysicalPhysicalThreadThread

PhysicalPhysicalThreadThread

PhysicalPhysicalThreadThread

PhysicalPhysicalThreadThread

PhysicalPhysicalThreadThread

PhysicalPhysicalThreadThread

PhysicalPhysicalThreadThread

PhysicalPhysicalThreadThread

PhysicalPhysicalThreadThread

PhysicalPhysicalThreadThread

PhysicalPhysicalThreadThread

PhysicalPhysicalThreadThread

URBISchedulerURBI

Scheduler

Synchronisation

Automatic load balancing of parallel commands on a variable number of cores and threads, with real-time scheduling capabilities (currently in development, v.2 only)

OSOS HardwareHardware

URBIURBIKernelKernelURBIURBI

KernelKernel

Page 18: Contact@urbiforge.com First URBI Workshop, March 2006 - Tutorial 1/25 Universal Real-time Behavior Interface Jean-Christophe Baillie ENSTA / Gostai URBI

18/[email protected] First URBI Workshop, March 2006 - Tutorial

Advanced Features

Many other advanced features:

Interconnection commands, variables by name, aliases, load/save files, safe checking, debugging options,…

None of these are required to move a joint!

joint = 30;

URBI can be used by non experts as well

URBI.INI is executed at start and usualy contains useful device groupings, aliases and an anim sequence.

CLIENT.INI is executed when a new client connects to the robot and usualy contains a welcome message or a battery monitor.

Important files:

URBI.INI

CLIENT.INI

Page 19: Contact@urbiforge.com First URBI Workshop, March 2006 - Tutorial 1/25 Universal Real-time Behavior Interface Jean-Christophe Baillie ENSTA / Gostai URBI

19/[email protected] First URBI Workshop, March 2006 - Tutorial

Examples

legR3

headPan

camera

// Ball tracking program:

whenever (ball.visible) { headPan = headPan + camera.xfov * ball.x & headTilt = headTilt + camera.yfov * ball.y};

// Ball tracking program:

whenever (ball.visible) { headPan = headPan + camera.xfov * ball.x & headTilt = headTilt + camera.yfov * ball.y};

// Get up on the Aibo

getup: { { leg2 = 90 time:2s & leg3 = 0 time:2s } | leg1 = 90 time:1s | leg2 = 10 time:1s | { leg1 = -10 time:2s & leg3 = 90 time:2s }};

// Get up on the Aibo

getup: { { leg2 = 90 time:2s & leg3 = 0 time:2s } | leg1 = 90 time:1s | leg2 = 10 time:1s | { leg1 = -10 time:2s & leg3 = 90 time:2s }};

// Event detection

at (headSensor ~ 2s) speaker.play("hello.wav");

at (distance < 40) emit collision;

...

// Event detection

at (headSensor ~ 2s) speaker.play("hello.wav");

at (distance < 40) emit collision;

...

ball detection module

Page 20: Contact@urbiforge.com First URBI Workshop, March 2006 - Tutorial 1/25 Universal Real-time Behavior Interface Jean-Christophe Baillie ENSTA / Gostai URBI

20/[email protected] First URBI Workshop, March 2006 - Tutorial

function robot.walk(duration) { echo "go for " + string(duration) + " secs"; direction = 1; if (duration <0) { duration = - duration, direction = -1 };

walk: timeout(duration) { for &(x=1;x<=2;x++) for &(y=1;y<=2;y++) for &(j=1;j<=3;j++) for &(d=1;d<=2;d++) robot.leg[x][y][j] = walk.mean[x][j] sin:walk.speed*walk.coef[d] ampli:walk.amp[x][j][d]*4

phase:direction*walk.phase[x][y][j][d]+pi*(direction-1)/2 }};

function robot.walk(duration) { echo "go for " + string(duration) + " secs"; direction = 1; if (duration <0) { duration = - duration, direction = -1 };

walk: timeout(duration) { for &(x=1;x<=2;x++) for &(y=1;y<=2;y++) for &(j=1;j<=3;j++) for &(d=1;d<=2;d++) robot.leg[x][y][j] = walk.mean[x][j] sin:walk.speed*walk.coef[d] ampli:walk.amp[x][j][d]*4

phase:direction*walk.phase[x][y][j][d]+pi*(direction-1)/2 }};

Walk Sequence

Simple walk:

Using an original walk from the robocup, we extracted the two main Fourier coefficients for each joints. With blend = add mode, these two components are added on each joint to reproduce the original periodic oscillation:

Page 21: Contact@urbiforge.com First URBI Workshop, March 2006 - Tutorial 1/25 Universal Real-time Behavior Interface Jean-Christophe Baillie ENSTA / Gostai URBI

21/[email protected] First URBI Workshop, March 2006 - Tutorial

// Tracking statefunction tracking() { whenever (ball.visible) { headPan = headPan + camera.xfov * ball.x & headTilt = headTilt + camera.yfov * ball.y }};

// Searching statefunction searching() { period = 10s; { headPan’n = 0.5 smooth:1s & headTilt’n = 1 smooth:1s } | { headPan’n = 0.5 sin:period ampli:0.5 & headTilt’n = 0.5 cos:period ampli:0.5 }};

// Tracking statefunction tracking() { whenever (ball.visible) { headPan = headPan + camera.xfov * ball.x & headTilt = headTilt + camera.yfov * ball.y }};

// Searching statefunction searching() { period = 10s; { headPan’n = 0.5 smooth:1s & headTilt’n = 1 smooth:1s } | { headPan’n = 0.5 sin:period ampli:0.5 & headTilt’n = 0.5 cos:period ampli:0.5 }};

Behavior example

This example shows how to write behavior graphswith URBI:

Trackball

Searchball

ball.visible == false

ball.visible == true

speaker = found;

speaker = lost;

// Transitionstrack_transition: at (ball.visible ~ 400ms) { stop search; speaker = found; track: tracking(); };

search_transition: at (!ball.visible ~ 400ms) { stop track; speaker = lost; search: searching(); };

// Transitionstrack_transition: at (ball.visible ~ 400ms) { stop search; speaker = found; track: tracking(); };

search_transition: at (!ball.visible ~ 400ms) { stop track; speaker = lost; search: searching(); };

Page 22: Contact@urbiforge.com First URBI Workshop, March 2006 - Tutorial 1/25 Universal Real-time Behavior Interface Jean-Christophe Baillie ENSTA / Gostai URBI

22/[email protected] First URBI Workshop, March 2006 - Tutorial

state 1

state 2

state 3state 4

Finite State Machines (another way to do behavior graphs)

cond1

cond4

cond3

cond2Action1

Action2

Action4

Action3

function state2.init() { state2.tag1: at (cond1) { action1|emit go_state4; stop state2};

state2.tag2: at (cond2) { action2|emit go_state3; stop state2};

state2.main: loop { ... };};

at (go_state2) state2: state2.init();at (go_state4) state4: state4.init();

function state2.init() { state2.tag1: at (cond1) { action1|emit go_state4; stop state2};

state2.tag2: at (cond2) { action2|emit go_state3; stop state2};

state2.main: loop { ... };};

at (go_state2) state2: state2.init();at (go_state4) state4: state4.init();

state 2cond1

Action1

cond2Action2

Local event gate

function state2.init() {

emit() in_state2; state2.main: loop { ... }};

state2.tag1: at (in_state2 && cond1) { action1 | state4: state4.init() ; stop state2 };

state2.tag2: at (in_state2 && cond2) { action2 | state3: state3.init() ; stop state2 };

function state2.init() {

emit() in_state2; state2.main: loop { ... }};

state2.tag1: at (in_state2 && cond1) { action1 | state4: state4.init() ; stop state2 };

state2.tag2: at (in_state2 && cond2) { action2 | state3: state3.init() ; stop state2 };

Separated

Integrated

freeze state2.tag2;

Page 23: Contact@urbiforge.com First URBI Workshop, March 2006 - Tutorial 1/25 Universal Real-time Behavior Interface Jean-Christophe Baillie ENSTA / Gostai URBI

23/[email protected] First URBI Workshop, March 2006 - Tutorial

How to use URBI?

URBI ServerURBI ServerURBI ServerURBI Server

// C++ code with liburbi C++

main() { UClient * client = new UClient("myrobot.ensta.fr"); int pos;

pos = complex_calculation(x,y); client->send(“headPan.val = %d;”,pos);}

C++ clientC++ client

URBI.INIURBI.INIonboard scriptsonboard scripts

URBI.INIURBI.INIonboard scriptsonboard scripts

// C++ object inherit fro UObjectUStart(ball);

class ball : UObject{ ball(string);

UVar x,y; . . .};

Remote/Plugged C++ ModuleRemote/Plugged C++ Module

// Java code with liburbi Java

import liburbi.UClient;

robotC = new UClient(robotname);robotC.send("motor on;");robotC.setCallback(image, "cam");

Java clientJava client

headPan.val = 15;headPan.val;[136901543:notag] 15.1030265089 ...

telnet or urbilab clienttelnet or urbilab client

other integrated clients(matlab, python, . . .)

• simple commandssimple commands• functions definitionfunctions definition• complex scriptscomplex scripts

Page 24: Contact@urbiforge.com First URBI Workshop, March 2006 - Tutorial 1/25 Universal Real-time Behavior Interface Jean-Christophe Baillie ENSTA / Gostai URBI

24/[email protected] First URBI Workshop, March 2006 - Tutorial

UObject Architecture

#include "uobject.h"using namespace urbi;

class ball : public UObject{ public:

ball(string);

// exported field UVar x; UVar y;

// exported methods void init(string color); float getSize();

// callbacks int newImage(UVar&);};

// external callbacksint newY(UVar&);

#include "uobject.h"using namespace urbi;

class ball : public UObject{ public:

ball(string);

// exported field UVar x; UVar y;

// exported methods void init(string color); float getSize();

// callbacks int newImage(UVar&);};

// external callbacksint newY(UVar&);

#include "ball.h"

UStart(ball);

ball::ball(string s) : UObject(s){ UAttachVar (ball,x); UAttachVar (ball,y); UAttachFunction (ball,init); UAttachFunction (ball,getSize);

UNotifyChange("camera.val", &ball::newImage); UNotifyChange(x); UNotifyChange(y, &newY); x = 0; y = 0;

int tmp = (int)x;}

// example of callbackint ball::newImage(UVar& img){ char* data = ((UBinary)img).image.data); ...}

#include "ball.h"

UStart(ball);

ball::ball(string s) : UObject(s){ UAttachVar (ball,x); UAttachVar (ball,y); UAttachFunction (ball,init); UAttachFunction (ball,getSize);

UNotifyChange("camera.val", &ball::newImage); UNotifyChange(x); UNotifyChange(y, &newY); x = 0; y = 0;

int tmp = (int)x;}

// example of callbackint ball::newImage(UVar& img){ char* data = ((UBinary)img).image.data); ...}

ball.h ball.cpp

ball detection module

ball_red = new ball("red");

On the URBI side:

Page 25: Contact@urbiforge.com First URBI Workshop, March 2006 - Tutorial 1/25 Universal Real-time Behavior Interface Jean-Christophe Baillie ENSTA / Gostai URBI

25/[email protected] First URBI Workshop, March 2006 - Tutorial

at (talk.finished == true)echo « Thank you for » +

« your attention »; 

at (talk.finished == true)echo « Thank you for » +

« your attention »; 

Contact : Jean-Christophe Baillie, [email protected]