SlideShare a Scribd company logo
1 of 44
Download to read offline
Programming using the PROFETA tool

Reactive Autonomous System Programming
using the PROFETA tool
Corrado Santoro

ARSLAB - Autonomous and Robotic Systems Laboratory
Dipartimento di Matematica e Informatica
Universit` di Catania, Italy
a
santoro@dmi.unict.it

Miniscuola WOA 2013 - Torino, 04 Dicembre 2013
Corrado Santoro - Using the PROFETA Tool - MiniScuola WOA 2013

1
Programming using the PROFETA tool

Outline

1 Introducing PROFETA

Basic Entities
Beliefs and Actions
Sensors
Execution Semantics
2 Special features of

3 Goals in PROFETA

Basics
Why Goals?
Goal Failure
4 Contexts in PROFETA

PROFETA
Special Kind of Beliefs
Special Kind of Actions

Corrado Santoro - Using the PROFETA Tool - MiniScuola WOA 2013

Motivation Scenarios
Defining and Using
Contexts

2
Programming using the PROFETA tool
Introducing PROFETA

Introducing PROFETA

Introducing PROFETA

Corrado Santoro - Using the PROFETA Tool - MiniScuola WOA 2013

3
Programming using the PROFETA tool
Introducing PROFETA
Basic Entities

PROFETA Basics

PROFETA (Python RObotic Framework for dEsigning
sTrAtegies) is Python tool for programming autonomous
systems (agents or robots) using a declarative approach.
PROFETA has been designed at ARSLAB @ UNICT in 2010.
The aim is to have a single environment to implement the
software of an autonomous robot.
It provides an “all-in-one” environment supporting both
imperative (algorithmical part) and declarative (behavioural
part) programming models.

Corrado Santoro - Using the PROFETA Tool - MiniScuola WOA 2013

4
Programming using the PROFETA tool
Introducing PROFETA
Basic Entities

PROFETA Basics

PROFETA provides
A set of classes to represent basic BDI entities, i.e.
Beliefs ⇒ Knowledge
Goals ⇒ States to be achieved
Actions ⇒ Things to do to reach the Goals

A declarative language—dialect of AgentSpeak(L)—to express
agent’s behaviour
An engine executing that behaviour
A Knowledge base storing the beliefs

Corrado Santoro - Using the PROFETA Tool - MiniScuola WOA 2013

5
Programming using the PROFETA tool
Introducing PROFETA
Basic Entities

PROFETA Declarative Syntax
A PROFETA behaviour is a set of rules in the form
Event / Condition >> set of Action
where:
Event can be: belief assert or retract, goal achievement
request, goal failure.
Condition refers to a certain state of the knowledge base.
Action can be: belief assert or retract, goal achievement
request, user defined atomic action.

Example:
+object_at("X","Y") / object_got("no") >>
[ move_to("X", "Y"), pick_object() ]

Such expressions are managed thanks to operator
overloading
Corrado Santoro - Using the PROFETA Tool - MiniScuola WOA 2013

6
Programming using the PROFETA tool
Introducing PROFETA
Basic Entities

Basic Parts of a PROFETA Program
Download PROFETA from:
http://github.com/corradosantoro/profeta
Import the PROFETA libraries
Define beliefs and goals as subclasses of Belief and Goal
Define user actions by subclassing Action and overriding
method execute()
Instantiate the PROFETA Engine
Define the rules by means of the declarative sytntax
Run the Engine
Corrado Santoro - Using the PROFETA Tool - MiniScuola WOA 2013

7
Programming using the PROFETA tool
Introducing PROFETA
Basic Entities

“Hello World” in PROFETA
# import libraries
from profeta.lib import *
from profeta.main import *
# instantiate the engine
PROFETA.start()
# define a rule
+start() >> [ show_line("hello world from PROFETA") ]
# assert the "start()" belief
PROFETA.assert_belief(start())
# run the engine
PROFETA.run()

start() is a library belief
show line() is a library action
Corrado Santoro - Using the PROFETA Tool - MiniScuola WOA 2013

8
Programming using the PROFETA tool
Introducing PROFETA
Basic Entities

The “Picking Object” Robot
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27

from profeta . lib import *
from profeta . main import *
class object_at ( Belief ):
pass
class object_got ( Belief ):
pass
class move_to ( Action ):
def execute ( self ):
x = self [0]
y = self [1]
# ... perform movement to x , y
class pick_object ( Action ):
def execute ( self ):
# drive the arm to pick object
PROFETA . start ()
+ object_at ( " X " , " Y " ) / object_got ( " no " ) >>
[ move_to ( " X " , " Y " ) , pick_object () , - object_got ( " no " ) , + object_got ( " yes " ) ,
- object_at ( " X " , " Y " ) ]
PROFETA . assert_belief ( object_got ( " no " ))
PROFETA . run ()
Corrado Santoro - Using the PROFETA Tool - MiniScuola WOA 2013

9
Programming using the PROFETA tool
Introducing PROFETA
Beliefs and Actions

Belief Syntax

A belief is defined as a subclass of Belief
In a rule, it is referred as an “atomic formula” with:
one or more ground terms, e.g. object at(123, 456)
one or more variables, e.g. object at("X", "Y")
A variable is expressed using a string starting with capitals

Within the set of actions:
+bel(...) asserts a belief in the KB
-bel(...) retracts a belief from the KB

As trigger event:
+bel(...) triggers the rule when the belief is asserted
-bel(...) triggers the rule when the belief is retracted

Corrado Santoro - Using the PROFETA Tool - MiniScuola WOA 2013

10
Programming using the PROFETA tool
Introducing PROFETA
Beliefs and Actions

Action Syntax

An action is defined as a subclass of Action
The execute() method has to implement the computation
which concretely performs the action; such a computation is
executed atomically
In a rule, it is referred as an “atomic formula” with:
one or more ground terms, e.g. move to(123, 456)
one or more variables, e.g. move to("X", "Y")
A variable is expressed using a string starting with capitals

In method execute() terms can be accessed as
self[term index]

Corrado Santoro - Using the PROFETA Tool - MiniScuola WOA 2013

11
Programming using the PROFETA tool
Introducing PROFETA
Beliefs and Actions

The “Picking Robot” Rule

1
2
3
4

+ object_at ( " X " , " Y " ) / object_got ( " no " ) >>
[ move_to ( " X " , " Y " ) , pick_object () , - object_got ( " no " ) , + object_got ( " yes " ) ,
- object_at ( " X " , " Y " ) ]

That rule says:
When an object is seen at a certain position and ...
No object has been picked from the robot, then ...
Move to that position, pick the object, and ...
Update the beliefs in order to reflect the new state.

Corrado Santoro - Using the PROFETA Tool - MiniScuola WOA 2013

12
Programming using the PROFETA tool
Introducing PROFETA
Sensors

Sensors

Belief object at() is intended to be asserted as soon as an
object is found (or detected) at a certain position.
How is such a detection performed?
A Sensor class is provided with the objective of allowing the
programmer to write the proper code to “sense” the
environment and generate the proper beliefs.
The programmer has to:
subclass Sensor
override the sense() method
inform the Engine that a new sensor has been added in the
program.

Corrado Santoro - Using the PROFETA Tool - MiniScuola WOA 2013

13
Programming using the PROFETA tool
Introducing PROFETA
Sensors

The “Picking Object” Robot with a Sensor
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21

....
class ObjectSensor ( Sensor ):
def sense ( self ):
Obj = detect_an_object ()
if Obj is None :
return None
else :
(x , y ) = Obj
return + object_at (x , y )
PROFETA . start ()
+ object_at ( " X " , " Y " ) / object_got ( " no " ) >>
[ move_to ( " X " , " Y " ) , pick_object () , - object_got ( " no " ) , + object_got ( " yes " ) ,
- object_at ( " X " , " Y " ) ]
PROFETA . assert_belief ( object_got ( " no " ))
PROFETA . add_sensor ( ObjectSensor ())
PROFETA . run ()

Corrado Santoro - Using the PROFETA Tool - MiniScuola WOA 2013

14
Programming using the PROFETA tool
Introducing PROFETA
Sensors

Sensor Semantics
1
2
3
4
5
6
7
8
9
10
11
12

....
class ObjectSensor ( Sensor ):
def sense ( self ):
Obj = detect_an_object ()
if Obj is None :
return None
else :
(x , y ) = Obj
return + object_at (x , y )
...

Method sense() may return
None, nothing has been sensed
+bel(...), something has been sensed, a belief is added to
the KB and the “add event” is generated.
bel(...), something has been sensed, a belief is added to
the KB but the “add event” is NOT generated.
Corrado Santoro - Using the PROFETA Tool - MiniScuola WOA 2013

15
Programming using the PROFETA tool
Introducing PROFETA
Execution Semantics

PROFETA Structures

Terminology (according to AgentSpeak):
A Plan is a rule of the PROFETA program
An Intention is a plan which is selected for execution (the
instantiation of a plan)
PROFETA Structures:
An Event Queue which stores add/retract belief events
An Intention Stack which stores Intentions to be executed
A Sensor Set which stores instantiated sensors

Corrado Santoro - Using the PROFETA Tool - MiniScuola WOA 2013

16
Programming using the PROFETA tool
Introducing PROFETA
Execution Semantics

PROFETA (Informal) Execution Semantics
PROFETA Main Loop Execution:
1

If the Intention Stack is not empty, execute an action step and
go to 1.

2

If the Event Queue is not empty, pick an event, find the
relevant plan, verify the condition part and then put the plan
at the top of Intention Stack, then go to 1.

3

If both the Intention Stack and Event Queue are empty, scan
sensors in Sensor Set and, for each of them, call the sense()
method and analyse the return value; if it is an event, put it in
the Event Queue.

4

Go to 1.

Corrado Santoro - Using the PROFETA Tool - MiniScuola WOA 2013

17
Programming using the PROFETA tool
Special features of PROFETA

Special features of PROFETA

Special features of PROFETA

Corrado Santoro - Using the PROFETA Tool - MiniScuola WOA 2013

18
Programming using the PROFETA tool
Special features of PROFETA
Special Kind of Beliefs

Special Kind of Beliefs

1
2
3
4

+ object_at ( " X " , " Y " ) / object_got ( " no " ) >>
[ move_to ( " X " , " Y " ) , pick_object () , - object_got ( " no " ) , + object_got ( " yes " ) ,
- object_at ( " X " , " Y " ) ]

Here ...
Belief object at() represents that “an object has been
detected”; after plan execution, the belief is removed.
Belief object got() represents a state of the robot, which
could have picked or not the object. Only one belief of this
kind can be present in the KB.

Corrado Santoro - Using the PROFETA Tool - MiniScuola WOA 2013

19
Programming using the PROFETA tool
Special features of PROFETA
Special Kind of Beliefs

Special Kind of Beliefs
To support such cases, the following “special beliefs” are provided:
Reactors, i.e. beliefs which are automatically removed from
the KB when the associated plan is executed.
SingletonBeliefs, i.e. beliefs which are “single instance”.
Therefore ...
1
2
3
4
5
6
7
8
9
10
11
12
13

...
class object_at ( Reactor ):
pass
class object_got ( SingletonBelief ):
pass
...
+ object_at ( " X " , " Y " ) / object_got ( " no " ) >>
[ move_to ( " X " , " Y " ) , pick_object () , + object_got ( " yes " ) ]
...

Corrado Santoro - Using the PROFETA Tool - MiniScuola WOA 2013

20
Programming using the PROFETA tool
Special features of PROFETA
Special Kind of Actions

Example: Factorial in PROFETA Using Reactors

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20

from profeta . lib import *
from profeta . main import *
class fact ( Reactor ):
pass
class KB ( Sensor ):
def sense ( self ):
e = raw_input ( " Enter Number : " )
return + fact ( int ( e ) , 1)

PROFETA . start ()
PROFETA . add_sensor ( KB ())
+ fact (1 , " X " ) >> [ show ( " the resuilting factorial is " ) , show_line ( " X " ) ]
+ fact ( " N " , " X " ) >> [ " Y = int ( N ) * int ( X ) " , " N = int ( N ) - 1 " , + fact ( " N " , " Y " ) ]
PROFETA . run ()

Corrado Santoro - Using the PROFETA Tool - MiniScuola WOA 2013

21
Programming using the PROFETA tool
Special features of PROFETA
Special Kind of Actions

Special Kind of Actions

1
2
3
4
5
6

...
+ fact (1 , " X " ) >> [ show ( " the resuilting factorial is " ) , show_line ( " X " ) ]
+ fact ( " N " , " X " ) >> [ " Y = int ( N ) * int ( X ) " , " N = int ( N ) - 1 " , + fact ( " N " , " Y " ) ]
...

show() and show line() are library actions which are used
to print an output onto the screen.
An action can also be any Python expression, given that it is
expressed as a string (string action)
A string action can manipulate and create any plan variable
but... look out!! PROFETA is not typed!

Corrado Santoro - Using the PROFETA Tool - MiniScuola WOA 2013

22
Programming using the PROFETA tool
Goals in PROFETA

Goals in PROFETA

Goals in PROFETA

Corrado Santoro - Using the PROFETA Tool - MiniScuola WOA 2013

23
Programming using the PROFETA tool
Goals in PROFETA
Basics

Goals

Goals are (according to AgentSpeak(L)) “states of the
systems which an agent wants to achieve”, but indeed ...
... a goal is something like a “procedure plan” which expresses
the things to do to achieve the goal itself.
In PROFETA, a goal:
is first defined as a subclass of Goal
it is expressed, in the plans, as an “atomic formula”, with zero
or more terms.

Corrado Santoro - Using the PROFETA Tool - MiniScuola WOA 2013

24
Programming using the PROFETA tool
Goals in PROFETA
Basics

Example: Factorial with goals
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25

from profeta . lib import *
from profeta . main import *
class do_factorial ( Reactor ):
pass
class fact ( Goal ):
pass
class KB ( Sensor ):
def sense ( self ):
e = raw_input ( " Enter Number : " )
return + do_factorial ( int ( e ))

PROFETA . start ()
PROFETA . add_sensor ( KB ())
+ do_factorial ( " N " ) >> [ show ( " computing factorial of " ) , show_line ( " N " ) ,
fact ( " N " , 1) ]
fact (1 , " X " ) >> [ show ( " the resuilting factorial is " ) , show_line ( " X " ) ]
fact ( " N " , " X " ) >> [ " Y = int ( N ) * int ( X ) " , " N = int ( N ) - 1 " , fact ( " N " , " Y " ) ]
PROFETA . run ()

Corrado Santoro - Using the PROFETA Tool - MiniScuola WOA 2013

25
Programming using the PROFETA tool
Goals in PROFETA
Basics

The “Object Picker” with Goals
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28

from profeta . lib import *
from profeta . main import *
class object_at ( Reactor ):
pass
class object_got ( SingletonBelief ):
pass
class pic k_object_at ( Goal ):
pass
class move_to ( Action ):
def execute ( self ):
# ... perform movement to x , y
class drive_arm ( Action ):
def execute ( self ):
# drive the arm to pick object
PROFETA . start ()
+ object_at ( " X " , " Y " ) / object_got ( " no " ) >> [ pick_object_at ( " X " , " Y " ) ,
+ object_got ( " yes " ) ]
pick _object_at ( " X " , " Y " ) >> [ move_to ( " X " , " Y " ) , drive_arm () ]
PROFETA . assert_belief ( object_got ( " no " ))
PROFETA . run ()
Corrado Santoro - Using the PROFETA Tool - MiniScuola WOA 2013

26
Programming using the PROFETA tool
Goals in PROFETA
Why Goals?

Why Goals?

Goals are “procedures”, thus they help to better organize your
PROFETA program, e.g.
1
2
3
4

... >> [ goal1 () , goal2 () , goal3 () ]
goal1 () >> [ ... do something ... ]
goal2 () >> [ ... do something ... ]
goal3 () >> [ ... do something ... ]

Goals can introduce branches since a condition is allowed in
the head of the rule, e.g.
1
2

pick_object_at ( " X " , " Y " ) / ( lambda : X < 100) >> [ move_to ( " X " , " Y " ) , ... ]
pick_object_at ( " X " , " Y " ) / ( lambda : X >= 100) >> [ # do other things ]

Goals may fail!

Corrado Santoro - Using the PROFETA Tool - MiniScuola WOA 2013

27
Programming using the PROFETA tool
Goals in PROFETA
Goal Failure

Goal Failure

Let us suppose that the robot cannot reach the object if it is
located around position (1500, 1000), so:
1
2
3
4
5
6
7
8
9

...
def is_reachable (x , y ):
return math . hypot ( x - 1500 , y - 1000) > 100
+ object_at ( " X " , " Y " ) / object_got ( " no " ) >> [ pick_object_at ( " X " , " Y " ) ,
+ object_got ( " yes " ) ]
pick_object_at ( " X " , " Y " ) / ( lambda : is_reachable (X , Y )) >>
[ move_to ( " X " , " Y " ) , ... ]
pick_object_at ( " X " , " Y " ) >> [ fail () ] # the goal fails !

Library action fail() causes the current goal to fail
Calling goals/plans fail in sequence (is something like an
exception)

Corrado Santoro - Using the PROFETA Tool - MiniScuola WOA 2013

28
Programming using the PROFETA tool
Goals in PROFETA
Goal Failure

Recovery Actions

A goal failure can be triggered also within the code of an
Action, by calling fail().execute()
A failure event can be catched by a rule in order to try a
recovery action
To catch a failure of a goal g, the related event is -g(), e.g.
1
2
3
4
5
6
7

...
+ object_at ( " X " , " Y " ) / object_got ( " no " ) >> [ pick_object_at ( " X " , " Y " ) ,
+ object_got ( " yes " ) ]
pick_object_at ( " X " , " Y " ) / ( lambda : is_reachable (X , Y )) >>
[ move_to ( " X " , " Y " ) , ... ]
pick_object_at ( " X " , " Y " ) >> [ fail () ] # the goal fails !
- pick_object_at ( " X " , " Y " ) >> [ ... do smthg to perform recovery ... ]

Corrado Santoro - Using the PROFETA Tool - MiniScuola WOA 2013

29
Programming using the PROFETA tool
Goals in PROFETA
Goal Failure

Goal Failure Semantics
If we have
1
2
3
4

... >> [ goal1 () , ... ]
goal1 () >> [ goal2 () ]
goal2 () >> [ goal3 () ]
goal3 () >> [ ... , fail () ]

In plan in line 4, we have a stack of goal calls goal1() →
goal2() → goal3(), and goal3() fails, thus
If a plan related to -goal3() exists, it is first executed;
otherwise, if a plan related to -goal2() exists, it is executed;
otherwise, if a plan related to -goal1() exists, it is executed;
otherwise, the calling plan of goal1() (line 1) is interrupted.
Corrado Santoro - Using the PROFETA Tool - MiniScuola WOA 2013

30
Programming using the PROFETA tool
Contexts in PROFETA

Contexts in PROFETA

Contexts in PROFETA

Corrado Santoro - Using the PROFETA Tool - MiniScuola WOA 2013

31
Programming using the PROFETA tool
Contexts in PROFETA
Motivation Scenarios

Scenario 1: Synchronous vs. Asynchronous Actions
According to PROFETA execution semantics, Sensors are
polled only if there are no intentions to be executed
Therefore, during intention execution, an agent/robot is
blind, w.r.t. events which could happen in the environment
Action dynamics/duration matters!! E.g.
If action move to(X,Y) is synchronous, i.e. it waits for the
robot to reach the desired position, no events can be captured
during the move!
In a robotic application this is quite undesirable.

Solution:
Make action move to(X,Y) asynchronous and add a Sensor
checking that the target position has been reached.
Corrado Santoro - Using the PROFETA Tool - MiniScuola WOA 2013

32
Programming using the PROFETA tool
Contexts in PROFETA
Motivation Scenarios

The “Object Picker” with Asynchronous move to()
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28

...
class object_at ( Reactor ): pass
class object_got ( SingletonBelief ): pass
class target_got ( Reactor ): pass
class move_to ( Action ):
def execute ( self ):
# ... trigger movement to x , y and i m m e d i a t e l l y return
class drive_arm ( Action ):
def execute ( self ):
# drive the arm to pick object
class TargetGot ( Sensor ):
def sense ( self ):
if motion_control . target_reached (): return + target_got ()
else : return None
PROFETA . start ()
PROFETA . add_sensor ( TargetGot ())
+ object_at ( " X " , " Y " ) / object_got ( " no " ) >> [ move_to ( " X " , " Y " ) ]
+ target_got () >> [ drive_arm () , + object_got ( " yes " ) ]
PROFETA . assert_belief ( object_got ( " no " ))
PROFETA . run ()
Corrado Santoro - Using the PROFETA Tool - MiniScuola WOA 2013

33
Programming using the PROFETA tool
Contexts in PROFETA
Motivation Scenarios

Uncontextualised beliefs

Here, target got() is asserted whatever movement has been
started.
If we want to check that a certain movement is completed, we
should add a proper belief, e.g. to make the robot following a
path:
1
2
3
4
5

... >> [ move_to (1000 , 0) , + movement ( " one " ) ]
+ target_got () / movement ( " one " ) > >[ move_to (1000 , 1000) , + movement ( " two " ) ]
+ target_got () / movement ( " two " ) > >[ move_to (0 , 1000) , + movement ( " three " ) ]
+ target_got () / movement ( " three " ) >> [ show ( " yeahhh !!! " ) ]
...

that is, we have to add a contextual information by means of
additional beliefs.
Corrado Santoro - Using the PROFETA Tool - MiniScuola WOA 2013

34
Programming using the PROFETA tool
Contexts in PROFETA
Motivation Scenarios

Scenario 2: A robot making “many things”

Let’s consider a robot which has to:
1
2
3

Gather at most 10 objects placed in the environment
Put the object into a specific container
Go to step 1.

Here we have two tasks or“macrostates” in which events
sensed from the environment may have require different
actions.
Contextual beliefs could be used but ...
... it could be better to have language constructs which allows
a better identification of the plans related to each task.

Corrado Santoro - Using the PROFETA Tool - MiniScuola WOA 2013

35
Programming using the PROFETA tool
Contexts in PROFETA
Defining and Using Contexts

Contexts in PROFETA

PROFETA let a programmer to define contexts:
macrostates in which only specified plans can be triggered.
A context is defined by placing the statement
context(ContextName) in the plan list; after it, all plans will
be referred to ContextName.
At run-time, a context is “entered” by calling the library
action set context(ContextName).
This action asserts the library reactor start() which is used
to trigger an “intialization plan” in the entered context.

Corrado Santoro - Using the PROFETA Tool - MiniScuola WOA 2013

36
Programming using the PROFETA tool
Contexts in PROFETA
Defining and Using Contexts

Contexts in PROFETA: An Example
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22

...
class go ( Goal ): pass
go () >> [ set_context ( " pick_objects " ) ]
context ( " pick_objects " )
# put here plans for ’ p i c k _ o b j e c t ’ task
+ start () >> [ + objects_got (0) ]
+ o b j e c t _ d et e ct ed _ at ( " X " , " Y " ) >> [ move_to ( " X " , " Y " ) ]
+ target_got () / objects_got ( " N " ) >> [ drive_arm () , " N = N + 1 " ,
+ objects_got ( " N " ) , after_pick () ]
after_pick () / objects_got (10) >> [ set_context ( " put_away_objects " ) ]

context ( " put_away_objects " )
# put here plans for ’ p u t _ a w a y _ o b j e c t ’ task
+ start () >> [ move_to (1500 , 1000) ] # the position of the c o n t a i n e r
+ target_got () >> [ r e le a s e _ a l l _ ob j e c t s () , set_context ( " pick_objects " ) ]

PROFETA . achieve ( go ())
PROFETA . run ()

Corrado Santoro - Using the PROFETA Tool - MiniScuola WOA 2013

37
Programming using the PROFETA tool
Other Features

Other features

Other features

Corrado Santoro - Using the PROFETA Tool - MiniScuola WOA 2013

38
Programming using the PROFETA tool
Other Features

Handling specific Sensor Dynamics
Sensors are polled using the latency derived from the
execution of the main PROFETA loop
If you need to poll a Sensor with a specific dynamics, the
AsyncSensorProxy allows a Sensor to be decoupled from the
main loop
It can have its own peridicity (NOT guaranteed!!).
1
2
3
4
5
6
7

...
class MyAsyncSensor ( Reactor ):
def sense ( self ):
time . sleep ( millisecs /1000.0)
# perform sensing
PROFETA . add_sensor ( AsyncSensorProxy ( MyAsyncSensor ()))

Corrado Santoro - Using the PROFETA Tool - MiniScuola WOA 2013

39
Programming using the PROFETA tool
Other Features

Handling specific Action Dynamics

Actions can be easily made asynchronous by subclassing
AsyncAction instead of Action.
An AsyncAction is executed in a different thread w.r.t. that of
PROFETA main loop
1
2
3
4
5
6
7

...
class MyAsyncAction ( AsyncAction ):
def execute ( self ):
# ....

... >> [ ... MyAsyncAction (...) ... ]

Corrado Santoro - Using the PROFETA Tool - MiniScuola WOA 2013

40
Programming using the PROFETA tool
Conclusions

Conclusions

PROFETA allows to define robot strategies in a flexible and
intuitive way, by using the principles of the BDI model.
PROFETA combines the advantages of both imperative and
declarative approach, while offering an all-in-one environment
PROFETA performs quite well also in systems with few
memory, and has been successfully applied in various robot
built at ARSLab

Corrado Santoro - Using the PROFETA Tool - MiniScuola WOA 2013

41
Programming using the PROFETA tool
Conclusions

TO DO List

Concurrent Plans. But under the strong control of the
programmer.
MAS Support. Currently PROFETA does not support
muliple-agents: one robot/agent for virtual machine.
Better notion of Task (or “Goal”). A Task is what the
agent should do to achieve a specific goal. Why not mulitple
and different choices for a goal/task? This could give a
“deliberation ability” to agents.
Porting to other languages. Only Python? Why not C++?

Corrado Santoro - Using the PROFETA Tool - MiniScuola WOA 2013

42
Programming using the PROFETA tool
Conclusions

References
http://github.com/corradosantoro/profeta
L. Fichera, D. Marletta, V. Nicosia, C. Santoro. Flexible Robot Strategy
Design using Belief-Desire-Intention Model. In Proc. of International
Conference on Research and Education in Robotics (EUROBOT 2010),
Spriger CCIS Series, Rappreswille, Swizerland), May 27-30, 2010.
L. Fichera, D. Marletta, V. Nicosia, C. Santoro. A Methodology to
Extend Imperative Languages with AgentSpeak Declarative Constructs.
In Proc. of Workshop on Objects and Agents (WOA2010), CEUR-WS
Publisher, ISSN 1613-0073, Rimini, Italy, Sept. 5-7, 2010.
G. Fortino, W. Russo, C. Santoro. Translating Statecharts-based into BDI
Agents: The DSC/PROFETA case. MAS&S Workshop @ MATES 2013.
F. Messina, G. Pappalardo, C. Santoro. Integrating Cloud Services in
Behaviour Programming for Autonomous Robots. CSmart-CPS
Workshop, LNCS, 2013.
Corrado Santoro - Using the PROFETA Tool - MiniScuola WOA 2013

43
Programming using the PROFETA tool
Conclusions

Reactive Autonomous System Programming
using the PROFETA tool
Corrado Santoro

ARSLAB - Autonomous and Robotic Systems Laboratory
Dipartimento di Matematica e Informatica
Universit` di Catania, Italy
a
santoro@dmi.unict.it

