Ada/Mindstorms 3.0: A Computational Environment for

Introductory Robotics and Programming

Barry Fagin

Department of Computer Science

US Air Force Academy

Colorado Springs, CO





The possibilities of robots in the classroom have intrigued educators for as long as robots have been a part of our culture.  Economic constraints, however, demanded patience on our part:  robots were initially too expensive and too difficult to work with for large-scale classroom use.  Initial attempts to capitalize on robots as teaching tools had to instead rely on software models:  the use of physical devices was simply not possible [1].


Over time, however, technology  becomes better, cheaper, and easier to use.  If we are patient, devices originally suited only for research labs and highly trained specialists may become cheap enough and user-friendly enough for classroom use.  We believe this is now the case with robots.


One well known example of affordable, mass-produced robotic technology is the Lego Mindstorms1 RCX programmable “brick” and associated hardware, shown in Figures 1 and 2.  The brick is a wallet-sized plastic block built around a Hitachi microcontroller, with an infra-red port, input and output ports, and an LCD display.  The support hardware includes wheels, wires, gears, and hundreds of building pieces.



The microcontroller inside the RCX can be programmed through the I/R port, making possible the construction of autonomous robots with fairly sophisticated behavior.  This suggests that the RCX and similar systems might be used to teach basic programming and robotics principles.  Many educators are enthusiastically exploring this possibility [2], [3], [4].


This paper describes one effort in this area:  Ada/Mindstorms 3.0, a software environment for teaching using the Mindstorms RCX kit.  We discuss the design choices made, the reasons for those decisions, and show examples of how the system works. Ada/Mindstorms has been used in computing classes at the Air Force Academy and around the world, and is freely available online.




The Lego Mindstorms kit comes with its own PC-based software development environment, shown in Figure 3.  It is a thoughtfully designed visual programming language, well suited for teaching bright children basic programming and robotics principles.


Unfortunately, this environment possesses many deficiencies that make it unsuitable for teaching more sophisticated concepts.  Subroutines cannot have parameters, for example, and variables are not supported.  To remedy this and other deficiencies, a knowledgeable Lego user community has emerged with many alternative Mindstorms programming environments2.


One of  the best known of these is Dave Baum’s Not Quite C, or NQC [6].  NQC makes high-level language programming possible on the RCX, with support for variables, subroutines with parameters, and low-level access to the underlying hardware.

NQC, however, is designed for experienced programmers.  Several aspects of NQC make it a poor first computing language, including relatively unsophisticated error messages and a command-line development environment.  Our goal was to construct a system that would a) leverage the existing hardware of the RCX, b) leverage the existing software knowledge of the Mindstorms community, so that we would not have to develop low-level RCX tools, c) support the teaching of sophisticated computing principles, and d) provide a high-quality development environment suitable for a student’s first exposure to computing and robotics.  The result was Ada/Mindstorms.




The technical framework of Ada/Mindstorms is shown in Figure 4.  Programs are written in an Ada subset plus an API of Mindstorms-specific function calls.  They are then compiled with the Ada/Mindstorms compiler.  This compiler is a fully validated Ada compiler, with additional logic to check that the student’s program uses only those constructs supported by the Ada/Mindstorms subset.  These constructs are necessarily much smaller than the full Ada language, due to both Ada’s considerable expressive power and the RCX’s hardware limitations.


One deficiency of many robotics programming environments is the lack of simulation capabilities.  Most educational institutions cannot permit students to take the robotics kits back to their rooms to experiment, removing a potentially valuable learning opportunity.  We felt this particularly keenly in our classroom efforts with Ada/Mindstorms 2.0, which had no simulation capability.  Release 3.0 addresses this problem by providing two execution paths:  simulation and hardware.


If the user’s program is a valid Ada/Mindstorms program, the compiler will produce 2 files:  an Ada linkable file (ALI)  for simulation, and an NQC file for the hardware. The ALI file is a conventional Ada object file, in which the Ada/Mindstorms API calls point to externally defined routines for an RCX simulator bundled with Ada/Mindstorms 3.0.  When built for simulation, the simulator libraries are linked with the user’s program to produce an executable file that displays the behavior of the RCX brick as the program is running.


If execution on an actual RCX is desired, the “build” button invokes NQC on the .nqc file produced by the compiler  (NQC is also bundled with Ada/Mindstorms 3.0).  It compiles the .nqc text file it into RCX byte codes, and downloads them into the RCX.  In simulation build mode, the .nqc file is ignored.  In hardware execution mode, the .ali file is ignored.  The current build mode is set by the user.


Figure 5 shows Ada/Mindstorms in use.  When built for simulation, a model of the RCX brick appears as shown in Figure 6.  The model displays in real time the values of the outputs (such as motor direction and power level), and permits the user to enter different inputs appropriate to current sensor configurations.  The bottom lines of the screen shot in Figure 7 show the process for downloading actual code into a robot.  If the program is valid, the compiler downloads the translated bytecodes through the RCX I/R transmitter and reports when the transmission has completed.





