AI Magazine Volume 27 Number 1 (2006) (© AAAI) Articles Using Educational to Motivate Complete AI Solutions

Lloyd Greenwald, Donovan Artz, Yogi Mehta, and Babak Shirmohammadi

■ Robotics is a remarkable domain that may be suc- (Nilsson1984) to more recent work on multia- cessfully employed in the classroom both to moti- gent systems and machine learning in vate students to tackle hard AI topics and to pro- RoboCup (Stone 2000). vide students experience applying AI represen- In addition to providing inspiration, explor- tations and algorithms to real-world problems. ing representations and This article uses two example robotics problems to illustrate these themes. We show how the ob- algorithms using robotics helps students to stacle-detection problem can motivate learning learn complete solutions. A complete solution neural networks and Bayesian networks. We also is one in which a student considers all the de- show how the robot-localization problem can mo- tails of implementing AI algorithms in a real- tivate learning how to build complete solutions world environment. These details range from based on particle filtering. Since these lessons can system design, to algorithm selection and im- be replicated on many low-cost robot platforms plementation, to behavior analysis and experi- they are accessible to a broad population of AI stu- mentation, to making the solution robust in dents. We hope that by outlining our educational the face of uncertainty. In our classes we find exercises and providing pointers to additional re- sources we can help reduce the effort expended by that robotics problems encourage students to other educators. We believe that expanding hands- investigate how AI algorithms interact with on active learning to additional AI classrooms pro- each other, with non-AI solutions, and with a vides value both to the students and to the future real-world environment. Students investigate of the field itself. how to convert sensor data into internal data structures, how to weigh the costs and benefits of physical exploration, whether or not to use rtificial intelligence has a number of offline simulation and tools, and how to deal wonderful domains that help motivate with the severe resource limitations and time Aundergraduate students to enroll in AI constraints of embedded computation. Despite courses and work hard to grasp advanced AI the added costs of building complete solutions, representations and algorithms. One particu- experience with real-world environments helps larly compelling domain is robotics. Robotics ground lessons and stimulates thinking about combines the fantasy of science fiction with new challenges and solutions. practical real-world applications and engages Although robotics has inspired research on both the imaginative and sensible sides of stu- AI representations and algorithms, until re- dents. Examples of robotics-inspired AI span cently the cost and size of these platforms has from early work on AI planning with Shakey made it difficult to convey the same line of in-

Copyright © 2006, American Association for Artificial Intelligence. All rights reserved. 0738-4602-2006 / $2.00 SPRING 2006 83 Articles

vestigation to undergraduate students. Low- neural networks or Bayesian networks and im- cost robot platforms, as surveyed earlier in this plementing the solution on a Handy Board– issue (Dodds et al. 2006), have the potential to based robot. The second theme is presented in mitigate this cost barrier. Investigators have be- the context of solving a robot-localization gun to report successful demonstrations of problem using particle filtering and imple- hands-on robotics using low-cost platforms in menting the solution on an RCX-based robot. AI courses (Greenwald and Kopena 2003; May- The projects described in this article were de- er, Weinberg, and Yu 2004, Dodds et al. 2004). signed primarily as part of a stand-alone robot- These reports, as well as the instructional mate- ics course for computer science majors. The rial on advanced AI topics in this special issue, hands-on topics covered in this course include provide critical supplements to existing texts robot structure, drive trains, sensors (infrared, and curricular material on general undergradu- photo, bump, active sonar), control (open ate artificial intelligence, engineering, and loop, closed loop), simple behaviors (obstacle computer science topics. detection, light following, obstacle avoidance), Even at low cost ($300–$600 per ), it reactive control, multiple behavior coordina- is possible to teach advanced AI with the hard- tion (algorithmic, priority-based, subsump- ware and software resources of these platforms. tion), odometry using wheel encoders, forward Low-cost platforms provide varying levels of kinematics and localization, inverse kinemat- mobility, sensors, development environments, ics, way-point navigation, simple feature detec- and processing power. Lego-based platforms tion using sonar, probabilistic localization, lo- like the RCX (Klassner 2002), or Handy Board cal and global map building, sensor fusion, (Martin 1999) are designed for flexible experi- vector field histograms, and simple path plan- mentation with mobility. Development envi- ning. For interested students this course pro- ronments include many standard program- vides hands-on experience that complements ming languages like Java, C, Pascal, Forth, and material taught in artificial intelligence courses ADA. Even Lisp is available, as detailed else- for advanced undergraduate and early graduate where in this issue of AI Magazine (Klassner students. The projects in this article have also 2006). Commonly available sensors include been used in workshops, including a recent photoresistors, infrared, touch, wheel encoders NSF-sponsored workshop for teachers learning (for odometry), and, most impressively, sonar. to use the RCX in education. Please refer to Greenwald and Kopena (2003) and Greenwald With respect to implementing advanced AI al- and Artz (2004) for further information on the gorithms, the processing power of low-cost structure and labs of this course. platforms can be problematic. At the low end, we get from 2 megahertz to 16 megahertz of central processing unit (CPU) speed and around 32 kilobytes of random-access memory Obstacle Detection with Neural (RAM). The education lessons discussed in this Networks, Bayesian Networks, article have been carefully designed to work successfully with such constrained resources. and the Handy Board We have found that these resource constraints A typical task in a robotics class is to program a often provide additional educational opportu- robot to detect and avoid obstacles. In our ro- nities to investigate AI topics like resource- bot-building lab course (Greenwald and Kope- bounded reasoning. These platforms addition- na 2003) we initially assigned this as a non-AI ally provide communications protocols so that exercise in processing noisy sensor readings. off-board processing can be included in com- We chose to use inexpensive and unreliable in- plete AI solutions. frared sensors as proximity detectors for this We have used low-cost robot platforms in exercise. In lectures we taught students stan- the classroom to teach many AI topics includ- dard methods for processing sensor data, in- ing heuristic search, planning, probabilistic cluding ambient light correction, surface re- planning, representing uncertainty, and ma- flectance calibration, thresholding, averaging, chine learning. In this article, we outline our and hysteresis. The students were later asked to classroom-tested material for teaching Bayesian use these processing methods to classify sensor networks, neural networks, and particle filter- data into one of four obstacle position states: ing. This article is organized around the two ed- left, right, center, or none. ucational themes just introduced: (1) robotics This seemingly simple exercise repeatedly problems motivate AI solutions, and (2) robotics led to frustration and failure. Students reported problems encourage complete AI solutions. The frequent invalid infrared readings in any non- first theme is presented in the context of solv- shielded application, indicating that these sen- ing a robot obstacle-detection problem using sors were useless as proximity detectors for ob-