Miniscuola WOA 2013 - Torino, 04 Dicembre 2013
Corrado Santoro - Using the PROFETA Tool - MiniScuola WOA 2013

44

More Related Content

What's hot

Introduction To Erlang Final
Introduction To Erlang   FinalIntroduction To Erlang   Final
Introduction To Erlang Final
SinarShebl
 
Why we cannot ignore Functional Programming
Why we cannot ignore Functional ProgrammingWhy we cannot ignore Functional Programming
Why we cannot ignore Functional Programming
Mario Fusco
 

What's hot (19)

Class method
Class methodClass method
Class method
 
Introduction To Erlang Final
Introduction To Erlang   FinalIntroduction To Erlang   Final
Introduction To Erlang Final
 
16. Java stacks and queues
16. Java stacks and queues16. Java stacks and queues
16. Java stacks and queues
 
Java PRACTICAL file
Java PRACTICAL fileJava PRACTICAL file
Java PRACTICAL file
 
Icom4015 lecture13-f16
Icom4015 lecture13-f16Icom4015 lecture13-f16
Icom4015 lecture13-f16
 
Java practical(baca sem v)
Java practical(baca sem v)Java practical(baca sem v)
Java practical(baca sem v)
 
Java small steps - 2019
Java   small steps - 2019Java   small steps - 2019
Java small steps - 2019
 
