卡雷尔+ +第1章

来源:百度文库 编辑:神马文学网 时间:2024/04/28 23:57:27
Karel J. Robot 卡雷尔j的机器人
A Gentle Introduction to the Art of Object-Oriented Programming in Java一个温柔的介绍面向对象的程序设计艺术在Java
Joseph Bergin约瑟夫贝尔然 Mark Stehlik马克斯特赫利克 Jim Roberts吉姆罗伯茨 Richard Pattis理查德Pattis
This manuscript has not been published.这手稿尚未发表。 It is Copyright, Joseph Bergin.它的版权,约瑟夫贝尔然。
1 The Robot World 1,机器人世界
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 1.1机器人世界
Robots live in a world that is unexciting by today's standards (there are no volcanoes, Chinese restaurants, or symphony orchestras), 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.图1-1是一个点结构图,说明了机器人的世界,它的形状是一个大平面上的标准与北,南,东,西指南针。 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.这些围墙是由固体neutronium,一个坚不可摧的金属,抑制从边缘世界机器人在下降。
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.为了帮助你区分街道和途径,请记住,“在”北大街站以南和V点。 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 usually work with only one robot at a time, however.我们通常会与机器人在同一时间只有一个,但是。 Robots have names so that we can send them messages individually.机器人的名称,以便我们可以给他们发送消息的个别。 When we work with a single robot we will often call it Karel, (Note. The name Karel is used in recognition of the Czechoslovakian dramatist Karel Capek, who popularized the word robot in his play RUR (Rossum's Universal Robots). The word robot is derived from the Czech word robota, meaning "forced labor.") though you are free to name the robots that you create with any names you like.当我们用一个机器人的工作,我们往往会调用它卡雷尔,(注本)的名称卡雷尔机器人是用于通用承认捷克剧作家卡雷尔恰佩克(Rossum的,谁推广这个词在他的发挥卢布机器人。机器人一词来自捷克robota字,意为“强迫劳动”。)虽然你是自由的机器人的名字,你喜欢的任何名称创建你。
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.一个位置的范例,亲戚会说,机器人是两条街区东和3次盖帽世界以北的一些共同点。 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.长城节是由不透,同时也制作金属neutronium,他们可以在任何模式生产所需要的长度和。 They are positioned 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.图1-2显示了一些典型的墙安排一个机器人可能会发现在世界上。
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.图1-3显示了一个传呼机可能的模式。 Beepers are small so there can be several on a corner, and they don't interfere with robot movement.寻呼机的小,因此可以有几个在角落里,他们不干扰机器人的运动。
1.2 Robot Capabilities 1.2机器人功能
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.机器人也可以直接感知和触摸自己的方向,周围用简陋的感官视觉,听觉。
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.所有机器人主要来自工厂,卡雷尔- Werke公司,这实际上可以提供多种不同型号的机器人。 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.卡雷尔- Werke公司是现有模型能够建立专门的机器人,是修改或扩展的。
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.这架直升机飞行员建立了机器人根据我们的规格和发送邮件的每个新的机器人一序列细节其任务,它是就能够进行。
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.但是,它是一个强大而简洁的语言,使我们能够为他们写简短明确的程序和。1.3 Tasks and Situations 1.3任务和局势
A task is something that we want a robot to do.一个任务是我们想要做一个机器人。 The following examples are tasks for robots:下面的例子是机器人任务: Move to the corner of 15th St. & 10th Ave.移动到第15届圣夫角落与第10位。 Run a hurdle race (with wall sections representing hurdles).运行障碍)跨栏跑(以墙部分代表。 Escape from an enclosed room that has a door.从一个封闭的房间里逃生,有一个门。 Find a beeper and deposit it on the origin.找到一个寻呼机和存款它的起源。 Escape from a maze.逃出迷宫。
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.要指定一个完全的情况,我们必须提供对下列问题的答案。 What is each robot's current position?什么是每个机器人的当前位置? We must specify both the robot's location (which corner it is on) and what direction it is facing.我们必须同时指定机器人的位置(它是在哪个角落),什么方向是面对的问题。 What is the location and length of each wall section in the world?什么是世界上的位置和长度在每一段长城? What is the location of each beeper in the world?什么是世界上每个位置的蜂鸣器吗? This information includes specifying the number of beepers in each robot's beeper-bag.这些信息包括指定袋数量传呼机在每个机器人的蜂鸣器-。
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.如果我们知道寻呼机号码,每个机器人的袋子在其蜂鸣器-,然后在图1-4的地图完全指定不同的情况。 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显示了六个章节来的初步情况是典型的任务将完成一个单一的机器人研究。
1.4 Robots and Objects 1.4机器人和对象
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.我们将探讨这个概念贯穿本书。 Java is a computer language in which it is easy to create objects, and in particular, robots. Java是一种计算机语言,它很容易创建对象,尤其是机器人。 The robot programming language was created using ideas like the ones presented in this book.该机器人编程语言是使用书的看法,这给喜欢的。
1.5 Important Ideas From This Chapter 1.5本章的重要思想
robot机器人
task任务
situation情况
program方案
object对象1.6 Problem Set 1.6习题集
The purpose of this problem set is to make sure that you have a good understanding of the robot world and the capabilities of robots before moving on to robot programming.在这个问题集的目的是要确保你有一个很好的了解世界机器人的编程机器人和机器人的功能前移动。
1. 1。 Which of the following directions can a robot face?下列哪一个方向,可以机器人的脸? northeast东北 east东 south-southwest西南偏南 north北 164 degrees 164度 vertical垂直 down向下
2. 2。 What things other than robots can be found in the robot world?什么东西比其他机器人可在机器人的世界?
3. 3。 Which of the things listed in Problem 2 can a robot manipulate or change?哪个或变更问题2所列的东西可以操纵一个机器人?
4. 4。 What reference points can be used in the robot world to describe a robot's exact location?参考点什么,可在全球使用机器人来描述机器人的确切位置?
5. 5。 How many robots can we have in a given robot world?怎样才能有很多机器人在给定的机器人世界?
6. 6。 Give the absolute location of each robot in each of the worlds shown in Figure 1-5.给图1-5中显示绝对的世界上每个位置的每个机器人。 Give a relative location of each robot in the worlds.给出一个在世界上的相对位置的每个机器人。