84 AI MAGAZINE Articles stacle detection and avoidance. The following mitter while detecting the ambient light being exercise helped us determine whether the received by the IR sensor’s receiver. source of the problem was the sensors or the The IR sensor transmits infrared light away programmers, and at the same time uncovered from the robot. Reflected IR signals are received our first educational theme: robotics problems if an object is sufficiently near the sensor. The motivate AI solutions. color, surface texture, angle, and other factors We initiated a project to see whether or not affect the distance required to register reflected these sensors were actually useless. The result- IR signals in the IR sensor’s receiver. High ing project demonstrated not only that these amounts of reflected infrared light yield high inexpensive sensors could be used for obstacle signal values. If there is little or no reflected in- detection but also that their inherent unrelia- frared, the IR sensor’s receiver registers a low bility provides a practical motivation for teach- signal value. ing advanced artificial intelligence techniques The sensors are placed approximately in a for sensor processing. We describe here how to two-dimensional plane. To differentiate be- take advantage of a low-cost robot platform tween an obstacle on the robot’s left or right, with inexpensive sensors to motivate and teach the IR sensors must be placed sufficiently far the artificial intelligence topics of neural net- apart. However, these sensors cannot be placed works and Bayesian networks. too far apart, or obstacles of small width locat- We focus this section on step-by-step instruc- ed directly between the sensors will not be de- tions for using a low-cost robot platform to tected. IR sensors have a very short range in teach neural networks (including perceptrons). which they are effective at detecting obstacles We then describe how to extend and modify (our sensors operate best at approximately six this lesson to teach Bayesian networks (includ- inches from an obstacle, as we determined em- ing naive Bayesian networks). The following pirically). steps are described: (1) building the robot, (2) If the robot is moving towards an obstacle, gathering experimental data, (3) designing a early detection is critical to prevent the robot neural network, (4) implementing the neural from colliding with it. The IR sensors must also network, and (5) analyzing the results. For be placed such that they will receive reflected added educational impact, this lesson can be IR light in the robot’s path as soon as possible. preceded by non-AI approaches. This is achieved by placing the IR sensors along the front edge of the robot (assuming a mostly Step One: Building the Robot forward-moving robot). The implemented ro- The robot (depicted in figure 1) is constructed bot has its IR sensors placed six inches apart from Legos, and it uses a Handy Board as a along its leading edge. computation platform and controller for the The robot’s primary movement is forward, sensors and motors. To help others replicate and its primary method for changing direc- the educational exercises in this article we tions is pivoting. The IR sensors are each angled sketch the major components of our mobile ro- approximately 20 degrees away from the cen- bot kit in Greenwald and Artz (2004). The mo- ter. This angling allows the robot to “see” ob- tors each have their own set of gears, enabling stacles at the front corners of the robot. The them to transfer rotational power to their cor- ambient light sensors are placed 10.5 inches responding wheel. The wheels are placed on apart on flat panels that are elevated above the the left and right of the robot, giving the robot plane on which the IR sensors sit. The light a differential drive. This enables the robot to sensors point straight ahead and are not shield- move forward, backwards, turn left or right, or ed (although more accurate information might pivot left or right. The gear ratio from each mo- be obtained by shielding). tor to its wheel is 45 to 1, trading off speed for power. The head of a plastic spoon is used as a Step Two: Gathering front caster; it is glued to Lego pieces and at- Experimental Data tached so that the robot can slide stably on a Training and validation data are collected from geometric plane. a series of experiments. Each experiment con- There are four sensors connected to the ro- sists of reading samples from the robot’s sensors bot: two infrared (IR) receiver/transmitter pairs while it is placed in a static environment. The (IR sensors) and two ambient light sensors robot remains stationary during each experi- (light sensors). Each IR sensor has a light sensor ment. The data read from the sensors during an associated with it. The light sensor is intended experiment are stored internally on the robot to provide data about the amount of ambient and transferred over a serial line to a desktop light near the associated IR sensor. The light computer for processing. The raw data are then sensor is placed to avoid the IR sensor’s trans- processed into a form that can be used for train-

SPRING 2006 85 Articles

Figure 1. A Robot Used to Teach Neural Networks and Bayesian Networks. Notice the Handy Board, two forward-facing infrared sensors, and two forward-facing photocells (and a lot of tape).

