Presentation is loading. Please wait.

Presentation is loading. Please wait.

Karel – Primitive Instructions

Similar presentations


Presentation on theme: "Karel – Primitive Instructions"— Presentation transcript:

1 Karel – Primitive Instructions
Now we start to the learn the robot programming language

2 Technical Term: Execute
In programming A robot executes an instruction The robot performs the action in the instruction A robot executes a program The robot performs the series of instructions delivered by the helicopter pilot.

3 Robot Programming Language Primitive Instructions
Primitives are basic tools with which all problems are solved (analogies: carpentry, geometry) move() turnLeft() putBeeper() pickBeeper() turnOff()

4 Change position with move()
forward only, one block “Error Shutoff” if trying to move into a wall (a duh! Look first!) Remember C++ and div by zero???

5 Turning in Place with turnLeft()
stay at same corner turn 90 degrees to the left cannot cause an error shutoff

6 Handling Beepers pickBeeper()
picks up beeper on current corner and places in beeper bag attempted on beeper-less corners causes an error shutoff

7 Handling Beepers putBeeper()
take beeper from beeper bag and put down on current corner attempted with an empty beeper bag causes an error shutoff

8 Finish a task with turnOff()
robot turns off and is incapable of executing another instruction until restarted the last instruction executed on a robot object

9 What’s the object? What’s the method?
OOP -ness Robot Program Instruction is object.method(); -A method acts on the object -objects are typically nouns (e.g., karel) -methods are typically verbs (e.g., move) and represent behavior Test your Understanding: karel.move() What’s the object? What’s the method?

10 Robot Description or Class
UrRobot class (the “Model-T” Robot) “primitive” You don’t need to define this class – it is in a library for you to use public class UrRobot { void move() {…} void turnOff() {…} void turnLeft() {…} void pickBeeper() {…} void putBeeper() {…} } void means just do and don’t remember

11 So what does a program look like?

12 import kareltherobot.*; public class SampleTest implements Directions
Sample Program import kareltherobot.*; public class SampleTest implements Directions { public static void main(String args[]) { ur_Robot karel = new UrRobot(2, 1, East, 0); karel.move(); karel.turnLeft(); karel.turnOff(); } static { … // code here that you need not worry much about

13 4 Types of Program Errors
lexical error (compiler catches) word not in its dictionary syntax error (compiler catches) incorrect grammar, punctuation, incorrect location of a statement execution error (run-time environment catches) can’t perform what you ask (at run-time) intent error (logic - guess who catches this one!) program terminates successfully – junk output, however Which is the hardest type of error to correct? Why?

14 Now You Try a Short Program on Paper – 10 minutes
start a robot (HBot) at position (1, 1) (a.k.a, the “origin”) facing North and having an infinite number of beepers Have the robot “print” (using beepers) the letter H (with 3-beeper sides and a 1-beeper bar) when done, the robot should be facing North back at the origin (leaving the world in its original state of being)

15 Programming the HBot together
Let’s go into BlueJ and write the HBot. We’ll cover these items: Your network drive and staying organized Creating a workspace Compile vs. Execute setting up things at home


Download ppt "Karel – Primitive Instructions"

Similar presentations


Ads by Google