The Air Force Academy is a 4-year nationally accredited undergraduate institution, charged with producing men and women who will serve as officers in the US Air Force.  All graduates receive a Bachelor of Science degree, in a major subject area of their choosing.  Upon graduation, cadets are commissioned as 2nd lieutenants.  All incur a 5-year service commitment when they graduate, but most remain in the Air Force for a full 20 years of service.


The Academy has an extensive core curriculum, with required courses in almost every subject area.  Accordingly, all cadets (approximately 1,000 in each class) take a required computer science course in either their freshman or sophomore year.  This course is mandatory for both majors and non-majors, and is thus different from “CS1” offerings at civilian institutions.


We used Ada/Mindstorms in several sections of this course during the 2000-2001 academic year3, each with approximately 20 students (see Figure 8).  The instructional laboratory consists of networked PC’s with Ada/Mindstorms, 1 Mindstorms kit for every 2 students, and 1 kit for every instructor teaching a robotics section.


The goal of the Academy’s basic computing science course is to impart a strong core competency in all aspects of computing for all future Air Force officers.   This competency includes programming skills.  Our experience indicates that robotics and Ada/Mindstorms can be used to teach many basic computing and control concepts in new and interesting ways.  We show some examples below.  These are taken from actual programming assignments given to freshman cadets at the Academy.


Sequential Control Flow


Sequential control flow is easy to demonstrate with a robot.  Any series of commands long enough to appear as a connected list of instructions is very effective.  Here is a fragment of Ada/Mindstorms code that gets a robot with two motors (connected to RCX outputs A and C) to move forward for 2 seconds, play a sound, go forward again for 1 second, and stop.  Note that the semantics of the “Output_On” routines start the motors running and then move execution to the next statement.


--sequential control flow example

Output_On_For(Output => Output_A,   

   Hundredths_Of_A_Second => 200);

Output_On_For(Output => Output_C,

   Hundredths_Of_A_Second => 200);

Play_Sound(Sound_To_Play => Up);

Output_On_For(Output => Output_A,

   Hundredths_Of_A_Second => 100);

Output_On_For(Output =>


      => 100);

Output_Off(Output => Output_A);

Output_Off(Output => Output_C);


The sequence of robot actions matches the sequential progression of code on the page.  This provides an experiential encounter with sequential control flow, and offers a refreshing alternative to more traditional sequential examples that, for example, accept a number from the user, go through a series of calculations, and produce a final number on the screen.


 Variables and Constants


Variables can be taught experientially by having a robot work with a quantity that changes while it is running.  Below is an Ada/Mindstorms code fragment that does just that, used in a laboratory that accompanies students’ first lessons on variables. The quantity changed is the distance a robot travels, to give the student a visual analog for a variable and to see how changes in its value affect behavior.


--an integer variable

Time_Forward : Integer := 500;     