ing or validating a neural network. The primary the dull surface, and a plastic-coated office programming environment for the Handy binder as the shiny surface. Board, Interactive-C, has several methods for Obstacle Distance (two states): The closer an transferring data from the robot to a desktop object is to the sensors, the greater the signal computer, including an “upload array” tool. registered by the IR sensors. We test this using The objective of each experiment is to collect two obstacle distances: near and far. In our ex- from the sensors data that represent a specific periments, near is measured as approximately state of the robot’s world. In addition to the one to two inches, and far is measured as ap- presence or absence of an obstacle, there are proximately five to six inches. several other parameters of the robot’s world Ambient Light (three states): Ambient light that affect sensor readings. For example, if a significantly affects the signal received by the bright incandescent lightbulb is shining near IR sensors’ receivers. If a lot of ambient light is the robot, the infrared sensors will receive extra present, the IR sensors will deceptively register infrared light even if no obstacle is present. In high signals. We use three states of ambient order to generate a robust neural network that light in our experiments: high, medium, and can detect obstacles in a wide range of environ- low. High light is achieved by using both the ments, it is necessary to train on data that vary overhead room lights with fluorescent light these environmental variables: bulbs and a desk light with an incandescent Obstacle Position (four states, primary para- bulb. Medium light is achieved by using only meter): The presence of an obstacle is described the fluorescent overhead lights. Low light is in one of four states: left, right, center, or none. achieved by turning off all light in the room Left indicates there is an obstacle on the left of and using a flashlight or the light of a comput- the robot (and should be detected by the left IR er monitor to conduct the experiment. No sun- sensor, and only this sensor); similarly for right. light is present in either the experiments or Center indicates there is an obstacle in front of demonstration of the robot. the robot (and should be detected by both IR There are thus 12 possible combinations of sensors). None indicates that no obstacle is pre- states for each of the obstacle positions, left, sent. right, and center, and an additional three possi- Obstacle Surface (two states): As infrared light ble states (ambient light variation) when there reflects differently off of different surfaces, we is no obstacle; for a total of 39 unique experi- use objects light in color with two different sur- ments. In each experiment, 1000 samples from faces: dull and shiny. We used a dish towel as each sensor are recorded.

86 AI MAGAZINE Articles

set is used to avoid overfitting the network to the training data. The experiments with no ob- O1 O2 state stacle in the robot’s sensor range were repeated 0 0 none 0 1 right additional times in the training and validation 1 0 left set to give them an equal weight with the ex- 1 1 center periments containing an obstacle. The number of hidden layers in the neural network and the number of neurons in each Table 1. The Interpretation of Obstacle Position hidden layer are determined by trial and error from the Neural Network’s Rounded Outputs. in our exercise. More sophisticated network de- sign methods may also be taught. The students might first attempt to solve the problem with a single layer perceptron network and then retry the exercise with hidden layers, testing whether or not this classification task is linearly We note that the two obstacles in our exper- separable. In our tests (described later on), a iments have relatively flat surfaces that are perceptron network was not as effective as one placed parallel to the robot’s front edge. The ex- with two hidden layers. perimental obstacles are not intended to model Figure 2a depicts our most successful net- any particular obstacles, but simply serve to al- work. This neural network consists of two ter the amount of light reflected in each case. hidden layers, the first with 16 nodes and the Step Three: Designing a second with 6 nodes. Mean squared error for Neural Network both the training and validation set went to ze- ro in fewer than 50 training cycles. The inputs to the neural network are: left in- frared sensor pair (LI), right infrared sensor pair Step Four: Implementing (RI), left ambient light sensor (LA), and right the Neural Network ambient light sensor (RA). Each sensor is ana- log, and the Handy Board conversion to digital Once a neural network is designed, trained, yields an integer value in the range [0, 255]. and validated on the host computer it must be Higher values indicate lower sensor readings. converted into code that runs on the robot. A For example, if there is very little ambient light, valuable feature of SNNS is its ability to auto- LA and RA should return very high values matically generate C code to implement a when sampled. For use in a neural network, neural network, through snns2c (a tool includ- each sensor input S is normalized to a floating- ed with SNNS distributions). However, the C i code generated did not compile for the version point value in the range of [0, 1]: Si = Si /255. The outputs from the neural network are ob- of Interactive C (the primary language used to stacle on left (O1) and obstacle on right (O2). program Handy Board–based ) that we Each output is a floating-point value in the use in the classroom. This is due to the large range [0, 1]. For interpretation, the outputs are memory usage and the linked list type data rounded to the closest integer value: 0 or 1. The structures used in the code generated by values of the rounded outputs yield the states snns2c. Another source of difficulty is that the described in table 1. Handy Board is not able to store and work with We experiment with fully connected, feed- large stores of floating-point numbers (though forward neural networks with varying number these problems may be alleviated as Interactive of hidden layers, trained using back propaga- C continues to improve). We developed soft- tion. ware that converts the automatically generated The activation function a(x) of each nonin- C code into legal Interactive C code. Our neur- put node is a logistic function: a(x) = 1/(1 + e–x). al network conversion software is limited to As mentioned in the previous section, the feed-forward neural networks using the logistic raw data from the robot are dumped to a host activation function, as described in this article. computer and processed into a form that can This software may be used on any SNNS-sup- be imported into standard neural network soft- ported platform. Note that since SNNS gener- ware. Any neural network software may be ates C code this exercise can be ported to many used on the host computer to design, train, and existing low-cost robot platforms. validate the network. In our experiments we To test whether or not the implemented use either JavaNNS or SNNS (Zell et al. 1992). neural network provides useful classifications We divide the experimental data into a train- of obstacles from sensor data, we downloaded ing set of 900 samples and a validation set of the resulting Interactive C code to the robot 100 samples, per experiment. The validation and incorporated it into a robot-control pro-