Introduction to theano, case study of Word Embeddings
Introduction to theano, case study of Word EmbeddingsIntroduction to theano, case study of Word Embeddings
Introduction to theano, case study of Word Embeddings
 
Wrapper classes
Wrapper classesWrapper classes
Wrapper classes
 
Java Script Workshop
Java Script WorkshopJava Script Workshop
Java Script Workshop
 
Deep Learning in theano
Deep Learning in theanoDeep Learning in theano
Deep Learning in theano
 
Lazy java
Lazy javaLazy java
Lazy java
 
Java Day-5
Java Day-5Java Day-5
Java Day-5
 
Java Generics for Dummies
Java Generics for DummiesJava Generics for Dummies
Java Generics for Dummies
 
Why we cannot ignore Functional Programming
Why we cannot ignore Functional ProgrammingWhy we cannot ignore Functional Programming
Why we cannot ignore Functional Programming
 
Java Generics
Java GenericsJava Generics
Java Generics
 
CS2309 JAVA LAB MANUAL
CS2309 JAVA LAB MANUALCS2309 JAVA LAB MANUAL
CS2309 JAVA LAB MANUAL
 
Pj01 4-operators and control flow
Pj01 4-operators and control flowPj01 4-operators and control flow
Pj01 4-operators and control flow
 
