Robot Control Techniques Editor: Paul Frenger, P O. Box 820506, Houston, TX 77282; [email protected]

Part One: A Review of Robotics Languages Paul Frenger

Abstract complished by polling of status information, or by inter- rupt servicing. Interaction with sensors may be achieved This two-part paper describes the author's recent expe- with device drivers, sensor variables, or object-oriented riences with robot control systems. First, three prin- techniques. Startup procedures involve self-testing, ini- cipal programming techniques are reviewed, including tializing data structures, powering up limb actuators and dedicated robotics languages; machine tool languages; putting the robot's appendages into a known configura- and general purpose computer programming languages. tion. Shutdown involves parking the robot's limbs, dis- Then, unconventional languages for robot control, such abling the actuators and powering all systems down. as PostScript and , are discussed. In the next install- World modelling may be added to the above, to de- ment, the use of Forth as an object-oriented language to scribe the properties of the objects in the robot's envi- develop the author's multiprocessor android control sys- ronment [2]. Programming support utilities, such as a tem is explored. command editor, debugger, system monitor and simula- tion facility, are generally required.

1 Introduction to Robot Control 2 Approaches to Robot Program- Reliable robot performance is an area of great theoreti- ming cal and commercial interest. Stable robot control systems are essential to achieving this goal, and a suitable robot To date, three primary techniques have been developed programming language is a crucial element in the control in the design of robot programming languages. The first equation. is to create the language de novo, specifically for robot Robot programming languages traditionally must sat- control. The second is to modify an existing computer isfy several requirements. They must facilitate the gen- language, such as C. The third is to modify an existing eral functions of any computer: perform numeric calcula- numerical control language (ie: one used for CNC ma- tions, process input-output, and so on. Additionally, they chining). Each approach has its strengths, weaknesses must control robot motion, operate with a degree of paral- and supporters. These methods are discussed below. lelism, communicate with other processors, synchronize external events, respond to stimuli in real-time, interact with sensors, and perform robot startup-shutdown proce- 2.1 Dedicated Robot Programming Lan- dures safely [1]. guages At a minimum, motion control requires a form of MOVE command. These movements may be modified In the first category is KAREL. It is a simple robot by force and position information from transducers via programming language many students have used since the SENSE command. Parallelism or concurrency may 1981 [3]. KAREL is a Pascal-like block structured lan- be achieved by multitasking and/or multiprocessing ar- guage which was originally intended more for teaching rangements. Interprocess communication may involve computer programming than for achieving robot control. shared memory, remote procedure calls, or message pass- KAREL provides position variables, speed control, mo- ing. Synchronization depends on detection and handling tion commands, input sensing, and output control. The of events: initiation or termination of an event, or detec- earlier Karel operated simulated robots on the user's CRT. tion of error conditions. Response to stimuli can be ac- Karel's most recent incarnation (1995) has the ability to

27 define new instructions, and has controlled actual robots it entered the robotics area it invested its resources in ex- in the lab. tending APT for general-purpose robot control. From this VAL-2 extends the KAREL format with special tool initial attempt grew other extended numerical control lan- handling capabilities and rich console I/O [4]. An inter- guages, which added the necessary robot programming esting feature of VAL-2 is its ability to produce smooth features. Nevertheless, this is not a highly popular ap- motion by not waiting for one MOVE command to com- proach outside the military community. plete before transferring to the next (this ability can be When I became seriously interested in medical disengaged with the BREAK command). VAL-2 also al- robotics, my only exposure to a robot programming lan- lows for sensor inputs to modify the motion of the con- guage was m the original version of KAREL. That ver- trolled component, which is particularly useful in gripper sion was not suitable for the kinds of complex systems I operations. hoped to create at a later date. Looking around for other The LM language supports programming by example approaches, I found the Logo language, a highly modi- [5]. In this case, a naive operator can generate a LM pro- fied Lisp [11]. Logo was used extensively by MIT's AI gram module by manually moving a robot through a sam- Lab, and by their Education Research Division. In the late ple operation using the TEACH statement. LM was a de- 1970's, Logo became available on the Apple II personal velopment of the earlier AL language, which attempted computer as well as others in due course. Many chil- to provide all of the necessary robot programming capa- dren have had pleasant experiences with the Lego plastic bilities in a high-level, structured language [6]. building blocks; there are Lego kits which can be inter- AML ("A Manufacturing Language") supports modu- faced to Logo on a PC for simple robotics experiments. lar programming and extensive error handling capabilities Nevertheless, I felt that I needed more control over the [7]. For example, if the GRASP command successfully programming environment than Logo offered. Around enables a robot gripper to grab an object, it will return an 1980, I became aware of the Forth language, which will "OK" string. Otherwise it will return "too big" or "too be discussed in the second part of this series. small" as appropriate. AML also supports supports pro- gramming by example via the XPROBE system [8]. 3 Postscript: A Non-Obvious Ap- 2.2 Modified Preexisting Computer Lan- proach guages