Output_On_For(Output => Output_A,   Hundredths_Of_A_Second


Output_On_For(Output =>       Output_C,Hundredths_Of_A_Second    

      => Time_Forward);

Time_Forward := Time_Forward*3/4;


--now the robot goes forward for ¾ as long

Output_On_For(Output =>       Output_A,Hundredths_Of_A_Second    

      => Time_Forward);

Output_On_For(Output =>       Output_C,Hundredths_Of_A_Second    

      => Time_Forward);


Constants, of course, are quantities that do not change while the program is running.  The code below shows how to get a robot to make a 90° turn.  This is accomplished by turning one motor on, and either leaving the other motor off or rotating it in the opposite direction for a specific amount of time.  The amount of time required for an accurate right turn is represented as a constant:


Turn_Duration : constant integer :=


Output_On(Output => Output_A);

Output_Off(Output => Output_C);

Wait(Hundredths_Of_A_Second =>


Output_On(Output => Output_C);


The need to “fine tune” the value of the constant  to get a good 90° turn for different robots and different surfaces illustrates another purpose of named constants in programs:  maintainability and ease of modification.




Robotics provide a very natural way to teach procedures:  a procedure is a task you want your robot to do. Accordingly, when students are assigned a robot behavior that requires a series of smaller tasks, they see very quickly that these subtasks should be written as procedures.  For example, the previous example can be encapsulated into a “Turn_Right” procedure that can be used in later assignments as robot behavior becomes more complex:


Turn_Duration : constant integer := 250;

procedure Turn_Right is


  Output_On(Output => Output_A);

  Output_Off(Output => Output_C);

  Wait(Hundredths_Of_A_Second => Turn_Duration);

  Output_On(Output => Output_C);

end Turn_Right;


Reaction to External Inputs


What makes robots interesting, of course, is their ability to react to their environment.

Mindstorms robots can receive input in a variety of forms, including light intensity, temperature, and a pulse when an input sensor is pressed.  The latter approach is demonstrated below.  Students were given a two-motor robot equipped with a bumper that sets an input sensor to 1 when pressed.  The robot was then tasked to engage in a specific behavior when it bumps into something:


if Get_Sensor_Value(Sensor =>

   Sensor_1) = 1  then


--code for desired behavior here



A logical choice for the desired behavior is backing up, turning, and going forward again. The power of decision making in computing can be dramatically illustrated by downloading one program that causes a robot to blindly stumble into a wall, and then another that has it back up and scurry elsewhere.




The addition of array support to recent releases of NQC permitted us to include similar support in Ada/Mindstorms.  This gives the robots considerable power for data collection and emulation.  The ability to support arrays can be used, among other things, to write programs for robot learning.  For example, the code fragment below is from a laboratory exercise where students store a vector of numbers in the robot through a series of button presses.  The robot then iterates through the array and follows the commands it finds there.


-- Accept course programming

for Index in 1..Max_Index loop

   Get_Touch_Count(Touches =>


   Turns(Index) := Turn_Value;

   Num_Points := Num_Points + 1;

   exit when Turn_Value >        

   Turn_Around or Turn_Value <= 0;

end loop;


-- Execute programmed course

for Index2 in 1..Num_Points loop

   Turn_Value := Turns(Index2);

   Beep_A_Digit(Digit =>



      => 50);

   if Turn_Value = Forward then


   elsif Turn_Value =  Right then

      Facing_Turn(Direction =>               Right,Time =>



   elsif Turn_Value =  Left then

      Facing_Turn(Direction =>

         Left, Time =>


   elsif Turn_Value = Turn_Around   


      Facing_Turn(Direction =>

         Right, Time =>

            Turn_90_Duration * 2);




   end if;


   Go_Forward(Time => 100);


   end loop;


Students are thus able to give robots not just the ability to follow a sequence of commands, but to follow *any* sequence of commands.  They write what is essentially an interpreter for a robotic programming language that executes on a robot.  We believe this is an impressive achievement for beginning programmers, particularly for students who will never take another computer science course.


Other features supported but not described here include iteration, message transmission and receipt with other RCX’s through the I/R port, and sound.




We believe our efforts to produce a system for using robots in the classroom as a teaching tool were quite successful:  all our design objectives were met, and the software functions very well.  Students enjoy working with robots, and instructors enjoy teaching them. 


However, robots are not a solution to every problem.  Some concepts work well with robots, others do not.  The I/O facilities for the RCX, for example, are quite primitive.  Graphics are nonexistent, and problems that require any but the most trivial arithmetic calculations are better suited to other platforms.  These are not indictments of robots per se, but rather reflect the economic considerations that went into the design of the RCX.  As the technology continues to advance, perhaps we will see mass-produced affordable robots with more sophisticated I/O, a more powerful CPU, support for floating point arithmetic, and so on.  Such devices would further enrich the classroom experience.


There are many features planned for future releases of Ada/Mindstorms, including support for tasking, separate compilation, and the addition of a 2-d virtual “world” to the simulator that would permit the simulation of actual robot designs in target environments.  Lego has recently added support for image processing with a small Mindstorms camera, suggesting many exciting possibilities for classroom robotics experiments.


Readers interested in learning more about Ada/Mindstorms are invited  to scan the bibliography. Ada/Mindstorms requires a PC running Windows and the standard Lego Mindstorms robotics kit.  It is available free of charge from  The software includes the AdaGIDE freeware Ada compiler, all supporting Ada/Mindstorms software, and NQC.


Support for this work has been provided by the USAF Institute for Information Technology and Applications, whose support is gratefully acknowledged.




[1]  R.E. Pattis, Karel the Robot:  A Gentle Introduction to the Art Of Programming, 2nd ed., Wiley 1981.


[2] U. Wolz, “Teaching design and project management with lego RCX robots,” in Proc. SIGCSE ’01,  2001, p. 95.


[3] R. Harlan et. al. “The khepera robot and the kRobot class:  a platform for introducing robotics in the undergraduate curriculum,” in Proc. SIGCSE ’01,  2001, p. 105.


[4] AAAI-2001 Spring Symposium on Robotics and Education, March 2001, numerous authors.


[5] R. Beer and H. Chiel, “Using autonomous robotics to teach science and engineering”, communications of the ACM, vol. 42 no 6, pp 85-92.


[6]     D. Baum, The NQC Web site.  Available


[7] B. Fagin, “Using ada-based robotics to teach computer science ,” in Proc. ITiCSE ’00, 2000, p. 148. Available


[8] B. Fagin, “An ada interface for lego mindstorms, Ada Letters,  Volume 21 No 2, September 2000. Available


[9] B. Fagin, “Teaching basic computer science concepts with robotics using ada/mindstorms 2.0,”  in Proc. SIGAda ’01, 2001.  Available




1 Mindstorms™ and RCX™ are registered trademarks of Lego Corporation.

2 See for examples.

3 The author was on sabbatical during the 2001-2002 academic year.




Figure 1:  The Lego RCX “brick”



Figure 2:  An RCX-based Robot


Figure 3:  The RCX Programming Environment


Figure 4:  Ada/Mindstorms 3.0



Figure 5:  Creating Programs With Ada/Mindstorms 3.0



Figure 6:  Running in Simulation Mode



Figure 7:  Running in Hardware Mode





Figure 8: Using Ada/Mindstorms at USAFA