Icom4015 lecture4-f17
Icom4015 lecture4-f17Icom4015 lecture4-f17
Icom4015 lecture4-f17
 

Similar to Reactive Autonomous System Programming using the PROFETA tool

Drools5 Community Training Module#1: Drools5 BLiP Introduction
Drools5 Community Training Module#1: Drools5 BLiP IntroductionDrools5 Community Training Module#1: Drools5 BLiP Introduction
Drools5 Community Training Module#1: Drools5 BLiP Introduction
Mauricio (Salaboy) Salatino
 

Similar to Reactive Autonomous System Programming using the PROFETA tool (20)

ARLEM draft spec - overview
ARLEM draft spec - overviewARLEM draft spec - overview
ARLEM draft spec - overview
 
03. oop concepts
03. oop concepts03. oop concepts
03. oop concepts
 
Transfer learning, active learning using tensorflow object detection api
Transfer learning, active learning  using tensorflow object detection apiTransfer learning, active learning  using tensorflow object detection api
Transfer learning, active learning using tensorflow object detection api
 
Cluj.py Meetup: Extending Python in C
Cluj.py Meetup: Extending Python in CCluj.py Meetup: Extending Python in C
Cluj.py Meetup: Extending Python in C
 
Unit 5 Introduction to Planning and ANN.pptx
Unit 5 Introduction to Planning and ANN.pptxUnit 5 Introduction to Planning and ANN.pptx
Unit 5 Introduction to Planning and ANN.pptx
 
IRJET- Unabridged Review of Supervised Machine Learning Regression and Classi...
IRJET- Unabridged Review of Supervised Machine Learning Regression and Classi...IRJET- Unabridged Review of Supervised Machine Learning Regression and Classi...
IRJET- Unabridged Review of Supervised Machine Learning Regression and Classi...
 
Group3-Gravitation.pdf
Group3-Gravitation.pdfGroup3-Gravitation.pdf
Group3-Gravitation.pdf
 
Declarative presentations UIKonf
Declarative presentations UIKonfDeclarative presentations UIKonf
Declarative presentations UIKonf
 
A new execution model for Nashorn in Java 9
A new execution model for Nashorn in Java 9A new execution model for Nashorn in Java 9
A new execution model for Nashorn in Java 9
 
Introduction to development
Introduction to developmentIntroduction to development
Introduction to development
 
Drools5 Community Training Module#1: Drools5 BLiP Introduction
Drools5 Community Training Module#1: Drools5 BLiP IntroductionDrools5 Community Training Module#1: Drools5 BLiP Introduction
Drools5 Community Training Module#1: Drools5 BLiP Introduction
 
maXbox starter75 object detection
maXbox starter75 object detectionmaXbox starter75 object detection
maXbox starter75 object detection
 
MT_01_unittest_python.pdf
MT_01_unittest_python.pdfMT_01_unittest_python.pdf
MT_01_unittest_python.pdf
 
