Robot? What’s a Robot? Introducing Karel-the-Robot.

Slides:



Advertisements
Similar presentations
Karel – Making More Complex Decisions IF / THEN / ELSE IF THEN BEGIN Instructions END ELSE BEGIN Instructions END Do these when test = False Do these when.
Advertisements

1 Note: Original slides provided by and modified for Mr. Smith’s AP Computer Science A classwww.apComputerScience.com.
1 Note: Original slides provided by and modified for this specific classwww.apComputerScience.com.
1 of 3 Karel Karel is an educational programming language for beginners, created by Richard E. Pattis (currently at Pace University, NY). Pattis used the.
Copyright, Joseph Bergin
Nested If Statements While Loops
Murphy’s Laws. Things are more complex than they seem to be. Things take longer than expected. Things cost more than expected. If something can go wrong,
Karel The Robot Nested If Statements While Loops Copyright © 2008 by Helene G. Kershner.
Karel the Robot -- ITERATE Problem Statement: Karel is told to “take a walk around the block!” Revise Algorithm: Define move ahead 5 streets Define turnright.
Karel The Robot In the beginning… software. Karel the Robot  All robots are controlled by software  Artificially intelligent robots that can “think”
Conditionals How do we solve tasks in which every particular of a task is not specifically known? – A robot needs the ability to survey its immediate environment.
Introduction to a Programming Environment
ROBOT Computer and its Programs
Programming. Software is made by programmers Computers need all kinds of software, from operating systems to applications People learn how to tell the.
10-1 Programming Remember: –programming language –how to program (conceptually) –intro to programming the “ROBOT” computer In this lecture: –programming.
Extending the Robot Programming Language In the Robot world 1 mile = 8 blocks Suppose we want a robot to run a marathon (26+ miles)? Does our program have.
Karel JRobot Karel is an educational programming language for beginners, created by Richard E. Pattis (currently at Pace University, NY). Pattis used the.
Chapter 5 Conditionally Executing Instructions
Programming Translators.
Ch. 2 1 Karel – Primitive Instructions Basic tools with which all problems are solved (analogies: LeftSpinngingRobot, RightSpinningRobot, GuardRobot, etc)
Karel J Robot An introduction to BlueJ and Object- Oriented Programming.
1 Classes begin with capital letters (i.e. UrRobot). Methods, objects, and variable names begin with lower case (camelCase) Use indentation to line up.
1 Note: Original slides provided by and modified for Mr. Smith’s AP Computer Science A classwww.apComputerScience.com.
1 Ch. 7 Recursion similar to iteration in that you repeatedly do a little bit of the task and then “loop” again and work on a smaller piece - eventually.
Programming Lifecycle
Karel J. Robot A Gentle Introduction to the Art of Object Oriented Programming.
Karel the Robot A Gentle Introduction to the Art of Programming.
Programming Errors Lexical errors – occur whenever Karel reads a word that is not in his vocabulary. Example in English: We are asking directions and instead.
Thanks to Dr. Kris Schindler for this (and all Karel the Robot slides)
Karel J. Robot Tool for learning OOP (Lecture covers Ch. 1 and 2)
1 karel_part2_Inheritance Extending Robots Tired of writing turnRight every time you start a new karel project. How do we avoid re-writing code all the.
1 Karel – Chapter 6 Instructions That Repeat Note: Original slides provided by and modified for Mr. Smith’s AP Computer Science.
1 Karel – Chapter 5 Conditionally Executing Instructions Note: Original slides provided by and modified for Mr. Smith’s AP Computer.
Karel the Robot A Gentle Introduction to the Art of Object- Oriented Programming in Java.
1 Program Planning and Design Important stages before actual program is written.
1 Karel J Robot OOP approach to learning computer science “Its study involves development of the ability to abstract the essential features of a problem.
15-100: Introduction to Programming w/ Java * Ananda Gunawardena -- Lecture – School of Computer Science – Phone : (x81559) – Office: Wean Hall.
Introduction to OOP in VB.NET using Robots ACSE Conference, Nov 2004 Michael Devoy Monsignor Doyle C.S.S., Cambridge
Extending Karel’s Vocabulary This PPT originated with Dr. Judy Hankins Modifications have been done by Dr. Untch & Dr. Cripps.
1 Note: Original slides provided by and modified for Mr. Smith’s AP Computer Science A classwww.apComputerScience.com.
Programming in Karel Eric Roberts CS 106A January 6, 2016.
Introduction to Computer Science
Ch. 2 1 Karel – Primitive Instructions Basic tools with which all problems are solved (analogies: carpentry, geometry) –move() –turnLeft() –putBeeper()
Mile-long hurdle race Suppose that we want to program Karel to run a one-mile long hurdle race, where vertical wall sections represent hurdles. The hurdles.
Karel the Robot – Review Primitive Commands move pickbeeper putbeeper turnleft turnoff Karel’s program statements are separated by a semicolon (;) Copyright.
1 Karel – Chapter 5 Conditionally Executing Instructions Note: Original slides provided by and modified for Mr. Smith’s AP Computer.
Karel the Robot – Review Primitive Commands move pickbeeper putbeeper turnleft Turnoff Karel’s program statements are separated by a semicolon (;) Copyright.
Compiler Errors Syntax error Lexical Can not resolve/find symbol Can not be applied Execution error Oh wait, a run time error Intent error It ran, but.
Karel the Robot – Review Primitive Commands move pickbeeper putbeeper turnleft Turnoff Karel’s program statements are separated by a semicolon (;) Copyright.
Victoria Ibarra Mat:  Generally, Computer hardware is divided into four main functional areas. These are:  Input devices Input devices  Output.
Karel – Primitive Instructions
Mile-long hurdle race Suppose that we want to program Karel to run a one-mile long hurdle race, where vertical wall sections represent hurdles. The hurdles.
In the beginning… software
Eric Roberts and Jerry Cain
Copyright © 2008 by Helene G. Kershner
Loops We have already seen instances where a robot needs to repeat instructions to perform a task turnRight(); moveMile(); Harvesting beepers in a field.
Copyright © 2008 by Helene G. Kershner
Karel J Robot.
Karel – Primitive Instructions
Karel J Robot.
Karel J Robot OOP approach to learning computer science
Algorithm The key is the step-by-step instructions.
Karel the Robot – Making Decisions
slides courtesy of Eric Roberts
A Gentle Introduction to the Art of Object Oriented Programming
Karel J Robot OOP approach to learning computer science
Algorithm The key is the step-by-step instructions.
ICT Gaming Lesson 2.
Nested If Statements While Loops
Karel – Primitive Instructions
Presentation transcript:

