490 likes | 698 Views
North Alabama Robotics Team Monkey Madness. FLL Intro Programming Workshop. 2012. Kim Daugherty bongju328@gmail.com 256-955-9521. Goals. Present NXT-G programming concepts that you can teach your FLL team Conduct a hands-on NXT workshop to facilitate learning
E N D
North Alabama Robotics Team Monkey Madness FLL Intro Programming Workshop 2012 Kim Daugherty bongju328@gmail.com 256-955-9521
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
Agenda • Introductions • Our motivation • NXT introduction • Basic movement • Sensors • Control flow (loops and switches) • Debugging
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
NXT Introduction • Programming window • Version checking • NXT brick basics
Start a New Program 1. Enter “MoveTest” 2. Click on Go to open program TIP: Use descriptive program names written in mixed case
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
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
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
NXT Version Number Help->About New Program V2.1.f3 Patch f3 located at http://education.lego.com/en-gb/preschool-and-school/secondary-11-18/11plus-lego-mindstorms-education/downloads/ TIP: Patch f3 reportedly fixes the Error 1003 Broken Wire problem in NXT 2.x
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 Version
A B C Before We Start 1 – Light 3 – Touch • The NXT • Outputs for Motors/Lights (A,B,C) • Inputs for Sensors (1,2,3,4) • Buttons (Enter, Back, Left, Right) • USB port • Motors • Middle (A), Left (B), Right (C) • Sensors • Light sensor (1), touch sensor (3), color sensor, ultrasonic sensor, rotation sensor
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 (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
Basic Movement • The easiest way to get around is the Move block • This is the block you will use the most
A B C Most Basic Command 1 – Light 3 – Touch 1. Click here and drag a Move block to the Start area 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
A B C Run the Program 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
A B C Two Ways to Turn 1 – Light 3 – Touch • Use slider bar on steering control • 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
A B C Experiment with Move 1 – Light 3 – Touch • Write a program to: • 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?
A B C Wait Block 1 – Light 3 – Touch 3. Repeat until 5 Wait blocks have been added 1. Click here, select 1st block (time), and drag after Move block 2. Enter 0.25 seconds TIP: Waiting a short time after each move improves repeatability and accuracy
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 bottom
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 1 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
A B C Sensors 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 sound
A B C Developing an algorithm 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
A B C Touch Sensor 1 – Light 3 – Touch 1. Click here to start a new program 2. Click here and drag a Move block to the Start area 8. Save program and name it TouchTest 9. Click here to download the program to the brick 5. Change port to 3 6. Click here and drag a Move block next to Wait block 4. Click here, select 2nd block (touch), and drag next to Move block 7. Select Stop for direction 3. Select Unlimited for Duration of Move TIP: Be sure to stop the motors after a Wait block
A B C Experiment with Touch 1 – Light 3 – Touch • Write a program to: • 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?
Questions? • Did you use copy and paste? • Did you remember to add waits after each move command?
A B C One Way to Do It 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
A B C The Loop Block (1 of 2) 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
A B C The Loop Block (2 of 2) 1 – Light 3 – Touch 2. Delete the remaining 12 blocks 1. Click and drag these blocks inside the Loop block 3. Save, download, and run TouchTest TIP: Wait for the Loop block to expand before you let go of the blocks
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
A B C Create MyBlock (1 of 4) 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
A B C Create MyBlock (2 of 4) 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
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
A B C Create MyBlock (3 of 4) 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
A B C Create MyBlock (4 of 4) 1 – Light 3 – Touch TIP: There is no way to remove the space without redoing the Loop block
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
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 Light Sensors Optimum height above mat is between ¼ and 1 inch; too low saturates sensor and too high gets poor reading of reflected light Left light sensor connected to port 1 TIP: Light sensors should be calibrated and shielded from ambient light
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
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
B C Another Algorithm 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
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
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?
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
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
Put it All Together • Use Line Following, WaitTimeBlock, and MoveTouchBlock to navigate robot from start of line to target area
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
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%20Mindstorms%20Education– NXT Education Base set and Resource set TIP: Be positive and always set a good example for your team