Presentation is loading. Please wait.

Presentation is loading. Please wait.

The LOGIC and MATH blocks Day 9 Computer Programming through Robotics CPST 410 Summer 2009.

Similar presentations


Presentation on theme: "The LOGIC and MATH blocks Day 9 Computer Programming through Robotics CPST 410 Summer 2009."— Presentation transcript:

1 The LOGIC and MATH blocks Day 9 Computer Programming through Robotics CPST 410 Summer 2009

2 7/1/09Harry Howard, CPST 410, Tulane University2 Course organization  Course home page 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.

3 Yes? No? Maybe? Kelly §17

4 7/1/09Harry Howard, CPST 410, Tulane University4 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.

5 7/1/09Harry Howard, CPST 410, Tulane University5 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.

6 7/1/09Harry Howard, CPST 410, Tulane University6 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 numbers  Note that p. 127 mistakenly uses COMPARE for LOGIC several times!!

7 7/1/09Harry Howard, CPST 410, Tulane University7 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 LOGIC  connect the Light logic plug to the A plug of LOGIC

8 7/1/09Harry Howard, CPST 410, Tulane University8 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.

9 7/1/09Harry Howard, CPST 410, Tulane University9 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.

10 7/1/09Harry Howard, CPST 410, Tulane University10 LOGIC.rbt, final

11 Logic in NXC

12 7/1/09Harry Howard, CPST 410, Tulane University12 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]

13 7/1/09Harry Howard, CPST 410, Tulane University13 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.

14 7/1/09Harry Howard, CPST 410, Tulane University14 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?)

15 7/1/09Harry Howard, CPST 410, Tulane University15 Logic.nxc int light, sound; task main() { light = Sensor(S3); sound = Sensor(S2); if (light > 30 && sound > 20) RotateMotor(OUT_BC, 75, 720); }

16 7/1/09Harry Howard, CPST 410, Tulane University16 LOGIC outputs T, TF, TT, FF, F && (and) TFFF || (or)TTTF XORFTTF ! (not)on plug A: T > F; F > T

17 Basic math Kelly §20

18 7/1/09Harry Howard, CPST 410, Tulane University18 The MATH block  Among the Data blocks  Does basic arithmetic:  addition  subtraction  multiplication  division

19 7/1/09Harry Howard, CPST 410, Tulane University19 First challenge  Tribot, display the sum of two random numbers between 0 and 50.

20 7/1/09Harry Howard, CPST 410, Tulane University20 Math1.rbt

21 7/1/09Harry Howard, CPST 410, Tulane University21 Second challenge  Tribot, display two random numbers between 0 and 50 and their sum, in the format: A + B = C.

22 7/1/09Harry Howard, CPST 410, Tulane University22 Math2a.rbt uses 3 DISPLAYs to put text on 3 lines

23 7/1/09Harry Howard, CPST 410, Tulane University23 Math2a.rbt connects TEXT to TEXT to put entire text on 1 line

24 7/1/09Harry Howard, CPST 410, Tulane University24 Next time  Math in NXC  Files and Bluetooth  Tasks, routines, subroutines: Kelly 26.


Download ppt "The LOGIC and MATH blocks Day 9 Computer Programming through Robotics CPST 410 Summer 2009."

Similar presentations


Ads by Google