Upload
chandler-lambert
View
24
Download
2
Tags:
Embed Size (px)
DESCRIPTION
The LOGIC and MATH blocks Day 9. 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. - PowerPoint PPT Presentation
Citation preview
The LOGIC and MATH blocksDay 9
Computer Programming through Robotics
CPST 410
Summer 2009
7/1/09 Harry Howard, CPST 410, Tulane University
2
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.
Yes? No? Maybe?
Kelly §17
7/1/09 Harry Howard, CPST 410, Tulane University
4
The challenge
Tribot, 1. If the Light sensor detects a level above 30,
2. and if the Sound sensor detects a level above 20,
3. move forward two rotations.
7/1/09 Harry Howard, CPST 410, Tulane University
5
Brain-storming
Can we do this with what we know so far?No, we can only use one sensor at a time as a
condition for a robot to do something.
7/1/09 Harry Howard, CPST 410, Tulane University
6
The LOGIC block
Like the COMPARE block, the LOGIC block performs a comparison.
For the LOGIC block, it is between two logical values (True/False), not two numbersNote that p. 127 mistakenly uses COMPARE
for LOGIC several times!!
7/1/09 Harry Howard, CPST 410, Tulane University
7
Program the conditions
Drop in a Sound and a Light sensor block and configure them. Sound < 20 Light < 30
Drop in a LOGIC block from the Data icons Operation = And Pull down the data hubs of each sensor
connect the Sound logic plug to the B plug of LOGICconnect the Light logic plug to the A plug of LOGIC
7/1/09 Harry Howard, CPST 410, Tulane University
8
LOGIC.rbt, first step
Note how wiring the first block to the second (B) hub prevents the wires from crossing, so you can understand what is going on better.
7/1/09 Harry Howard, CPST 410, Tulane University
9
Program the response
SPOT must move forward 3 rotations if the output of LOGIC is True.
How would we do that?Use a SWITCH with the True compartment
containing a MOVE.
7/1/09 Harry Howard, CPST 410, Tulane University
10
LOGIC.rbt, final
Logic in NXC
7/1/09 Harry Howard, CPST 410, Tulane University
12
LOGIC in NXC
There is no such operation as LOGIC in NXC,
so you have to break it down into its components,
using the logical operators:&& [logical AND]|| [logical OR]! [logical negation]
7/1/09 Harry Howard, CPST 410, Tulane University
13
Repeat the challenge
Tribot, 1. If the Light sensor detects a level above 30,
2. and if the Sound sensor detects a level above 20,
3. move forward two rotations.
7/1/09 Harry Howard, CPST 410, Tulane University
14
Brainstorming
Collect the reading of the light sensor into a variable.
Collect the reading of the sound sensor into a different variable.
Compare both to the stipulated values.Combine the comparison with ‘and’.Rotate the motor twice (how many
degrees?)
7/1/09 Harry Howard, CPST 410, Tulane University
15
Logic.nxc
int light, sound;task main(){
light = Sensor(S3);sound = Sensor(S2);if (light > 30 && sound > 20) RotateMotor(OUT_BC, 75, 720);
}
7/1/09 Harry Howard, CPST 410, Tulane University
16
LOGIC outputs
T, T F, T T, F F, F
&& (and)
T F F F
|| (or) T T T F
XOR F T T F
! (not) on plug A: T > F; F > T
Basic math
Kelly §20
7/1/09 Harry Howard, CPST 410, Tulane University
18
The MATH block
Among the Data blocksDoes basic arithmetic:
additionsubtractionmultiplicationdivision
7/1/09 Harry Howard, CPST 410, Tulane University
19
First challenge
Tribot, display the sum of two random numbers between 0 and 50.
7/1/09 Harry Howard, CPST 410, Tulane University
20
Math1.rbt
7/1/09 Harry Howard, CPST 410, Tulane University
21
Second challenge
Tribot, display two random numbers between 0 and 50 and their sum, in the format: A + B = C.
7/1/09 Harry Howard, CPST 410, Tulane University
22
Math2a.rbtuses 3 DISPLAYs to put text on 3
lines
7/1/09 Harry Howard, CPST 410, Tulane University
23
Math2a.rbtconnects TEXT to TEXT to put entire
text on 1 line
7/1/09 Harry Howard, CPST 410, Tulane University
24
Next time
Math in NXCFiles and BluetoothTasks, routines, subroutines: Kelly 26.