Urbiscript
urbiscript is a programming language for robotics.[3] It features syntactic support for concurrency and event-based programming. It is a prototype-based object-oriented scripting language. It is dynamic: name resolution is performed during the program execution (late binding); slots (member variables) can be added/removed at runtime, and even prototypes (superclasses) of an object can be changed at runtime. Memory management is performed by reference counting. Tightly bound to the Urbi platform it supports seamless integration of C++/Java components. Syntax and semanticsInspirationFrom the syntactical point of view, urbiscript belongs to the C-family of programming languages. Its prototype-based object-oriented design was influenced by the Self and the Io programming languages.[2] It is designed to program, but also interact with robots;[2] as such, it is influenced by Unix shells and other languages that provide a read-eval-print loop style interactive toplevel. However, contrary to others, there is no prompt for user input but answers from the system are prefixed by a timestamp (in milliseconds) between square brackets: 1 + 1; sleep(1s); 1 + 2 * 3;
Sequential statements and control flowurbiscript statements include (among others):[4]
Actually, contrary to most C-like languages and despite what the syntax suggests, statements "have a value", and therefore are expressions, provided they are embedded in braces: var status = { if (closed) "closed" else "open" };
var pass = { try { foo } catch { false } else { true } };
Concurrent statements and control flowIn urbiscript, some control-flow constructs come in several "flavors": two types of sequential composition, and two types of concurrent composition. Under the hood, concurrency is implemented using coroutines.[5] Statement compositionLike in C, the semicolon denotes sequential composition: Similarly urbiscript features two means to compose statements concurrently. With Scopes are boundaries for backgrounded jobs, as demonstrated in the following example:[5] {
{ sleep(2s); echo(2) },
{ sleep(1s); echo(1) },
};
echo(3);
Concurrent flavors of sequential constructsMost looping constructs in urbiscript come in several "flavors", which are based on the four statement separators: For instance // This is actually "for;".
for (var i : [0, 1, 2])
{
echo(i);
echo(i ** 2);
};
displays
i.e., the loop bodies are not executed sequentially, while the for& (var i : [0, 1, 2])
{
echo(i);
echo(i ** 2);
};
Event-based programmingAiming at the development of portable robotic applications,[6] urbiscript relies on specific syntactic constructs to specify reactive behaviors such as "go to the charging dock when the battery is low", "play a friendly sound when a known face is recognized", or "stop when an obstacle is detected". Explicit event handlingEvent handling goes into three steps. First, define an event var e = Event.new;
Second, specify event handlers at (e?)
echo("received event e");
Third, "emit" this event e!;
Events can have payloads, and event handlers enjoy pattern matching on the payload: at (e?(1, var x) if x % 2 == 0)
echo("received event e(1, %s)" % x);
e!(1, 1);
e!(1, 2);
Implicit eventsThe urbiscript language also allows to monitor expressions: at (batteryLevel <= 0.2)
robot.goToChargingDock;
The following example demonstrates the feature: var x = 0;
var y = 0;
var z = 0;
at (x + y == z)
echo("%s + %s == %s" % [x, y, z]);
x = 1;
z = 1;
See alsoReferences
External links |