More loops, switches Day 5 Computer Programming through Robotics CPST 410 Summer 2009 Course organization Course home page (http://robolab.tulane.edu/CPST410/) Lab (Newcomb 442) will be open for practice.
Download
Report
Transcript More loops, switches Day 5 Computer Programming through Robotics CPST 410 Summer 2009 Course organization Course home page (http://robolab.tulane.edu/CPST410/) Lab (Newcomb 442) will be open for practice.
More loops, switches
Day 5
Computer Programming
through Robotics
CPST 410
Summer 2009
Course organization
Course home page
(http://robolab.tulane.edu/CPST410/)
Lab (Newcomb 442) will be open for
practice with 3-4 Macs, but you can bring
your own laptop and all robots.
7/1/09
Harry Howard, CPST 410, Tulane University
2
Loops within loops
Tribot, do a little dance. Move forward for 1
rotation and then turn right for 180°. Do
this 3 times and then turn left 2 rotations.
Beep and wait 2 seconds. Stop when the
center NXT button is pressed. After you
stop, laugh.
7/1/09
Harry Howard, CPST 410, Tulane University
3
NestedLoopMove.rbt
7/1/09
Harry Howard, CPST 410, Tulane University
4
MysteryLoop.rbt
7/1/09
Harry Howard, CPST 410, Tulane University
5
Decision, decisions
Kelly §12
Review
Tribot, I want you to pivot in a circle for 3.5
rotations, stop, and beep. If your Light
sensor detects a light level greater than 30,
turn left.
7/1/09
Harry Howard, CPST 410, Tulane University
7
Switch0.rbt
7/1/09
Harry Howard, CPST 410, Tulane University
8
Challenge
SPOT, I want you to pivot in a circle for 3.5
rotations, stop, and beep. If your Light
sensor detects a light level greater than 30,
turn left. Otherwise, turn right.
7/1/09
Harry Howard, CPST 410, Tulane University
9
The SWITCH block
You will have to use a SWITCH block:
which is the last block that we have not
used under the Common palette
7/1/09
Harry Howard, CPST 410, Tulane University
10
Using a switch
Pull out a SWITCH block, set it to Light
Sensor, change it to 'greater than 30', and
delete the Light WAIT block.
Drag your last MOVE block into the
SWITCH block for the left turn, and then
another MOVE block beneath it for the
right turn.
7/1/09
Harry Howard, CPST 410, Tulane University
11
Switch.rbt
7/1/09
Harry Howard, CPST 410, Tulane University
12
Switches in switches
Tribot, move forward, and when your
ultrasonic sensor detects an object less than
25 cm in front of you, turn left if your sound
sensor detects a sound level greater than 20.
7/1/09
Harry Howard, CPST 410, Tulane University
13
SwitchFake.rbt
7/1/09
Harry Howard, CPST 410, Tulane University
14
SwitchinSwitch.rbt
7/1/09
Harry Howard, CPST 410, Tulane University
15
Next time
More switches.
STOP/break a loop.
Random numbers.
7/1/09
Harry Howard, CPST 410, Tulane University
16