urbiscript is a programming language for robotics.
[
] It features syntactic support for concurrency and event-based programming. It is a
prototype-based object-oriented
Object-oriented programming (OOP) is a programming paradigm based on the concept of "objects", which can contain data and code. The data is in the form of fields (often known as attributes or ''properties''), and the code is in the form of pro ...
scripting language
A scripting language or script language is a programming language that is used to manipulate, customize, and automate the facilities of an existing system. Scripting languages are usually interpreted at runtime rather than compiled.
A scripting ...
. It is dynamic:
name resolution is performed during the program execution (
late binding
In computing, late binding or dynamic linkage—though not an identical process to Dynamic linker, dynamically linking imported code Library (computing), libraries—is a computer programming mechanism in which the Method (computer programming), ...
); slots (
member variable
In object-oriented programming, a member variable (sometimes called a member field) is a variable that is associated with a specific object, and accessible for all its methods (''member functions'').
In class-based programming languages, these are ...
s) can be added/removed at runtime, and even prototypes (
superclasses) of an object can be changed at runtime.
Memory management
Memory management is a form of resource management applied to computer memory. The essential requirement of memory management is to provide ways to dynamically allocate portions of memory to programs at their request, and free it for reuse when ...
is performed by
reference counting
In computer science, reference counting is a programming technique of storing the number of references, pointers, or handles to a resource, such as an object, a block of memory, disk space, and others.
In garbage collection algorithms, referenc ...
.
Tightly bound to the
Urbi platform it supports seamless integration of C++/Java components.
Syntax and semantics
Inspiration
From 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
The self is an individual as the object of that individual’s own reflective consciousness. Since the ''self'' is a reference by a subject to the same subject, this reference is necessarily subjective. The sense of having a self—or ''selfhood ...
and the
Io programming languages.
It is designed to program, but also interact with robots;
as such, it is influenced by
Unix shells
A Unix shell is a command-line interpreter or shell that provides a command line user interface for Unix-like operating systems. The shell is both an interactive command language and a scripting language, and is used by the operating system to ...
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;
:
0005420
54 may refer to:
* 54 (number)
* one of the years 54 BC, AD 54, 1954, 2054
* ''54'' (novel), a 2002 novel by Wu Ming
* Studio 54, a New York City nightclub from 1977 until 1981
* ''54'' (film), a 1998 American drama film about the club
* ...
2
:
0006420
64 or sixty-four or ''variation'', may refer to:
* 64 (number)
Dates
* one of the years 64 BC, AD 64, 1864, 1964, 2064, etc.
* June 4th (6/4)
** the date of the 1989 Tiananmen Square protests and massacre
* April 6th (6/4)
* April 6 AD (6/4)
...
7
Sequential statements and control flow
urbiscript statements include (among others):
* The
if
statement, which conditionally executes a block of code, along with
else
.
* The traditional
for
statement, as in C which iterates over an iterable object, capturing each element to a local variable for use by the attached block.
* Another
for
statement, which iterates over an iterable object, capturing each element to a local variable for use by the attached block.
* The
while
statement, which executes a block of code as long as its condition is true.
* The
try
statement, which allows exceptions thrown in its attached code block to be caught and handled by
catch
clauses. An optional
else
clause is run if no exception was thrown. Clean-up code can be guaranteed to be run in every case when given in a
finally
-clause.
* The
assert
statement, used during debugging to check for conditions that ought to apply. urbiscript also feature
assert
blocks, which can be used to factor several
assert
statements.
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 = ;
var pass = ;
Concurrent statements and control flow
In 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
coroutine
Coroutines are computer program components that generalize subroutines for non-preemptive multitasking, by allowing execution to be suspended and resumed. Coroutines are well-suited for implementing familiar program components such as cooperative ...
s.
Statement composition
Like in C, the semicolon denotes sequential composition:
a;b
stands for "run statement
a
then run statement
b
. Other tasks may be run between
a
and
b
. Another statement separator, pipe, denotes "tight sequential composition": no other task can be run between
a
and
b
in
a, b
.
Similarly urbiscript features two means to compose statements concurrently. With
a,b
, first
a
is run, and at some point
b
will be --- possibly while
a
is still running. This is very similar to the
&
operator in Unix shells. Alternatively, with
a&b
, both
a
and
b
are started together; in interactive sessions, this means that
a
won't be run until
b
is fully entered and properly followed by either a
;
or a
,
.
Scopes are boundaries for backgrounded jobs, as demonstrated in the following example:
;
echo(3);
:
0012451
1 (one, unit, unity) is a number representing a single or the only entity. 1 is also a numerical digit and represents a single unit of counting or measurement. For example, a line segment of ''unit length'' is a line segment of length 1 ...
*** 1
:
0013447*** 2
:
0013447*** 3
Concurrent flavors of sequential constructs
Most looping constructs in urbiscript come in several "flavors", which are based on the four statement separators:
;
,
,
,
,
, and
&
.
For instance
// This is actually "for;".
for (var i : , 1, 2
;
displays
:
0002919*** 0
:
0002921*** 0
:
0002921*** 1
:
0002922
9 (nine) is the natural number following and preceding .
Evolution of the Arabic digit
In the beginning, various Indians wrote a digit 9 similar in shape to the modern closing question mark without the bottom dot. The Kshatrapa, Andhra and ...
*** 1
:
0002922
9 (nine) is the natural number following and preceding .
Evolution of the Arabic digit
In the beginning, various Indians wrote a digit 9 similar in shape to the modern closing question mark without the bottom dot. The Kshatrapa, Andhra and ...
*** 2
:
0002922
9 (nine) is the natural number following and preceding .
Evolution of the Arabic digit
In the beginning, various Indians wrote a digit 9 similar in shape to the modern closing question mark without the bottom dot. The Kshatrapa, Andhra and ...
*** 4
i.e., the loop bodies are not executed sequentially, while the
for&
keyword runs the loop bodies concurrently:
for& (var i : , 1, 2
;
:
0021680
Year 168 ( CLXVIII) was a leap year starting on Thursday (link will display the full calendar) of the Julian calendar. At the time, it was known as the Year of the Consulship of Apronianus and Paullus (or, less frequently, year 921 '' Ab urbe c ...
*** 0
:
0021680
Year 168 ( CLXVIII) was a leap year starting on Thursday (link will display the full calendar) of the Julian calendar. At the time, it was known as the Year of the Consulship of Apronianus and Paullus (or, less frequently, year 921 '' Ab urbe c ...
*** 1
:
0021680
Year 168 ( CLXVIII) was a leap year starting on Thursday (link will display the full calendar) of the Julian calendar. At the time, it was known as the Year of the Consulship of Apronianus and Paullus (or, less frequently, year 921 '' Ab urbe c ...
*** 2
:
0021682
Year 168 ( CLXVIII) was a leap year starting on Thursday (link will display the full calendar) of the Julian calendar. At the time, it was known as the Year of the Consulship of Apronianus and Paullus (or, less frequently, year 921 '' Ab urbe c ...
*** 0
:
0021682
Year 168 ( CLXVIII) was a leap year starting on Thursday (link will display the full calendar) of the Julian calendar. At the time, it was known as the Year of the Consulship of Apronianus and Paullus (or, less frequently, year 921 '' Ab urbe c ...
*** 1
:
0021682
Year 168 ( CLXVIII) was a leap year starting on Thursday (link will display the full calendar) of the Julian calendar. At the time, it was known as the Year of the Consulship of Apronianus and Paullus (or, less frequently, year 921 '' Ab urbe c ...
*** 4
Event-based programming
Aiming at the development of portable robotic applications,
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 handling
Event 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!;
:
0014333*** received 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);
:
0014336*** received event e
e!(1, 2);
:
0014336*** received event e
:
0014336*** received event e(1, 2)
Implicit events
The urbiscript language also allows to monitor expressions:
at (batteryLevel <= 0.2)
robot.goToChargingDock;
The following example demonstrates the feature:
var x = 0;
:
0002165
Year 165 (Roman numerals, CLXV) was a common year starting on Monday (link will display the full calendar) of the Julian calendar. At the time, it was known as the Year of the Consulship of Orfitus and Pudens (or, less frequently, year 918 ''Ab ...
0
var y = 0;
:
0002166
Year 166 ( CLXVI) was a common year starting on Tuesday (link will display the full calendar) of the Julian calendar. At the time, it was known as the Year of the Consulship of Pudens and Pollio (or, less frequently, year 919 '' Ab urbe condit ...
0
var z = 0;
:
0002167
Year 167 ( CLXVII) was a common year starting on Wednesday (link will display the full calendar) of the Julian calendar. At the time, it was known as the Year of the Consulship of Aurelius and Quadratus (or, less frequently, year 920 '' Ab urbe ...
0
at (x + y z)
echo("%s + %s %s" % , y, z;
:
0002168
Year 168 ( CLXVIII) was a leap year starting on Thursday (link will display the full calendar) of the Julian calendar. At the time, it was known as the Year of the Consulship of Apronianus and Paullus (or, less frequently, year 921 '' Ab urbe c ...
*** 0 + 0 0
x = 1;
:
0002169
Year 169 ( CLXIX) was a common year starting on Saturday (link will display the full calendar) of the Julian calendar. At the time, it was known as the Year of the Consulship of Senecio and Apollinaris (or, less frequently, year 922 '' Ab urbe ...
1
z = 1;
:
0002170
Seventeen or 17 may refer to:
*17 (number), the natural number following 16 and preceding 18
* one of the years 17 BC, AD 17, 1917, 2017
Literature
Magazines
* ''Seventeen'' (American magazine), an American magazine
* ''Seventeen'' (Japanese m ...
1
:
0002170
Seventeen or 17 may refer to:
*17 (number), the natural number following 16 and preceding 18
* one of the years 17 BC, AD 17, 1917, 2017
Literature
Magazines
* ''Seventeen'' (American magazine), an American magazine
* ''Seventeen'' (Japanese m ...
*** 1 + 0 1
See also
*
Urbi
Urbi is an open-source cross-platform software platform in C++ used to develop applications for robotics and complex systems. Urbi is based on the UObject distributed C++ component architecture. It also includes the urbiscript orchestration langu ...
References
External links
* {{github, urbiforge/urbi
Docker repositoryurbiscript Tutorial
C programming language family
Dynamically typed programming languages
Free compilers and interpreters
Cross-platform free software
High-level programming languages
Object-oriented programming languages
Programming languages created in 2003
Prototype-based programming languages
Scripting languages
Text-oriented programming languages
Robot programming languages