ESERCITAZIONE Implementazione di un sistema reattivo per la navigazione sulla base robotica Pioneer...

43
ESERCITAZIONE Implementazione di un sistema reattivo per la navigazione sulla base robotica Pioneer I

Transcript of ESERCITAZIONE Implementazione di un sistema reattivo per la navigazione sulla base robotica Pioneer...

Page 1: ESERCITAZIONE Implementazione di un sistema reattivo per la navigazione sulla base robotica Pioneer I.

ESERCITAZIONE

Implementazione di un sistema reattivo per la navigazione sulla base

robotica Pioneer I

Page 2: ESERCITAZIONE Implementazione di un sistema reattivo per la navigazione sulla base robotica Pioneer I.

Il sistema robotico Pioneer IReal Word Interface, USA

Base robotica mobile a 3 ruote dotata di 7 sensori ad ultrasuoni (due laterali e 5 frontali intervallati di 15 gradi) e di due motori dotati di encoder per le ruote anteriori

Velocità max: 90 cm/s 300°/s

Payload: 4.5 Kg Sensori: 10cm-5m Controllore: MC68HC11 Peso: 7.7 Kg

Page 3: ESERCITAZIONE Implementazione di un sistema reattivo per la navigazione sulla base robotica Pioneer I.

Architettura del sistema

Dati sensoriDati sensori

ComandiComandi ControllorControllore di basso e di basso

livellolivello

SensoriSensori(US, Encoder)(US, Encoder)

MotoriMotoriInterfaccia Interfaccia

UtenteUtenteSoftware di alto Software di alto

livellolivelloAmbiente di Ambiente di

svilupposviluppo

RSRS 232 o connessione 232 o connessione radioradio

Page 4: ESERCITAZIONE Implementazione di un sistema reattivo per la navigazione sulla base robotica Pioneer I.

Architettura del sistema

Cavo Seriale

SaphiraColbert Language and Evaluator

Software di acquisizione e elaborazione

RWI-Pioneer I

Page 5: ESERCITAZIONE Implementazione di un sistema reattivo per la navigazione sulla base robotica Pioneer I.

Saphira: l’interfaccia per il controllo del sistema

RobotRobot

Distanza Distanza rilevata dai rilevata dai sensori USsensori US

Comandi in Comandi in Linguaggio Colbert Linguaggio Colbert

e messaggi di e messaggi di sistemasistema

StatoStato

Connessione Connessione con il robotcon il robot

Page 6: ESERCITAZIONE Implementazione di un sistema reattivo per la navigazione sulla base robotica Pioneer I.

Saphira: il simulatore

SimulatoreSimulatore

Page 7: ESERCITAZIONE Implementazione di un sistema reattivo per la navigazione sulla base robotica Pioneer I.

Il sistema di coordinate di riferimento

Page 8: ESERCITAZIONE Implementazione di un sistema reattivo per la navigazione sulla base robotica Pioneer I.

I comandi da tastiera

Page 9: ESERCITAZIONE Implementazione di un sistema reattivo per la navigazione sulla base robotica Pioneer I.

I comandi

Page 10: ESERCITAZIONE Implementazione di un sistema reattivo per la navigazione sulla base robotica Pioneer I.

Il linguaggio Colbert Colbert is a C-like language with a

semantics based on finite state machines. It has the standard C constructs such as sequences, iteration, and conditionals, interpreted in a way that makes sense for robot programming.

The main construct of Colbert is the activity schema or act, a procedure that describes a set of coordinated actions that the robot should perform.

Page 11: ESERCITAZIONE Implementazione di un sistema reattivo per la navigazione sulla base robotica Pioneer I.

Il linguaggio Colbert Colbert is an interpreted language,

which means that you write text files containing Colbert activities, load them into a Saphira client, and then start them up. The Colbert evaluator parses and executes the activities, and reports back results and errors.

Page 12: ESERCITAZIONE Implementazione di un sistema reattivo per la navigazione sulla base robotica Pioneer I.

Il linguaggio Colbert

The Colbert evaluator has the following capabilities Direct execution of control statements from a running Saphira