SPRING 2006 87 Articles

a

Obstacle Obstacle

Left Right Left Right Light Light Light Light

Left Right Left Right IR IR IR IR

bc

Figure 2. Demonstrating Robust Obstacle Detection and Classification Using Low-Cost Infrared Sensors. (a) A neural network designed to demonstrate robust obstacle detection and classification using low-cost infrared sensors. The network clas- sifies obstacle location (none, center, left, right) given left and right infrared measurements and left and right ambient light measurements. (b) A naive Bayesian network for the same classification task. (c) A Bayesian network for the same classification task, removing the assump- tion of conditional independence of sensors given the cause (obstacle).

gram. The neural network code itself is con- (as determined by the neural network code). If tained in a separate file and does not contain an obstacle is encountered on the left, the ro- any Handy Board–specific instructions. We first bot backs up and pivots right to avoid the ob- successfully tested the code in the same static stacle. If an obstacle is encountered on the environments as used for gathering experimen- right, the robot backs up and pivots left to tal data, using the LCD display to show the avoid the obstacle. If an obstacle is encoun- classification results in real time. We then test- tered in the center, the robot backs up to make ed the code by programming the robot to move some turning room and pivots 180 degrees in a straight line until it encounters an obstacle (turns around).

88 AI MAGAZINE Articles

Step Five: Analyzing the Results computationally unmanageable tables. In the Test runs of the resulting neural network con- following exercises we discretize each sensor trol code were successfully performed in a vari- signal into 10 uniformly sized bins. Teaching ety of ad hoc, indoor obstacle courses. The Bayesian network representation and inference trained neural network is effective at detecting methods using continuous valued variables objects in most tested conditions. Both moving would avoid this step. objects (hands or feet) and static objects Our Bayesian network exercises consist of (books, bags, boxes, and walls) are detected as the following ten abbreviated steps: expected. Although we did not detect any de- Step 1: Build robot (see previous section). crease in classification accuracy with robot Step 2: Gather experimental data (see previ- movement, as expected, faster-moving robots ous section). had more difficulty reacting to a detected ob- Step 3: Use the training data to build the full stacle. The robot used in this exercise is rela- joint probability distribution table over all tively slow (due to the high gear ratio), and atomic events. Although it is possible to build thus does not appear to be affected by potential the conditional probability tables directly from sensor illusions caused by movement. An inter- the data, we found it instructive to have the esting extension to this exercise would be to in- students build the full joint table and then im- clude robot speed as an input to the neural net- plement marginalization and normalization work and gather data from dynamic runs of the functions to obtain conditional distributions robot. from the joint. We empirically determined that the IR sen- Step 4: Derive (from the joint) the condition- sors used with the robot are not capable of de- al probability tables needed to complete the tecting dark obstacles. Neither a black shiny naive Bayesian network depicted in figure 2b. obstacle (a black, plastic office binder) nor a The students first try to solve the classification black dull obstacle (a black laptop bag) caused task using naive Bayesian networks before in- the sensors to register values even slightly dif- troducing more complex variable relationships. ferent from the readings taken when no obsta- Step 5: Implement the naive Bayesian classi- cle is present. Thus, dark obstacles were elimi- fication computation. nated from the experiment. In real-world Step 6: Evaluate the classification accuracy of environments including dark obstacles, the ro- the naive Bayesian network on the validation bot will need a different method for detecting set. Note that any fraction of the original data dark obstacles. Obstacles that are closer to dark may be set aside to provide separate training than light in color simply take longer to regis- and testing sets. For simplicity we used the ter as an obstacle, causing the robot to move original training set (90 percent of the data) for closer to the obstacle than expected. training and the validation set (10 percent of the data) for testing. Teaching Bayesian Networks Step 7: Derive (from the joint) the condition- We have also successfully employed the robot al probability tables needed to complete the obstacle-detection problem to motivate stu- Bayesian network depicted in figure 2c. Note dents to learn Bayesian networks. Bayesian net- that this network removes some of the condi- works may be taught as a solution to this clas- tional independence assumptions of the naive sification task by using a similar set of Bayesian network and permits the students to step-by-step instructions to that of our neural evaluate any increased classification accuracy network exercise. Steps 1 and 2 (building the due to the richer representation. robot and gathering data) are identical. In fact Step 8: Derive an equation to compute the we exploit this fact by using the data generated maximum a posteriori query for the obstacle in our neural network exercise to teach variable given the sensor variables. Implement Bayesian networks in a nonrobotics course. As this equation. specified elsewhere in this article, this data is Step 9: Evaluate the classification accuracy of freely available for others to replicate these ex- the Bayesian network on the validation set. ercises. Compare this classification accuracy to that of In our undergraduate AI course we focus on the naive Bayesian network. Bayesian networks with discrete-valued vari- Step 10: Implement stochastic sampling us- ables and discrete conditional probability ta- ing likelihood weighting to perform other bles. To adapt the neural network data for these (nonclassification) queries on the Bayesian net- exercises we had to first discretize the continu- work. ous data. We experimentally determined that Comparing the naive Bayesian network of using 4 bins per sensor variable was inadequate figure 2b and the Bayesian network of figure 2c, and using 20 bins per variable led to huge, the students learn that the Bayesian network

