Using
Ada-Based Robotics to Teach Computer Science
Department of Computer Science
www.rmi.net/~fagin
We present an Ada-based interface to Lego Mindstorms ™, a
programmable robotics kit that has attracted considerable attention in the
computing community. We discuss our motivations for choosing
Computer science is an intellectually demanding discipline. Much must be taught in the classroom in a short amount of time, and much of the knowledge is foundational: newer concepts require mastery of those taught before.
Accordingly, introductory computer science courses are often
frustrating for both students and faculty.
When asked to complete simple programming tasks that seem to accomplish
little, students are frustrated at the amount of work they must put in for what
seems to them little benefit. Faculty in turn are challenged by the different learning
styles of their students, and by the breakneck pace of the material.
This has led computer science faculty to
constantly experiment with new approaches to introductory computer science
courses [HP98] [UW99]. Educators are
always looking for new approaches that can a) provide a more “hands-on”
approach to computing, one that is seen as both relevant and interesting by the
student, and b) teach the same concepts more efficiently, presenting the
essential material while requiring less time for faculty to present and
students to master.
We believe that recent technological advances in the marketplace make the use of simple robotics projects a viable way to address some of these problems. We discuss our proposed system below.
Mindstorms is a product from Lego Corporation that enables
kids (and, judging from the number of web sites, many enthusiastic adults) to
construct programmable robots. The robots are built of conventional lego parts
attached to a programmable Lego brick called the RCX, which contains three
input ports and three output ports attached to a Hitachi H8/3292
microcontroller. A simple robot built around the RCX is shown in Figure
1. The RCX is the box in the center; its input ports are connected to
wires.
The kit also comes with a Windows-based visual pro-gramming environment for programming the robots you build, shown in Figure 2. The resulting code is downloaded into the RCX through an infra-red transmitter (supplied with the kit) that plugs into the PC serial port.
While the visual
programming environment provided with the RCX is perfectly adequate for its
intended market, we believe it unsuited for teaching introductory computer
science. Most of the programming tasks students are likely to encounter
when they need to use the computer to solve a problem are not likely to be
solvable with visual programming languages, nor do we see this changing in the
foreseeable future. Additionally, RCX code contains no variables.
This would substantially limit the kind of problems our students could
solve. Finally, there are considerable restrictions on subroutines in the
visual environment: you can't have subroutines (called "my
commands" in the RCX world, see Figure 2) call other subroutines, and they
cannot have arguments. Again, this seems unnecessarily restrictive for
computer science instruction.
There are many
candidates for a high level language to replace the RCX code interface.
We chose
Choosing
Once the language
was chosen, we faced different implementation choices. One possibility
was to compile
Instead, we chose
to leverage existing resources in the Mindstorms user community. There is
a C interface to Mindstorms called Not Quite C, or NQC for short, developed by
David Baum [Ba99]. Using aflex and ayacc, Ada versions of lex and yacc
developed at the University of California at Irvine, and the AdaGOOP parser
generator developed by our colleague Dr Martin Carlisle, we are building an
Ada-to-NQC translator that takes simple Ada programs (strictly speaking, an Ada
subset for Mindstorms that we will define) and converts them to their NQC
equivalents. This enables us to get the
We provide student
access to the translator through a new button on AdaGIDE, the GUI interface to
our
If translation is successful, the NQC compiler and downloader will be invoked to send the program to the student's robot.
Since our course is
a computer science course and not a robotics course, and since it is intended
for both technical and non-technical majors, we focus on the programming of the
robots and basic computer science constructs,
not the construction of the robots themselves. Basic concepts can be
illustrated with a very simple robot with two motors connected to separate
wheels and output ports, and a Mindstorms touch sensor connected to a bumper and
an input port.
Our goals are to
introduce students to basic computing ideas, including sequential control flow,
selection, iteration, input/output, arrays, graphics, procedures, and file
processing. Some of these concepts easily lend themselves to robotics, others are a better suited for a more conventional
paradigm.
Sequential control
flow is the easiest to demonstrate. Here is a simple sequential
with Lego_Package;
use Lego_Package;
procedure Sequential_Robot_Demo
is
begin
Motors_Onfwd(Outputs => Output_A + Output_B);
--can use additive notation to combine ports
Wait(Time => 20);
--Time intervals are in tenths of a second
Motors_Off(Outputs => Output_A + Output_B);
Wait(Time => 10);
Motors_Onfwd(Outputs => Output_A);
--moving left wheel causes turn to right
Wait(Time => 10);
Motors_Off(Outputs => Output_A);
end Sequential_Robot_Demo;
Selection is not too much harder, and dramatically shows students the power of decision making in a computer by giving a device the ability to react to its environment. The code below shows how to make a robot react if it runs into something by backing up, turning right for one second, and continuing:
if Sensor_1 = 1 then
--contact with the
bumper activates touch sensor
Motors_OnRev(Outputs => Output_A + Output_B);
--back up robot
Wait(Time => 10);
--for one second
Motors_Off(Outputs => Output_A);
--start the turn
Wait(Time => 10);
Motors_OnFwd(Outputs => Output_A + Output_B);
--and go forward again
end if;
Iteration can be shown with simple loop constructs.
Here is a program fragment that causes the robot to play successively higher
tones (the RCX unit comes with a built-in speaker):
for I in 1..10 loop
Play_Tone(Freq => I
* 100, Duration => 10);
Wait(Time => 10);
end loop;
The advantages of procedures for repetitive tasks can be shown in a number of ways. Here's a procedure that makes the robot turn back and forth a given number of times:
procedure Shake(Times : in
Integer) is
begin
for i in 1..Times loop
Motors_OnFwd(Outputs => Output_A);
Motors_OnRev(Outputs => Output_B);
Wait(Time => 10);
Motors_OnRev(Outputs => Output_A);
Motors_OnFwd(Outputs => Output_B);
Wait(Time => 10);
end loop;
end Shake;
Although NQC and the RCX support additional features like data logging and a simple display, it is our current belief that topics that might use those features (like file processing, I/O, and graphics) do not map particularly well to simple robotics projects. At this point, our plans are to teach these topics using conventional programming exercises.
7 Conclusions and Future Work
We have only
scratched the surface of the possibilities that Mindstorms presents for
computer science education. Much of what is described here is dictated by our
target audience of both technical and non-technical majors. If similar approaches
are taken for the standard introductory course for computer science majors,
considerably more sophisticated tasks can be attempted. Institutions that want
to try something similar, however, need to be aware of important logistical
issues, including inventory control for dozens or perhaps hundreds of
Mindstorms kits.
Nonetheless, future
work includes incorporating Mindstorms into our upper level programming
courses, where we can develop more advanced programming challenges and
demonstrate more sophisticated programming concepts like real time processing.
We also are developing a simulator for a simple robot and the
This work was
funded by a grant from the Institute for Information Technology Applications,
whose support is gratefully acknowledged.
We also gratefully acknowledge the use of the
[Ba99] Baum, The NQC web site (http://
www.enteract.com/~dbaum/nqc/)
[Fe99] Feldman, Ada as a Foundation
Programming Language, Fall 1999
[HP98]
N. Herrmann and J. Popyack, “Creating an Authentic Learning Experience in
Introductory
Programming
Courses”, ACM SIGCSE Bulletin, Vol
27, No 1, pp 199-203.
[Kn99] Knudsen, The Unofficial Guide to LEGO
MINDSTORMS Robots , O'Reilly & Associates, ISBN:
1565926927
[Le95] Levy, Computer Language Usage In CS 1: Survey
Results, September 1995 SIGCSE Bulletin, Volume
27, Number 3
[No99] Noga, The LegOS Operating System web site
(http://www.noga.de/legOS/)
[UW99]
M. Urban-Lurain and D. Weinshank, “I Do and I Understand: Mastery Model Learning for
a Large Non-Major Course”, Proceedings
of the 30th SIGCSE Technical Symposium on Computer Science Education,

Figure 1: A Simple RCX Robot

Figure 2: The
RCX Programming Environment
