+ All Categories

CSE 111

Date post: 03-Jan-2016
Category:
Upload: velma-combs
View: 83 times
Download: 0 times
Share this document with a friend
Description:
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 - PowerPoint PPT Presentation
Popular Tags:
25
CSE 111 Karel the Robot' Thanks to Dr. Kris Schindler for this (and all Karel the Robot slides)
Transcript
  • CSE 111Karel the Robot'

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

  • Logging into KarelAvailable on all cybrary computersFrom home, or in lab use UB Virtual Computing LabWe will go over this in labGuide available at http://www.buffalo.edu/ubit/service-guides/software/my-virtual-computing-lab.htmlLinked from course website

  • Karels WorldPlain made of streets & avenuesCorners Describe intersection of streets and avenuesReferenced by avenue numberstreet numberAvenue & street numbersPositive integersOrigin1st avenue & 1st streetLocationsRelativeAbsolute

  • Karels WorldWallsMade of neutroniumObstaclesKarel cannot pass through a wallLocationsBetween streetsBetween avenuesForm boundaries on west side & south side

  • Karels WorldBeepersPinging beeperSituated at intersectionsCan be picked upcarriedput down

  • Karels CapabilitiesCan Karel the Robot think?Take a look at the path following exampleKarel navigates a mazeThe configuration of the maze is unknown to KarelThe end of the maze is determined by a single beeper placed at the exit

  • Karels CapabilitiesKarel canmove forwardturn in placeKarel knowswhich direction it is facingKarel is equipped with three camerasCameras faceforwardrightleftRange1/2 block

  • Karels CapabilitiesKarel can hearCan detect a beeper on the same corner Karel is standingKarels Beeper BagStores beepersKarel can put beepers in the bag and remove beepers from the bagSoundproofKarel cannot hear beepers in the bag

  • Karels TasksHow does Karel know what to do?Karel can follow a detailed set of instructionsCalled a programThe language Karel understands is called a programming languageDefined byvocabularypunctuation marksrules of grammarSimple, yet powerful

  • Tasks & SituationsWhat is a task?Something we want Karel to doWhat is a situation?Description of Karels worldIncludesSize & location of each wallLocation & number of beepersKarels location & direction Karel is facing Initial SituationKarels world at beginning of taskIncludes Karels initial location, direction Karel is facing, and the number of beepers in the beeper bagFinal SituationKarels world after task is completedIncludes Karels final location, direction Karel is facing, and the number of beepers in the beeper bag

  • Primitive InstructionsInstructionsmoveturnleftpickbeeperputbeeperturnoffThey allow Karel to move through world & handle beepersProvide for avoiding obstacles & transporting beepers

  • Program & Instruction ExecutionAn instruction is executed when Karel performs the action associated with the instructionA program is executed when the instructions in a program are carried out

  • Primitive Instruction DetailsChanging PositionmoveKarel moves forward one blockKarel remains facing in the same directionIf a wall is in Karels way & a move instruction is executed, Karel shuts off Error shutoffturnleftKarel pivots 90 degrees to leftLocation does not changeCannot cause error shutoffWhy not?There is no turnright instructionHow does Karel turn right?

  • Primitive Instruction DetailsHandling BeeperspickbeeperKarel picks up a beeper from the corner on which it is standing and deposits the beeper in the beeper bagOnly one beeper is picked upNote that there may be multiple beepers on a cornerWhat if no beeper exists on the corner?Error shutoffputbeeperKarel takes a beeper out of beeper bag and places beeper on cornerWhat if there are not any beepers in the bag?Error shutoff

  • Primitive Instruction DetailsHandling BeeperspickbeeperKarel picks up a beeper from the corner on which it is standing and deposits the beeper in the beeper bagOnly one beeper is picked upNote that there may be multiple beepers on a cornerWhat if no beeper exists on the corner?Error shutoffputbeeperKarel takes a beeper out of beeper bag and places beeper on cornerWhat if there are not any beepers in the bag?Error shutoff

  • Primitive Instruction DetailsCompleting a TaskturnoffKarel must be shut down after task is completedLast instruction in every program

  • Program StructureGeneral Structure

    BEGINNING-OF-PROGRAMBEGINNING-OF-EXECUTION

    Instructions, all but last ending with a semicolon (;)

    END-OF-EXECUTIONEND-OF-PROGRAM

  • Executing a ProgramInstructions 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 programSimulateSystematically execute program just as Karel would perform each instructionTraceStep through program, maintaining each stepVerificationSimulation & tracing through program to ensure that it works properly

  • Using Karel the Robot in LabEnter programCompile programChecks for syntax errors, getting program ready to runSetup initial worldInitialize worldExecute programRunExecution beginsEnds with either:a proper shutdown (turnoff instruction)a runtime errorTraceStepUnstep

  • Saving Your WorkPrograms and worlds can be saved!

  • Sample ProgramTaskPick up beeper located at intersection of avenue 3, and street 4Initial WorldKarel is at the intersection of avenue 1 and street 1 facing northBeeper placed at intersection of avenue 3 and street 4

  • Sample ProgramProgramBEGINNING-OF-PROGRAMBEGINNING-OF-EXECUTION

    turnleft;turnleft;turnleft;move;move;turnleft;move;move;move;pickbeeper;turnoff

    END-OF-EXECUTIONEND-OF-PROGRAM

  • Sample ProgramFinal World

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

  • Your Task in LabRun tutorial, learning how to program using Karel the Robot


Recommended