SPRING 2006 89 Articles

Representation Correct Accuracy (out of 7500) (classification percentage) Naive Bayes 5999 79.99 Bayes 6365 84.86 Perceptron 6200 82.66 NN (1 hidden/4) 6200 82.66 NN (1 hidden/8) 6400 85.33 NN (2/4,8) 6400 85.33

Table 2. Classification Accuracy on Discretized Data.

captures additional influences among variables bot obstacle detection provides an effective compared to the naive Bayesian network. method to motivate and teach AI solutions. These influences lead to better classification ac- curacy. Additionally, modeling the data with a Bayesian network permits the study of different Localization with Particle Filter- inference algorithms with more varied queries ing and the RCX (other than classification). Although we em- Localization is also a great problem to motivate ployed this exercise in a class without actual ro- bots, the use of data from real robot experi- AI solutions. Localization is the problem of de- ments made the task more interesting to the termining a robot’s position within a local or students. global reference frame (for example, a map). In addition to learning about different repre- Contrasted to the obstacle-detection exercise sentations for uncertainty, and differing infer- described above, localization is considered a ence algorithms for classification, students can more challenging problem in need of intelli- compare the classification accuracy of the re- gent solutions. Localization solutions of vary- sulting Bayesian and neural networks. In our ing complexity and real-world applicability ex- experiments with continuous data, the percep- ist and can be characterized (Borenstein, tron network provided a 94.66 percent accura- Everett, and Feng 1996) into either relative or cy while all variants of the multilayer neural absolute localization methods. The former cat- network achieved 100 percent classification ac- egory includes odometry (measuring wheel ro- curacy. Our experiments with discretized data tation) and inertial navigation (measuring rate show that the Bayesian network and a neural of rotation and acceleration), and the latter cat- network with at least one layer of eight hidden egory includes active beacons, artificial and nodes perform the best. Naive Bayesian net- natural landmark recognition, and map match- works and perceptron networks are slightly less ing. An educator can teach one or more of accurate. Example results using discretized data these localization techniques depending on the are summarized in table 2. Note that discretiza- platform’s capabilities and the students’ back- tion leads to many redundant training exam- ground preparation in mathematics and algo- ples for the neural network experiments. This rithms. redundancy caused only a fraction of the test- At the lowest-cost end, an educator can ing file to contain distinct values. teach localization with any platform that in- Further comparisons between Bayesian and cludes a timer and a way to record motor com- neural networks can provide student insight in- mands. Odometry or dead reckoning can then to the human readability of the resulting net- be used to figure out where a robot has traveled works, the trade-offs between continuous and with respect to a known initial pose using discretized variables, and the ability to simulta- trigonometry. However, this solution leads to neously capture both classification output and fairly inaccurate localization. Another low-cost the degree of belief in that output with method for localization includes the use of a Bayesian networks. These educational lessons ground sensor, such as a reflective optosensor, demonstrate that the real-world problem of ro- and artificial landmarks, such as black tape on

90 AI MAGAZINE Articles

wall door wall door wall

Figure 3. A Simplified Robot-Localization Problem.

a white background. At a slightly higher cost is cost using the RCX platform with a sonar prox- true odometry for localization, using a sensor imity sensor and axle-rotation sensors. Imple- that measures wheel rotation, for example a menting localization with a low-cost physical break-beam IR attached to a Handy Board or an robot challenges students to consider all the axle-rotation sensor with the RCX. These inex- details of applying an AI solution to a real- pensive sensors are sufficient for teaching kine- world problem and lets us introduce our sec- matics and inverse kinematics and provide lo- ond educational theme: robotics problems en- calization that can be reliably used for courage complete AI solutions. way-point navigation. With additional algo- Given the limited memory and processing rithmic lessons for error correction (Borenstein power of the RCX platform, and the restriction and Feng 1995), these platforms can then be of using a single proximity sensor pointed in a used to teach map building or at least simple fixed direction, we scale down the typical ro- vector field histograms (Borenstein and Koren bot-localization problem. In this exercise, we 1991). These algorithms require that the target ask the students to solve the problem depicted platform be able to compute the required equa- in figure 3, inspired from an example in Fox tions (floating-point math) efficiently (in time (2003). Similar tasks are also discussed in Rus- and space) and process the wheel-rotation mea- sell and Norvig (2003). The task is to program surements rapidly. Both the Handy Board and the robot to locate itself in a one-dimensional RCX platforms provide just enough resources map consisting of “doors” and “walls” using for these purposes. Localization solutions that Monte Carlo localization. More specifically, the require GPS (global positioning system) or laser program computes a probability distribution range-finder sensors are beyond the scope of (belief state) over possible current poses in a low-cost robot platforms. However, as we one-dimensional map, given (1) an (optional) demonstrate above for obstacle detection, we initial pose, (2) a one-dimensional map of demonstrate in this section that these expen- doors and walls with metric lengths, (3) the sive sensors can be replaced by a localization history of robot movement actions, (4) the his- solution that combines inexpensive sensors tory of robot sensor (sonar and axle) readings, and AI representations and algorithms. (5) a probabilistic movement model, and (6) a Localization can be used to motivate proba- probabilistic sensor model. bilistic AI techniques, such as particle filtering. In order to provide a complete AI solution A version of particle filtering applied to robot we ask the students to address the following localization is Monte Carlo localization (Thrun tasks: (1) build a robot that moves parallel to et al. 2001). A recent paper (Dodds et al. 2004) the wall, (2) build movement and sensor mod- describes a step-by-step approach to teaching els, and (3) implement particle filtering for be- Monte Carlo localization using a camera, a lap- lief-state updating. To help the students debug top computer, and the odometry built into the their programs we provide a simple visualiza- Evolution ER1 platform. Here we describe how tion program and communication protocol for to teach Monte Carlo localization at very low the robot to send particles to the PC host using

