SLAM - quasylab/sibilla GitHub Wiki

A system in SLAM consists of a set of interacting agents. Each agent is equipped with a set of attributes. Some of these attributes are under the agent's control and are updated during its evolution. In contrast, others depend on the environment where the agent operates, and their values are updated as time passes. These are used to model the fact that an agent, like in YODA, can sense its environment.

In SLAM, agents interact via explicit message passing via attribute-based communication primitives: an agent sends messages to other agents satisfying a given predicate. When a new message is received or given time is passed, due to a timeout, an agent can send a set of messages and change its state.

The stochastic process associated with a SLAM specification is a Timed Process where actions and activities may have a duration sampled by generic distributions. The behaviour of an agent consists of a set of states. Each agent state describes how the agent reacts when a message is received and how agent attributes are changed while time is passing.

A time-out behaviour can be also defined in a state to execute a sequence of actions when no message is received for the given amount of time.

SLAM Model

Besides the declaration of constants and parameters, a SLAM Model consists of the declaration of the following elements:

  • Messages
  • Agent
  • Measures
  • Predicates
  • Configurations

Messages

We have already remarked that SLAM agents interact with each other via message passing. A message consists of a tag and a, possibly empty, sequence of values.

To be used a message must be declared by using the following syntax:

message <tagname> (of <type>(* <type>)*)?;

Values occurring in a message are typed. Possible types are int, real and bool.

Agents

The declaration of a SLAM agent contains:

  • attributes, that represent the agent knowledge;
  • views, that provide info collected from the enclosing environment;
  • behaviour, that consists of a set of states;
  • time dynamics of attributes.

The structure of the declaration of an agent is the following:

agent <agentname> ([ (<type> <varname>(, <type> <varname>)*)? ])? :
        attributes :
            (<type> <name> = <expr> ;)*
        views :
            (<type> <name> = <expr> ;)*
        behaviour :
            <state>*
        on time {
            (<name> = <expr>;)*        
        }
end

Even if decalaration of attributes and views look similar, they are quite different. Indeed, while an attribute is initialised by using an expression containing only scalar values, constants and model parameters, a view contains an environmental expression (see below).

The assignments on the block on time are executed when the time is passing. Each expression can use the special symbol dt to refer the amount of time passed since the last event.

The behaviour of the agent is represented in terms of a set of states. Each state has the following structure:

('init')? state <name> {
        <handlers>*
        (after <expr> <block>)?
        on time {
            (<name> = <expr>;)*        
        }
}

In a state we declare:

  • a set of handlers that indicates how the agent react when a message is received;
  • a time out behaviour that is executed when the given amount of time passes from the last event;
  • a state specific attribute dynamic.

Each message handler has the following structure:

on receive <tag> [ <pattern> (, <pattern>)* ']' 
   from <agentPattern> when <expr> <block>

Messages are selected via pattern matching on the content of the message, and on the properties of the sender. Values in a message are inspected via a sequence of <pattern> that can be either the symbol _, matching any value, or the variable declaration ?<name> that binds the corresponding value to the given <name>.
The variables bound in the pattern can be used in both the <agentPattern> and when expression. An agent pattern is a term of the form <name>[<booleanexpr>] and it is satisfied by all the agents with the given name and attributes satisfying the given boolean expression. When expression is a boolean expression referring to the attributes of the receiver and to the variables bound in the matching.

When a matching message is received, or when the time out is passed, a <block> is executed. This consists of a sequence of assignents followed by the reference to the name of the state where we are jumping.

A SLAM Example

A typical scenario where SLAM can be used is the one consisting of a swarm of robots moving in an area to perform a given task like, for instance, find objects that are spread over a given area.

Robots randomly move in the are and when an object is perceived it sends a message to communicate its position.

Each robot can be represented by means of an agent that has two attributes indicating its position, x and y, one that is used to indicate the direction of the robot, dir, and one that indicates if the object to search is perceived or not, perceive.

The considered agent has a single state MOVING. In that state each agent moves along a randomly selected direction for a time between 30 and 300 seconds. After that another direction is randomly selected.

Every step seconds an agent checks if an object is perceived. In case, a message is sent to every one that is delivered in 1 seconds. The coordinates of a robot are change while time is passing according to direction and speed.

agent Robot[real init_x, real init_y]
    attributes:
        real x = init_x;
        real y = init_y;
        real dir = rnd*2*PI;
        real speed = robot_speed;
        real timeToChangeDirection = U[30, 300];
    views:
        boolean perceived = exists{ Object[ distance(it.x, it.y, x, y)<delta ]};
    states:
        init MOVING {
            after step -> MOVING { 
                if (changetime <= now) {
                    dir = rnd*2*PI;      
                    timeToChangeDirection = timeToChangeDirection + U[30, 300];
                } 
                if (perceveived) {
                    send FOUND[x,y] to any in 1;
                }
            }
            on time {
                x = speed*cos(dir)*dt;
                y = speed*sin(dir)*dt;
            }
        }
    end
⚠️ **GitHub.com Fallback** ⚠️