The Ring programming language version 1.7 book - Part 85 of 196
The Ring programming language version 1.7 book - Part 85 of 196The Ring programming language version 1.7 book - Part 85 of 196
The Ring programming language version 1.7 book - Part 85 of 196
 
Introduction toandroid
Introduction toandroidIntroduction toandroid
Introduction toandroid
 
The Ring programming language version 1.3 book - Part 7 of 88
The Ring programming language version 1.3 book - Part 7 of 88The Ring programming language version 1.3 book - Part 7 of 88
The Ring programming language version 1.3 book - Part 7 of 88
 
Aspect oriented programming with spring
Aspect oriented programming with springAspect oriented programming with spring
Aspect oriented programming with spring
 
Introduction to android
Introduction to androidIntroduction to android
Introduction to android
 
Android studio plugin 作ってみた 〜 create intent method generator 〜
Android studio plugin 作ってみた 〜 create intent method generator 〜Android studio plugin 作ってみた 〜 create intent method generator 〜
Android studio plugin 作ってみた 〜 create intent method generator 〜
 
Architecting Single Activity Applications (With or Without Fragments)
Architecting Single Activity Applications (With or Without Fragments)Architecting Single Activity Applications (With or Without Fragments)
Architecting Single Activity Applications (With or Without Fragments)
 

More from Corrado Santoro

Presentation @ WOA 2015
Presentation @ WOA 2015 Presentation @ WOA 2015
Presentation @ WOA 2015
Corrado Santoro
 
Using Ready-for-PIC and SDR Libraries
Using Ready-for-PIC and SDR LibrariesUsing Ready-for-PIC and SDR Libraries
Using Ready-for-PIC and SDR Libraries
Corrado Santoro
 
Analog to digital converter
Analog to digital converterAnalog to digital converter
Analog to digital converter
Corrado Santoro
 
Exercises with timers and UART
Exercises with timers and UARTExercises with timers and UART
Exercises with timers and UART
Corrado Santoro
 
Handling Interrupts in Microchip MCUs
Handling Interrupts in Microchip MCUsHandling Interrupts in Microchip MCUs
Handling Interrupts in Microchip MCUs
Corrado Santoro
 
Using Timers in PIC18F Microcontrollers
Using Timers in PIC18F MicrocontrollersUsing Timers in PIC18F Microcontrollers
Using Timers in PIC18F Microcontrollers
Corrado Santoro
 
Programming the Digital I/O Interface of a PIC microcontroller
Programming the Digital I/O Interface of a PIC microcontrollerProgramming the Digital I/O Interface of a PIC microcontroller
Programming the Digital I/O Interface of a PIC microcontroller
Corrado Santoro
 
Introduction to microcontrollers
Introduction to microcontrollersIntroduction to microcontrollers
Introduction to microcontrollers
Corrado Santoro
 

More from Corrado Santoro (20)

Physical Flying Agents: Ummanned Aerial Vehicles Control, Coordination and Em...
Physical Flying Agents: Ummanned Aerial Vehicles Control, Coordination and Em...Physical Flying Agents: Ummanned Aerial Vehicles Control, Coordination and Em...
Physical Flying Agents: Ummanned Aerial Vehicles Control, Coordination and Em...
 
The I2C Interface
The I2C InterfaceThe I2C Interface
The I2C Interface
 
Using Timer1 and CCP
Using Timer1 and CCPUsing Timer1 and CCP
Using Timer1 and CCP
 
Pulse Width Modulation Signal Generation with MCUs
Pulse Width Modulation Signal Generation with MCUsPulse Width Modulation Signal Generation with MCUs
Pulse Width Modulation Signal Generation with MCUs
 
Using Timer2 in Microchip MCUs
Using Timer2 in Microchip MCUsUsing Timer2 in Microchip MCUs
Using Timer2 in Microchip MCUs
 
Handling Asynchronous Events in MCUs
Handling Asynchronous Events in MCUsHandling Asynchronous Events in MCUs
Handling Asynchronous Events in MCUs
 
Presentation @ Miniscuola WOA 2015
Presentation @ Miniscuola WOA 2015Presentation @ Miniscuola WOA 2015
Presentation @ Miniscuola WOA 2015
 
Presentation @ WOA 2015
Presentation @ WOA 2015 Presentation @ WOA 2015
Presentation @ WOA 2015
 
Soc
SocSoc
Soc
 
Using Ready-for-PIC and SDR Libraries
Using Ready-for-PIC and SDR LibrariesUsing Ready-for-PIC and SDR Libraries
Using Ready-for-PIC and SDR Libraries
 
Introduction to Erlang
Introduction to ErlangIntroduction to Erlang
Introduction to Erlang
 
Introduction to shell scripting
Introduction to shell scriptingIntroduction to shell scripting
Introduction to shell scripting
 
Pillole di C++
Pillole di C++Pillole di C++
Pillole di C++
 
Analog to digital converter
Analog to digital converterAnalog to digital converter
Analog to digital converter
 
Exercises with timers and UART
Exercises with timers and UARTExercises with timers and UART
Exercises with timers and UART
 
UART MCU
UART MCUUART MCU
UART MCU
 
Handling Interrupts in Microchip MCUs
Handling Interrupts in Microchip MCUsHandling Interrupts in Microchip MCUs
Handling Interrupts in Microchip MCUs
 
Using Timers in PIC18F Microcontrollers
Using Timers in PIC18F MicrocontrollersUsing Timers in PIC18F Microcontrollers
Using Timers in PIC18F Microcontrollers
 
Programming the Digital I/O Interface of a PIC microcontroller
Programming the Digital I/O Interface of a PIC microcontrollerProgramming the Digital I/O Interface of a PIC microcontroller
Programming the Digital I/O Interface of a PIC microcontroller
 
Introduction to microcontrollers
Introduction to microcontrollersIntroduction to microcontrollers
Introduction to microcontrollers
 

Recently uploaded

1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
QucHHunhnh
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
kauryashika82
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
PECB
 
Making and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdfMaking and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdf
Chris Hunter
 

Recently uploaded (20)

1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
psychiatric nursing HISTORY COLLECTION .docx
psychiatric  nursing HISTORY  COLLECTION  .docxpsychiatric  nursing HISTORY  COLLECTION  .docx
psychiatric nursing HISTORY COLLECTION .docx
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
 
fourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingfourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writing
 
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
Making and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdfMaking and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdf
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SD
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
 