SPRING 2006 91 Articles

wall, at a constant distance away from the wall. A hardware solution for parallel movement is to carefully design a single drive-train robot base. This is a difficult task to engineer with Lego pieces. A combination hardware and soft- ware solution is to build a differential drive ro- bot and teach the students to program a wall- following routine. A wall-following routine uses either the sonar sensor or additional prox- imity sensors and a closed-loop control pro- gram to adjust robot orientation to maintain a fairly consistent distance from the wall. In addition to building and programming a robot that moves parallel to the wall, students design their robot base so that they can get as much useful information from wheel-rotation sensors as possible. Slippage and friction cause wheel-rotation measurements to yield poor odometry estimates. Students address these problems by observing good design principles such as building larger wheelbases to avoid ex- cess orientation errors and building castor wheels that do not bear significant weight or Figure 4. Real-Time Belief-State Visualization induce uneven frictional forces. Students also Tool Showing Initial Localization Particles. learn to limit robot speed while making orien- tation adjustments and to limit accelerations in movement. Although the purpose of this exer- cise is to understand Monte Carlo localization, the RCX communications tower. The visualiza- students learn that implementing an AI solu- tion program runs on the PC and provides a tion in the real world includes paying careful view of the belief state in real-time, as depicted attention to the non-AI components of the in figure 4. complete solution as well. AI educators and stu- dents can take advantage of the resources dis- Step One: Building the Robot cussed throughout this special issue and select The main components of the robot needed for a desirable level of time and effort to apply to- this exercise are a drive train for moving the ro- ward learning complete solutions. These re- bot parallel to the wall, axle sensors to read sources include tools for building and program- wheel rotations for use in odometry estimates, ming low-cost platforms, simulation alter- and a sonar attachment fixed to point toward natives, and robot programming abstractions. the wall. There are many sources of design op- tions for single and differential drive robots us- Step Two: Building the Models ing Lego pieces, including the attachment and The robot-localization problem is a state-track- programming of axle sensors using LEJOS (Bag- ing problem in which the values of state vari- nall 2002). LEJOS is the Java development en- ables are updated over time in response to vironment for the RCX that we use in this ex- movement actions and sensor feedback. The ercise. state variables track robot location and orienta- There are several sonar sensors designed and tion. In a global frame of reference on a two-di- sold for the RCX (Dodds et al. 2006). We select- mensional plane the variables are x-position, y- ed a low-cost sensor with a range of 30–150 position, and orientation µ. In probabilistic centimeters and an accuracy of 4–5 centime- localization we maintain probability distribu- ters. This sensor becomes difficult to use if the tions over these three variables, also called the robot is permitted to move too close to or too belief state. far away from the wall. The sensor is also prob- Localization state variables cannot be ob- lematic if readings are taken when the sensor is served directly in this exercise. They are hidden oriented more than a few degrees away from variables whose values at a given time can be perpendicular to the wall. For these reasons, estimated from the observed variables, namely students are encouraged to engineer either a sensor readings and actions. The mappings hardware or software solution so that the robot from values of observed variables to those of moves as close as possible to parallel to the hidden localization variables are noisy due to

92 AI MAGAZINE Articles

xt–1,yt–1,θt–1 xt,yt,θt xt+1,yt+1,θt+1

Pr((xt,yt,θt)|(xt–1,yt–1,θt–1), move)

Pr(sonart–1|(xt–1,yt–1,θt–1), known map)

sonart–1 sonart sonart+1

Figure 5. A Dynamic Bayesian Model for the Simplified Robot-Localization Problem.

