Learning Roomba: Teacher s Guide Module 5 Localization Drew Housten (dhousten@gmail.com) 1
1 Introduction Determining where a robot is in its environment is not an easy task. The problem of localization is one that researchers have been considering for many years. There are many approaches that work reasonably well but have some drawbacks. Rather than trying to have the students solve this problem, the Module will introduce the topic, several of the approaches, and how the approaches can be used to support the robot programs. A relatively simple and inexpensive approach using a fixed-position camera is provided as a way for the students to write programs that need to know where the Roomba is located. The Module describes how to set up the camera and localization service and how to write programs using that positional information. 2 Educational Merit This Module is used as a sneak-peek of one of the problems robotics researchers are currently trying to solve. To that end, this Module is more valuable as a way to get students excited or aware of some of the real tasks that a career in robotics, engineering, or computer science would involve. It also introduces the ability to use available services to make programs more capable. There are plenty of resources available on this topic for the especially excited or interested students. The principles of the fixed-camera localization section is intended for an older audience. It includes discussions of graphs, algorithms, and image tracking. This would be a good opportunity to tie in geometry and trigonometry principles and the reason that they are useful in real-world situations. For middle-school students, this section can simply be skipped. 3 Topics Covered The following topics are covered by this Module: What is localization? Why is localization important? Why is localization hard? Some approaches Using the Fixed-Camera Localization Exercises 2
4 Running the Camera Localization Service This Module uses the Camera Localization Service, which is provided as part of the Roomba Network toolkit. On the services starter GUI (where you start a Roomba service - See Figure 1), there are two services that now need to be started: the Color Finder Service and the Camera Localization Service. Figure 1: Services Starter GUI 4.1 Color Finder Service The Color Finder Service finds an object in an image after the service is calibrated. To start the service, click the Start button next to the Color Finder label. The configuration window will appear (See Figure 2). Give the service a name, select a camera to use, and click the Start button. Figure 2: Color Finder Service Configuration GUI The Color Finder calibration GUI will appear (See Figure 3). The service needs to know what to track. To tell it this information, click on the Add Track button and then click on the object in the image. A track information window will appear (See Figure 4) where you can enter the name of the track. Once you click the Ok button, the track snippet will appear on the right side of the 3
window and a small square will show on the image where the object currently is (See Figure 5). Figure 3: Color Finder Service Calibration GUI Figure 4: Color Finder Track Configuration GUI Figure 5: Color Finder Service Calibration GUI after a track has been added 4.2 Camera Localization Service The Camera Localization Service localizes the Roomba given the Roomba s odometry readings and the tracked position of the Roomba in the camera images. To start the service, click the Start button next to the Camera Localization label. The configuration window will appear (See Figure 6). Enter the 4
name of the Roomba used when creating the Roomba Service and the name of the Image Track specified when calibrating the Color Finder GUI. Once those fields have been entered, click the Start button and the Camera Localization will be enabled. Figure 6: Camera Localization Service Configuration GUI 5 Exercise Solutions Exercise 1 Program: This program will have the Roomba drive forward until a virtual wall is detected. Once the wall is detected, the Roomba will stop and the program will print the localized position. import roomba. roombanetwork. s e r v i c e s. u s e r s e r v i c e. ; public c l a s s MyRoombaProgram{ public static void main ( S t r i n g [ ] args ){ U s e r S e r v i c e. s etserveraddress ( l o c a l h o s t ) ; U s e r S e r v i c e. setname ( Your Name ) ; Roomba roomba = new Roomba ( ) ; roomba. forwardspeed (. 3 ) ; roomba. waitforvirtualwall ( ) ; roomba. forwardspeed ( 0 ) ; try{ Thread. s l e e p ( 1 0 0 0 ) ; catch ( Exception e ){ System. out. p r i n t l n ( X P o s i t i o n : + roomba. getlocalizedx ( ) ) ; System. out. p r i n t l n ( Y P o s i t i o n : + roomba. getlocalizedy ( ) ) ; 5
Exercise 2 Program: This program will have the Roomba drive in a 1 meter square 10 times. It will print the odometry position and the localized position continuously every 1 second. import roomba. roombanetwork. s e r v i c e s. u s e r s e r v i c e. ; public c l a s s MyRoombaProgram{ public static void main ( S t r i n g [ ] args ){ U s e r S e r v i c e. s etserveraddress ( l o c a l h o s t ) ; U s e r S e r v i c e. setname ( Your Name ) ; Roomba roomba = new Roomba ( ) ; for ( int i =0; i <40; i ++){ roomba. d r i v e ( 1 ) ; roomba. turn ( 9 0 ) ; while ( true ){ System. out. p r i n t l n ( X Odometry P o s i t i o n : + roomba. getodometryx ( ) ) ; System. out. p r i n t l n ( Y Odometry P o s i t i o n : + roomba. getodometryy ( ) ) ; System. out. p r i n t l n ( X L o c a l i z e d P o s i t i o n : + roomba. getlocalizedx ( ) ) ; System. out. p r i n t l n ( Y L o c a l i z e d P o s i t i o n : + roomba. getlocalizedy ( ) ) ; try{ Thread. s l e e p ( 1 0 0 0 ) ; catch ( Exception e ){ 6 Homework Solutions The homework for this Module is split into two parts. In the first part, the students are asked to describe a way that the robot could get back to the start position given that it knows where it currently is. The student is further asked 6
if additional information would be helpful to solve this problem. In the second part, the student is asked to describe a way to map the location of virtual wall units given that they can detect the wall unit and the robot knows where it is. For the first part, you can get the robot s current position. Then, move forward a small amount and get the current position again. From those two positions, you can determine the robot s current heading. With the heading information, you can calculate how much you need to turn to face the initial position. Then, drive forward until you reach the initial position (assuming that there are no obstacles in the environment). If you had the heading information, the first step forward would not be necessary and you could head to the initial position directly. If there are obstacles, the problem becomes more difficult, because the robot would need to navigate around the obstacles whenever it encounters them. For the second part, build a blank grid representing the environment. Whenever the Roomba detects a virtual wall unit, record the current position and mark that grid coordinate as occupied by a wall unit. Over time, the grid will be a detailed map of all virtual wall unit locations that had been discovered. 7 Related Resources D. Housten and W. Regli. Low-Cost Localization for Educational Robotic Platforms via an External Fixed-Position Camera. AAAI AI Education Colloquium, 2008. A paper written by the same author as these Modules discussing the fixed camera localization method in much more detail. M. Matarić. Robotics Primer. MIT Press, 2007. Chapter 19 of Robotics Primer briefly discusses localization and mapping techniques. S.J. Russell and P. Norvig. Artificial intelligence: a modern approach. Prentice-Hall, Inc. Upper Saddle River, NJ, USA, 1995. Artificial intelligence: a modern approach provides additional background on search techniques used in the fixed camera localization algorithm. R.R. Murphy. Introduction to Ai Robotics. MIT Press, 2000. 7
Introduction to Ai Robotics provides some additional background material on localization approaches. 8