CURRENT ISSUE Contests

bottom corner

Feature Article





Issue #212 March 2008

Robotics with Ada95
by Daniel Ramirez

Start | Why Use Ada95 For Robotics? | GNAT Ada95 Tools | Debugging Ada95 Applications | Ada95 Coding Style |Wireless Sensor Controller | Wireless Messages | The Glove In Action | XYZ Accelerometers | XBee-PRO Wireless UART | Controller Range | USB 2.0 Interface | Ethernet | The Kernel | Ada95 vs. Other Languages | Future Applications | Sources & PDF

Ada95 VS. OTHER LANGUAGES

C and other languages allow great flexibility when assigning variables of any type, including automatic promotion of types (i.e., the char type can be assigned to an int type variable with no errors issued from the C compiler). But doing these kinds of operations can lead to runtime errors and system crashes usually caused by unhandled exceptions such as divisions by zero, overflow, underflow, and the square root of negative numbers. In addition, C pointers are even more troublesome when they point to invalid addresses that can cause data to be overwritten (boundary problems).

Other features of Ada that make it an excellent candidate for a robotics language are the multitasking and multiprocessing support that is directly built into it using tasks, a rendezvous mechanism, interrupts, priorities, protected records, and a deterministic scheduler. Ada tasks provide a mechanism for the parallel execution of applications that map well to robotics hardware (e.g., being able to read and process sensors while simultaneously having a servo task update servo positions). This programming feat can be accomplished in Ada while not having to resort to semaphores or unnecessary system calls. In my application, I can collect telemetry from the Gilbert III Explorer using a sensor collection task. I can then display the collected data on a laptop using a real-time display task, while also polling the joystick and keyboard for operator input.

Best of all, the GNAT Ada95 tool suite is free. It has already been paid for by U.S. tax payers. A new release of Ada 2005 is already going through the ISO approval process and I hope the GNAT 2005 tools will also be available at no cost to the user. The tool suite includes a graphical user interface (IDE), a GNU Ada95 compiler/translator, and GNU C++. In addition, a debugger (gvd) or (gdb) is also available and directly executes from the IDE. Even non-Windows users can take advantage of programming in Ada95 because it also runs in UNIX and LynxOS.

Libraries for accessing the serial port (COM) and the graphics display are also available. There is even a TCP/IP library available that enables Ethernet programming (UDP datagrams), Windows sockets, and more.

Ada95 variable attributes include ranges, types, and subtypes, which provide the basic data types used to increase software safety and reliability. Because range checking or limit checking is performed automatically during the execution of an application by the Ada95 runtime, if variables exceed their predefined limits or ranges, they will generate an Ada95 exception. The exception can be handled by the local package, procedure, or function or propagated to a higher level or handled by the software designer. Other runtime errors that can generate Ada95 exceptions include file I/O errors, invalid user input, math overflow, math underflow, and more. Each of the conditions can be addressed with its own error handler. An example of an Ada95 exception handler is shown in Listing 1. When the handler traps a runtime error, it can either process it or propagate it to the calling routine. It will also display the actual error message and line number where it occurred.

By thoughtfully specifying the minimum, maximum, and nominal values for each variable and giving them their own type or subtype and range values, the software designer adds a level of confidence and increases the reliability of the embedded Ada95 application. The techniques are not limited just to Ada95, because C++, Jovial, and Visual Basic have similar features, although they are not as convenient to code because variable attributes may not be available in some of these languages. Refer to Listing 2 for examples of Ada95 types, subtypes, and ranges.

As a BASIC and C programmer, I love being able to assign one variable to another, regardless of their types and whether it makes any sense. I am guilty of this, and it can lead to severe runtime errors that can cause applications to crash when one variable overwrites another’s space. Arrays are particularly susceptible to the errors when the array index exceeds the array limits. C++ and Java support typing and exception handling (try, catch, and throw). Limit checks can be implemented in any language, although they add some overhead. In Ada95, an exception raised is equivalent to the C++ throw keyword:

raise SENSOR_READ_ERROR;

Variable types are easily converted from one type to another by retyping them (X := float(I);) as long as the retyped variable being assigned is large enough to hold the information. In this case, X is a 32-bit float and I is a 32-bit integer, so there is not a problem with the assignment. Refer to the Circuit Cellar FTP site for an example of an Ada95 exception handler.

Previous | Next

 


bottom corner