Robot? What’s a Robot? Introducing Karel-the-Robot

Robot “A robot is a virtual or mechanical artificial agent.” “Usually an electro-mechanical system which, by it’s appearance or movements,” gives the sense that it is operating on its own. “The word robot can refer to both physical robots and virtual software agents…” If these virtual robots run over the Internet they are often called bots. Robotics – “the science and technology of robots, and their design, manufacture and application. Robotics has connections to electronics, mechanics and software.” Copyright © 2009 by Helene G. Kershner

Robots Roomba (Robot Vacuum) Commercial Climbing Robot Robot play the violin Robot History Copyright © 2009 by Helene G. Kershner

Robots and Karel Karel is not a robot like the ones in the videos. Karel is not a fictional robot like C3P0 from Star Wars Rather Karel is a software “entity” that you program in a version of a high level language called PASCAL. You, the human controller (programmer), tell Karel exactly what to do. Karel is very good at following instructions. You however, have to learn to Speak Karel’s very limited language. Copyright © 2009 by Helene G. Kershner

Karel the Robot Karel’s World –Plain made of streets & avenues –Corners or intersection –Location determined by avenue & street numbers Positive integers –Origin/Start is 1st avenue & 1st street Copyright © 2008 by Helene G. Kershner

Karel the Robot Walls Made of neutronium Obstacles –Karel cannot pass through a wall Located –Between streets –Between avenues From origin, Karel’s World has a huge immoveable wall on his west side & south side Copyright © 2008 by Helene G. Kershner

Karel the Robot Beepers Pinging beeper –Found at intersections Karel can do things with the beepers –pick up one at a time –carry –put down Copyright © 2008 by Helene G. Kershner

Karel the Robot Karel is a Robot Karel cannot think –Karel is remarkable at his ability to follow instructions –As long as these instructions are VERY detailed Copyright © 2008 by Helene G. Kershner

Karel the Robot Karel’s Capabilities –Move forward (move) turn in place (turnleft) –Knows which direction it is facing – compass is equipped with three cameras forward right left –These cameras have a ½ block range Copyright © 2008 by Helene G. Kershner

Karel the Robot Karel’s Capabilities –Karel can hear Can detect a beeper on the same corner Karel is standing – Karel’s has a Beeper Bag Stores beepers Soundproof Karel cannot hear beepers in the bag –Karel can put beepers in the bag and remove beepers from the bag Copyright © 2008 by Helene G. Kershner

Karel the Robot Karel’s Abilities Not isn’t very smart But, Karel is very good at following instructions The algorithm or step-by-step set of instructions Karel follows is called a program Karel understands a very simple programming language By computer standards, it is a high-level language The computer inside Karel doesn’t actually “speak” the language of our programs Our programs will have to be translated into the machine code (0,1) that the computer understands. To do this we will compile our programs. Copyright © 2008 by Helene G. Kershner

Karel the Robot How does Karel know what to do? –Karel only does what we tell it to do. –We write a program that gives Karel its instructions. Copyright © 2008 by Helene G. Kershner

Karel the Robot Karel’s Programming Language –vocabulary –punctuation marks –rules of grammar –Simple, yet powerful Copyright © 2008 by Helene G. Kershner

