html5-img
1 / 70

DISPLAY and MOVE Day 2

DISPLAY and MOVE Day 2. Computer Programming through Robotics CPST 410 Summer 2009. Course organization. Course home page (http://robolab.tulane.edu/CPST410/) Hand out syllabi. Notice that Aug. 10 is the final day to turn in the final project.

ledell
Télécharger la présentation

DISPLAY and MOVE Day 2

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. DISPLAY and MOVEDay 2 Computer Programming through Robotics CPST 410 Summer 2009

  2. Course organization • Course home page • (http://robolab.tulane.edu/CPST410/) • Hand out syllabi. • Notice that Aug. 10 is the final day to turn in the final project. • 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. Photos Harry Howard, CPST 410, Tulane University

  4. Preliminaries

  5. Update on robots • Are they all assembled? • Who has a laptop? • Start installing software. Harry Howard, CPST 410, Tulane University

  6. Upgrade firmware on robot • Launch the Mindstorms NXT application on your laptop. • Turn on the NXT brick. • Connect the next brick to your laptop via the USB cable. • From the Tools menu (at the top), select Update NXT Firmware. • In the Update NXT Firmware window, click 1.05 version to highlight it. • Click Download. • Don't unplug it! Harry Howard, CPST 410, Tulane University

  7. The first screen Harry Howard, CPST 410, Tulane University

  8. Hello World! Kelly §3

  9. The Tradition • The first program anyone writes displays 'Hello World!' on the screen. • Who are we to break with tradition? • So let's get started … • ... with pseudo-code: • SPOT, I'd like you to display the words "Hello World!" on your LCD screen. Harry Howard, CPST 410, Tulane University

  10. Start your first program In the text box under Start New Program, type 'HelloWorld' -- the name for our first program -- and click on ‘Go >>’. Harry Howard, CPST 410, Tulane University

  11. The palette Harry Howard, CPST 410, Tulane University

  12. The DISPLAY block Drag a DISPLAY block from the common column into the 'Start' space Harry Howard, CPST 410, Tulane University

  13. The DISPLAY block’s settings Harry Howard, CPST 410, Tulane University

  14. Action Image Text Drawing Reset Display Clear File Position x (length) y (height) The settings in detail Harry Howard, CPST 410, Tulane University

  15. Enter the text • Change your block’s action to Text and enter "Hello, world!" in the box. • Note the x and y values, plus the appearance of the line number. • File > Save. • Connect the robot to your laptop with the USB cable, if you haven’t already done so. Harry Howard, CPST 410, Tulane University

  16. The controller • Five buttons that turn orange when the mouse rolls over them: • NXT window • Download and run selected • Stop • Download • Download and run Harry Howard, CPST 410, Tulane University

  17. The NXT window: Comm tab • Look at the battery charge • Tell me whenever it goes down under 25%, so I can recharge the batteries. • If you are authorized: change the name to the name you choose (max 8 characters) and push the return key. Harry Howard, CPST 410, Tulane University

  18. The NXT window: Memory tab • You can manually upload (and download) files from this screen, as well as delete them to free up memory. Harry Howard, CPST 410, Tulane University

  19. Download and run the program • In the Controller, click the right arrow in the center (Download and run). • On the NXT brick, press the orange button. Harry Howard, CPST 410, Tulane University

  20. What happened? • The text was displayed so quickly that you may not have seen it. • But that is easy to fix. • New pseudo-code: • SPOT, I'd like you to display the words "Hello World!" on your LCD screen for 10 seconds. Harry Howard, CPST 410, Tulane University

  21. The WAIT blocks • There are several ways to implement this pseudo-code, but the one we shall use here involves a TIME WAIT block. • Go to the application, click on the hourglass icon in the Common palette, and look at the WAIT blocks that spring out from it. Harry Howard, CPST 410, Tulane University

  22. DISPLAY + WAIT Drag out a TIME WAIT block (timer icon) from the hourglass, and drop it right after the DISPLAY block Harry Howard, CPST 410, Tulane University

  23. The TIME WAIT block • Take a look at its settings, • and enter the number of seconds to wait. • Notice how this number appears on the block. • Save and download to the NXT brick. Harry Howard, CPST 410, Tulane University

  24. Play time • Take about 10 minutes to vary the settings of the DISPLAY and TIME WAIT blocks and see what happens. • Obviously, you want to predict what will happen before the program runs. Harry Howard, CPST 410, Tulane University

  25. Data hubs - skip! • The settings of the DISPLAY block can be changed from other parts of the program by revealing its data hub. • Put your cursor at the bottom of the DISPLAY block and try to pull down the indented line. • Running the cursor over each icon reveals the kind of information that it accepts. Harry Howard, CPST 410, Tulane University

  26. The VARIABLE block - skip! • What Kelly describes does not work! • To illustrate the usefulness of the data hub, change to the Complete palette (the 3 interlocking squares at the bottom left). • Select the big orange plus sign (Data), • pull out a suitcase (Variable), and • drop it in front of the DISPLAY block. • Change its setting from Logic 1 to Number 1. Harry Howard, CPST 410, Tulane University

  27. The text-based language NXC Hansen

  28. PC users • Bricx Command Center 3.3 • http://bricxcc.sourceforge.net/ Harry Howard, CPST 410, Tulane University

  29. First look at BricxCC • Open BricxCC and move the Brick Command Center window to the left so that the Templates window is visible (see next slide). Harry Howard, CPST 410, Tulane University

  30. Now go to the File menu and start a new program. Harry Howard, CPST 410, Tulane University

  31. A basic program (p. 148) • A program must always have at least one task, followed by braces that contain the code that the task executes: task name() { // the task's code is placed here } • From the Templates window, click on the Programs box and then click Task…(){…}. [next] Harry Howard, CPST 410, Tulane University

  32. Replace “name” with main, which is used for a task that has no obvious name. Harry Howard, CPST 410, Tulane University

  33. Hello, world! In NXC

  34. NXC HelloWorld • Instead of blocks, NXC has functions. • We need two, one to display the text and the other to keep the text on the screen for a while. Harry Howard, CPST 410, Tulane University

  35. TextOut • NXC supplies a function specifically to display text, TextOut. • This function asks you for 3 pieces of information • How many pixels from the left the text begins, • What line the text begins on, • And the text itself. • This information is put between parentheses, with each piece separated by a comma. The text is also quoted: • TextOut(0, LCD_LINE1, “Hello, world!”) Harry Howard, CPST 410, Tulane University

  36. TextOut in BricxCC • In BricxCC, select “body” in the task, and • In the Templates window, open the Drawing box and click on the topmost TextOut function. [see next] Harry Howard, CPST 410, Tulane University

  37. Harry Howard, CPST 410, Tulane University

  38. Filling in TextOut in BricxCC Harry Howard, CPST 410, Tulane University

  39. Wait • The function for keeping the text on the screen is Wait. • It measures time in milliseconds: • Wait(10000) • In BricxCC, open the Timing box in the Templates window, and click on the Wait function. [see next] Harry Howard, CPST 410, Tulane University

  40. Now replace “time(1 ms)”with 10000. Harry Howard, CPST 410, Tulane University

  41. Wait(10000) Harry Howard, CPST 410, Tulane University

  42. Compiling • Now go to the Compile menu and select Compile. • If you did everything right, nothing much happens. • However, if you made a mistake, the compiler might catch it. • It will find typos; • It will find syntax errors; for instance, it expects that every line of code must be terminated by a semi-colon. Harry Howard, CPST 410, Tulane University

  43. Test the compiler • As an example, • change LCD_LINE1 > LCD_LIN1 • leave off the semicolon after Wait(10000) • Compile and see what happens. • Try some more. Harry Howard, CPST 410, Tulane University

  44. Summary

  45. DISPLAY vs. TextOut TextOut(0,LCD_LINE8,”test”) Harry Howard, CPST 410, Tulane University

  46. TIME WAIT vs. Wait Wait(1) Harry Howard, CPST 410, Tulane University

  47. Get Movin' Kelly §4

  48. The MOVE block • Start a new program and name it 'Move'. • Drag a MOVE block (interlocking gears) onto the working area. • Look at its settings. Harry Howard, CPST 410, Tulane University

  49. MOVE block settings • Ports: A, B, C (at top of NXT block). • Direction: forwards (up), reverse (down), stop. • Steering: if two motors are connected, dragging the control away from center makes the robot go in a circle. • Power: changes speed of a motor. • Duration: unlimited, degrees, rotations, seconds • Degrees & rotations must be positive, but you can make them negative by changing Direction to reverse. • Rotations also allows fractions. • Next Action: brake, coast • Brake applies the brakes for a quick, accurate stop that uses power. • Coast disengages the motors. If the robot has inertia, it will keep moving. Harry Howard, CPST 410, Tulane University

  50. Play time • Take about 10 minutes varying the settings of the MOVE block and see what happens. • Obviously, you want to predict what will happen before the program runs. Harry Howard, CPST 410, Tulane University

More Related