A prime example of the second category is RCCL [9]. PostScript by Adobe Systems is a device-independent RCCL is a collection of robot control subroutines pro- page description language for laser printers. Most of the vided as a C library. Its author intended RCCL's robot PostScript language is devoted to graphics and typeset- programming system to be similar in flavor to UNIX I/O ting. Writing graphics display programs in PostScript is system calls (ie: an extension of the underlying computer commonplace [ 12]. But considering PostScript as merely ). RCCL has been very successful since a formatting utility for laser printers would be a mistake. it was originally offered in 1983: it has been used by PostScript can serve as an excellent general-purpose pro- Jet Propulsion Laboratories, RCA Advanced Technology gramming language [13]. It is a lot like its predecessor Labs and the NASA Goddard Space Flight Center. In Forth in many respects: it is based on a simple two-stack the latter case, NASA used RCCL and PUMA-760 robot virtual machine, it uses postfix ("reverse Polish") nota- arms to demonstrate tasks necessary for orbital space sta- tion for its operations, its syntax is easy to learn, and it tion maintenance. has powerful features like reentrancy, extensibility and an interpreter interface. Could PostScript serve as a suitable robot program- 2.3 Modified Preexisting Numerical Con- ming language? If one considers the electromechanical trol Languages complexity of a modern laser printer system, the answer should be "yes". Use of PostScript should be especially The third category is modifying an existing tool control attractive for schools and universities, since there are lit- language. The US Air Force settled on the APT language, erally thousands of unused "obsolete" or "broken" laser used for metal-cutting machines, for production of air- printers with still-functional motherboards available with craft parts [ 10]. The military evidently considered a robot PostScript in their ROMs. This kind of unexpected wind- to be just another machine process component, so when fall, if tapped, would make robotics education and ex-

