1 / 24

The LOGIC and MATH blocks Day 9

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.

Download Presentation

The LOGIC and MATH blocks Day 9

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. The LOGIC and MATH blocksDay 9 Computer Programming through Robotics CPST 410 Summer 2009

  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. Harry Howard, CPST 410, Tulane University

  3. Yes? No? Maybe? Kelly §17

  4. The challenge Tribot, • If the Light sensor detects a level above 30, • and if the Sound sensor detects a level above 20, • move forward two rotations. 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. 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 numbers • Note that p. 127 mistakenly uses COMPARE for LOGIC several times!! 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 LOGIC • connect the Light logic plug to the A plug of LOGIC 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. 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. Harry Howard, CPST 410, Tulane University

  10. LOGIC.rbt, final Harry Howard, CPST 410, Tulane University

  11. Logic in NXC

  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] Harry Howard, CPST 410, Tulane University

  13. Repeat the challenge Tribot, • If the Light sensor detects a level above 30, • and if the Sound sensor detects a level above 20, • move forward two rotations. 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?) 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); } Harry Howard, CPST 410, Tulane University

  16. LOGIC outputs Harry Howard, CPST 410, Tulane University

  17. Basic math Kelly §20

  18. The MATH block • Among the Data blocks • Does basic arithmetic: • addition • subtraction • multiplication • division Harry Howard, CPST 410, Tulane University

  19. First challenge • Tribot, display the sum of two random numbers between 0 and 50. Harry Howard, CPST 410, Tulane University

  20. Math1.rbt 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. Harry Howard, CPST 410, Tulane University

  22. Math2a.rbtuses 3 DISPLAYs to put text on 3 lines Harry Howard, CPST 410, Tulane University

  23. Math2a.rbtconnects TEXT to TEXT to put entire text on 1 line Harry Howard, CPST 410, Tulane University

  24. Next time • Math in NXC • Files and Bluetooth • Tasks, routines, subroutines: Kelly 26. Harry Howard, CPST 410, Tulane University

More Related