1 / 22

Math in NXC Day 10

Math in NXC Day 10. 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. Math in NXC.

Télécharger la présentation

Math in NXC Day 10

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. Math in NXCDay 10 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. Math in NXC

  4. Simple arithmetic • Just what you would expect: + - * / Harry Howard, CPST 410, Tulane University

  5. Challenge • Tribot, move forward one meter, and then back up one meter and roll to a stop. • Assume that the wheels are 56 mm in diameter. • Convert diameter to circumference by multiplying it by π (pi in NXC). Harry Howard, CPST 410, Tulane University

  6. movemeter.nxc int WHEEL_DIAM = 56; int METER2MM = 1000; int DEG2ROT = 360; int degrees; task main() { degrees = METER2MM*DEG2ROT/(PI*WHEEL_DIAM); RotateMotor(OUT_AC, 75, degrees); RotateMotor(OUT_AC, 75, -degrees); Coast(OUT_AC); } Harry Howard, CPST 410, Tulane University

  7. Your own filing cabinet Kelly §22

  8. Data loss • If your robot turns off or loses power, all of the data in your program is lost. • But you can save your data to a file on the NXT brick, using the FILE ACCESS block. Harry Howard, CPST 410, Tulane University

  9. The FILE ACCESS block • Among the Advanced blocks • Actions: read, write, close, delete • A FILE ACCESS block can only perform one of these at a time. • Type: text, number (no logic!) • Previous values are not erased • New values are simply added to the end of the file • To erase, the file must be deleted and then re-created with the same file name Harry Howard, CPST 410, Tulane University

  10. Challenge • Tribot, • Step 1 • The number '10' will be called A; • add a random number between 0 and 50 to it; • display the results in the format A + B = C; • save C in a file. • Do the same thing again, reading C from the file to be the new A; • do this 3 times. Harry Howard, CPST 410, Tulane University

  11. FileAccessLoop.rbt, step 1 Harry Howard, CPST 410, Tulane University

  12. Preparation to step 2 • You need to put the preceding material into a loop. • How does the loop begin? • If it is the first repetition of the loop, A = 10; • otherwise, A = C. • So there must be a SWITCH. • And it must be triggered by the count of the loop. Harry Howard, CPST 410, Tulane University

  13. FileAccessLoop1b.rbt Harry Howard, CPST 410, Tulane University

  14. FileAccessLoop1c.rbt Harry Howard, CPST 410, Tulane University

  15. Messages Kelly §25

  16. Pairing • Before wireless messages can be sent or received, the participating NXTs must be set up for wireless communication (paired). • Choose one to be the 'master'. • On its NXT brick, • navigate to the Bluetooth category, • choose Search, • when the search is complete, choose which connection number (1, 2, or 3) you want the second (slave) NXT to be known as. Harry Howard, CPST 410, Tulane University

  17. Pairing, cont. • The first time a connection is established between two NXTs, a prompt to enter the Passkey will appear on both NXTs; • this needs to be accepted by both. • Now when you navigate to the Connection category on the master NXT, the slave NXT should be shown by its name occupying the selected connection number. • On the slave NXT, the master NXT should be shown occupying connection number 0. • At this point, the master NXT is ready to initiate communication with the slave NXT. Harry Howard, CPST 410, Tulane University

  18. Multiple pairing • If the master NXT needs to communicate with multiple NXTs (up to a maximum of three), you should repeat the above process. • Note! If you have multiple NXT devices talking to each other, and your master NXT is also talking to more than one NXT device, you will need to have at least a one second delay built in to the program to allow the Bluetooth radio to change channels before sending the messages. • It’s only necessary to go through this process on one NXT. The receiving NXT will automatically update its connection when the master NXT is setting up its connection number. Harry Howard, CPST 410, Tulane University

  19. The SEND & RECEIVE MESSAGE blocks • Two blocks enable communication between robots, SEND and RECEIVE MESSAGE. • Each NXT brick has 10 mailboxes. • Each mailbox can hold up to 5 values (of the same type). Harry Howard, CPST 410, Tulane University

  20. Challenges • SPOT, send a message to someone! • SPOT, receive a message from someone! Harry Howard, CPST 410, Tulane University

  21. Send.rbt & Receive.rbt Harry Howard, CPST 410, Tulane University

  22. Next time • Anything we didn’t finish. • Tasks, routines, subroutines: Kelly 26. Harry Howard, CPST 410, Tulane University

More Related