1 The Robot World


This chapter introduces a class of robots and sketches the world they inhabit. In later chapters, where a greater depth of understanding is necessary, we will amplify this preliminary discussion.

1.1 The Robot World

Robots live in a world that is unexciting by today's standards (there are no volcanoes, Chinese restaurants, or even ipods), but it does include enough variety to allow robots to perform simply stated, yet interesting, tasks. Informally, the world is a grid of streets that robots can traverse. It also contains special things that a robot can sense and manipulate.

Figure 1-1 is a map illustrating the structure of the robot world, whose shape is a great flat plane with the standard north, south, east, and west compass points. The world is bounded on its west side by an infinitely long vertical wall extending northward. To the south, the world is bounded by an infinitely long horizontal wall extending eastward. These boundary walls are made of solid neutronium, an impenetrable metal that restrains robots from falling over the edges of the world.

Figure1-1 The Robot World

Crisscrossing the world are horizontal streets (running east-west) and vertical avenues (running north-south) at regular, one-block intervals. To help you distinguish between streets and avenues, remember that the A in "Avenue" points north and the V points south. A corner, sometimes called a street corner or intersection, is located wherever a street and an avenue intersect.

One or more robots can occupy any corner, facing any of the four major compass directions. Any number of robots may occupy the same corner, because the streets and avenues are quite wide. We will often work with only one robot at a time, however. Robots are referenced by names so that we can send them messages individually. When we work with a single robot we will often call it karel,[1] though you are free to name the robots that you create with any names you like.

Both streets and avenues have numbers; consequently, each corner is identified uniquely by its street and avenue numbers. The corner where 1st Street and 1st Avenue intersect is named the origin. The positions of robots and other things in this world can be described using both absolute and relative locations. The absolute location of the origin, for example, is the intersection of 1st Street and 1st Avenue. An example of a relative location would be to say that a robot is two blocks east and three blocks north of some thing in the world. The origin also has a relative location; it is the most southwesterly corner in the robot world. Sometimes we will describe a robot task using language that gives a different interpretation to the robot world, with north as up, south down, and west and east being left and right, respectively. This is how we (in the Northern Hemisphere) normally look at maps, of course.

Besides robots, two other kinds of things can occupy this world. The first of these kinds of things is a wall section. Wall sections are also fabricated from the impenetrable metal neutronium, and they can be manufactured in any desired length and pattern. They are positioned half way between adjacent street corners, effectively blocking a robot's direct path from one corner to the next. Wall sections are used to represent obstacles, such as hurdles and mountains, around which robots must navigate. Enclosed rooms, mazes, and other barriers can also be constructed from wall sections. Figure 1-2 shows some typical wall arrangements a robot might find in the world. Robots are objects since, as we shall see, they have behavior. Walls are simpler stuff, however.

  
Fig 1-2-A North-South Wall Segments             Fig 1-2-C. A Maze of Wall Segments

  
Fig 1-2-B East-West Wall Segments                  Fig 1-2-D A Room With No Doors or Windows

Figure 1-2 Different Wall Segment Arrangements in the Robot World

The second kind of thing in the world is a beeper. Beepers are small plastic cones that emit a quiet beeping noise. They are situated on street corners and can be picked up, carried, and put down by robots. Some tasks require one or more robots to pick up or put down patterns made from beepers or to find and transport beepers. Figure 1-3 shows one possible pattern of beepers. Beepers are small so there can be several on a corner, and they don't interfere with robot movement. There can even be an infinite number on a corner. Like walls, beepers have no behavior, so are not objects. They can be manipulated by objects, however.

Figure 1-3 One Pattern of Beepers in the Robot World

1.2 Robot Capabilities

Let's now shift our attention away from the robot world and concentrate on the robots themselves. Robots are mobile; a robot can move forward (in the direction it is facing), and it can turn in place. Robots can also perceive their immediate surroundings using rudimentary senses of sight, sound, direction, and touch. They have behavior.