client. Tracing of activities: users can see exactly what statements are

being executed. Signaling between activities: activities may start sub-activities, or

interrupt already running activities. Trapping of errors: fatal errors, such as divide by 0, just disable

the offending activity and print an error message. Error correction: buggy activities can be edited with a text editor

and reloaded, without exiting the running Saphira client.

Page 13: ESERCITAZIONE Implementazione di un sistema reattivo per la navigazione sulla base robotica Pioneer I.

Il linguaggio Colbert: esempio/* Colbert example exercising the direct motion calls */

act patrol(int a) /* go back and forth 'a' times */{

while (a != 0){a = a-1;move(1000);turnto(0);move(1000);turnto(180);}

}

Page 14: ESERCITAZIONE Implementazione di un sistema reattivo per la navigazione sulla base robotica Pioneer I.

Il linguaggio Colbert: esempio/* Colbert example exercising the direct motion calls */

act square /* move in a square */{

int a;a = 4;while(a){a = a-1;move(1000);urn(90);}

}

Page 15: ESERCITAZIONE Implementazione di un sistema reattivo per la navigazione sulla base robotica Pioneer I.

Il linguaggio Colbert: scrittura ed esecuzione del codice

Colbert source files may be input from text files, using the load command

Load files can contain definitions of activities, as well as commands to be executed, including any commands that can be typed in the user interaction area. So, for example, it’s possible to load a file that loads other files

Istruzione: load <file> loads file from the current load directory

Colbert source files can have an arbitrary extension (except for .so or .dll), but by convention their extension is .act

Page 16: ESERCITAZIONE Implementazione di un sistema reattivo per la navigazione sulla base robotica Pioneer I.

Il linguaggio Colbert:Direct Motion Commands

The evaluator provides a set of direct motion commands that can move and rotate the robot.

The direct motion commands are not C functions, and do not return any value. They also have a syntax

for specifying a timeout value and a non-blocking mode. The general form of a direct motion command is:

command(int arg) [timeout n] [noblock]; where timeout n specifies a time in 100 ms increments for the

command to complete, and noblock means that the command will be executed without blocking,

i.e., control will continue with the next statement. Some motion commands are implicitly nonblocking:

speed and rotate.

Page 17: ESERCITAZIONE Implementazione di un sistema reattivo per la navigazione sulla base robotica Pioneer I.

Il linguaggio Colbert:Direct Motion Commands move(int mm); turn(int deg); turnto(int deg); speed(int mms); rotate(int degs); halt;

Page 18: ESERCITAZIONE Implementazione di un sistema reattivo per la navigazione sulla base robotica Pioneer I.

Il linguaggio Colbert:Activity Schemas

act <aname> [([<type> <param>]*)]

{

[<type> <local-var>]*

[update <stmt>]

<stmts>

}

Page 19: ESERCITAZIONE Implementazione di un sistema reattivo per la navigazione sulla base robotica Pioneer I.

Il linguaggio Colbert:tipi e variabili

C ColbertDichiarazioni

int sfINT int a;

float sfFLOAT ptr tonowhere;

void sfVOID float **f;

string sfSTRING robot *r;

act sfACTIVITY

void * sfPTR

Page 20: ESERCITAZIONE Implementazione di un sistema reattivo per la navigazione sulla base robotica Pioneer I.

Il linguaggio ColbertConditinal Statement:

if (<c_exp>) <stmts> [ else <stmts> ]

waitfor <c_exp> [timeout <n>];

Iteration and Branching Statements

while (<c_exp>) <stmts>

<label>:

goto <label>;

Page 21: ESERCITAZIONE Implementazione di un sistema reattivo per la navigazione sulla base robotica Pioneer I.

Il linguaggio Colbert: Assignment Statements

point p; b = &a;

int a; *b = 3;

int *b; a = 2;

float *c; p.x = 1.0;

*c = *b; c = &p.x;

Page 22: ESERCITAZIONE Implementazione di un sistema reattivo per la navigazione sulla base robotica Pioneer I.

Saphira API: State Reflection

