1 / 39

Oregon Robotics Tournament and Outreach Program

Oregon Robotics Tournament and Outreach Program. Programming Techniques Workshop for Mindstorms  NXT. 2011. Opening doors to the worlds of science and technology for Oregon’s youth. Ken Cone ken_cone@ous.edu 503-725-2918. Jim Ryan james.r.ryan@intel.com 971-215-6087. Roger Swanson

gomeze
Download Presentation

Oregon Robotics Tournament and Outreach Program

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. Oregon Robotics Tournament and Outreach Program Programming Techniques Workshop for Mindstorms NXT 2011 Opening doors to the worlds of science and technology for Oregon’s youth

  2. Ken Cone ken_cone@ous.edu 503-725-2918 Jim Ryan james.r.ryan@intel.com 971-215-6087 Roger Swanson swanson@hevanet.com 503-297-1824 Dale Jordan Dale_A_Jordan@msn.com Instructor Contacts

  3. ORTOP Project Administrator Cathy Swider Cathy_Swider@ous.edu (503) 725-2920

  4. Workshop Goals • In Workshops 1, 2, and 3 we have introduced very basic programming to get you started with your robots • In this Workshop we delve more deeply into just the programming • Introduce techniques that we think you are likely to use sometime in your coaching careers • Discuss the Why as well as the How

  5. Agenda • Tour the NXT software to review all the available NXT blocks • Distinguish those with high utility from those with lower utility • Hands on exercises to try out the new, high utility blocks

  6. Caveat about this Workshop • Don’t expect to go right back to your teams and teach them all this new stuff you have learned. • Look for opportunities when the youngsters are ready to pick up a new fundamental technique • Our goal is to prepare you better so you are ready when a new teaching opportunity arises • And remember: “The kids do the work!”

  7. Review the NXT G Software to look at all programming blocks that are available NXT Block Review

  8. High Utility Blocks Move Wait Loop Switch Sensor Blocks Stop Data Blocks (variables) My Blocks Low Utility Blocks Record/Play Motor Send Message Lamps Mini Blocks Random Advanced NXT Block Summary • Useful for Debugging • Sound • Display • Number to Text • Text You should know already Will cover tonight

  9. Steps to Develop a Program • Understand what is to be accomplished • Write down a list of tasks describing how you would solve the problem • Break the tasks up into simpler subtasks • Program the subtasks, try them, and debug them • Put the subtasks together for the final program

  10. Program to Stop on Green • Do you remember the light sensor exercises in Workshops 1 and 3? • Stop on black or green • Stop only on black • Obvious follow-up is to stop only on green • What is the description of the problem? • Initial condition • Final condition • Environment in which robot is operating • What is the list of tasks that you would use? • Each team develop a list of tasks

  11. An Answer Is in the Slides Throughout this workshop an answer is given in the slide set so you have something to review when you get home. Don’t look ahead until you have tried the exercise yourself. 

  12. Program to Stop on Green • One possible list of tasks • Go forward and stop on green or black (We did this program in Workshops 1 and 3. No need to reinvent the wheel.) • Decide if robot has stopped on green or black • If green, stop the program • If black, continue the program to the next green or black block

  13. Use a Switch Block • How will we decide if it’s a green or black bar? • Look at Switch Blocks in the software

  14. Stop on Green Block • You try it • You’ll probably need a Switch Block • Don’t forget the Loop Blocks that you used in other workshops

  15. Stop on Green – One Answer Note the additions I made that were not in our steps, which I discovered in the debugging process.

  16. Enhance Stop on Green • What if I wanted to use this logic in several places throughout my program? • With the way it’s written, the whole program stops when it finds green. • What could we do so that the program continues when green is encountered?

  17. Stop on Green – First Version • We need to find a way to terminate the infinite loop • Ideas??

  18. Using Variables • First define the variable using Define Variables in the Edit Menu • Click on Create • Give the variable a name • Set its type: logic, number, or text • Use the Variable Blocks (Data Block section) to: • Read the variable • Write the variable • Manipulate the variable with other Data Blocks • Demonstrate in the software

  19. Different Forms of Loop Block • Look at Loop Blocks in the software • Notice the “Data Hub” on the Loop on Logic Value block

  20. Data Hubs • Look at Data Hubs in the software

  21. Stop on Green and Continue Program • You try it • Change your Stop on Green program by removing the Stop program block and adding some blocks so that the program can continue after exiting the Loop Block

  22. Stop on Green and Continue Program – One Solution • Note the following • Variable GreenStop has been defined and initialized to False before start of loop • GreenStop is set to True when green is found • GreenStop is used to control the Loop on Logic Value

  23. Data Wire Tips • Easiest way to connect a data wire: click on the port at the left end and then click on the port on the right end • To delete a data wire: click on the right end of the wire

  24. Data Wire Tips (cont.) • You cannot connect a wire from an output port on a data hub unless there is a wire going into the corresponding input port Broken wire Add a new variable block in the read state

  25. Data Wire Tips (cont.) • Don’t run long data wires from a variable block to a data hub. Instead, insert a variable block for the variable you want to use near where you want to use it so that the data wire is short. Not so good Better

  26. Subroutines or My Blocks • What if you find that you are using the same sequence of blocks in many places in your program? • Examples: • 90 degree spin turn • Go forward to stop on a black line • Define that sequence as a My Block and save memory in the process

  27. Building a My Block • Select the blocks from the program • Choose Make A New My Block in the Edit menu • Give the My Block a name, fill in the description, and build an icon (optional)

  28. Move in a Square • A “primitive” way to move in a square • How big is this program? • Use the NXT Window to manage memory • Size is 3.7KB • Demonstrate memory management in the software

  29. Move in a Square with My Blocks • Same program with My Blocks is 2.8KB

  30. Managing My Blocks • Where does the NXT Software keep My Blocks? • Use Manage Custom Palette in the Edit Menu • The My Blocks sub folder has your My Blocks • You can email a file from the My Blocks folder to share the My Block • If you receive a My Block, move it to the My Blocks directory to make it visible in the Custom Palette

  31. Build a My Block to Display Number • Convert number to text • Display block If the bounding box you use to select the blocks for the My Block crosses a data wire, then that value becomes an input or output parameter for the My Block.

  32. Display Number My Block • Note the Wait For block to wait for 3 seconds to give time to read the result • Note the number as input parameter to the MyBlock

  33. Debugging Example • Go back to your Stop on Green Program • Use your display number My Block to compare the values read by the light sensor when the robot first stops and after it has moved forward a bit to be sure it is fully in the block at which it stopped.

  34. Using the Display Number MyBlock • Note that after each block that stops the robot, two blocks have been added: • A Light Sensor block to provide the value the light sensor is reading • The Display Number Myblock

  35. Other Debugging Ideas • I don’t know where the robot is in the program. Use a Sound Block to just play a tone to see if the robot has gotten to a particular point. • What value does my variable have? “Print” the value to the NXT screen to see the value. • Take a subtask out of a more complex larger program and debug it separately rather than trying to debug it in the full more complex environment.

  36. More Exercises for the High Achievers or To Do at Home • Do a My Block that takes an integer as input and moves that many centimeters or inches • Use distance sensor in CanDo challenge • Use color sensor to do the Stop on green only exercise

  37. Class Exercises -- Summary • Stop on green only – Switch Block • Stop on green with logic variable to control the loop – Variable and Loop controlled by variable • Develop Display Number My Block – Number to Text, Display Block, My Block with input parameter, and memory management • Use the Display Number to understand why you need to move a bit in the Stop on Green program – Debugging idea and using a My Block

  38. Your Input • How does the workshop compare to what you expected or hoped would be covered? • Does the “lecture” material provide sufficient background for the exercises? • Are the exercises appropriate to demonstrate the new material? Too easy or too hard? • How was the time for the workshop? • Should anything be deleted or added? • Other comments?

  39. Contact Us Web site: http://www.ortop.org Email: questions@ortop.org Phone: 503-821-1136

More Related