8 .~. perimentation much less expensive. Furthermore, other embeddable interpreter with a familiar syntax (that of computer languages, such as SmallTalk or Prolog, can be PostScript). Next, Tps has some special features: for written in PostScript [14]. Indeed, Forth has been writ- example, a running Tps program can be interrupted and ten in PostScript [15], and PostScript has been written in saved in a format that can be restored on a different ma- Forth and in other languages like C. chine, then restarted safely from the point of interrup- tion. Also, like Java (discussed below), Tps provides controlled access to unsafe computer resources to deter 3.1 Ghostscript: A Postscript Workalike viruses and hackers. Tps is based on a three-stack VM (for operands, the dictionary and execution stacks). Tps This brings us to Ghostscript, a PostScript clone written programs can be single-stepped, which is a powerful aid in C, by L. Peter Deutsch [ 16]. Aladdin Enterprises owns to debugging. Multiple Tps interpreters can be run simul- the Ghostscript copyright; Ghostscript is distributed with taneously on a system, giving a form of multithreading or the GNU General Public License. GhostScript consists multitasking. And like Forth and PostScript, Tps is easily of a set of software modules that provides an interpreter extensible. for the PostScript language, and a set of C procedures (the The lesson to be derived here is that, if you need a flexi- Ghostscript library) that implement the graphics capabili- ble programming language to control your robot projects, ties of the PostScript language. Ghostscript currently runs and you like PostScript and can program in C or C++, on the following platforms: IBM PCs and compatibles then you have Tps or the GhostScript interpreter kernel under MS-DOS, Microsoft Windows and OS/2; various available for use. Using the C compiler with your fa- Unix systems using X Windows; Sun run- vorite microcontroller, you should be able to port these ning SunView; and the Apple Macintosh. Version 4.01 languages to a wide variety of robot control computers in- has recently been released. cluding some very small ones. Suitable portions of RCCL Ghostscript is really two programs: a language inter- mentioned above could be rewritten for these PostScript preter, and a graphics library. The Ghostscript inter- clones for the robotic environment. preter was designed to properly execute any PostScript Level 1 and Level 2 source program (as described in the PostScript Language Reference Manual published by 4 The Java Language Addison-Wesley). Because Ghostscript's C source code is provided, it can Java is an interpreted programming language developed be user-modified to better suit the needs of a robot control by , most widely known for its use in language. For example, special device drivers and richer creating World Wide Web applications on the Internet I/O can be added in low-level C rather than attempting [18]. Java is based on a simple, 32-bit two-stack VM this in high-level PostScript. Since the graphics com- architecture, usually written in C. One stack is used for mands are separate from the interpreter, a smaller, leaner parameter-passing, as in Forth; the other involves C-style GhostScript can be built. stack frames. Java was created for control of networked devices from Personal Digital Assistants ("PDAs" like the 3.2 Tps: A Light Postscript Apple Newton) on up, as well as in embedded applica- tions and even in "smart appliances". Someone has already done this [17]. Tps, a tiny, trans- The Java language, which is vaguely like C++, uses portable PostScript, is under development at the Univer- a form of bytecode to represent its partially-compiled sity of Colorado. It is supported by the US Air Force Ma- source code. These bytecode programs can be interpreted terial Command and by the Advanced Research Projects or further compiled into machine code. Bytecode makes Agency as the Arcadia Project. Tps was created as an Java programs transportable over the Internet between es- embeddable interpreter which would look like PostScript sentially any CPU or operating system, as long as the with all of the graphics operators removed. It is said client is running a Java-smart browser, such as HotJava or to be about the same size, and useful for the same pur- the newer Netscape versions. The same code transporta- poses, as Unix Tcl. Tps is written in C++ and has been bility should be available for embedded applications. tested in the IBM PC, Sun, Indigo and HP-9000 environ- Embedded applications? Sun Microsystems and others ments. The latest version (2.1d) includes object-oriented are developing which directly execute programming extensions. Java VM primitives [ 19], much like the Forth processors Why was Tps created? First, as a simple, transportable, which will be mentioned in part two of this series. Sun

29 is licensing a processor design it calls "picoJava" to other 5 Discussion manufacturers. Another company, Patriot Scientific, has already created a Java chip it calls "ShBoom", which ex- So far, we have reviewed the elements of the major types ecutes the Java bytecode as well as performing its other of robot control languages. We have looked at some con- CPU duties [20]. ventional (and some unconventional!) programming lan- Why would anyone consider Java in any of its forms guages, with an eye to their strengths and weaknesses to be a suitable basis for a robot programming language? for robotics. There have been a few surprises along the Besides the Forth VM connection, and the bytecode con- way: for example, the possibility of using PostScript (a nection, there is the ability of Java to run in a wide net- laser printer page description language) or Java (an In- working environment (what could be wider than the In- ternet WWW application language) for robot control. In ternet?). Java applications and applets can be created, the next installment of this paper, we will be introduced stored, transported and run anywhere in that network, on to Forth (an extensible language originally developed for any platform. In fact, Java has already been used in an control of radio astronomy observatories), to see how it Internet-based robotics project: the Telerobot [21]. This can be made into an object oriented robot control lan- project, based at the University of Western Australia, en- guage. We will also see some of Forth's close cousins in abled anyone with Web access to control a 6-axis robotic action. arm remotely. The most recent incarnation of the sys- tem utilized a Java interface between the University web server and the local Telerobot controller. The remote op- erator receives video of the robot's gripper before and af- 6 References ter each motion command. The arm has been used for moving wooden blocks around and for searching for "ar- [1] McKerrow, RJ., "Programming", Introduction to tifacts" buried in a sandbox. This device has been suc- Robotics, Addison-Wesley Co., Menlo Park, CA, cessfully used by over 15,000 Internet sites around the 1991, Chap. 12, pg.707-758. world, from a distance of up to 14,000 miles away. So, in effect, the suitability of Java for robotics is largely a moot [2] Chooi, E., "Robotic Programming Languages", issue. Dept. of Computer System Engineering, Curtin But there are a few difficulties associated with using University of Technology, Perth, Western Australia. Java in a real-time system. The first is the garbage collec- http://www.kernow.curtin.edu.au/www/robot 1/5- tion (GC) problem. Java's automatic memory manage- 0.htm. ment occasionally forces other processes to pause until it finishes GC. This would be intolerable for monitoring [3] Pattis, R., et al, Karel the Robot, John Wiley & Sons, the movement of a robot in motion, and possibly danger- New York, 2nd Ed., 1995. ous to bystanders. This problem has been overcome by at least one manufacturer [22], who has developed an incre- [4] Shimano, B., VAL: A Versatile Robot Programming mental, preemptive, real-time memory defragmentation and Control Language, IEEE Cat. No. EH0207-1, process for its Java interpreter. ISBN 0-8186-0515-4, 1986, pg.366-371 The other difficulty arises from a Java strength: appli- cations are confined to an execution "sandbox" to pre- [5] Latombe, J.C. et al., "The LM Robot Programming vent them from damaging system resources. One has to System", Robotics Research 2nd Int. Sympos., MIT go to native methods (and C) to gain full control of the Press, Boston, 1985, pg.377-391. hardware, but this hampers transportability and security. Finkel, R. et al, "An Overview of AL, a Programming I personally believe that this is a non-issue in most in- [6] System for Automation", Proc. 4th Int. Joint Conf. stances, since any alternative language would similarly on AI, 1975, pg.758-765. breach security and be nontransportable. Perhaps some- day there will be a Java generic robotics library, or Java [71 Taylor, R.H. et al, "AML: A Manufacturing Lan- system calls (like those for C in RCCL). Until then, these guage", IJRR, Vol.1 No.3, 1982, pg.19ff. considerations should not be considered as disqualifying. [8] Summers, RD. and Grossman, D.D., "XPROBE: An Experimental System for Programming Robots by Example", IJRR, Vol.3 No.l, 1984, pg.25-39.

