+ All Categories
Home > Documents > ITK 168 Decisions

ITK 168 Decisions

Date post: 31-Dec-2015
Category:
Upload: tamekah-hardin
View: 22 times
Download: 0 times
Share this document with a friend
Description:
ITK 168 Decisions. Dr. Doug Twitchell September 20, 2005. IF. What if I want the robot to pick a thing up if there’s one there, but not pick a thing up if there isn’t?. if. if(bob.canPickThing()){ bob.pickThing(); }. if(){ }. if. - PowerPoint PPT Presentation
22
ITK 168 Decisions Dr. Doug Twitchell September 20, 2005
Transcript
Page 1: ITK 168 Decisions

ITK 168 Decisions

Dr. Doug Twitchell

September 20, 2005

Page 2: ITK 168 Decisions

IF

What if I want the robot to pick a thing up if there’s one there, but not pick a thing up if there isn’t?

Page 3: ITK 168 Decisions

if

if(bob.canPickThing()){bob.pickThing();

}

if(<<test>>){<<list of statements>>

}

Page 4: ITK 168 Decisions

if

if(bob.canPickThing()){bob.pickThing();

}

if(<<test>>){<<list of statements>>

}

boolean statement

Page 5: ITK 168 Decisions

if

if(bob.canPickThing()){bob.pickThing();

}

if(<<test>>){<<list of statements>>

}

boolean statement

true or false

Page 6: ITK 168 Decisions

if Flowchart

Page 7: ITK 168 Decisions

if

Can I use this to see if there is a wall in front of me?

Page 8: ITK 168 Decisions

if

if(bob.frontIsClear()){bob.move();

}bob.turnLeft();bob.move();

<<previous statements>>if(<<test>>){

<<list of statements>>}<<continue with following>>

Page 9: ITK 168 Decisions

if

What if I want it to left if the front isn’t clear?

Page 10: ITK 168 Decisions

if

if(!bob.frontIsClear()){bob.turnLeft();

}bob.move();

<<previous statements>>if(<<test>>){

<<list of statements>>}<<continue with following>>

Page 11: ITK 168 Decisions

if

Can I check to see if the robot is on a certain street?

Page 12: ITK 168 Decisions

if

if(bob.getStreet == 1){bob.move();

}

if(<<test>>){<<list of statements>>

}

== equal> greater than< less than>= g.t. or equal<= l.t. or equal!= not equal

Page 13: ITK 168 Decisions

while

what if I want the robot to pick up all of the things in a row

Page 14: ITK 168 Decisions

while

while(bob.canPickThing()){bob.pickThing();bob.move();

}

while(<<test>>){<<list of statements>>

}

Page 15: ITK 168 Decisions

while

while(bob.canPickThing()){bob.pickThing();bob.move

}

while(<<test>>){<<list of statements>>

}

boolean statement

true or false

Page 16: ITK 168 Decisions

while Flowchart

Page 17: ITK 168 Decisions

while

How about moving the robot until it gets to avenue 50?

Page 18: ITK 168 Decisions

while

while(bob.getAvenue() < 50){bob.move

}

while(<<test>>){<<list of statements>>

}

Page 19: ITK 168 Decisions

if…else

What about when want to turn right if wall is in front and turn left otherwise?

Page 20: ITK 168 Decisions

if…else

if(bob.frontIsClear()){bob.turnLeft();

} else {bob.turnRight();

}bob.move();

if(<<test>>){<<list of statements>>

}

boolean statement

true or false

Page 21: ITK 168 Decisions

if…else Flowchart

Page 22: ITK 168 Decisions

Example

How can we change the street cleaning robots to make it work better with if and/or while statements?


Recommended