CHANGING POSITION Directory UMM :wiley:Public:college:compsci:bergin:

7 2 PRIMITIVE INSTRUCTIONS AND SIMPLE PROGRAMS

2.1 CHANGING POSITION

o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o This chapter begins ur study f the r b t pr gramming language. We will start with a detailed explanati n f the primitive instructi ns that are built int every r b t’s v cabulary. Using these instructi ns, we can instruct any r b t t m ve thr ugh the w rld and handle beepers. Secti n 2.6 sh ws a c mplete r b t pr gram and discusses the elementary punctuati n and grammar rules f the r b t pr gramming language. By the end f this chapter we will be able t write pr grams that instruct r b ts t perf rm simple bstacle av idance and beeper transp rtati n tasks. Bef re explaining the primitive instructi ns f the r b t pr gramming language, we must first define the technical term A r b t executes an instructi n by per- f rming the instructi n’s ass ciated acti n r acti ns. The r b t executes a pr gram by executing a sequence f instructi ns that are given t it by the helic pter pil t. Each instructi n in such a sequence is delivered t the r b t in a message, which directs ne r b t t perf rm ne instructi n in the pr gram. Every r b t understands tw primitive instructi ns that change its p siti n. The first f these instructi ns is , which changes a r b t’s l cati n. When a r b t executes a instructi n, it m ves f rward ne bl ck; it c ntinues t face the same directi n. T av id damage, a r b t will n t m ve f rward if it sees a wall secti n r b undary wall between its current l cati n and the c rner t which it w uld m ve. Instead, it turns itself ff. This acti n, called an will be explained further in Secti n 2.7. Fr m this definiti n we see that a r b t executes a instructi n by m ving f r- ward t the next c rner. H wever, the r b t perf rms an err r shut ff when its fr nt is bl cked. B th situati ns are illustrated in Figure 2-1. Figure 2-1 sh ws the successful executi n f a instructi n. The wall secti n is m re than ne half-bl ck away and cann t bl ck this r b t’s m ve. execute: error shutoff, move move move move move Robot has executed an error shutoff 2 Primitive Instructions and Simple Programs 8 Figure 2-1 A Figure 2-1 B Figure 2-2

2.2 TURNING IN PLACE