Reactive Autonomous System Programming using the PROFETA tool

  • 1. Programming using the PROFETA tool Reactive Autonomous System Programming using the PROFETA tool Corrado Santoro ARSLAB - Autonomous and Robotic Systems Laboratory Dipartimento di Matematica e Informatica Universit` di Catania, Italy a santoro@dmi.unict.it Miniscuola WOA 2013 - Torino, 04 Dicembre 2013 Corrado Santoro - Using the PROFETA Tool - MiniScuola WOA 2013 1
  • 2. Programming using the PROFETA tool Outline 1 Introducing PROFETA Basic Entities Beliefs and Actions Sensors Execution Semantics 2 Special features of 3 Goals in PROFETA Basics Why Goals? Goal Failure 4 Contexts in PROFETA PROFETA Special Kind of Beliefs Special Kind of Actions Corrado Santoro - Using the PROFETA Tool - MiniScuola WOA 2013 Motivation Scenarios Defining and Using Contexts 2
  • 3. Programming using the PROFETA tool Introducing PROFETA Introducing PROFETA Introducing PROFETA Corrado Santoro - Using the PROFETA Tool - MiniScuola WOA 2013 3
  • 4. Programming using the PROFETA tool Introducing PROFETA Basic Entities PROFETA Basics PROFETA (Python RObotic Framework for dEsigning sTrAtegies) is Python tool for programming autonomous systems (agents or robots) using a declarative approach. PROFETA has been designed at ARSLAB @ UNICT in 2010. The aim is to have a single environment to implement the software of an autonomous robot. It provides an “all-in-one” environment supporting both imperative (algorithmical part) and declarative (behavioural part) programming models. Corrado Santoro - Using the PROFETA Tool - MiniScuola WOA 2013 4
  • 5. Programming using the PROFETA tool Introducing PROFETA Basic Entities PROFETA Basics PROFETA provides A set of classes to represent basic BDI entities, i.e. Beliefs ⇒ Knowledge Goals ⇒ States to be achieved Actions ⇒ Things to do to reach the Goals A declarative language—dialect of AgentSpeak(L)—to express agent’s behaviour An engine executing that behaviour A Knowledge base storing the beliefs Corrado Santoro - Using the PROFETA Tool - MiniScuola WOA 2013 5
  • 6. Programming using the PROFETA tool Introducing PROFETA Basic Entities PROFETA Declarative Syntax A PROFETA behaviour is a set of rules in the form Event / Condition >> set of Action where: Event can be: belief assert or retract, goal achievement request, goal failure. Condition refers to a certain state of the knowledge base. Action can be: belief assert or retract, goal achievement request, user defined atomic action. Example: +object_at("X","Y") / object_got("no") >> [ move_to("X", "Y"), pick_object() ] Such expressions are managed thanks to operator overloading Corrado Santoro - Using the PROFETA Tool - MiniScuola WOA 2013 6
  • 7. Programming using the PROFETA tool Introducing PROFETA Basic Entities Basic Parts of a PROFETA Program Download PROFETA from: http://github.com/corradosantoro/profeta Import the PROFETA libraries Define beliefs and goals as subclasses of Belief and Goal Define user actions by subclassing Action and overriding method execute() Instantiate the PROFETA Engine Define the rules by means of the declarative sytntax Run the Engine Corrado Santoro - Using the PROFETA Tool - MiniScuola WOA 2013 7
  • 8. Programming using the PROFETA tool Introducing PROFETA Basic Entities “Hello World” in PROFETA # import libraries from profeta.lib import * from profeta.main import * # instantiate the engine PROFETA.start() # define a rule +start() >> [ show_line("hello world from PROFETA") ] # assert the "start()" belief PROFETA.assert_belief(start()) # run the engine PROFETA.run() start() is a library belief show line() is a library action Corrado Santoro - Using the PROFETA Tool - MiniScuola WOA 2013 8
  • 9. Programming using the PROFETA tool Introducing PROFETA Basic Entities The “Picking Object” Robot 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 from profeta . lib import * from profeta . main import * class object_at ( Belief ): pass class object_got ( Belief ): pass class move_to ( Action ): def execute ( self ): x = self [0] y = self [1] # ... perform movement to x , y class pick_object ( Action ): def execute ( self ): # drive the arm to pick object PROFETA . start () + object_at ( " X " , " Y " ) / object_got ( " no " ) >> [ move_to ( " X " , " Y " ) , pick_object () , - object_got ( " no " ) , + object_got ( " yes " ) , - object_at ( " X " , " Y " ) ] PROFETA . assert_belief ( object_got ( " no " )) PROFETA . run () Corrado Santoro - Using the PROFETA Tool - MiniScuola WOA 2013 9
  • 10. Programming using the PROFETA tool Introducing PROFETA Beliefs and Actions Belief Syntax A belief is defined as a subclass of Belief In a rule, it is referred as an “atomic formula” with: one or more ground terms, e.g. object at(123, 456) one or more variables, e.g. object at("X", "Y") A variable is expressed using a string starting with capitals Within the set of actions: +bel(...) asserts a belief in the KB -bel(...) retracts a belief from the KB As trigger event: +bel(...) triggers the rule when the belief is asserted -bel(...) triggers the rule when the belief is retracted Corrado Santoro - Using the PROFETA Tool - MiniScuola WOA 2013 10
  • 11. Programming using the PROFETA tool Introducing PROFETA Beliefs and Actions Action Syntax An action is defined as a subclass of Action The execute() method has to implement the computation which concretely performs the action; such a computation is executed atomically In a rule, it is referred as an “atomic formula” with: one or more ground terms, e.g. move to(123, 456) one or more variables, e.g. move to("X", "Y") A variable is expressed using a string starting with capitals In method execute() terms can be accessed as self[term index] Corrado Santoro - Using the PROFETA Tool - MiniScuola WOA 2013 11
  • 12. Programming using the PROFETA tool Introducing PROFETA Beliefs and Actions The “Picking Robot” Rule 1 2 3 4 + object_at ( " X " , " Y " ) / object_got ( " no " ) >> [ move_to ( " X " , " Y " ) , pick_object () , - object_got ( " no " ) , + object_got ( " yes " ) , - object_at ( " X " , " Y " ) ] That rule says: When an object is seen at a certain position and ... No object has been picked from the robot, then ... Move to that position, pick the object, and ... Update the beliefs in order to reflect the new state. Corrado Santoro - Using the PROFETA Tool - MiniScuola WOA 2013 12
  • 13. Programming using the PROFETA tool Introducing PROFETA Sensors Sensors Belief object at() is intended to be asserted as soon as an object is found (or detected) at a certain position. How is such a detection performed? A Sensor class is provided with the objective of allowing the programmer to write the proper code to “sense” the environment and generate the proper beliefs. The programmer has to: subclass Sensor override the sense() method inform the Engine that a new sensor has been added in the program. Corrado Santoro - Using the PROFETA Tool - MiniScuola WOA 2013 13
  • 14. Programming using the PROFETA tool Introducing PROFETA Sensors The “Picking Object” Robot with a Sensor 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 .... class ObjectSensor ( Sensor ): def sense ( self ): Obj = detect_an_object () if Obj is None : return None else : (x , y ) = Obj return + object_at (x , y ) PROFETA . start () + object_at ( " X " , " Y " ) / object_got ( " no " ) >> [ move_to ( " X " , " Y " ) , pick_object () , - object_got ( " no " ) , + object_got ( " yes " ) , - object_at ( " X " , " Y " ) ] PROFETA . assert_belief ( object_got ( " no " )) PROFETA . add_sensor ( ObjectSensor ()) PROFETA . run () Corrado Santoro - Using the PROFETA Tool - MiniScuola WOA 2013 14
  • 15. Programming using the PROFETA tool Introducing PROFETA Sensors Sensor Semantics 1 2 3 4 5 6 7 8 9 10 11 12 .... class ObjectSensor ( Sensor ): def sense ( self ): Obj = detect_an_object () if Obj is None : return None else : (x , y ) = Obj return + object_at (x , y ) ... Method sense() may return None, nothing has been sensed +bel(...), something has been sensed, a belief is added to the KB and the “add event” is generated. bel(...), something has been sensed, a belief is added to the KB but the “add event” is NOT generated. Corrado Santoro - Using the PROFETA Tool - MiniScuola WOA 2013 15
  • 16. Programming using the PROFETA tool Introducing PROFETA Execution Semantics PROFETA Structures Terminology (according to AgentSpeak): A Plan is a rule of the PROFETA program An Intention is a plan which is selected for execution (the instantiation of a plan) PROFETA Structures: An Event Queue which stores add/retract belief events An Intention Stack which stores Intentions to be executed A Sensor Set which stores instantiated sensors Corrado Santoro - Using the PROFETA Tool - MiniScuola WOA 2013 16
  • 17. Programming using the PROFETA tool Introducing PROFETA Execution Semantics PROFETA (Informal) Execution Semantics PROFETA Main Loop Execution: 1 If the Intention Stack is not empty, execute an action step and go to 1. 2 If the Event Queue is not empty, pick an event, find the relevant plan, verify the condition part and then put the plan at the top of Intention Stack, then go to 1. 3 If both the Intention Stack and Event Queue are empty, scan sensors in Sensor Set and, for each of them, call the sense() method and analyse the return value; if it is an event, put it in the Event Queue. 4 Go to 1. Corrado Santoro - Using the PROFETA Tool - MiniScuola WOA 2013 17
  • 18. Programming using the PROFETA tool Special features of PROFETA Special features of PROFETA Special features of PROFETA Corrado Santoro - Using the PROFETA Tool - MiniScuola WOA 2013 18
  • 19. Programming using the PROFETA tool Special features of PROFETA Special Kind of Beliefs Special Kind of Beliefs 1 2 3 4 + object_at ( " X " , " Y " ) / object_got ( " no " ) >> [ move_to ( " X " , " Y " ) , pick_object () , - object_got ( " no " ) , + object_got ( " yes " ) , - object_at ( " X " , " Y " ) ] Here ... Belief object at() represents that “an object has been detected”; after plan execution, the belief is removed. Belief object got() represents a state of the robot, which could have picked or not the object. Only one belief of this kind can be present in the KB. Corrado Santoro - Using the PROFETA Tool - MiniScuola WOA 2013 19
  • 20. Programming using the PROFETA tool Special features of PROFETA Special Kind of Beliefs Special Kind of Beliefs To support such cases, the following “special beliefs” are provided: Reactors, i.e. beliefs which are automatically removed from the KB when the associated plan is executed. SingletonBeliefs, i.e. beliefs which are “single instance”. Therefore ... 1 2 3 4 5 6 7 8 9 10 11 12 13 ... class object_at ( Reactor ): pass class object_got ( SingletonBelief ): pass ... + object_at ( " X " , " Y " ) / object_got ( " no " ) >> [ move_to ( " X " , " Y " ) , pick_object () , + object_got ( " yes " ) ] ... Corrado Santoro - Using the PROFETA Tool - MiniScuola WOA 2013 20
  • 21. Programming using the PROFETA tool Special features of PROFETA Special Kind of Actions Example: Factorial in PROFETA Using Reactors 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 from profeta . lib import * from profeta . main import * class fact ( Reactor ): pass class KB ( Sensor ): def sense ( self ): e = raw_input ( " Enter Number : " ) return + fact ( int ( e ) , 1) PROFETA . start () PROFETA . add_sensor ( KB ()) + fact (1 , " X " ) >> [ show ( " the resuilting factorial is " ) , show_line ( " X " ) ] + fact ( " N " , " X " ) >> [ " Y = int ( N ) * int ( X ) " , " N = int ( N ) - 1 " , + fact ( " N " , " Y " ) ] PROFETA . run () Corrado Santoro - Using the PROFETA Tool - MiniScuola WOA 2013 21
  • 22. Programming using the PROFETA tool Special features of PROFETA Special Kind of Actions Special Kind of Actions 1 2 3 4 5 6 ... + fact (1 , " X " ) >> [ show ( " the resuilting factorial is " ) , show_line ( " X " ) ] + fact ( " N " , " X " ) >> [ " Y = int ( N ) * int ( X ) " , " N = int ( N ) - 1 " , + fact ( " N " , " Y " ) ] ... show() and show line() are library actions which are used to print an output onto the screen. An action can also be any Python expression, given that it is expressed as a string (string action) A string action can manipulate and create any plan variable but... look out!! PROFETA is not typed! Corrado Santoro - Using the PROFETA Tool - MiniScuola WOA 2013 22
  • 23. Programming using the PROFETA tool Goals in PROFETA Goals in PROFETA Goals in PROFETA Corrado Santoro - Using the PROFETA Tool - MiniScuola WOA 2013 23
  • 24. Programming using the PROFETA tool Goals in PROFETA Basics Goals Goals are (according to AgentSpeak(L)) “states of the systems which an agent wants to achieve”, but indeed ... ... a goal is something like a “procedure plan” which expresses the things to do to achieve the goal itself. In PROFETA, a goal: is first defined as a subclass of Goal it is expressed, in the plans, as an “atomic formula”, with zero or more terms. Corrado Santoro - Using the PROFETA Tool - MiniScuola WOA 2013 24
  • 25. Programming using the PROFETA tool Goals in PROFETA Basics Example: Factorial with goals 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 from profeta . lib import * from profeta . main import * class do_factorial ( Reactor ): pass class fact ( Goal ): pass class KB ( Sensor ): def sense ( self ): e = raw_input ( " Enter Number : " ) return + do_factorial ( int ( e )) PROFETA . start () PROFETA . add_sensor ( KB ()) + do_factorial ( " N " ) >> [ show ( " computing factorial of " ) , show_line ( " N " ) , fact ( " N " , 1) ] fact (1 , " X " ) >> [ show ( " the resuilting factorial is " ) , show_line ( " X " ) ] fact ( " N " , " X " ) >> [ " Y = int ( N ) * int ( X ) " , " N = int ( N ) - 1 " , fact ( " N " , " Y " ) ] PROFETA . run () Corrado Santoro - Using the PROFETA Tool - MiniScuola WOA 2013 25
  • 26. Programming using the PROFETA tool Goals in PROFETA Basics The “Object Picker” with Goals 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 from profeta . lib import * from profeta . main import * class object_at ( Reactor ): pass class object_got ( SingletonBelief ): pass class pic k_object_at ( Goal ): pass class move_to ( Action ): def execute ( self ): # ... perform movement to x , y class drive_arm ( Action ): def execute ( self ): # drive the arm to pick object PROFETA . start () + object_at ( " X " , " Y " ) / object_got ( " no " ) >> [ pick_object_at ( " X " , " Y " ) , + object_got ( " yes " ) ] pick _object_at ( " X " , " Y " ) >> [ move_to ( " X " , " Y " ) , drive_arm () ] PROFETA . assert_belief ( object_got ( " no " )) PROFETA . run () Corrado Santoro - Using the PROFETA Tool - MiniScuola WOA 2013 26
  • 27. Programming using the PROFETA tool Goals in PROFETA Why Goals? Why Goals? Goals are “procedures”, thus they help to better organize your PROFETA program, e.g. 1 2 3 4 ... >> [ goal1 () , goal2 () , goal3 () ] goal1 () >> [ ... do something ... ] goal2 () >> [ ... do something ... ] goal3 () >> [ ... do something ... ] Goals can introduce branches since a condition is allowed in the head of the rule, e.g. 1 2 pick_object_at ( " X " , " Y " ) / ( lambda : X < 100) >> [ move_to ( " X " , " Y " ) , ... ] pick_object_at ( " X " , " Y " ) / ( lambda : X >= 100) >> [ # do other things ] Goals may fail! Corrado Santoro - Using the PROFETA Tool - MiniScuola WOA 2013 27
  • 28. Programming using the PROFETA tool Goals in PROFETA Goal Failure Goal Failure Let us suppose that the robot cannot reach the object if it is located around position (1500, 1000), so: 1 2 3 4 5 6 7 8 9 ... def is_reachable (x , y ): return math . hypot ( x - 1500 , y - 1000) > 100 + object_at ( " X " , " Y " ) / object_got ( " no " ) >> [ pick_object_at ( " X " , " Y " ) , + object_got ( " yes " ) ] pick_object_at ( " X " , " Y " ) / ( lambda : is_reachable (X , Y )) >> [ move_to ( " X " , " Y " ) , ... ] pick_object_at ( " X " , " Y " ) >> [ fail () ] # the goal fails ! Library action fail() causes the current goal to fail Calling goals/plans fail in sequence (is something like an exception) Corrado Santoro - Using the PROFETA Tool - MiniScuola WOA 2013 28
  • 29. Programming using the PROFETA tool Goals in PROFETA Goal Failure Recovery Actions A goal failure can be triggered also within the code of an Action, by calling fail().execute() A failure event can be catched by a rule in order to try a recovery action To catch a failure of a goal g, the related event is -g(), e.g. 1 2 3 4 5 6 7 ... + object_at ( " X " , " Y " ) / object_got ( " no " ) >> [ pick_object_at ( " X " , " Y " ) , + object_got ( " yes " ) ] pick_object_at ( " X " , " Y " ) / ( lambda : is_reachable (X , Y )) >> [ move_to ( " X " , " Y " ) , ... ] pick_object_at ( " X " , " Y " ) >> [ fail () ] # the goal fails ! - pick_object_at ( " X " , " Y " ) >> [ ... do smthg to perform recovery ... ] Corrado Santoro - Using the PROFETA Tool - MiniScuola WOA 2013 29
  • 30. Programming using the PROFETA tool Goals in PROFETA Goal Failure Goal Failure Semantics If we have 1 2 3 4 ... >> [ goal1 () , ... ] goal1 () >> [ goal2 () ] goal2 () >> [ goal3 () ] goal3 () >> [ ... , fail () ] In plan in line 4, we have a stack of goal calls goal1() → goal2() → goal3(), and goal3() fails, thus If a plan related to -goal3() exists, it is first executed; otherwise, if a plan related to -goal2() exists, it is executed; otherwise, if a plan related to -goal1() exists, it is executed; otherwise, the calling plan of goal1() (line 1) is interrupted. Corrado Santoro - Using the PROFETA Tool - MiniScuola WOA 2013 30
  • 31. Programming using the PROFETA tool Contexts in PROFETA Contexts in PROFETA Contexts in PROFETA Corrado Santoro - Using the PROFETA Tool - MiniScuola WOA 2013 31
  • 32. Programming using the PROFETA tool Contexts in PROFETA Motivation Scenarios Scenario 1: Synchronous vs. Asynchronous Actions According to PROFETA execution semantics, Sensors are polled only if there are no intentions to be executed Therefore, during intention execution, an agent/robot is blind, w.r.t. events which could happen in the environment Action dynamics/duration matters!! E.g. If action move to(X,Y) is synchronous, i.e. it waits for the robot to reach the desired position, no events can be captured during the move! In a robotic application this is quite undesirable. Solution: Make action move to(X,Y) asynchronous and add a Sensor checking that the target position has been reached. Corrado Santoro - Using the PROFETA Tool - MiniScuola WOA 2013 32
  • 33. Programming using the PROFETA tool Contexts in PROFETA Motivation Scenarios The “Object Picker” with Asynchronous move to() 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 ... class object_at ( Reactor ): pass class object_got ( SingletonBelief ): pass class target_got ( Reactor ): pass class move_to ( Action ): def execute ( self ): # ... trigger movement to x , y and i m m e d i a t e l l y return class drive_arm ( Action ): def execute ( self ): # drive the arm to pick object class TargetGot ( Sensor ): def sense ( self ): if motion_control . target_reached (): return + target_got () else : return None PROFETA . start () PROFETA . add_sensor ( TargetGot ()) + object_at ( " X " , " Y " ) / object_got ( " no " ) >> [ move_to ( " X " , " Y " ) ] + target_got () >> [ drive_arm () , + object_got ( " yes " ) ] PROFETA . assert_belief ( object_got ( " no " )) PROFETA . run () Corrado Santoro - Using the PROFETA Tool - MiniScuola WOA 2013 33
  • 34. Programming using the PROFETA tool Contexts in PROFETA Motivation Scenarios Uncontextualised beliefs Here, target got() is asserted whatever movement has been started. If we want to check that a certain movement is completed, we should add a proper belief, e.g. to make the robot following a path: 1 2 3 4 5 ... >> [ move_to (1000 , 0) , + movement ( " one " ) ] + target_got () / movement ( " one " ) > >[ move_to (1000 , 1000) , + movement ( " two " ) ] + target_got () / movement ( " two " ) > >[ move_to (0 , 1000) , + movement ( " three " ) ] + target_got () / movement ( " three " ) >> [ show ( " yeahhh !!! " ) ] ... that is, we have to add a contextual information by means of additional beliefs. Corrado Santoro - Using the PROFETA Tool - MiniScuola WOA 2013 34
  • 35. Programming using the PROFETA tool Contexts in PROFETA Motivation Scenarios Scenario 2: A robot making “many things” Let’s consider a robot which has to: 1 2 3 Gather at most 10 objects placed in the environment Put the object into a specific container Go to step 1. Here we have two tasks or“macrostates” in which events sensed from the environment may have require different actions. Contextual beliefs could be used but ... ... it could be better to have language constructs which allows a better identification of the plans related to each task. Corrado Santoro - Using the PROFETA Tool - MiniScuola WOA 2013 35
  • 36. Programming using the PROFETA tool Contexts in PROFETA Defining and Using Contexts Contexts in PROFETA PROFETA let a programmer to define contexts: macrostates in which only specified plans can be triggered. A context is defined by placing the statement context(ContextName) in the plan list; after it, all plans will be referred to ContextName. At run-time, a context is “entered” by calling the library action set context(ContextName). This action asserts the library reactor start() which is used to trigger an “intialization plan” in the entered context. Corrado Santoro - Using the PROFETA Tool - MiniScuola WOA 2013 36
  • 37. Programming using the PROFETA tool Contexts in PROFETA Defining and Using Contexts Contexts in PROFETA: An Example 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 ... class go ( Goal ): pass go () >> [ set_context ( " pick_objects " ) ] context ( " pick_objects " ) # put here plans for ’ p i c k _ o b j e c t ’ task + start () >> [ + objects_got (0) ] + o b j e c t _ d et e ct ed _ at ( " X " , " Y " ) >> [ move_to ( " X " , " Y " ) ] + target_got () / objects_got ( " N " ) >> [ drive_arm () , " N = N + 1 " , + objects_got ( " N " ) , after_pick () ] after_pick () / objects_got (10) >> [ set_context ( " put_away_objects " ) ] context ( " put_away_objects " ) # put here plans for ’ p u t _ a w a y _ o b j e c t ’ task + start () >> [ move_to (1500 , 1000) ] # the position of the c o n t a i n e r + target_got () >> [ r e le a s e _ a l l _ ob j e c t s () , set_context ( " pick_objects " ) ] PROFETA . achieve ( go ()) PROFETA . run () Corrado Santoro - Using the PROFETA Tool - MiniScuola WOA 2013 37
  • 38. Programming using the PROFETA tool Other Features Other features Other features Corrado Santoro - Using the PROFETA Tool - MiniScuola WOA 2013 38
  • 39. Programming using the PROFETA tool Other Features Handling specific Sensor Dynamics Sensors are polled using the latency derived from the execution of the main PROFETA loop If you need to poll a Sensor with a specific dynamics, the AsyncSensorProxy allows a Sensor to be decoupled from the main loop It can have its own peridicity (NOT guaranteed!!). 1 2 3 4 5 6 7 ... class MyAsyncSensor ( Reactor ): def sense ( self ): time . sleep ( millisecs /1000.0) # perform sensing PROFETA . add_sensor ( AsyncSensorProxy ( MyAsyncSensor ())) Corrado Santoro - Using the PROFETA Tool - MiniScuola WOA 2013 39
  • 40. Programming using the PROFETA tool Other Features Handling specific Action Dynamics Actions can be easily made asynchronous by subclassing AsyncAction instead of Action. An AsyncAction is executed in a different thread w.r.t. that of PROFETA main loop 1 2 3 4 5 6 7 ... class MyAsyncAction ( AsyncAction ): def execute ( self ): # .... ... >> [ ... MyAsyncAction (...) ... ] Corrado Santoro - Using the PROFETA Tool - MiniScuola WOA 2013 40
  • 41. Programming using the PROFETA tool Conclusions Conclusions PROFETA allows to define robot strategies in a flexible and intuitive way, by using the principles of the BDI model. PROFETA combines the advantages of both imperative and declarative approach, while offering an all-in-one environment PROFETA performs quite well also in systems with few memory, and has been successfully applied in various robot built at ARSLab Corrado Santoro - Using the PROFETA Tool - MiniScuola WOA 2013 41
  • 42. Programming using the PROFETA tool Conclusions TO DO List Concurrent Plans. But under the strong control of the programmer. MAS Support. Currently PROFETA does not support muliple-agents: one robot/agent for virtual machine. Better notion of Task (or “Goal”). A Task is what the agent should do to achieve a specific goal. Why not mulitple and different choices for a goal/task? This could give a “deliberation ability” to agents. Porting to other languages. Only Python? Why not C++? Corrado Santoro - Using the PROFETA Tool - MiniScuola WOA 2013 42
  • 43. Programming using the PROFETA tool Conclusions References http://github.com/corradosantoro/profeta L. Fichera, D. Marletta, V. Nicosia, C. Santoro. Flexible Robot Strategy Design using Belief-Desire-Intention Model. In Proc. of International Conference on Research and Education in Robotics (EUROBOT 2010), Spriger CCIS Series, Rappreswille, Swizerland), May 27-30, 2010. L. Fichera, D. Marletta, V. Nicosia, C. Santoro. A Methodology to Extend Imperative Languages with AgentSpeak Declarative Constructs. In Proc. of Workshop on Objects and Agents (WOA2010), CEUR-WS Publisher, ISSN 1613-0073, Rimini, Italy, Sept. 5-7, 2010. G. Fortino, W. Russo, C. Santoro. Translating Statecharts-based into BDI Agents: The DSC/PROFETA case. MAS&S Workshop @ MATES 2013. F. Messina, G. Pappalardo, C. Santoro. Integrating Cloud Services in Behaviour Programming for Autonomous Robots. CSmart-CPS Workshop, LNCS, 2013. Corrado Santoro - Using the PROFETA Tool - MiniScuola WOA 2013 43
  • 44. Programming using the PROFETA tool Conclusions Reactive Autonomous System Programming using the PROFETA tool Corrado Santoro ARSLAB - Autonomous and Robotic Systems Laboratory Dipartimento di Matematica e Informatica Universit` di Catania, Italy a santoro@dmi.unict.it Miniscuola WOA 2013 - Torino, 04 Dicembre 2013 Corrado Santoro - Using the PROFETA Tool - MiniScuola WOA 2013 44