1 / 25

CSE 111

CSE 111. Karel the Robot' Thanks to Dr. Kris Schindler for this (and all Karel the Robot slides). Logging into Karel. Available on all cybrary computers From home, or in lab use UB Virtual Computing Lab We will go over this in lab

sdanny
Télécharger la présentation

CSE 111

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. CSE 111 Karel the Robot' Thanks to Dr. Kris Schindler for this (and all Karel the Robot slides)

  2. Logging into Karel • Available on all cybrary computers • From home, or in lab use UB Virtual Computing Lab • We will go over this in lab • Guide available at http://www.buffalo.edu/ubit/service-guides/software/my-virtual-computing-lab.html • Linked from course website

  3. Karel’s World • Plain made of streets & avenues • Corners • Describe intersection of streets and avenues • Referenced by • avenue number • street number • Avenue & street numbers • Positive integers • Origin • 1st avenue & 1st street • Locations • Relative • Absolute

  4. Karel’s World • Walls • Made of neutronium • Obstacles • Karel cannot pass through a wall • Locations • Between streets • Between avenues • Form boundaries on west side & south side

  5. Karel’s World • Beepers • Pinging beeper • Situated at intersections • Can be • picked up • carried • put down

  6. Karel’s Capabilities • Can Karel the Robot think? • Take a look at the path following example • Karel navigates a maze • The configuration of the maze is unknown to Karel • The end of the maze is determined by a single beeper placed at the exit

  7. Karel’s Capabilities • Karel can • move forward • turn in place • Karel knows • which direction it is facing • Karel is equipped with • three cameras • Cameras face • forward • right • left • Range • 1/2 block

  8. Karel’s Capabilities • Karel can hear • Can detect a beeper on the same corner Karel is standing • Karel’s Beeper Bag • Stores beepers • Karel can put beepers in the bag and remove beepers from the bag • Soundproof • Karel cannot hear beepers in the bag

  9. Karel’s Tasks • How does Karel know what to do? • Karel can follow a detailed set of instructions • Called a program • The language Karel understands is called a programming language • Defined by • vocabulary • punctuation marks • rules of grammar • Simple, yet powerful

  10. Tasks & Situations • What is a task? • Something we want Karel to do • What is a situation? • Description of Karel’s world • Includes • Size & location of each wall • Location & number of beepers • Karel’s location & direction Karel is facing • Initial Situation • Karel’s world at beginning of task • Includes Karel’s initial location, direction Karel is facing, and the number of beepers in the beeper bag • Final Situation • Karel’s world after task is completed • Includes Karel’s final location, direction Karel is facing, and the number of beepers in the beeper bag

  11. Primitive Instructions • Instructions • move • turnleft • pickbeeper • putbeeper • turnoff • They allow Karel to move through world & handle beepers • Provide for avoiding obstacles & transporting beepers

  12. Program & Instruction Execution • An instruction is executed when Karel performs the action associated with the instruction • A program is executed when the instructions in a program are carried out

  13. Primitive Instruction Details • Changing Position • move • Karel moves forward one block • Karel remains facing in the same direction • If a wall is in Karel’s way & a move instruction is executed, Karel shuts off • Error shutoff • turnleft • Karel pivots 90 degrees to left • Location does not change • Cannot cause error shutoff • Why not? • There is no turnright instruction • How does Karel turn right?

  14. Primitive Instruction Details • Handling Beepers • pickbeeper • Karel picks up a beeper from the corner on which it is standing and deposits the beeper in the beeper bag • Only one beeper is picked up • Note that there may be multiple beepers on a corner • What if no beeper exists on the corner? • Error shutoff • putbeeper • Karel takes a beeper out of beeper bag and places beeper on corner • What if there are not any beepers in the bag? • Error shutoff

  15. Primitive Instruction Details • Handling Beepers • pickbeeper • Karel picks up a beeper from the corner on which it is standing and deposits the beeper in the beeper bag • Only one beeper is picked up • Note that there may be multiple beepers on a corner • What if no beeper exists on the corner? • Error shutoff • putbeeper • Karel takes a beeper out of beeper bag and places beeper on corner • What if there are not any beepers in the bag? • Error shutoff

  16. Primitive Instruction Details • Completing a Task • turnoff • Karel must be shut down after task is completed • Last instruction in every program

  17. Program Structure • General Structure BEGINNING-OF-PROGRAM BEGINNING-OF-EXECUTION Instructions, all but last ending with a semicolon (;) END-OF-EXECUTION END-OF-PROGRAM

  18. Executing a Program • Instructions between BEGINNING-OF-EXECUTION and END-OF-EXECUTION sequentially executed until a turnoff instruction or error shutoff is encountered. • Since Karel is a cyber robot, we simulate & trace the program • Simulate • Systematically execute program just as Karel would perform each instruction • Trace • Step through program, maintaining each step • Verification • Simulation & tracing through program to ensure that it works properly

  19. Using Karel the Robot in Lab • Enter program • Compile program • Checks for syntax errors, getting program ready to run • Setup initial world • Initialize world • Execute program • Run • Execution begins • Ends with either: • a proper shutdown (turnoff instruction) • a runtime error • Trace • Step • Unstep

  20. Saving Your Work • Programs and worlds can be saved!

  21. Sample Program • Task • Pick up beeper located at intersection of avenue 3, and street 4 • Initial World • Karel is at the intersection of avenue 1 and street 1 facing north • Beeper placed at intersection of avenue 3 and street 4

  22. Sample Program • Program BEGINNING-OF-PROGRAM BEGINNING-OF-EXECUTION turnleft; turnleft; turnleft; move; move; turnleft; move; move; move; pickbeeper; turnoff END-OF-EXECUTION END-OF-PROGRAM

  23. Sample Program • Final World

  24. References • Richard E. Pattis (revised by Jim Roberts & mark Stehlik), Karel the Robot, John Wiley & Sons, Inc., 2nd edition, 1995, pp 1-11

  25. Your Task in Lab • Run tutorial, learning how to program using Karel the Robot

More Related