sensing and movement noise. Modeling the re- distribution of observed changes in x, y, and µ. lationship between observed and hidden vari- If wheel rotation and odometry are employed, ables can be done using a hidden Markov mod- students will need to measure the wheel diam- el or dynamic Bayesian network, as depicted in eter, drive length, and gear ratio of their robots. figure 5. This figure differentiates the observ- The sensor model models the expected sensor able sonar sensor readings from the hidden lo- readings in different locations of the problem’s calization variables. It also depicts the two frame of reference. The sensor model depends models that students are asked to build in order on how successfully the students design a robot to implement a probabilistic localization algo- that takes sonar readings only when it is a fixed rithm, the movement model and the sensor distance from and parallel to the wall. In the model. Rather than learning particle filtering best case, in our simplified localization prob- using instructor-supplied models, implement- lem, the sensor model need only capture the ing a complete probabilistic localization solu- distribution of sonar readings when either in tion on a robot includes building models that front of a wall or in front of a door (or some- capture the movement uncertainty and sensor where in between, if necessary), Pr(sonart–1 ) = uncertainty of the students’ specific platform. wall or door|(xt–1, yt–1, µt–1), features of known The movement model models how the local- map). Note that the fixed-position sonar re- ization state variables change over time in re- moves any need for pivoting toward the wall. sponse to robot movement. We can also ignore the y-position and orienta- In a Markov model the state variables at time tion variables if wall following is implemented t are a probabilistic function of the state vari- well. ables at time t – 1 and the last movement ac- Step Three: Implementing tion, Pr((xt, yt, µt)|(xt–1, yt–1, µt–1), movement ac- tion). This model is robot-specific and varies Particle Filtering with the drivetrain design, wall-following code, Given a dynamic Bayesian network capturing and odometry implementation for a specific ro- movement and sensor models (including bot (as well as environment-specific noise). Stu- known map information), we can ask students dents can build these models through a combi- to implement any probabilistic inference algo- nation of empirical experience with issuing rithm to solve the robot-localization problem movement commands to the robot and any (see Russell and Norvig [2003] for discussion). prior knowledge of the robot motion, includ- In this exercise we ask the students to imple- ing the use of wheel-rotation sensors and ment approximate probabilistic inference us- odometry calculations. In the simplest case we ing particle filtering (that is, Monte Carlo local- assume the robot is always given a single move- ization). Particle filtering has three basic steps: ment action, such as move forward for one sec- (1) particle propagation, (2) weighing, and (3) ond, and the students empirically measure the resampling. However, to implement particle fil-

SPRING 2006 93 Articles

tering on a physical robot, students consider plete AI solutions. We show how the robot ob- additional steps to form a complete solution. stacle-detection problem can motivate learning A complete particle filtering implementation neural networks and Bayesian networks. We al- includes the following steps: (1) distribute ini- so show how the robot-localization problem tial samples over x-locations in the map; (2) can motivate learning how to build complete move robot a fixed distance (or duration)—in- solutions based on particle filtering. These clude wall following and odometry computa- lessons are demonstrated using two different tions here; (3) if end-of-course reached, reverse low-cost robot platforms and can be replicated direction and go to 2; (4) propagate particles ac- on any robot platform providing mobility, cording to movement model (be careful to deal sensing, an effective development environ- with end-of-map conditions correctly); (5) read ment and sufficient processing resources. These sonar (take several sonar readings); (6) weigh lessons are designed for low-cost platforms so particles according to sensor model; (7) resam- that they can be accessible to the broadest pop- ple particles according to weights; (8) send new ulation of AI students. belief state (particles) to PC host for visualiza- Using robotics to teach undergraduate AI is tion; and (9) calculate the variance in location time consuming. In our experience, however, across particles; if variance is small, stop the ro- we find that this effort is justified by stimulat- bot—location converged; else go to 2. ing student imagination and connecting stu- Students can experiment with the number of dents more closely to real-world applications. particles used in order to trade off accuracy for Robotics problems additionally encourage stu- real-time updating and gain experience with dents to investigate how AI solutions interact limited-memory constraints. Implementing with solutions from other fields. This article particle filtering on a low-cost robot platform and others in this special issue can help reduce really gets to the heart of these trade-offs. In the effort required for AI educators and stu- our experiments with the RCX we are able to dents to employ robotics in the classroom by store at most 125 samples in the available pointing out available resources and experi- memory (with communication protocol in ence. In our opinion, the hands-on active memory for off-board visualization). This num- learning that students gain using robotics is ber of samples is enough to repeatedly achieve worth the effort and provides value both to the successful localization in this simplified prob- student and to the future of the field itself. lem. However, we provide the following addi- While the intention of this article is to convey tional tips to help replicate this success. For ef- the educational value of robotics, the article al- ficient memory usage, locations can be so provides evidence that AI can make low-cost discretized and movements rounded to the robotics possible in many other contexts as nearest location bin. With so few particles, stu- well. For example, we show how expensive sen- dents may observe rapid convergence to wrong sors (for example, laser range finders) can be re- answers. The limited memory makes it difficult placed by a combination of inexpensive sen- to apply common solutions to misconvergence sors (for example, IR) and AI solutions. such as periodically adding additional random Tools and experimental data files described (noise) samples or redistributing existing sam- in this article (for example, obstacle detection ples during localization. Limited forms of these training and validation sets, supporting scripts, corrections can be applied, as well as taking software) are available at our web site,1 current- care to understand the sonar sensor’s response ly under the heading “Laboratory Exercises.” profile and use it to build a useful sensor mod- el. Maintaining parallel fixed-distance move- Acknowledgements ment also helps avoid problems. We thank Brian Summers for his efforts in test- We have employed this exercise successfully ing the Bayesian network exercises. We thank to teach particle filtering in the classroom us- Zachary Dodds and Jerry Weinberg for their ing the RCX. Additionally, we have presented feedback on drafts of this article. This research this exercise as a four-hour workshop to teach is sponsored in part by a National Science educators with no background in artificial in- Foundation (NSF) Instrumentation Award un- telligence how to replicate these lessons. der grant CISE-9986105. Discussion Note 1. http://www.cs.hmc.edu/roboteducation. This article uses two example robotics prob- lems to demonstrate the role of robotics in References both motivating AI solutions and providing Bagnall, B. 2002. Core LEGO MINDSTORMS Program- students experience with implementing com- ming. Upper Saddle River, NJ: Prentice Hall.

94 AI MAGAZINE Articles