Karel the Robot 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 wall(s) Location & number of beepers –Karel’s location & direction Karel is facing Initial Situation (Initialize) –Situation when Karel is assigned a task Final Situation –After task is completed Copyright © 2008 by Helene G. Kershner

Karel the Robot Primitive Instructions –move –turnleft –pickbeeper –putbeeper –turnoff They allow Karel to move through world & handle beepers Provide for avoiding obstacles & transporting beepers Copyright © 2008 by Helene G. Kershner

Karel the Robot Program & Instruction Execution An instruction is Executed (Run) when Karel performs the task it is told to perform. A program is Executed when the instructions in a program are carried out. Copyright © 2008 by Helene G. Kershner

Karel the Robot 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 When Karel turns off due to an error this is called an Error shutoff –turnleft Karel pivots 90 degrees to left Location does not change Cannot cause error shutoff Why not? Copyright © 2008 by Helene G. Kershner

Karel the Robot Handling Beepers pickbeeper –Karel picks up a beeper from the corner on which it is standing and deposits beeper in the beeper bag –The pickbeeper command work on one beeper at a time –There may be more than one beeper on a corner What if Karel tries to pick up a beeper when no beeper is at 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 Copyright © 2008 by Helene G. Kershner

Karel the Robot Completing a Task – When a task is complete, Karel must be told to that the program is finished. –turnoff Karel must be shut down after task is completed Last instruction in every program Copyright © 2008 by Helene G. Kershner

Karel the Robot What does a Karel the Robot Program look like? BEGINNING-OF-PROGRAM BEGINNING-OF-EXECUTION Instructions, ending with a semicolon (;) END-OF-EXECUTION END-OF-PROGRAM The instructions are made up of the Primitive commands Karel understands. Karel’s Language has Reserved Words that structure the program. BEGINNING-OF-PROGRAM BEGINNING-OF-EXECUTION instructions END-OF-EXECUTION END-OF-PROGRAM Copyright © 2008 by Helene G. Kershner

Karel the Robot Errors, Bugs, Debugging Four kinds of errors can occur in Karel’s Language 1.Lexical Errors –When Karel tries to read a word it doesn’t understand –Spelling 2.Syntax Errors –Errors in Grammar and Punctuation, Ex. –Reserved words in the wrong order –Missing semicolon (;) Copyright © 2008 by Helene G. Kershner

Karel the Robot Errors, Bugs, Debugging Four kinds of errors can occur in Karel’s Language 3.Execution Errors –When Karel is asked to do something it cannot do –Pick up a bepper where none exists –Walk into a wall 4.Logic Errors –Hardest to find and recognize –Where program has no obvious errors but it doesn’t solve the problem –Or Karel executes part way and turns off Copyright © 2008 by Helene G. Kershner

Karel the Robot Running/Executing a Program Instructions between BEGINNING-OF-EXECUTION and END-OF- EXECUTION are acted on in order (from top to bottom) until a turnoff instruction or error shutoff is encountered. How do we know what to ask Karel to do? –Simulate – we model our solution on paper before we ever write a line in Karel’s language –We trace the program to make sure we have given Karel all the instructions needed Graph paper might be a good idea –Verification What-If we run Karel’s program, and our goal is not achieved? –We again trace the program seeing if we can find where be gave Karel incorrect information. –Verification Copyright © 2008 by Helene G. Kershner

Karel the Robot –Using Karel the Robot in Lab –Different “Windows” World View (Window) Program View (Window) Execution Window Copyright © 2008 by Helene G. Kershner

Karel the Robot Create a World Beeper inside a box Retrieve and Return Write a Program Copyright © 2008 by Helene G. Kershner

Karel the Robot Problem statement: Karel is to go to the open side of the box, go inside and retrieve the beeper, then go home. Remember our Algorithm Planner Define the output Define the input Define the initial algorithm Refine the algorithm Define the program Copyright © 2008 by Helene G. Kershner

Karel the Robot Define the output: Karel ends up at the origin having retrieved a beeper from the box Define the input: Karel starts at the origin with no beepers in the beeper-bag Define the initial algorithm –Karel is at the origin –Karel is to go to the open side of the box –Karel goes inside and retrieve the beeper –Karel goes home Copyright © 2008 by Helene G. Kershner

Karel the Robot Refine the algorithm Karel is initialized at the origin with an empty beeper-bag Karel is to go to the open side of the box –Go up to 5th street –Turnright –Go another 4 blocks –Make another right Karel goes inside and retrieve the beeper –Go one more block –Pickup the beeper (and put it in the beeper-bag) Karel goes home Travel the reverse of the directions given before Copyright © 2008 by Helene G. Kershner

Karel the Robot Refine Again –Karel is initialized at the origin with an empty beeper-bag –Go up to 5th street –Turnright –Go another 4 blocks –Make another right –Go one more block –Pickup the beeper (and put it in the beeper-bag) –Turn around –Go one block –Make a left –Go 4 blocks –Turnleft again –Go 4 blocks –Turnaround End Copyright © 2008 by Helene G. Kershner