The state reflector is a set of data structures in the client that reflects the

sensor and motor state of the robot.

Page 23: ESERCITAZIONE Implementazione di un sistema reattivo per la navigazione sulla base robotica Pioneer I.

Saphira API: Robot Statestruct robot sfRobot

Page 24: ESERCITAZIONE Implementazione di un sistema reattivo per la navigazione sulla base robotica Pioneer I.

Saphira API: Sonar bucketsThe current range reading of a sonar sensors is held in an sdata structure, defined below.

sdata *sfSonarBucket(int num)int sfSonarRange(int num)float sfSonarXCoord(int num)float sfSonarYCoord(int num)

The first function returns a pointer to the data structure of the num’th sonar, or NULL if there is no such sonar.The next three functions return the range and x,y coordinates of the sonar reading.

Page 25: ESERCITAZIONE Implementazione di un sistema reattivo per la navigazione sulla base robotica Pioneer I.

Saphira API: Direct Motion Control

void sfSetVelocity(int vel)void sfSetRVelocity(int rvel)Set the translational and rotational setpoints in the state reflector. Values for translational velocity are in mm/sec; for rotational velocity, degrees/sec.

void sfSetHeading(int head)void sfSetDHeading(int dhead)The first function sets the absolute heading setpoint in the state reflector. The argument is in degrees, from 0 to 359.The second function increments or decrements the heading setpoint. The argument is in degrees, from –180 to +180.

Page 26: ESERCITAZIONE Implementazione di un sistema reattivo per la navigazione sulla base robotica Pioneer I.

Saphira API: Direct Motion Controlvoid sfSetPosition(int dist)void sfSetMaxVelocity(int vel)The first function sets the distance setpoint in the state reflector. Argument is in mm, either positive (forwards) or negative (backwards). The maximum velocity attained during motion is given by sfSetMaxVelocity, in mm/sec.

int sfDonePosition(int dist)int sfDoneHeading(int ang)Checks whether a previously-issued direct motion command has completed. The argument indicates how close the robot has to get to the commanded position or heading before it is considered completed. Arguments are in mm for position, and degrees for heading.

Page 27: ESERCITAZIONE Implementazione di un sistema reattivo per la navigazione sulla base robotica Pioneer I.

Saphira API: Direct Motion Control

float sfTargetVel(void)

float sfTargetHead(void)

These functions return the current reflected values for the velocity and heading setpoints, respectively. Values are in mm/sec and degrees.

Page 28: ESERCITAZIONE Implementazione di un sistema reattivo per la navigazione sulla base robotica Pioneer I.

Implementazione della architettura subsumption di Brooks per il Pioneer nel linguaggio Colbert

Page 29: ESERCITAZIONE Implementazione di un sistema reattivo per la navigazione sulla base robotica Pioneer I.

Il livello 2

Page 30: ESERCITAZIONE Implementazione di un sistema reattivo per la navigazione sulla base robotica Pioneer I.

Sonar

void sonar(double *s){int i;for (i=0;i<7;i++)

s[i]= (double) sfSonarRange(i);}

Page 31: ESERCITAZIONE Implementazione di un sistema reattivo per la navigazione sulla base robotica Pioneer I.

FeelForce

void feelforce(double *s, double *direction, double *magnitude){

int i,imin;

int a[7] = {90, 30, 15, 0, -15, -30, -90};

imin=0;

for (i=1;i<7;i++)

if (s[i] < s[imin]) imin = i;

*direction = a[imin];

*magnitude = s[imin];

}

Page 32: ESERCITAZIONE Implementazione di un sistema reattivo per la navigazione sulla base robotica Pioneer I.

Runawayvoid runaway(double direction, double magnitude, double

*angle, double *distance){if (magnitude <= SAFE_DIST){

*distance = -(SAFE_DIST - magnitude);*angle=direction;

}else{

*distance = 0;*angle = 0;

}}

Page 33: ESERCITAZIONE Implementazione di un sistema reattivo per la navigazione sulla base robotica Pioneer I.

Turn

void turn(double angle){

sfSetDHeading((int) angle);

}