Borenstein, J., and Feng, L. 1995. Correction of Sys- Thrun, S.; Fox, D.; Burgard, W.; and Dellaert, F. 2001. tematic Odometry Errors in Mobile Robots. In Pro- Robust Monte Carlo Localization for Mobile Robots. ceedings of the IEEE 1995 International Conference on Artificial Intelligence Journal 128(1-2): 99–141. Intelligent Robots and Systems (IROS ‘95). Piscataway, Zell, A.; Mache, N.; Huebner, R.; Schmalzl, M.; Som- NJ: Institute of Electrical and Electronics Engineers. mer, T.; and Korb, T. 1992. SNNS: Stuttgart Neural Net- Borenstein, J., and Koren, Y. 1991. The Vector Field work Simulator. Technical Report. Stuttgart, Germany: Histogram—Fast Obstacle Avoidance for Mobile Ro- Institute of Informatics and Information, University bots. IEEE Transactions on Robotics and of Stuttgart. 7(3): 278–288. Borenstein, J.; Everett, H. R.; and Feng, L. 1996. Where Am I? Sensors and Methods for Po- sitioning. Ann Arbor, MI: University of Michigan. Lloyd Greenwald is currently a Dodds, Z.; Greenwald, L.; Howard, A.; and Weinberg, member of technical staff at Bell J. 2006. Components, Curriculum, and Community: Labs in the Internet Research De- Robots and Robotics in Undergraduate AI Education: partment pursuing research on ad- A Survey. AI Magazine 27(1). vanced algorithms for network se- Dodds, Z.; Santana, S.; Erickson, B.; Wnuk, K.; and Fis- curity including anomaly cher, J. 2004. Teaching Robot Localization with the detection, vulnerability analysis, Evolution ER1. In Accessible Hands-on Artificial Intelli- penetration testing, wireless securi- gence and Robotics Education, ed. L. Greenwald, Z. ty, and mobile ad hoc networks. Dodds, A. Howard, S. Tejada, and J. Weinberg, 18–23. Greenwald received a Ph.D. and Sc.M. in computer Technical Report SS-04-01. Menlo Park, CA: AAAI Press. science from Brown University and a B.S.E. in com- Fox, D. 2003. Adapting the Sample Size in Particle Fil- puter science and engineering from the University of ters through KLD Sampling. International Journal of Pennsylvania. Greenwald’s robotics education contri- Robotics Research (IJRR) 22(12): 985–1004. butions were primarily pursued while he was an assis- Greenwald, L., and Artz, D. 2004. Teaching Artificial tant professor of computer science and director of the intelligence with Low-Cost Robots. In Accessible Intelligent Time-Critical Systems Lab at Drexel Uni- Hands-on Artificial Intelligence and Robotics Education, versity. He can be reached at lgreenwa@alumni. ed. L. Greenwald, Z. Dodds, A. Howard, S. Tejada, and upenn.edu. J. Weinberg, 35–40. Technical Report SS-04-01. Men- Donovan Artz is a Ph.D. student at lo Park, CA: AAAI Press. the Information Sciences Institute, Greenwald, L., and Kopena, J. 2003. Mobile Robot University of Southern California, Labs: On Achieving Educational and Research Goals and formerly a MS student in com- with Small, Low-cost Robot platforms. IEEE Robotics puter science at Drexel University. and Automation, Special Issue on Robotics in Education: His interests include knowledge An Integrated Systems Approach to Teaching 10(2): representation, multiagent sys- 25–32. tems, network security, and statisti- Klassner, F. 2006. Launching into AI’s October Sky cal machine learning. Although with Robotics and Lisp. AI Magazine 27(1). Donovan’s current work is modeling trust on the Klassner, F. 2002. A Case Study of LEGO MindStorms’ web, he is still actively involved in robotics as a men- Suitability for Artificial Intelligence and Robotics tor for a local high school club. Courses at the College Level. In Proceedings of the Yogi Mehta is pursuing a Master’s in Thirty-Third SIGCSE Technical Symposium on Computer computer science at Drexel Universi- Science Education (SIGCSE- 2002), 8–12. New York: As- ty. He is currently working at sociation for Computing Machinery. Susquehanna International Group as Martin, F. G. 1999. The Handy Board Technical Refer- a co-op (software developer). ence. Technical Report. Cambridge, MA: Media Labo- ratory, Massachusetts Institute of Technology. Mayer, G.; Weinberg, J.; and Yu, X. 2004. Teaching Babak Shirmohammadi earned a Deliberative Navigation Using the LEGO RCX and B.Sc. in computer science from Ba- Standard LEGO Components. In Accessible Hands-on ha’i Institute for Higher Education Artificial Intelligence and Robotics Education, ed. L. (BIHE) in Iran in 1998. He has Greenwald, Z. Dodds, A. Howard, S. Tejada, and J. worked in industry in various areas Weinberg, 30–34. Technical Report SS-04-01. Menlo including embedded program- Park, CA: AAAI Press. ming, automation, and robotics. Nilsson, N. 1984. Shakey the Robot. Tech Note 323. He earned his M.Sc. in computer Menlo Park, CA: AI Center, SRI International. science (AI and robotics track) Russell, S., and Norvig, P. 2003. Artificial Intelligence: from Drexel University in 2005. He is currently work- A Modern Approach, 2nd ed. Englewood Cliffs, NJ: ing as a research specialist at GRASP laboratory in the Prentice Hall. University of Pennsylvania and is also working to- Stone, P. 2000. Layered Learning in Multiagent Systems: wards his Ph.D. A Winning Approach to Robotic Soccer. Cambridge, MA: MIT Press.

SPRING 2006 95