30 [9] Hayward, V. and Lloyd, J., "Installation of RCCL Systems", 1994. Paul Frenger is a medical doctor who has been profes- http://www.cim.mcgill.ca/CimIn fo/93- sionally involved with computers since 1976. He has 94AnnualReport/. worked as a computer consultant, published over eighty articles in the bioengineering and computer literature, [10] Hollingshead, L., "Elements of Industrial Robot edited the ACM SIGForth Newsletter for four years and Software", Handbook of Industrial Robotics, John acquired three computer patents along the way. Paul Wiley & Sons, 1985, pg.337-351. was bitten by the reverse Polish bug in 1981 and has used Forth ever since. Occasionally, he practices a bit [11] Abelson, H., and Abelson, A., Logo for the Macintosh, An Introduction Through ObjectLogo, of medicine. Paradigm Software, Cambridge MA, 1992.

[12] Geschke, C., PostScript Language Tutorial and Cookbook, Addison-Wesley Co., Menlo Park, CA, 1985. [13] Lancaster, D., "What is PostScript?", ACM SIG- Forth Newsletter, Vol.3 No.2, Fall 1991, pg.15-19. [14] Woodruff, B., "PostScript as a Programming Lan- guage", Real World PostScript, Addison-Wesley Co., Menlo Park, CA, 1988, pg.17-46.

[15] Bradley, M., "Forth in PostScript", ACM SIGForth Newsletter, Vol.3 No.2, Fall 1991, pg.20-24. [16] Deutsch, R, "Release of Aladdin Ghostscript 4.01", July 1996. http://www.cs.wisc.edu/ghost/index.html. [17] Heimbigner, D., "Tps: Embedded, Transportable, Agent Language", January 1996. http ://www.cs.colorado.edu/~-,arcadia/software! tps.html. [18] Waddington, S. and Li, S., "Java: Virtual Ma- chine for Virtually Any Platform", Embedded Sys- tems Programming, Vol.9 No.6, June 1996, pg.26- Correction 42. The Forth Report for February 1997, "An [19] Myrvaagnes, R., "Hardware processors poise to Introduction to the Beetle Forth Virtual widen Java appeal", Electronic Products, Vol.38 Processor," was incorrectly attributed in the No.11, April 1996, pg.17. Table of Contents and on the cover. Reuben [20] Collins, L., "Java: in with a ShBoom?", Electronic Thomas was the author. We regret the error. Times, No.798, 15 Feb 1996, pg.14. - The Editor [21] Taylor, K. and Trevelyan, J., "Australia's Telerobot on the Web", October 1995. http://telerobot.mech.uwa.edu.au/roboffsingapor.htm. [22] Nilsen, K., "Discussions on Real-time Java", 12 June 1996. http://www.newmonics.comJWebRoot/ technologies/j ava.html.

31