North Alabama Robotics Team Monkey Madness FLL Intro Programming Workshop 2012 Kim Daugherty bongju328@gmail.com 256-955-9521 1 Goals Present NXT-G programming concepts that you can teach your FLL team Conduct a hands-on NXT workshop to facilitate learning Provide tips and strategies that have been learned through trial and error over five years 2 Agenda Introductions Our motivation NXT introduction Basic movement Sensors Control flow (loops and switches) Debugging 3 Our Motivation To help Alabama FLL teams be competitive at the national (US Open) and international level (World Festival) Robot design is typically not an obstacle for teams – programming is… Teams can design robust software if they are given a few tips… To help teams have a great FLL experience so they consider continuing into FTC/FRC 4 NXT Introduction Programming window Version checking NXT brick basics 5 Start a New Program 1. Enter “MoveTest” 2. Click on Go to open program TIP: Use descriptive program names written in mixed case 6 Programming Window 1 of 2 Move Record/play Sound Display Wait Loop Switch Common palette TIP: The common palette is usually sufficient for basic navigation 7 Programming Window 2 of 2 Common Move Action Record/play Sensor Sound Flow Display Data Wait Advanced Loop Switch Complete palette TIP: The complete palette contains advanced commands 8 Comment and Pan Tools Comment tool allows you to add documentation Pan tool allows you move the screen around Pointer tool allows you to select and insert blocks TIP: Document your program so you can remember what it does 9 NXT Version Number Help->About New Program V2.1.f3 Patch f3 located at http://education.lego.com/en-gb/preschool-and-school/secondary11-18/11plus-lego-mindstorms-education/downloads/ TIP: Patch f3 reportedly fixes the Error 1003 Broken Wire problem in NXT 2.x10 Firmware Version Number Tools>Update NXT Firmware… Version 1.31 is the latest TIP: Check the NXT firmware on the brick by going to Settings->NXT Version11 A B Before We Start Outputs for Motors/Lights (A,B,C) Inputs for Sensors (1,2,3,4) Buttons (Enter, Back, Left, Right) USB port Motors 1 – Light 3 – Touch The NXT C Middle (A), Left (B), Right (C) Sensors Light sensor (1), touch sensor (3), color sensor, ultrasonic sensor, rotation sensor 12 Practice Robot Horizontal mount points Two light sensors Caster wheel Good balance and weight distribution over drive wheels High torque for lifting (small gear connected to large gear) Low center of gravity for stability Robot instructions obtained from Oregon Robotics Tournament and Outreach Program 13 (ORTOP) http://www.ortop.org/Workshops/index2011.html Name Your Robot This tab allows you to delete files from the brick This is where you name the brick Connect robot to laptop using USB cable This button brings up the NXT window TIP: You can delete sound files and demo programs to free up space on the NXT 14 Basic Movement The easiest way to get around is the Move block This is the block you will use the most 15 A B Most Basic Command 1. Click here and drag a Move block to the Start area C 1 – Light 3 – Touch 2. Click here to download the program to the brick Speed control Direction control Motor selection Steering control Degrees OR rotations should be used; rarely use seconds It is usually better to brake than coast TIP: Get familiar with all aspects of the Move command 16 A B Run the Program C 1 – Light 3 – Touch First menu is “My Files” Select with orange button Second menu is “Software Files” Select with orange button Use arrow keys to find “MoveTest” Select with orange button Press orange button to Run 17 A B Two Ways to Turn Use slider bar on steering control C 1 – Light 3 – Touch Middle position means robot will go straight The further the slider is from the middle (but not all the way to one side), the sharper the curve will be (swing turn) If the slider is all the way to one side, the robot will turn in place by turning one wheel forward and the other backward Make sure motors on steering control set to B and C Move one wheel only Click on either port B or C, but not both Only one wheel will turn; this is a pivot turn TIP: Pivot turns are the most precise, but swing turns are faster 18 A B Experiment with Move 1 – Light 3 – Touch Write a program to: C Move forward 100% speed for 2 rotations Make a right pivot turn at 75% speed (hint 390 deg) Move backward 50% speed for 360 degrees Make a left swing turn at 75% speed for 1 second Turn in place clockwise all the way around at 25% speed (hint 800 deg) Move forward 100% speed for 1 rotation Observations? What could improve repeatability and accuracy? 19 A B Wait Block 1. Click here, select 1st block (time), and drag after Move block C 1 – Light 3 – Touch 3. Repeat until 5 Wait blocks have been added 2. Enter 0.25 seconds TIP: Waiting a short time after each move improves repeatability and accuracy 20 Help Screen Move cursor over block to get short description in this window Click here to get detailed help screen TIP: Access help for selected block by clicking on “More help” on NXT right bottom21 For Improved Navigation Use Wait blocks after Move blocks to allow robot motion to completely stop Start in the same position in base each time; it is common to have the robot bumper pressed again the wall1 Use pivot turns instead of swing turns Don’t exceed 50% power when turning In previous years, FLL mat is centered East West and flush with South wall; distance between East or West wall and mat can vary on different tables 1 22 A B Sensors C 1 – Light 3 – Touch Allows the robot to feel (touch), see (light), hear (sound), and measure distance (ultrasonic) Are often used to determine when to stop moving TIP: Light and touch sensors are more useful in FLL than ultrasonic and sound23 A B Developing an algorithm C 1 – Light 3 – Touch An algorithm is a step-by-step logical sequence Example: Move forward until robot runs into wall Step 1: Turn on motors 100% speed Step 2: Wait until touch sensor is pressed Step 3: Turn off motors TIP: It is a good idea to write an algorithm before you start writing the program 24 A B Touch Sensor C 1 – Light 3 – Touch 1. Click here to start a new program 2. Click here and drag a Move block to the Start area 6. Click here and drag a Move block next to Wait block 5. Change port to 3 4. Click here, select 2nd block (touch), and drag next to Move block 7. Select Stop for direction 8. Save program and name it TouchTest 9. Click here to download the program to the brick 3. Select Unlimited for Duration of Move TIP: Be sure to stop the motors after a Wait block 25 A B Experiment with Touch 1 – Light 3 – Touch Write a program to: C Move forward 100% speed until robot touches wall Move backwards 50% speed for 2 rotations Make a right turn at 50% speed (Hint 390 deg) Move forward 100% speed until robot touches wall Move backwards 50% speed for 2 rotations Make a right turn at 50% speed (Hint 390 deg) Move forward 100% speed until robot touches wall Move backwards 50% speed for 2 rotations Make a right turn at 50% speed (Hint 390 deg) Observations? 26 Questions? Did you use copy and paste? Did you remember to add waits after each move command? 27 A B One Way to Do It C 1 – Light 3 – Touch Repeat these blocks 3 times Move forward 100% speed unlimited Move backwards 50% speed for 2 rotations Right pivot turn 50% speed for 390 degrees TIP: Copy and paste can save you a lot of time 28 A B The Loop Block (1 of 2) C 1 – Light 3 – Touch 1. Click here and drag a Move block next to Wait block 2. Set Control to Count and set Count to 3 3. Make sure Counter is not checked TIP: The Loop block allows you to repeat commands 29 A B The Loop Block (2 of 2) 1. Click and drag these blocks inside the Loop block C 1 – Light 3 – Touch 2. Delete the remaining 12 blocks 3. Save, download, and run TouchTest TIP: Wait for the Loop block to expand before you let go of the blocks 30 Reusing Blocks You may have a specific block or a sequence of blocks that you want to repeat many times in the program Wait time block a) Move unlimited block followed by b) Wait sensor block followed by c) Move stop block followed by d) Wait time block One or more blocks can be captured in a MyBlock which can be reused 31 A B Create MyBlock (1 of 4) C 1 – Light 3 – Touch 1. Select Wait block and then click on Create My Block 2. Name block WaitTimeBlock and click Finish TIP: Use mixed case and name MyBlock something descriptive 32 A B Create MyBlock (2 of 4) C 1 – Light 3 – Touch 3. Select WaitTimeBlock and drag to previous locations of Wait blocks 4. You can edit the MyBlock by double clicking on it 2. Delete these Wait blocks 1. Select Custom palette TIP: When you edit a MyBlock, save it and download the main program 33 Why is this Better? Change the wait from .25 seconds to 1.0 seconds; you only need to change it in the MyBlock instead of changing every Wait block Don’t download the MyBlock; download the program that uses the MyBlock 34 A B Create MyBlock (3 of 4) C 1 – Light 3 – Touch 1. Select first four blocks and then click on Create My Block 2. Name block MoveTouchBlock and click Finish TIP: When selecting blocks in a Loop, click outside the loop then drag 35 A B Create MyBlock (4 of 4) C 1 – Light 3 – Touch TIP: There is no way to remove the space without redoing the Loop block 36 You Now Have Two MyBlocks WaitTimeBlock Wait a specified time MoveTouchBlock a) Move unlimited block b) Wait for touch sensor block c) Move stop block d) WaitTimeBlock TIP: MyBlocks are useful for reusing specific blocks or sequences of blocks 37 Light Sensors Left light sensor connected to port 1 • • • • • • • • Turn on robot Use arrow keys to move to “View” Select with orange button User arrow keys to find “Reflected Light” Select with orange button Use arrow keys to find “Port 1” Select with orange button Read different areas of the mat – values will be 0 to 100 Optimum height above mat is between ¼ and 1 inch; too low saturates sensor and too high gets poor reading of reflected light TIP: Light sensors should be calibrated and shielded from ambient light 38 Light Sensor Readings Percent Mode: 5% = lowest dark, 100% = very bright Reflected Light Mode: shines a red light The light can be turned off – detecting ambient light (surrounding light) TIP: The light sensor reads reflected light over an area determined by its height 39 Simple Line Following Does not actually follow the line… Then what does it follow? HINT: Line following would NOT work well on a very thin line 40 B Another Algorithm C 1 – Light 3 – Touch Follows Left Edge of Line Two states: Left of desired position, Right of desired position Determine state to control robot movement If Sensor1 > Boundary (Left) Set Motor B to 60 Stop Motor C If Sensor1 < Boundary (Right) Set Motor C to 60 Stop Motor B TIP: It is a good idea to write an algorithm before you start writing the program 41 Line Following 5. Add Move blocks 1. Start new program and name it LineFollow 2. Click and drag Loop block 3. Click Switch block and put into Loop 4. Select Control to be Sensor and Sensor to be Light Sensor 5. Make sure Port is 1 TIP: Make sure to set motor ports correctly when line following 42 Experiment with Line Following Write a program to: Test line following at 60 percent speed Test line following at 40 percent speed Test line following at 100 percent speed Observations? 43 Line Following Observations Faster line following makes large swerves back and forth and can lose the line Slower line following is smoother It is good to have a strategy to end line following 44 End Line Following 1. Click on Loop block 2. Select Control to be Sensor and Sensor to be Rotation Sensor 3. Make sure Port is B 4. Set Until to be > 500 degrees TIP: Use the rotation sensor to stop line following after a specified distance 45 Put it All Together Use Line Following, WaitTimeBlock, and MoveTouchBlock to navigate robot from start of line to target area 46 A Possible Solution (1 of 2) Line follow for 1150 degrees at 60% speed WaitTimeBlock Right pivot turn at 50% speed for 390 degrees WaitTimeBlock MoveTouchBlock Move backward 50% speed for 1 rotation WaitTimeBlock Left pivot turn at 50% speed for 390 degrees WaitTimeBlock MoveTouchBlock 47 A Possible Solution (2 of 2) 48 Resources usfirst.org/roboticsprograms/fll – Official FLL site www.alabamafll.com – Official Alabama FLL site www.nxtprograms.com – NXT designs (not all robots) and sample programs www.techbrick.com – Coaching tips and challenge worksheets www.forums.usfirst.org/forumdisplay.php?f=24 – Get help from the FLL community; must register to post www.teammonkeymadness.com – Our team site www.ortop.org/Workshops/index2011.html – Coaches workshop materials www.ortop.org/NXT_Tutorial/index.html – Online NXT tutorial www.education.rec.ri.cmu.edu/content/lego/curriculum/index.htm – Carnegie Mellon Robotics Academy www.hightechkids.org/for-teams/coaches-library – Coaches materials http://www.legoeducation.us/eng/characteristics/ProductLine~LEGO%20Mind storms%20Education – NXT Education Base set and Resource set 49 TIP: Be positive and always set a good example for your team