A robot sees by using its TV camera, which points straight ahead. This camera is focused to detect a wall exactly one-half block away from the robot. A robot also has the ability to hear a beeper, but only if the robot and the beeper are on the same corner; the beepers beep very quietly. By consulting its internal compass, a robot can determine which direction it is facing. Finally, each robot is equipped with a mechanical arm that it can use to pick up and put down beepers. To carry these beepers, each robot wears a soundproof beeper-bag around its waist. A robot can also determine whether it is carrying any beepers in this bag by probing the bag with its arm. A robot can also use its arm to determine whether there are other robots on the same corner that it occupies. Finally, a robot can turn itself off when its task is complete.

As you might expect, robots are made in factories. All robots come from the main factory, Karel-Werke, which can actually supply several different models of robots. When we need a robot for a task, we can use the standard model, or we can write a specification for a new model. Karel-Werke is able to build specialized robots that are modifications or extensions of the existing models.

Whenever we want a collection of robots to accomplish a task in the robot world, we must supply a detailed set of instructions that describe any special features of the robots that are needed and also explain how to perform the task. For most tasks one robot is all that is needed. When a robot is ordered from the factory, it is delivered to the robot world by helicopter. The helicopter pilot sets up the robots according to our specifications and sends each new robot a sequence of messages to detail its task, which it is then able to carry out. This sequence of instructions is sometimes called its script, or its main task.

What language do we use to program (here we use "program" to mean "write instructions for") robots? Instead of programming these robots in English, a natural language for us, we program them in a special programming language. This language was specially designed to be useful for writing robot programs. The robot programming language, like any natural language, has a vocabulary, punctuation marks, and rules of grammar, but this language, unlike English, for example, is simple enough for robots to understand. However, it is a powerful and concise language that allows us to write brief and unambiguous programs for them. This language is built from and based on the Python Programming Language.

1.3 Tasks and Situations

A task is something that we want a robot to do. The following examples are tasks for robots:

A situation is an exact description of what the world looks like. Besides the basic structure of the world, which is always present, wall sections and beepers can be added. To specify a situation completely, we must provide answers for the following questions.

Situations are specified in this book by a small map or brief written description. If we know the number of beepers that each robot has in its beeper-bag, then the maps in Figure 1-4 completely specify different situations. The initial situation for any task is defined to be the situation in which all of the robots are placed at the start of the task. The final situation is the situation that each robot is in when it turns itself off. Figure 1-4 shows six initial situations that are typical for tasks that a single robot will accomplish in the coming chapters.

1.4 Robots and Objects

Robots are examples of things called Objects. An object is an electronic thing, though it is useful to think of objects as if they were real, just as robots can be real. Objects can do things and they can remember things. We can ask robots (and objects in general) to do the things they know how to do, and we can ask them about the things they remember. We will explore this idea throughout this book. Python is a computer language in which it is easy to create objects, and in particular, robots. The Robot Programming Language was created using ideas like the ones presented in this book. In Chapter 4 we shall see other, somewhat more abstract, kinds of objects. Objects can be used to represent things like robots or ideas like a game strategy. The key idea, however, is that objects have behavior and can be asked to exhibit that behavior, either by carrying out some action or by giving us some information that it has remembered.

1.5 Important Ideas From This Chapter

robot
task
situation
program
object

  
Fig A. A room has one door.                Fig B. A diagonal line of beepers
Robot is at the origin, facing                Robot is facing East and must pick
North and must enter the room              all beepers.

  
Fig C. A "+" wall arrangement with                   Fig D. Robot must escape the maze
beepers. From a starting position            and pick the beeper.
robot must pick the beepers

  
Fig E. Beepers are scattered in a box.      Fig F. A box with one beeper.
Robot is facing South in the North-         Robot is facing North in the North-
West corner. Robot must pick all           East corner. Robot must find the
the beepers in the box.                          Beeper.

Figure 1-4 Six Sample Tasks for a Robot to Perform

1.6 Problem Set

Omitted



[1] The name Karel is used in recognition of the Czech dramatist Karel ńĆapek, who popularized the word robot in his play R.U.R. (Rossum's Universal Robots). The word robot is derived from the Czech word robota, meaning "forced labor."