Otto: A Low-Cost Robotics Platform for Research and Education by Edwin B. Olson Submitted to the Department of Electrical Engineering and Computer Science in Partial Fulfillment of the Requirements for the Degree of Master of Engineering In Electrical Engineering and Computer Science at the Massachusetts Institute of Technology May 23, 2001 Copyright 2001 by Edwin B. Olson. All rights reserved The author hereby grants to M.I.T. permission to reproduce and distribute publicly paper and electronic copies of this thesis and to grant others the right to do so. Signature of Author ………………………………………………………………………... Department of Electrical Engineering and Computer Science May 1, 2001 Certified by ………………………………………………………………………………... Lynn Andrea Stein Associate Professor of Computer Science Thesis Supervisor Accepted by ……………………………………………………………………………….. Arthur C. Smith Chairman, Department Committee on Graduate Theses Department of Electrical Engineering and Computer Science Otto: A Low-Cost Robotics Platform for Research and Education by Edwin B. Olson Submitted to the Department of Electrical Engineering and Computer Science May 23, 2001 in Partial Fulfillment of the Requirements for the Degree of Master of Engineering In Electrical Engineering and Computer Science ABSTRACT We have developed a high-performance, low-cost robotics platform named “Otto” designed for robotics researchers and educators. The platform consists of a microcontroller board as well as software development and runtime tools. Greater computational power allows more complex artificial intelligence and control algorithms to be implemented, enabling more sophisticated robot behavior. Over the course of two manufacturing runs, the platform has evolved significantly. This thesis documents the platform’s evolution, lessons learned during its design, and future planned enhancements. In addition, we taught a robotics engineering class at MIT using the Otto platform. The course and the students’ feedback on the Otto platform are also discussed. Thesis Supervisor: Lynn Andrea Stein Title: Associate Professor, Electrical Engineering and Computer Science 2 Table of Contents 1. Introduction .................................................................................................................... 7 1.1 Existing Robotics Platforms...................................................................................... 9 2. Design of a New Platform............................................................................................. 13 2.1 Computational Core ................................................................................................ 14 2.1.1 Microcontroller................................................................................................. 15 2.1.2 Memory ............................................................................................................ 16 2.1.3 Persistent Memory............................................................................................ 18 2.2 Interfaces and Extensibility..................................................................................... 19 2.2.1 Motor Control................................................................................................... 19 2.2.2 Servo Control ................................................................................................... 21 2.2.3 Power Supply ................................................................................................... 23 2.2.4 User Configurable Hardware ........................................................................... 27 2.2.5 Analog I/O........................................................................................................ 29 2.2.6 Digital I/O ........................................................................................................ 32 2.2.7 Serial Port......................................................................................................... 32 2.2.8 Expansion Connector ....................................................................................... 33 2.3 Other Design Issues................................................................................................. 33 2.3.1 Safety................................................................................................................ 34 2.3.2 Schematic Capture, Layout, Manufacturing and Assembly............................. 36 2.3.3 Hardware Comparison...................................................................................... 38 3. Software Development Environment ............................................................................ 40 3 3.1 Development of the gdbstub ................................................................................... 40 3.2. Memory Map and Code Location .......................................................................... 41 3.3 Provided Software Libraries.................................................................................... 47 3.4 Kernel ...................................................................................................................... 47 4. Mobile Autonomous Systems Laboratory (MASLab) .................................................. 50 4.1 Motivation ............................................................................................................... 50 4.2 The Challenge ......................................................................................................... 51 4.3 Class Timeline......................................................................................................... 54 4.4 Exhibition................................................................................................................ 55 4.5 Results, Future Plans and Conclusions about MASLab.......................................... 57 5. Conclusion..................................................................................................................... 58 Appendix A. Schematics ................................................................................................... 60 References ......................................................................................................................... 69 4 List of Figures Figure 1. Block diagram of Otto controller board, revision 2........................................... 13 Figure 2. PWM waveform with large duty cycle. ............................................................. 20 Figure 3. PWM waveform with small duty cycle. ............................................................ 20 Figure 4. Analog input module block diagram. ................................................................ 30 Figure 5. Sensor connector providing power and ground. ................................................ 36 Figure 6. Photograph of the Otto controller board. ........................................................... 38 Figure 7. A robot in a playing field................................................................................... 51 Figure 8. Infrared transceiver with a baffle, viewed in the infrared.................................. 53 Figure 9. A student-made robot......................................................................................... 57 List of Tables Table 1. Comparison of existing low-cost robotics platforms. ......................................... 12 Table 2. Otto board capabilities. ....................................................................................... 14 Table 3. Capabilities of the SH-2 7045 Microcontroller................................................... 16 Table 4. Analog port sampling performance..................................................................... 31 Table 5. Comparison of existing low-cost robotics platforms and the Otto board. .......... 39 Table 6. Memory map of the Otto board........................................................................... 43 5 Acknowledgements We are indebted to Hitachi Semiconductor, the MIT EECS department, and PADS Software for funding portions of our work. We would also like to thank Altera, Acroname, ISSI, Maxim, National Semiconductor, and Pulse Engineering for providing discounted or free components. This work was completed under the supervision of Professor Lynn Andrea Stein whose work is supported by the National Science Foundation under CISE Educational Innovation Grant #99-79859. Any opinions, findings, conclusions or recommendations expressed in this material are those of the author(s) and do not necessarily reflect the views of the National Science Foundation. We would also like to acknowledge the MIT undergraduate students who gave us invaluable feedback on our platform during the MASLab robotics course in January, 2001. Collaboration Note This report documents the work of two MIT students, Edwin Olson and Max Bajracharya. In this document, I will be discussing both the overall project as well as my specific contributions. I highly recommend Bajracharya’s Master’s thesis, as it is a companion to this one. 6 1. Introduction Many researchers and educators are drawn to robotic systems. For artificial intelligence researchers, robots are an excellent bridge from theory to the real world. For example, a research robot may incorporate path-planning and machine vision algorithms in order to explore an environment. Robots must also physically interact with their environment, posing interesting problems for the mechanical engineer and control systems designer. Educators are attracted to robots for two basic reasons: students find the idea of working with robots inherently appealing, and robotics provide a rich union of many disciplines which can enhance and accelerate the learning process. It is economically infeasible for everyone wanting to build a robot to develop a custom platform. Consequently, there is a need for general-purpose platforms that can be used by many people. Development of a simple platform can require man months of engineering labor, and the unit cost of manufacturing is usually exorbitant for small quantity runs. Of course, it is impossible to meet the demands of every user; a user doing stereo vision research might require an array of dedicated DSP chips, an impossible burden on a teacher working with high school students. However, many users seem to have surprisingly similar requirements, which has led to the success of several commercially available general-purpose platforms. These general-purpose platforms save users the cost and effort of developing their own platforms. In addition, the production of generalpurpose platforms can take place on a larger scale, resulting in dramatically lower unit costs. 7 After experimenting with several existing general-purpose platforms, we realized that by using modern components, we could produce a platform with superior capabilities without increasing the cost. For many of these platforms, their limited capabilities are a result of the technology available when the boards were designed—in some cases more than 10 years ago. It seemed clear that a better platform could be built with today’s technology. In 1998, we began work on a new general-purpose platform, with the goal of providing superior capabilities by leveraging modern electronics components. We began with a blank slate, unconcerned with maintaining backwards compatibility with existing platforms, but with an intense desire to mimic the simplicity and user-friendliness of the most popular existing platforms. Our goal was to provide a massive improvement in computational horsepower, memory capacity, and an enhanced ability to interface with motors, servos, and sensors. This thesis documents the design, implementation, and ongoing evolution of our new robotics platform. Our platform includes both the controller board itself and the software that runs on it. Section 1.1 summarizes many of the popular platforms used in robotics work today. The heart of this thesis, the design and implementation of the Otto controller board, is discussed in Section 2, with subsections discussing the board’s various functional modules. Section 3 is devoted to the software development environment and 8 runtime utilities, which accelerate application development. In Section 4, we describe the robotics engineering course we taught during January 2001, which used the Otto board. 1.1 Existing Robotics Platforms Several robotics platforms are currently available with widely varying capabilities. At the low-end are microcontroller chips that can be used without any additional hardware at a cost of less than $5. High-end platforms include single board computers running Linux costing thousands. Existing platforms can give a good indication of what features users need and want, so we examined several that were roughly the same price range we were targeting: several hundred dollars or less, an amount easily afforded by individuals. A few dollars can buy a simple microcontroller that can be used as a single-chip solution for robots. A good example is the Microchip PIC line, which integrates a fairly fast CPU (<5MIPS) with various combinations of timers, A/D converters, and D/A converters. Timers are immensely useful for both controlling motors and processing sensor data from devices like rotary optical encoders. A/D converters allow users to process analog voltages, which are output by many types of sensors. For these simple microcontrollers, however, memory is often a limiting factor. Robots building a map of their environment or performing other complex tasks can very easily exhaust the memory capacity of most PICs (typically <<1KB), and most models do not support adding additional external memory. 9 Other platforms add external components to a microcontroller to increase their functionality. However, because every additional component added to the board increases the size, complexity, and cost of the platform, the features offered by the microcontroller itself usually comprise the bulk of the board’s features. Additional components usually only add minor features, or make the board easier to work with (e.g., adding user-friendly connectors.) Therefore, the microcontroller at the heart of a controller board is one of the most important considerations. A minimalist robotics platform called The Cricket [1], developed at the MIT Media Lab, is barely larger than a 9V battery. Its primary component is a small PIC microcontroller. The board adds only IR communications, a pair of buttons, and header to ease interfacing to the PIC. However, its small size and extreme low cost make it an appealing platform to those developing simple devices. Programming is performed in assembly or a simplified Logo or BASIC dialect. A popular robotics platform is the Lego Mindstorms RCX Kit [2]. It has a relatively fast CPU at 16MHz, and a modest suite of on-chip peripherals including A/D converters and a few timer channels. However, the RCX module has a limiting 512 bytes of RAM, and is packaged in a way that artificially limits its total functionality to three sensor inputs and three actuator outputs. Several development environments are available, including a child-friendly graphical environment and various simplified versions of C, Logo, and other languages. 10 Widely used around MIT is the Handyboard [3] and its relative, the 6.270 Controller Board. Based on a design from around 1989 [4], the Handyboard’s feature set was limited by the technology available at the time. The CPU is a rather sluggish Motorola 68HC11 at 2MHz. The Handyboard provides an impressive set of on-board peripherals compared to the Cricket and Mindstorms RCX, and makes all of them easily accessible to the user via header connections. An easy-to-use development environment called “Interactive C” [5] is almost universally used, but since Interactive C is an interpreted language, code runs more slowly than would compiled code. The Compaq Skiff[6] is a robotics platform designed around the Compaq Personal Server platform. It has an Intel StrongArm SA110 running at up to 206MHz and 16MB of DRAM which gives it a large advantage in computational power over the platforms described above. However, the SA110 is a general-purpose microprocessor, not a microcontroller; it does not provide any features useful for robotics, requiring many components to be added externally. The resulting Skiff robotics board is extremely complex, large, and expensive. It occupies twice the circuit board area of the Handyboard, even though integrated circuits are mounted on both sides of each circuit board. The board runs Linux or NetBSD, and development can be done in virtually any standard development environment, including the GNU toolchain (C, C++) or Java. The Skiff is not commercially available. 11 Another possibility for robot developers is to use a single board computer. Many single board computers are available commercially, many with 486 or Pentium processors. Few offer built-in peripherals useful for robotics, but these can be added with expansion cards. Solutions based around general-purpose microprocessors are typically considerably more expensive than those based around microcontrollers since they require additional components to add robotics-specific features. The features of the above platforms are summarized in Table 1. While some feature categories are easily quantified (e.g., RAM capacity), other feature categories are virtually impossible to quantify (e.g., extensibility). We have therefore subjectively and qualitatively summarized several categories. While cost is usually quantifiable, two of the boards are not yet commercially available—consequently, we have loosely estimated the cost of the platforms and provided a qualitative comparison. CPU RAM Sensor Capability Motor Driving Servo Driving Extensibility Cost Cricket Microchip PIC16F84 (1 MHz) 68 bytes Poor Lego RCX Hitachi H8/3292 (16 MHz) 512 bytes Okay HandyBoard Motorola 68HC11E9 (2 MHz) 32 KB Excellent Skiff Intel SA110 (200MHz) Up to 16MB Excellent Okay Okay Excellent Excellent Poor Poor Good Excellent Okay Very Low None Moderate Excellent Moderate Good High Table 1. Comparison of existing low-cost robotics platforms. 12 2. Design of a New Platform We designed and implemented a new robotics platform to provide superior computational performance while maintaining the low-cost and easy-to-use nature of existing robotics platforms. This board would later be named the “Otto”, the name of the bus driver on the television series “The Simpsons”, but also a homophone of “autonomous”. Before examining each part of the controller board in detail, it is useful to briefly identify the major subsystems (see Figure 1). The Otto board combines a Hitachi SH-2 microcontroller that directly interfaces to 2MB of DRAM (expandable to 16MB). The board supports 23 analog inputs, seven directly into the SH-2 plus sixteen more through a 16-to-1 analog mux. A Complex Programmable Logic Device (CPLD) provides the interface to digital peripherals such as buttons and the LCD. The SH-2 also provides two serial channels. Switches (DIP and momentary) Analog Mux 16 Analog IO 7 Digital IO 16 CPLD LCD 2MB DRAM Hitachi SH-2 Motor Drivers RS-232 chargepump RS-232 Figure 1. Block diagram of Otto controller board, revision 2. 13 While other configurations are possible, the most typical configuration of the Otto controller board has capabilities below in Table 2. An asterisk denotes that the feature is planned for the next board revision. CPU Memory LCD Reconfigurable Hardware Analog Inputs Digital I/O High Current DC Motors (PWM) Servo controllers Quadrature Phase Decoders Serial Ports Hitachi SH-2 704x @ 30MHz 2-16MB DRAM 512KB of FLASH* Standard character-based LCDs supported. Altera 7128 or Xilinx FPGA* 23 16 4 channels, 2A each 6 2 2 Table 2. Otto board capabilities. 2.1 Computational Core We expect that many users will be drawn to the Otto because of its impressive computational capabilities. The computational power of the SH-2 is complemented by both volatile and persistent memory. 14 2.1.1 Microcontroller The most important design decision for a low-cost robotics platform is the selection of the microcontroller. In a low-cost platform, it is essential to keep the number of components on the circuit board at a minimum; thus, the features provided by the microcontroller itself form the bulk of the features of the whole board. We considered a large number of microcontrollers, including the Motorola 68332, Motorola 6812 (a modified version of the processor used in the HandyBoard), Hitachi H8 (used in the RCX), and the StrongArm SA110 (used in the Skiff), but ultimately settled on the Hitachi SH-2. The SH-2 is a fast RISC CPU with a rich set of on-board peripherals well suited to robotics applications. The on-board peripherals allow very simple board design; a minimalist implementation could consist of just a power supply and the SH-2. While the SH-2 represents an excellent combination of performance and built-in peripherals, our feature goals for the microcontroller board require adding external components. The capabilities of the SH-2 are summarized in Table 3. 15 Speed Architecture Instruction word On-Chip RAM DRAM controller On-Chip FLASH A/D Converter Package Serial Ports Timers 29.49 MHz 32 bit pipelined RISC, inorder single issue 16 bit, 2 register format 4 KB Up to 16MB 256 KB 10 bits x 8 channels FP-144 or FP-112 2 5 Channels (each can do several PWM outputs or a single more complex operation) Table 3. Capabilities of the SH-2 7045 Microcontroller The SH-2 7045 is available in two different packages, both of which are fine pitch surface mount variants. The chips are almost identical in functionality, except the FP-144 exports a full 32 bit data bus rather than the 16 bit data bus used by the FP-112. We elected to use the FP-112 on our first two board revisions rather than the much smaller pitch FP-144 in order to simplify assembly in the hopes that users might be able to assemble their own boards. Since both parts require professional assembly anyway, the ease of assembly is somewhat irrelevant—future versions will use the FP-144 since it allows for a higher-speed memory subsystem and therefore faster overall performance. 2.1.2 Memory The SH-2 supports both SRAM and DRAM off-chip memory. SRAMs provide significantly faster access times than DRAMs; SRAMs can provide data in a single cycle 16 whereas DRAMs typically require two or three cycles to access a random location. However, SRAM is considerably more costly than DRAM. We wished to provide megabytes of memory, which would be very costly if implemented in SRAM, so we chose to use DRAM. We included a 2MB DRAM chip, organized as 1Mx16. The SH-2 supports memory widths of 8b, 16b, and also 32b on the FP-144 part. An 8b wide memory would provide wholly inadequate performance: fetching a single instruction (16 bits) would require two memory accesses, and processing performance could not possibly reach the chip’s capacity of roughly one instruction per cycle. The 16 bit wide part we chose allows good performance on straight-line code; the SH-2 supports burst DRAM accesses, so consecutive memory locations can often be accessed in one cycle each. However, load/store operations cause significant performance hits since a total of 48 bits (16 bits of instruction plus 32 bits of data) must be transferred in a single cycle. We will combat this in the next revision of the board by using a 32b wide DRAM. Every cycle, the next two instructions can be fetched, freeing the SH-2 to begin a data memory access the next cycle if necessary. Loads and stores will still result in a processor stall, but the performance impact is minimized by a larger bus width. The SH-2 has a very small instruction cache on-die. It has a capacity of 1KB and is direct-mapped (non-associative). The instruction cache can be accessed in a single cycle, drastically improving performance compared to fetching instructions from the slow 17 DRAM. While cache hit rate statistics for the SH-2 are not available, we can estimate the hit rate based on a similar architecture’s hit rate on a similar cache. For a MIPS processor (similar to the SH-2 but with 32bit rather than 16bit instructions), a 1KB direct-mapped cache achieves a hit rate of 96.94% on SpecInt92 code [7]. We reasonably conclude that even the SH-2’s small 1KB cache can result in a significant performance improvement. However, our existing software does not enable the SH-2’s integrated cache since the cache would interfere with the operation of the debugging software (discussed in Section 3.). Future revisions of the board and debugging software will solve this problem by invalidating the cache when changes to instruction memory occur (i.e., modification of breakpoints). 2.1.3 Persistent Memory It is essential that a robotics controller board provide some form of persistent storage, so that when it is powered on it can run a basic debugging monitor or a user program. The SH-2 7045 includes 256KB of FLASH memory on-chip, which is more than enough capacity for any reasonable program (we rarely used more than 40KB for our programs). Unfortunately, the FLASH on the SH-2 is rated for “hundreds” of rewrite cycles. This means that after several hundred erase/rewrite cycles that the FLASH may not operate properly, making the board useless. It is necessary, therefore, to minimize the number of rewrite cycles performed on the SH-2. If every iteration of a user’s edit-compile-debug cycle caused an erase/rewrite cycle, a user could thus quickly “use up” the FLASH. 18 Future board revisions will add a high-endurance FLASH chip. This will allow us to write as often as we desire to the FLASH. However, our first two board revisions did not have this additional FLASH chip. We implemented a method for providing persistent storage of user programs in the SH-2’s FLASH while minimizing the number of erase/rewrite cycles. This technique, which imposes some inconvenient burdens on the user, is described in Section 3.2. An additional FLASH chip will avoid these inconveniences. 2.2 Interfaces and Extensibility Computational performance is only one aspect of the Otto controller board. The ability to interface with motors, sensors, and personal computers for programming and debugging purposes is critically important. The board and its peripherals must also be provided with electrical power, which presents certain problems and design trade-offs. In addition, we have provided several ways of extending the capability of the Otto board through expansion connectors and reconfigurable hardware. 2.2.1 Motor Control The SH-2 has extensive on-chip timer resources that can be used to generate PulseWidth-Modulation (PWM) signals. PWM is useful for controlling motors with finer resolution than simply “on” or “off”. Imagine a motor controlled by the following signal, where a high value indicates “on” and a low value indicates “off”: 19 on off time Figure 2. PWM waveform with large duty cycle. A motor driven with the above waveform is likely to rotate more slowly than if the control signal were left “on”, but it will rotate more quickly than a motor driven by: on off time Figure 3. PWM waveform with small duty cycle. The operation of a PWM generator is specified in terms of two parameters: Tpulse and Tperiod. Tpulse is the length of time that the PWM signal is high during every interval of Tperiod. The duty cycle of the PWM signal is equal to Tpulse/Tperiod. Due to the non-linear nature of an inductive motor load, the duty cycle is not linearly proportional to rotational speed. However, PWM provides an invaluable method of achieving intermediate output power levels. With PWM, users can regulate the acceleration of their robot, preventing the robot’s wheels from slipping due to a large impulse. If motor feedback is available (either through a tachometer or optical encoder), PWM can be used to implement speed control. 20 The SH-2’s PWM generators cannot directly drive high-power motors. We therefore used two dual-channel 2A full H-bridge motor driver chips, providing a total of four independent, high-current, bi-directional motor drivers. Since the motor drivers contain full H-bridges, motors can be driven both forward and backward. However, a PWM waveform only controls speed; to control direction, an additional signal is required. This “direction” signal is implemented with simple digital I/O on the Otto board. We also provide current-sense feedback circuitry for each channel, so that the amount of current being consumed by the motors can be monitored in software. For motors with quadrature-phase encoders, this is not terribly useful, but for less expensive motors without encoders, current consumption can be a helpful source of feedback. For example, if current consumption suddenly increased for a motor, one might deduce that the wheel had become stuck on an obstacle, causing the motor to stall. The robot could then back up and try to find a route around the obstacle. The feedback circuit is implemented with a precision low-ohm resistor connected between the motor’s load and ground; the voltage drop across the resistor is proportional to the current drawn by the motor. After being low-pass filtered to reduce noise, this data is sent to the board’s A/D converters. 2.2.2 Servo Control Servos are motors fitted with integrated control circuitry that allow them to accurately rotate to a specified angle within a certain range of motion (typically 180 degrees). They are often used to build robotic arms or to pan a sensor. 21 Servos are controlled by periodically sending a pulse whose width, Tangle, corresponds to the desired angle. The neutral position, corresponding to the middle of the rotational range, is represented by a pulse of Tneutral. Pulses of different widths signal different positions, according to the following relation: Tangle=Tneutral+(angle)*Tp -90