390 likes | 402 Views
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
E N D
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 swanson@hevanet.com 503-297-1824 Dale Jordan Dale_A_Jordan@msn.com Instructor Contacts
ORTOP Project Administrator Cathy Swider Cathy_Swider@ous.edu (503) 725-2920
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
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
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!”
Review the NXT G Software to look at all programming blocks that are available NXT Block Review
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
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
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
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.
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
Use a Switch Block • How will we decide if it’s a green or black bar? • Look at Switch Blocks in the software
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
Stop on Green – One Answer Note the additions I made that were not in our steps, which I discovered in the debugging process.
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?
Stop on Green – First Version • We need to find a way to terminate the infinite loop • Ideas??
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
Different Forms of Loop Block • Look at Loop Blocks in the software • Notice the “Data Hub” on the Loop on Logic Value block
Data Hubs • Look at Data Hubs in the software
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
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
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
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
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
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
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)
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
Move in a Square with My Blocks • Same program with My Blocks is 2.8KB
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
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.
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
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.
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
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.
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
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
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?
Contact Us Web site: http://www.ortop.org Email: questions@ortop.org Phone: 503-821-1136