Palm OS Based Autonomous Robot Controller For the Micro Mouse Autonomous Robot Using the Palm M125 Undergraduate Senior Project by: Jimmy Moore San
Diego State University May
19, 2003
Computer
Engineering 490A & B
Project Advisor: John Kennedy
Abstract
Many of the devices that we encounter in our daily lives contain embedded control systems. Every time that you press a button, something has to respond with an appropriate output. Automobiles, televisions, elevators, even modern washing machines must contain a control system that processes user input from some type of interface of push-buttons or sensors. These embedded control systems must contain a minimum of a processor, a memory device, and the ability to communicate with the device that is being controlled as well as the user or operator of the device. A personal digital assistant (PDA) contains all of theses features and more. Therefore, the PDA can be a low cost, self-contained control system capable of being incorporated into many devices.
In the development of the Micro Mouse autonomous robot that will be discussed in this report, the initial design team decided to use a personal digital assistant (PDA) as the system control unit. A personal digital assistant (PDA) contains all of the components necessary to handle operation of many devices. The purpose of this project, specifically, was to design search algorithms and execute these algorithms on a PDA in such a manner as to control a robot capable of competing in the Micro Mouse competition described below. For further information on design considerations of the robot chassis, please refer to the report titled Micro Mouse Control System, December 24, 2002 by Raied Salem, on file in the Senior Project Lab, room E217, San Diego State University College of Engineering.
Micro Mouse is an annual competition sponsored by the Institute of Electrical and Electronic Engineers. Design teams build robots with the ability to solve a maze in much the same way that a mouse will find its way through a maze to reach a piece of cheese. The strategy of the contest is to map the entire maze and determine the fastest route from the starting point to the destination. The winner is the robot that is able to complete a trip from start to destination in the shortest amount of time. While each team’s robot is allowed a total time of 10 minutes in the maze, each time the robot leaves the starting element a new timed run will begin in order to record the time of that trip to the destination.
The maze is comprised of a two dimensional array of squares. Each square, or element, of the array is 18x18 centimeters. The full maze is 16x16 elements. The points within the maze where the corners of elements come together are referred to as lattice points. Each lattice point will contain the end of at least one wall, except for the center or destination point. The destination will be four adjacent elements arranged in a square with no internal walls and will be the four elements at the center of the maze. Also, the starting point will be on one of the four corners of the maze and will be bounded by walls on three sides. This is all of the maze data necessary for this project. For full details, refer to Appendix A.
For the scope of this project, the main requirement of the robot that must be considered is that it must be completely autonomous, no external communication of any kind during the contest. The only exceptions are that minor adjustments may be made when the robot is within the starting element, such as using switches to change operational settings. Full details of robot design specifications may be found in Appendix A.
The robot that this control system is being designed for will have a minimum of four sensors. Three of these are to be used to detect walls in front or to either side of the robot. No such sensor is required on the back since the robot does not have to travel in the reverse direction. This operation may be achieved by the control system by directing the robot to turn 180o and traveling forward. By eliminating the need for a sensor on the back of the robot, cost was reduced by the price of the sensor as well as the extra data recording and processing that would be required by the sensor. The fourth sensor that is needed is a device that will measure distances traveled by the robot. Presumably, this sensor will be of the type used in an optical mouse and will be located in the bottom of the robot. By locating the sensor off of the center point of the chassis, it may also be used to measure the rotation of the robot while turning and to insure that the robot is traveling in a straight line.
The system designed by Raied Salem contains all of the necessary sensors, as well as implementation of a Field Programmable Gate Array (FPGA) to interface between the robot’s sensors/motor controller and the system being designed in this project. The embedded system to be designed here must be able to read the sensor values output from the FPGA and return the appropriate directional commands to the FPGA, which will control the motors. All processing of optical sensor feedback to maintain proper direction of travel will be handled by the FPGA.
Programming Language All software for this project was developed in the C programming language. Since the programs must be implemented to operate on a PDA, a language that could be easily converted for a PDA development environment was necessary. The C language met this requirement as well as being a language that is widely used by students in the San Diego State University engineering department.
Representing the Maze Map Due to the limited size of the maze to be mapped, the maze may be represented very simply as a two dimensional array of C structures. Commonly referred to as structs, structures are an aggregate data type that may be defined to hold several variables of different data types. In the beginning, each element was mapped as a struct that contained boolean values to record the condition of each wall. Either a wall existed or did not exist, represented as the wall being true or false. As it became necessary to record more information in the map, such as whether or not the element is part of a desired path or how many times the robot has visited an element, more variable were added to the structs.
Decisions After the control system has recorded the current surroundings of the robot, a decision must be made on which direction to travel. Since all accessible elements of the array should be mapped in order to assure that all possible routes have been found, the most important consideration in moving through the maze is to attempt to travel to areas that have not yet been mapped. This called for the addition of an integer variable to each struct of the map that is incremented each time the robot enters the element. The values held in these variables for each accessible element from the current location can then be compared and the robot will be directed to the one with the smallest value. So, if the maze conditions are such that the robot may move to either the left or right, the decision will be made to move to the one that has been visited the fewer number of times. Default conditions exist in case the elements have been visited an equal number of times.
The function “NextStep()” will determine what direction to move. The function first determines which direction the robot is currently facing. This value is stored in a global variable and is changed each time the robot must change directions. If the wall in front of the robot is open and has never been visited, the robot will proceed forward. If the element in front has been visited, each side is check for accessibility and a lesser number of visits. If the element in front is not accessible, the element to each side is checked for accessibility and the fewest number of visits.
Eliminating Dead-Ends When the robot has reached a dead-end, the elements in front and on each side are not accessible, the element is made inaccessible to further movement and eliminated from the maze. Upon finding this condition, the global boolean variable “backtrack” is set to true and the function “CheckWalls()” is called. This function rotates the robot 180o and moves it back to the previous element. The walls of the element on the end are set to true within the struct and the wall that is currently behind the robot is also set to true. Once this is done, the robot will no longer see the element as accessible when reading from the map array and will not enter it again. The function “CountWalls()” is now called to see if the dead- end condition still exists. If an integer value of three is returned, the same operation describe above will be repeated without the rotation. This process will continue until “CountWalls()” returns a value of less than 3. Then, “backtrack” is set to “false” and “NextStep()” is called to continue mapping.
Marking The Destination After every step, or movement from one element to an adjacent element, the robot takes, “CheckDest()” is called to determine if the destination has been reached. Since the destination is always in the center of the maze, it is possible to find that the center has been reached by checking for current coordinates of (7,7), (7,8), (8,7), or (8,8). Once the robot has successfully entered any one of these elements, the destination has been found and a global boolean variable “dest” is set to “true”.
Completion of Mapping When the robot has returned to the starting element, and the “dest” value is “true”, the map is complete. (This condition is true using the current algorithm and one useable path from start to destination. More intelligence is required for multiple paths to be properly mapped.)
At this point in the project, it became necessary to run tests to verify that the algorithms that had been developed up to this point would actually work. But, as is often found in multi-layered projects with different engineers working on different layers, the robot did not exist and testing could not be performed. It became necessary to create a simulator to emulate the maze and robot with sensor array. The actual maze and robot can be completed later and the software can then be modified to operate properly with the hardware.
Simulation of the maze is obvious at this point. The maze can be represented by a two dimensional array of structs just as the map has been created. The representation of the maze may consist of only the existence of each wall of each element. No further information would be determined by the sensor array of the robot so no further data needs to be recorded in the simulator for the maze.
First Stage Testing In order to test the algorithms, a single application was created that contained the maze simulation and the map as well as all of the necessary functions for mapping. The application was designed to be executed on a desktop computer. (These tests can be found on the compact disk that accompanies this report) Each time the simulated robot takes a step, the appropriate coordinate is adjusted so that the new location is the maze is represented and the next determination can be made. As the test code executes, the map of the maze is drawn to the window on the desktop computer in order to see what is being executed by the code. The maze used for simulation in this project is shown in figure 1.
Second Stage Testing The next step in the process was to separate the simulation application from the control system. The source code for each operation was separated into two separate applications that can be executed on a desktop computer. Serial communication was established between the two applications by using the WriteFile(…) and ReadFile(…) system commands. One application was written to communicate with the COM 1 serial port and the other on COM 2. The serial ports were then connected together with a null modem cable to establish a connection. At other times, the applications were executed on two separate computers, connected with a null modem cable. The WriteFile() command of the mapping application is executed on starting the application, requiring that the maze simulator be running and waiting with the ReadFile() command. The mapping application sends the X and Y coordinates of the current location of the robot to the simulator. The simulator records these values and uses the WriteFile() command to send the boolean value of the walls of the corresponding element back to the control system. The control system records these values into the map element at the current location and executes NextStep() to determine where to move next. Later, when the robot development is complete, the control system will pass commands to the FPGA of the robot to move it to the desired coordinate and the sensor outputs will be used to determine the Boolean wall conditions that will be recorded in the map.
Third Stage Testing At this point, the control system was to be adapted to be executed on a PDA. The design team selected the Palm M125. It uses Palm Operating System 4.0.1 and has a 33MHz Motorola Dragonball processor, 8 Mbytes of memory for storing/execution of the mapping application and the map array, and a serial communication port for transfer of data to and from an external device such as the robot’s FPGA. Metrowerks’ “Code Warrior for Palm OS” integrated development environment (IDE) was used for creating the application to be executed on the M125. Even the most simple of applications on the M125, or any PDA using the Palm OS, requires interaction between several system functions. By using source code written by Lonnon Foster, author of Palm OS Programming Bible, for establishing serial communication to transfer text from a PDA to an external device, many of these functions only needed to be adapted for the specific use required by this project. Once communication was established with the desktop computer, the system control functions were brought in from the desktop application to the PDA application. Functions calls were added in the proper areas of the main function of the PDA application to allow mapping to be performed, and the application was ready for testing. Code Warrior creates the equivalent of an executable file for the PDA, and that file was downloaded to the M125 through the normal synchronization process with a desktop computer. Since the M125’s primary means of connection to the desktop is through a Universal Serial Bus (USB) connection, a special cable was developed to connect to the serial port. Wiring diagrams of the cables designed for connection to the Palm 16-pin Universal Connector and a description of how the cable for this test was made are in Appendix B.
After connecting the M125 to the desktop, testing showed that the application ran in the same manner on the PDA as it had on the desktop computer. Some decrease in the speed of mapping was noted. This is believed to be caused by the slower speed of the PDA processor compared to that of the desktop. During simulations in which mapping was performed by the PDA, in situations where longer sections of code (200-300 lines) were required to determine which element to move to, the movement took noticeably more time to execute than those in which only one or two lines were required.
The control system on the M125 is now ready for adaptation and testing in a robot. The source code for the control system may be modified to include additional sensors by increasing the amount of data that is read by each ReadFile() command. Modifications must be made to process data from each sensor, as sent by the FPGA, and save data to the appropriate variable within the element struct. The reply data from the control system to the robot will probably remain at very basic level of simply instructing the robot to move to the next element.
Further development is needed in order to completely map a maze with multiple paths from start to destination as well as to determine the shortest available paths. The control system developed for this project only works adequately with one path.
It has been determined through extensive testing during the completion of this project that a Palm OS based PDA like the M125 can be used as a system controller for the Micro Mouse competition robot. Other than limited processor speed, relatively small amounts of memory, and slow data transfer through serial communication, the system is very appealing for a multitude of applications. As newer PDA’s are becoming available, faster processors and larger amounts of memory are very common in devices that are more expensive than the M125. The serial communication problem can be avoided completely by using a USB interface that operates at much higher data transfer rates. Overall, the PDA appears to have many applications in the future of electronics other than those that are currently utilized.
Competition Rules
Appendix A
MICROMOUSE CONTEST RULES
REGION 6
These rules were revised November 30, 2001 and are valid for the Spring 2002 contest. The 2001 revisions are: (1) The MicroMouse competition is intended to be a design contest, culminating the aggregate knowledge earned in a typical undergraduate degree. To support this, the participants will submit a report including a summary of the project, schematics, layout, Bill of Materials (with costs), and software code. The participants will present their design for review and answer questions from the judges prior to competing on the maze. The following rules were adapted from 1986 OFFICIAL RULES for NORTH AMERICAN MICROMOUSE CONTEST.
Wiring Diagram
Appendix B
Wiring Diagram of the Palm 16-Pin Universal Connector to a DB-9 Serial Connector
Description of Cable Construction:
Starting with a Targus USB Hotsync cable, disassemble the connector that attaches to the PDA. The pins in the connector may be pulled out of the connector block from the inside. Pins are then reinserted in the appropriate locations to connect to the 16-pin Universal Connector as desired. For this project, only pins 1, 10 and 11 are used. All others were removed from the connector. The USB connector on the opposite cable end was removed and replace with a generic DB-9 connector using only pins 2 and 3 and the shield.