Page 34: ESERCITAZIONE Implementazione di un sistema reattivo per la navigazione sulla base robotica Pioneer I.

Forward

void forward(double distance){

sfSetPosition((int) distance);}

Page 35: ESERCITAZIONE Implementazione di un sistema reattivo per la navigazione sulla base robotica Pioneer I.

Livello_zerovoid Level0(){

static double s[7];static double direction;static double magnitude;static double distance;static double angle;int i;

switch(process_state){case sfINIT:case 18:

sonar(&s[0]);process_state = 19;break;

case 19:feelforce(&s[0],&direction,&magnitude);process_state = 20;break;

case 20:runaway(direction,magnitude,&angle,&distance);process_state = 21;break;

Page 36: ESERCITAZIONE Implementazione di un sistema reattivo per la navigazione sulla base robotica Pioneer I.

Livello_zerocase 21:

runaway(direction,magnitude,&angle,&distance);if ( (direction != 0) && (angle != 0)) process_state = 22;else process_state = 18;break;

case 22:turn(angle);process_state = 23;break;

case 23:if (sfDoneHeading(10)) process_state=24;break;

case 24:forward(distance);process_state = 25;break;

case 25:if (sfDonePosition(10)) process_state=18;break;

Page 37: ESERCITAZIONE Implementazione di un sistema reattivo per la navigazione sulla base robotica Pioneer I.

Livello_zerocase sfSUSPEND:

sfSMessage("suspended");break;

case sfRESUME:sfSMessage("Level 0 resumed");process_state=18;break;

}}

Page 38: ESERCITAZIONE Implementazione di un sistema reattivo per la navigazione sulla base robotica Pioneer I.

Wandervoid wander(double *ang_act, double *dis_act){

*dis_act = 250; *ang_act = 15;

}

Page 39: ESERCITAZIONE Implementazione di un sistema reattivo per la navigazione sulla base robotica Pioneer I.

Avoidvoid avoid(double dir_rep, double mag_rep, double dir_act,

double mag_act, double *angle, double *distance){

if (mag_rep <= SAFE_DIST){*angle=dir_rep + dir_act;*distance = mag_act;

}else{

*distance = mag_act;*angle = dir_act;

}}

Page 40: ESERCITAZIONE Implementazione di un sistema reattivo per la navigazione sulla base robotica Pioneer I.

Livello_Unovoid Level1(){

static double s[7];static double direction;static double magnitude;static double distance;static double angle;static double dist_rnd;static double ang_rnd;static struct _timeb timestart;static struct _timeb timecurr;static sfprocess *proc;int i;char str_s[12];

switch(process_state){

case sfINIT:case 18:

_ftime( &timestart);process_state = 19;break;

Page 41: ESERCITAZIONE Implementazione di un sistema reattivo per la navigazione sulla base robotica Pioneer I.

Livello_Unocase 19:

_ftime( &timecurr);

if ((timecurr.time - timestart.time)>15){sonar(&s[0]);feelforce(&s[0],&direction,&magnitude);wander(&ang_rnd,&dist_rnd);process_state = 20;

}break;

case 20:sfSMessage("suspending Level 0");proc=sfFindProcess("Level0");sfSetProcessState (proc,sfSUSPEND);process_state = 22;break;

case 22:avoid(direction,magnitude,ang_rnd,dist_rnd,&angle,&distance);process_state = 23;break;

Page 42: ESERCITAZIONE Implementazione di un sistema reattivo per la navigazione sulla base robotica Pioneer I.

Livello_Unocase 23:

sfSMessage("state 23");turn(angle);process_state = 24;break;

case 24:if (sfDoneHeading(10)) process_state=25;break;

case 25:forward(distance);process_state = 26;break;

case 26:if (sfDonePosition(10)) {

sfSetProcessState (proc,sfRESUME);process_state=18;

}break;

Page 43: ESERCITAZIONE Implementazione di un sistema reattivo per la navigazione sulla base robotica Pioneer I.

Livello_Unocase sfSUSPEND:

break;

case sfRESUME:process_state=18;break;

}}