LEGO Mindstorms NXT Robotics Workshops Hands-On Robotics Programming Workshop Play: Robotics In Education video (4:40) Play: ZOOM FLL Promo video (6:24) Programming Resource Book July 2011 Paul R Keeney [email protected] (763) 506-5692 www.anoka.k12.mn.us/ovms.mr.keeney © Copyright 2011 Paul R Keeney rev 5.2 1 Introduction © This training guide was designed to help classroom teachers, F.I.R.S.T LEGO League coaches, and students with the new LEGO Mindstorms NXT Robotics System. Materials also include suggestions to help keep your LEGO pieces organized and inventoried. The packet will go over the process of developing good robotic programming skills from the concept stage through computer programming and file maintenance. There are numerous people developing other good training materials and videos being posted on-line, so there is no shortage to the amount of training available. NXT Robotics Programming Resource rev 5.2 Copyright 2011 Paul R Keeney No reproduction of this material is allowed without written permission from the author 2 Table of Contents ORGANIZATION Keeping parts organized --------------------- 4 Tray diagrams ---------------------------------- 5 LEGO PARTS Parts diagram ----------------------------------- 6 NXT Brick -------------------------------------- 7 Motors ------------------------------------------- 8 Sensors --------------------------------------- 9-12 SOFTWARE & CURRICULUM LEGO Mindstorms Edu NXT (NXT-G)- 13 Robot Educator ------------------------------- 14 Data Logging -----------------------------------15 Carnegie Mellon Robotics Engineering -- 16 Carnegie Mellon NXT Video Trainer ---– 17 Green City Challenge--------------------------18 Carnegie Mellon Robots In Motion-- ---– 19 Using Profiles --------------------------------- 20 PROGRAMMING Brainstorming & Pseudocode -------------- 21 Simple Text ------------------------------------ 22 Creating a new program --------------------- 23 Saving a program ----------------------------- 24 Opening an existing program -------------- 25 Downloading a program to the NXT ---- 26 Running a program on the NXT ---------- 27 Common Pallet ------------------------------- 28 Complete Pallet ------------------------------- 29 Custom Pallet --------------------------------- 30 Sequence Beam ------------------------------- 31 Adding commands --------------------------- 32 Configuration Panel -------------------------- 33 COMMON PALLET Move Block forward & reverse----------- 34 Modifying Move commands -------------- 35 Comments ----------------------------------- 36 *Hands-On Activity Challenge #1 ------------37 Point Turn ----------------------------------- 38 Swing Turn ---------------------------------- 39 Curve Turn ---------------------------------- 40 *Hands-On Activity Challenge #2 ---------- 41 COMPLETE PALLET Motor Block -------------------------------- 42 Configuration Panel ----------------------- 43 Forward & Reverse ------------------------ 44 Swing Turn ---------------------------------- 45 Point Turn ----------------------------------- 46 Curve Turn ---------------------------------- 47 Selecting & moving blocks --------------- 48 Rewiring with sequence beam ----------- 49 Wait For Blocks ------------------------ 50-51 Sensor Blocks (reset) ---------------------- 52 *Hands-On Activity Challenge #3 ---------- 53 Sound Block -------------------------------- 54 Loop Block --------------------------------- 55 *Hands-On Activity Challenge #4 ---------- 56 Switch Block -------------------------------- 57 Sensor Threshold ---------------------- 58-59 View Mode on NXT ---------------------- 60 Line Tracking using Light Sensor ------- 61 *Hands-On Activity Challenge #5 ---------- 62 Parallel Sequence Beams(multitasking)-- 63 Display Block ---------------------------- 64-65 NXT Buttons Block ----------------------- 66 Sensor Feedback Box ---------------------- 67 Using multiple sensors (cascading) ------ 68 Data Hubs & Data Wiring ---------------- 69 Number To Text Block ------------------- 70 Variables --------------- ------------------ 71-72 Math Block ---------------------------------- 73 Logic Commands -------------------------- 74 Reset Motor Block ------------------------- 75 Calibrate Sensors ----------------------- 76-77 Data Logging ---------------------------- 78-81 *Hands-On Activity Challenge #6 ---------- 82 CUSTOM PALLET Creating a My Block (subroutine) -------83 Adding a My Block to a program ------- 84 My Block with variables ------------------ 85 *Hands-On Activity Challenge #7 ---------- 86 ADVANCED COMMUNICATIONS NXT Window information -------------- 87 BlueTooth Communications ------------ 88 FILE MAINTANENCE Deleting files from NXT ------------- 89-92 Deleting files from the computer ------- 93 Updating Firmware (operating system)--94 Backing up & transferring files ---------- 95 Downloading to multiple NXTs -------- 96 Technical Support & Problems --------- 97 Bibliography / Resources ---------------- 99 3 Organization suggestions Tray organizer diagrams are provided by LEGO in each kit to help the students keep their parts organized and they list the quantities of each part to help with inventory. Fishing tackle box with multiple bins and/or removable trays to sort the LEGO pieces individually are sometimes very helpful for organizing the many pieces for FLL teams. Create teacher lab rules and procedures: hold students to them so the classroom runs smoothly. Build student responsibilities: develop procedures to help keep the students on-task and all of the equipment taken care of properly. Develop a plan for where you will store the parts and make sure students understand your expectations for them at clean-up time. 4 LEGO NXT robotics kits The basic #9797 NXT kit contains 431 LEGO pieces stored in orange and white trays that fit inside the white storage bin to keep everything organized. FIRST LEGO LEAGUE (FLL) team kits also include a blue resource bin (#9648) with 672 additional LEGO building elements for more advanced building projects. You can download the pdf file from my website and then print copies of these tray diagrams onto sticky-back paper. Cut them into individual pictures and stick them on the bottom of the tray compartments to help sorting. View the images of Storage Trays pdf 5 view interactive parts illustration Get To Know the LEGO Pieces 6 LEGO Mindstorms NXT brick Rechargeable Lithium battery with charger is included with the LEGO Educational version of the NXT and also with the FLL sets. Otherwise, the “brick” will run on 6- AA batteries (not 1.2 volt NiCad batteries) 3 Output Ports for actuators (ports A, B, C on top edge of brick) View the interactive NXT image 4 Input Ports for sensors (ports 1, 2, 3, 4 on bottom edge of brick) ● ● USB data port for communication between computer & robot (downloading) Wireless Bluetooth compatible communications are possible if you have a Bluetooth dongle or transmitter for your computer (Bluetooth is not allowed at most FLL tournaments). 7 NXT Motors ● ● ● The NXT servo motors have built-in rotation sensors that can very accurately measure how the motor spins in number of rotations or degrees of travel. They will always be connected to output ports (A, B, C). When you set a Move or Motor block’s direction, you are specifying the direction the motor will spin. This may be different than the direction your robot actually moves. View the interactive Motor images Depending on how you build your robotic invention, setting the motors to go forwards may actually cause your creation to move backwards. The image here shows a motor spinning in the default, forwards direction. The motors spin at approximately 150 RPM at full power. 8 NXT Sensors Sound sensor Measures sound level in decibals (dB) or modified frequencies (dBA) Ultrasonic sensor Distances in inches or centimeters Light sensor Measures ambient or reflected light levels Touch sensor Can be pressed, released, or bumped Rotation sensor (built into motors) Measures motors in degrees or rotations RCX sensors You can connect old RCX style sensors or lights using the RCX to NXT converter cables. View the interactive Sensors images 9 Additional NXT Sensors LEGO Color sensor Acts as a color sensor, distinguishing among six colors; it works as a light sensor, detecting light intensities (both reflected light and ambient light); and it works as a color lamp, emitting red, green, or blue light. LEGO temperature sensor Digital temperature sensor that can be calibrated to measure both Celsius and Fahrenheit. HiTechnic acceleration sensor Measures acceleration in three axes – x, y, and z. It also measures tilt along each axis. HiTechnic compass sensor This digital compass measures Earth’s magnetic field. HiTechnic color sensor Detects an extended range of more than 15 target colors. Sensor blocks for HiTechnic sensors are available for free download at www.LEGOeducation.us/hitechnic 10 Additional NXT Sensors HiTechnic Gyro sensor Contains a single-axis gyroscopic sensor that detects rotation and returns value that represents the number of degrees per second of rotation. a HiTechnic IR seeker sensor Will detect IR beacons using a specially designed curved lens and five internal detectors. The IRSeeker V2 has a 240-degree view. HiTechnic IRLink sensor The IRLink enables the NXT programming system to read values from the RCX sensors and control motors connected to the RCX. Codatex RFID sensor Can read five-byte transponder numbers into the NXT Intelligent Brick. HiTechnic IRReceiver sensor Decodes commands from a LEGO® Power Functions IR Remote Control. Sensor blocks for HiTechnic sensors are available for free download at www.LEGOeducation.us/hitechnic 11 Additional NXT Sensors HiTechnic EOPD sensor Electro Optical Proximity Detector, uses an internal light source to detect the presence of a target or determine changes in distance to a target HiTechnic NXT angle sensor Provides a method to determine the angular position and rotation speed of an axle HiTechnic magnetic sensor Detects magnetic fields present around the front of the sensor in a vertical orientation. Vernier sensor adapter for NXT With this sensor adapter, any of the 40+ Vernier analog (BTA) sensors can be incorporated into NXT creations. Venier programming block can be downloaded for free at www.LEGOeducation.us/vernier LogIT NXT sensor adapter Compatible with more than 50 LogIT Microsense® sensors and adapters. Free projects, software sensor block downloads, and resources are available at www.LogITNXT.com 12 LEGO Mindstorms Education NXT v2.1 Software Unlike the previous RCX robotics kit, teachers must purchase software separately to do programming for the NXT robot set. The software is available as an individual CD set, or site license that allows you to install it on multiple computers for classroom use. FLL teams who order an NXT kit through the FLL registration process will receive the NXT software with an individual software license with their FLL kit. 13 LME Robot Educator (basic training software) The LEGO Education & FLL versions of the “Mindstorms Edu-NXT 1.0 thru 2.1” programming software includes a built-in set of 39 or 46 simple teaching activities that can help students learn about how their robot can do several types of tasks using many different sensors and actuators. (not available on LME Edu NXT retail programming disc #8527) • Challenge Brief Video or multi-step series of images to visually demonstrate what robot should do. • • Building Guide Step by step diagrams detailing how the robot and attachments should be built. • • Programming Guide Step by step instructions to teach the students how to create the program that will make their robot work correctly. • Launch LME Edu NXT software 14 Data Logging New feature of LME 2.0 & 2.1 software To switch between the “NXT Programming” and the “NXT Data Logging” portion of the software, click on the adjoining orange symbols in the top left corner of the menu bar. The NXT Programming portion opens with an orange background and the Data Logging portion opens with a blue background. • Advanced users of the NXT (especially science and engineering teachers), may find the Data Logging portion of the software quite interesting. More information is found on pages 78-81 of this booklet. • • • The basic idea of data logging is to run an experiment, but have the NXT and a computer do the data recording for you. Data logging functionalities embedded in the software, including graph viewer, make it easy to collect and analyze data from any of the NXT sensors using special Data blocks. Data can easily be uploaded to a computer where it can be used by a variety of third-party software such as spreadsheets and graphs. 15 Carnegie Mellon Mobile Robotics curriculum If you plan to use the NXT system in a classroom setting, I used this curriculum succcesfully for 2 years with my 8th grade students using a CD set of activities developed by Carnegie Mellon University. It is called: Robotics Engineering: Introduction to Mobile Robotics Disc 1 covers basic robotic programming and engineering and has up to 6 weeks of activities. Disc 2 guides students through more independently structured challenges for up to 12 additional weeks. The current cost of the curriculum is $274.95 each. The sets do include a Teacher Resource CD with curriculum guides, worksheets, tests, and answer keys that can be printed. Much of the training material in this packet came from that curriculum. 16 Carnegie Mellon NXT Video Trainer I have used this classroom curriculum set for teaching my 8th grade students programming and testing with the NXT robots since 2010. It is called: NXT Video Trainer •This software is designed with elementary and middle schoolaged student in mind. The self-directed video delivery system allows it to be used as either a whole-class or individually student-paced instruction. •The current cost of the curriculum is $270. The sets include integrated video-delivered instruction and several robotic “challenges” that can be printed out for reference. Many of the live demonstrations I use for my teacher and student trainings come from this software. 17 Green City Combo Pack This combination of Green City Challenge Set & Activity Pack combo is ideal as a step-by-step introduction to robotics in the classroom or as preparation for robotics competitions. They were released in 2011 and called: Green City Combo Pack The Green City Challenge Set contains three training mats, a challenge mat, and more than 1,300 elements for building the challenge models, such as a power plant, wind turbine, and dam. The training mats provide a field where students can test and practice their programming skills. The challenge mat offers a real-life setting for solving different missions so students can apply the skills acquired through the training. The Green City Challenge Activity Pack includes seven easy-to-follow training activities, each supported by student worksheets, which guide the students from simple to more advanced programming. Comprehensive teacher notes provide everything needed for easy implementation. •The current cost of the Combo Pack is $319.95 The”challenges” are very similar in structure to the ones done during FIRST LEGO League. 18 Carnegie Mellon Robots In Motion This interactive “smart tutor” This web-based instruction is currently undergoing beta testing and is scheduled for public release in 2011-2012 The 19 Working with “Profiles” Mindstorms NXT Education software Setting up “Profiles” for each team/group of students will allow you to use one computer for more than one group of students. It will automatically keep their software programming files in separate folders on that computer. • To Create a new Profile: (set up only once) • • • • • • Click “Edit” in top menu bar Select “Manage Profiles” Click on the “Create” button Type in the new group name Click on the “Close” button Make sure students select their profile every time they log onto their computer. Launch LME Edu NXT software 20 Turning Your Ideas into Robotics Code (How do I suggest getting started with writing a program?) • • • • • • • Begin by brainstorming ideas of what you want your robot to do. Select your best idea. Convert your written robot actions into pseudocode (not quite sentences & not quite computer code). Describe all of the steps your robot will need to do (go forward, turn left, lift an arm, etc). Create a pictorial representation (flow chart) of your solution. This linear set of actions is called an algorithm. Define what computer code will make your robot perform the actions you have described. Start to write your program on the computer & test your ideas one step at a time. 21 Using “Simple Text” For File Names & Robot Commands The supported characters for the NXT display are the capital and lower letters A-Z, the numerals 0-9, and the punctuation and symbols shown below. !”#$%&’()*+,-./0123456789:;<=>? @ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_ º abcdefghijklmnopqrstuvwxyz{|}~√ Simple Text is used for the brick name, My Blocks, file names, and displaying text on the NXT device using the Display Block. If simple text fields contain other than simple characters or symbols, they will display a blank instead. To avoid confusion caused by lots of blanks, you should always use simple characters for the marked text fields. All places mentioned above require that you use “Simple Text”. They won’t let you type in other characters. The exceptions are the program filename and the text in the Display Block. 22 Creating a new program • • • • • If you have decided to use “Profiles”, have students click on their profile. Click in the “Start New Program” window and type in the name you want students to call their program. Click the “Go” button. Close the “Robot Educator” window if you want more space on the screen to write the program. The NXT software will automatically create a set of folders on the hard drive where the programs will be saved., so file maintenance is very easy. 23 Saving a program • “File – Save” • Can be used if the program has been correctly named already and you want to save it. • You can also click on the icon on the top menu bar to save a program. “File – Save As…” ● Should be used when a program needs to be renamed before it is saved. Type the new name and follow the prompts in the window that appears. (you can also use this command if the student has created their program within the wrong “Profile” by clicking the “Browse” button and navigating to the correct “Profile” folder) • 24 Opening an existing program • • • • If you are using “Profiles”, click on your team’s profile to get to the correct folders. Open existing files by clicking on “File” and then “Open”. Select the file that you want to open and then click on “OK”. You can also click on the triangle in the “Open Recent Program” window to select a recently used program. Select the file that you want to open and then click on “GO”. Close the “Robot Educator window if you want more space on the screen to view or modify your program. The LME Edu NXT software will automatically remember your preferences & keep the Robot Educator window closed unless you open it again. 25 Downloading programs to the NXT Hook up the USB cable that is provided in each kit to connect the computer to the NXT brick. • Open the program that you want to download. • Make sure the NXT power is on. • Click the “Download” button from the window in the bottom right corner ( down arrow=download). • After the download is complete, the NXT will beep and the screen will briefly say “Download Complete”. • Bluetooth communications are possible if the NXT settings for Bluetooth is turned on. You must click on the “NXT window” button to connect using the Bluetooth. You will be asked to go through a process of setting up a passkey to make sure you are communicating with the correct NXT unit. (Bluetooth setup covered on page #88) • 26 Running a program on your NXT • • • • • Turn on your NXT by pressing the large orange button. Tones will sound when you turn on the NXT. If it is already on, press the dark grey button repeatedly until the words “My Files” appear. Press the orange button to select “My Files”. View the NXT movie (1:24 ) Press the orange button again to select “Software files”. Use the light grey arrow buttons to navigate from side to side until you see the name of the file you want to run. (hint: the last program file you download will always show up first). • • • Press the orange button to select that program. To run the program, press the orange button again and your program will immediately start. The file name will appear in the LCD To stop a running program, press the dark grey button once. 27 Common Pallet • Move • • Record/Play • • Time, Touch, Light, Sound, or Distance variable controls Loop • • To view image or text on the NXT display screen Wait For • • To play audio sound file or tone Display • • To record and later playback actions for the robot Sound • • To make one or more motors move forward, backward or stop To repeat sequences of code Switch • “If/Then” command to choose between 2 sequences of code 28 Complete Pallet • Common • • Action • • Move – Record/Play – Sound – Display – Wait For – Loop - Switch Motor – Sound – Display – Send Message – RCX Motor – RCX Lamp Sensor Touch Sensor – Sound Sensor – Light Sensor – Ultrasonic Sensor – NXT Buttons – Rotation Sensor – Timer – Receive Message – Temperature sensor – Color Sensor- Emeter In – Emeter Out RCX Touch Sensor – RCX Rotation Sensor – RCX Light Sensor – RCX Temperature Sensor • • Flow • • Data • • Wait – Loop – Switch - Stop Logic – Math – Compare – Range – Random – Variable - Constant Advanced Number To Text - Text – Keep Alive – File Access – Calibrate – Reset Motor – Start Datalog – Stop Datalog • 29 Custom Pallet • My Block (subroutine) Lets you take a number of blocks you select in the work area and group them together into your own “My Block” with a customized icon. Over time you may develop a library of “My Blocks” that you can use over again in other programs. (discussed on pages # 77-79) • Web Downloads To use programs you have downloaded from the Internet. These are not allowed in FLL tournaments. 30 Sequence Beam The sequence beam controls the flow of your program. Generally, one block represents one command given to the robot. Blocks perform their operations in order along the Sequence Beam. Blocks connected to the sequence beam can be downloaded to the NXT to perform tasks on the robot. Other blocks in the work area that are not connected to the sequence beam will appear grayed out and will not function as any part of the working program. The “Start Block” will appear automatically for new programs and will always indicate the starting point. 31 Adding commands to the Sequence Beam • • • • • Hold the curser over the task palette. Click and drag on the command that you want added to the sequence beam. Move the command to the right side of the existing commands and drop it in place to add it to the end of the existing sequence. You can also drop a new command into the middle of an existing sequence by holding it in place until a space opens up and then dropping it there. If an icon becomes grey/opaque, that means that it is not connected to the sequence beam any more. Reconnect it by dragging it to a different place on the screen and then dropping it back into place where it should be connected. 32 Configuration Panel • • • (for modifying attributes of commands on the sequence beams) Click on an icon in the sequence beam to view the attributes for that command. A teal colored outline around the icon indicates that it is the command that is selected and has its attributes displayed in the configuration panel at the bottom of the screen. Change any of the attributes of that block within the configuration panel and that block will be modified. 33 Forward using “Move” Block ● ● ● ● The “Move” block can be configured to make your robot go forwards or backwards in a straight line or to turn in a curved path. You must define how far your robot will go by using the Duration property in the Configuration Panel. The letters at the top right corner of the block show which of the ports on the NXT will be controlled through this block. This icon shows which direction your motor is programmed. This icon shows the power level. The default level is 75%. Your robot’s speed may also be affected by other conditions, such as wheel size, the friction of the surface it is moving over, or whether it is moving up or down a slope. This icon shows whether you have set the Duration property to unlimited, degrees, rotations, seconds, or stop. Note: Setting the motors’ duration to anything other than “Unlimited” will cause the program to wait until the robot completes the set duration; only then will the program continue to the next command. 34 Modifying Move Commands With The Configuration Panel Select the motors you would like to control. If you choose to control motors B & C, the motors will be synchronized; going forward or backwards at exactly the same power. If you select all three motors, then A, B & C will all work at the same time. Choose whether the motors will go “forward”, “backwards”, or “stop”. Selecting “Stop” will also reset the motor rotations to zero. The slider or the editable input box will let you set the power level (speed) [0-100%]. Either slide the marker on the bar or type in your power level. Using the Duration pull-down menu, you can set the motors to run for an unlimited interval or for a set number of seconds, rotations [default] or degrees. By choosing Time, Rotation or Degrees you can control how far your robot will travel. Choose whether the motors will brake or coast after they’ve finished their action. If you want your robot to stop precisely at an exact location, set the motors to brake. Setting your motors to brake will also keep your robot from slowly rolling backwards on a slope but the setting will wear out the NXT’s batteries quicker because the motors are doing work to keep the robot in place. 35 Comments Comments are typewritten notes or directions left by the programmer but they do not change the way the robot behaves in any way. Comments are very important to the programmer’s ability to remember what a certain piece of code does, or so other programmers can understand what is being attempted in the program. To use the Pointer Tool, double click anywhere on the grey programming workspace where you want the comment added. To use the Comment Tool, single click on the workspace. Type the important information you want noted for that area. 36 View Robot Educator Activities #3 & #4 HANDS-ON ACTIVITY SET #1 Program your robot to drive forward Use the “Move Block” and “Configuration Panel skills you just learned about to make your robot drive forward exactly 25cm/10” and then stop. Record the number of rotation/degrees needed. Shake a single dice to find out how many spaces your robot must move (lines are spaced every 25cm/10”). Using your previous testing of distance traveled, accurately calculate the number of degrees/rotations the motors must spin in order to travel the required distance. Modify your program for the required amount of travel and save it with a new name. Download the new program onto your robot in order to test your calculations. Set your robot just behind the starting line and place the LEGO minifig onto the appropriate line based on the roll of your dice. Run the program on your robot and watch to see if you were successful. If your robot stops more than 12mm (1/2”) from the minifig character or of the robot touches any part of the minifig, you must evaluate what you must change, modify your program as necessary, and retest the robot until you are successful. After the instructor verifies a successful test run, repeat steps 2 through 7 until you have successfully completed all 6 distances. 37 Point Turns Using “Move” Block A “Point Turn” (sometimes also called a skid or spin turn) is very useful for making the robot turn quickly in a small amount of space. It sits in one location and spins as it turns. If you’re using two motors to drive a vehicle (with one on each side), and you want to use a Move Block, the Steering slider will appear with the chosen port letters indicated at each side. Move the slider to set a curved path for your robot. With the slider all the way to either side, your vehicle will spin in place. View Robot Educator Activity #7 38 Swing Turns Using “Move” Block A “Swing Turn” is very useful for making the robot turn around an object without bumping it with only one wheel moving and the other wheel stopped. If you’re using two motors to drive a vehicle (with one on each side), and you want to use a Move Block, move the slider 1 notch from either end of the Steering slider bar. Your vehicle will spin with one wheel stopped and the other going forward or backwards. To slow down your robot so it does not skid, slow down the wheel by adjusting the Power setting to a lower number. View Move & Turn video 39 Curve Turns Using “Move” Block A “Curve Turn” is very useful for making the robot turn at the same time it continues to drive forward or backwards using both wheels going the same direction. If you’re using two motors to drive a vehicle (with one on each side), and you want to use a Move Block, move the slider to any location except the last 2 notches. The closer the slider is to the ends, the sharper the robot will turn to the left or right. Exactly in the center will make the robot drive perfectly straight again. View Robot Educator Activity #6 Caution: It is very difficult to fine-tune your robot’s turns using the slider bar! 40 HANDS-ON ACTIVITY SET #2 Program your robot to make 3 different turns using the “Move” block Use the Move Block and Configuration Panel to make your robot make a “Point Turn” to the right exactly 3 wheel rotations (1080 degrees) and then stop. Make sure you include “comments” in your program. Save your program with the name “pointRx3”. Download it onto your robot and test it. Modify that program to make the robot do a “Swing Turn” to the left for 3 wheel rotations and then stop. Save that program as “swingLx3”. Download it onto your robot and test it. Make another program so the robot will make a “Curve Turn” to the right for 3 wheel rotations, then stop. Save that program as “curveRx3”. Download to your robot & test it. Compare the turns. Create a new program that uses one style of turn to drive in a “Figure Eight” around two obstacles. BONUS ACTIVITY: Navigate the course using all 3 styles of turns View Robot Educator Activities #6 & #7 41 “Motor” Block The Motor block allows for precise control of one motor’s speed. You can “ramp up” to a set speed or “ramp down” to a stop. By deselecting “Wait for Completion,” your program can move on to the next block once the Motor block has started a motor. 1. 2. 3. 4. 5. The letter at the top right corner of the block shows which NXT port is set to control this particular motor. This icon shows which direction the motor will go. This icon shows the power level. This icon shows whether you have set the Duration property to unlimited, degrees, rotations, seconds, or stopped. You can change many of the values dynamically by connecting data wires to this block’s data hub. This will de discussed later in the booklet. 42 Configuring the “Motor” Block 1) 2) 1) 2) 3) 4) 5) 6) Select the motor to control. Choose whether the motor should go “forwards”, . “backwards”, or “stop”. You can precisely control the acceleration of the motor by selecting “Ramp Up” or “Ramp Down.” A motor set to “Constant” will reach full power immediately and will stop quickly. The slider and the editable input box will let you set the power level (speed) [0-100%]. Either slide the marker on the bar or type in your desired power. Select this checkbox if you’d like to turn on power control to attempt to compensate for any resistance or slippage that the motor encounters to maintain the same rotation amount per second. Using the Duration pull-down menu, set the motor to run for an unlimited interval or for a set number of rotations, degrees, or seconds. With “Wait for completion” selected, the motor will finish its action completely before allowing the program to move on. If you de-select “Wait for completion,” other blocks in the program can proceed while your motor completes its action. Choose whether the motor will brake or coast after finishing its action. 43 Forward & Reverse using “Motor” Block If you use Motor blocks in your programming instead of Move blocks, you will often have many more options on how to control the behavior of the motors. A motor block will only control one output port, so you will need a Motor block for each motor that will be moving (2 wheel drive= 2 motor blocks) You can start 2 or 3 motors simultaneously, if they are wired in sequence along the beam and the Duration time is set to Infinite. Use a Wait For block to control how long you want the motor(s) to do the desired action. Use more Motor blocks with other commands (stop, change direction, etc) to begin the next set of actions. 44 Swing Turn using “Motor” Blocks Swing turns are very easy to create and fine-tune the robot performance if they are created using a series of Motor blocks and Wait For blocks. Because a swing turn only has one motor running at a time, it is very easy to program it with a Motor block. To make the robot turn to the left, turn on the motor on the right side of the robot. Use a Wait For block to control how long you want the motor(s) to do the desired action. Use more Motor blocks with other commands (stop, change direction, etc) to begin the next set of actions. 45 Point Turn using “Motor” Blocks Point turns will allow your robot to spin quickly in either direction. Because the robot moves so quickly, I suggest that you slow down the motors to keep wheels from slipping. Point turns are sometimes called spin turns because the wheels are running at the same speed but in opposite directions. To make the robot spin to the left, set the motor on the right side of the robot to run forward and the left side motor to run in reverse. Use a Wait For block to control how long you want the motors to do the desired action. (you will only need to wait for one motor if using rotations or degrees) Use more Motor blocks with other commands (stop, change direction, etc) to begin the next set of actions. 46 Curve Turn using “Motor” Blocks Curve turns will allow your robot to drive forward or backwards while turning at the same time. Using Motor Blocks is the most accurate way to create curve turns that you can accurately adjust later. Curve turns are usually the fastest method of allowing the robot to move a new spot if it cannot drive in a straight line. To make the robot spin to the left, set the motor on the right side of the robot to run forward at a higher power level. The larger the difference in power levels are, the sharper the robot will turn. Use a Wait For block to control how long you want the motors to do the desired action. (you will only need to wait for one motor if using rotations or degrees) Use more Motor blocks with other commands (stop, change direction, etc) to begin the next set of actions. 47 Selecting & Moving Blocks Around Sometimes it is very helpful to move blocks around on the workspace. If a block was created correctly, it can easily be moved to a different part of the sequence beam. Click on the block that you want moved so a blue border appears around it. You can also select multiple blocks together by clicking and dragging a box around all of them together. While the block(s) are still outlined with blue, drag them to the location where you want them. The other blocks will automatically move to open up space to add them. Click to drop the blocks in the new location. If they become greyed out, reselect them, wiggle them around a bit and then place them back to reconnect to the sequence beam. 48 Rewiring Long Sequence Beams Sequence beams sometimes need to be routed into odd paths, especially when the programs get very long with many blocks strung together. Use the arrow keys on the keyboard to navigate left, right, up, or down to determine which blocks you want to move. Click & drag to create a window of blocks you want to move. Drag the selected blocks to the location you would like them, then click to drop them in the new spot. To reconnect the moved blocks to the sequence beam, hold the “shift” key while clicking from the end sequence beam hub to the beginning hub of the moved blocks. Re-select any greyed out blocks, wiggle them around the screen a bit, and when they are placed back in the correct location, they will be connected. 49 “Wait For” Block The Wait For block lets your robot sense its environment for a certain condition before it continues. Use the slider or type in a value to set a trigger point (threshold) so that the program continues when sensor values are below or above that level. The number or letter at the top right corner of the Wait block shows the port the block is monitoring. The configuration panel will let you change ports if necessary. If you have chosen to wait for a light, sound, or ultrasonic sensor, this icon indicates at what level the trigger point (threshold) is set; the more colored bars displayed, the higher the trigger point. If you have chosen to wait for a touch sensor, the icon will display the touch sensor condition (bumped, pressed, or released) that will trigger the block and allow the program to move on. 50 “Wait For” Block Options There are many options for how to turn on and off motors in your program: View the Wait For movie (2:29) Wait For Light Sensor (Waits for light reading to get above or below the #) Wait For Rotation Sensor (Waits for motor to rotate) Wait For Touch Sensor (Waits for sensor to be pressed, released, bumped) Wait For Sound Sensor (Waits for sound to get above or below the # Wait For Ultrasonic Sensor (Waits for distance to get above or below) Wait For NXT Buttons (Waits for orange or grey NXT buttons) Wait For Receive Message (Used with Bluetooth messages) Wait For *RCX sensors (Light*, Rotation*, Temperature*, Touch*) Wait For Time/Timer (Waits for time in seconds) 51 Sensor Blocks (yellow) Using a Sensor block is most commonly used to read or reset rotations for the motors. Choose which port you would like the block to monitor (A, B, or C). Choose either to read a rotation sensor's current value or to reset a sensor's value back to zero (resetting is required for multi-step programming chains using Motor Blocks). Set the direction you want to monitor using the radio buttons: forwards or backwards. It is important to make sure that you choose the right direction or the block may never be able to count to your set trigger value. Use the pull-down menu to set whether the block should count the number of rotations or degrees (using degrees is more accurate for detailed measurements) Type the trigger value into the input box and use the pull-down menu to specify whether you want the “true” region to be greater than or less than the trigger value. The feedback box will show the current count in full rotations or degrees. Push the reset button to clear the count and start from zero. The feedback value will be displayed in black-colored text for rotations or degrees in the forward (positive) direction; it will be in red-colored text rotations or degrees in the backward (negative) direction. 52 HANDS-ON ACTIVITY SET #3 Program your robot to drive using the “Motor” & “Wait For” blocks Use Motor blocks and Wait For blocks to make your robot drive forward exactly 2 rotations (720 degrees) and then stop. Make sure you include “comments” in your program. Save your program with the name “forwardX2”. Download it onto your robot and test it. Modify that program to make the robot do a “Point Turn” to the left and then stop. Save that program as “pointL”. Download it onto your robot and test it to see if the robot turns exactly 90 degrees. Continue to modify & save the program until it makes a perfect right turn. (hint: four 90 degree turns equals 360 degrees) BONUS ACTIVITY: combine the programs to make the robot drive in a clockwise square and then drive backwards in a square. Hint: use the “copy” and “paste” commands to speed up the process 53 Sound Block You can use the Sound block to play a pre-recorded sound file or a single tone using one Sound block. To compose a melody of tones, arrange several sound blocks in a row with each set to play different tones. If you select “Wait for completion” in the configuration panel, the sound file or tone will finish playing before the program moves on to the next block. With this item unchecked, the sound file or tone will continue to play while the next block on the sequence beam of your program proceeds. Choosing “Repeat” will cause a sound file to play again & again. 1. 2. 3. This icon shows whether the block will play a sound file or a tone. This icon shows whether the block will start or stop playing a sound. This icon shows the block’s volume. An icon with four orange bars is set to the loudest volume. Caution: using sound blocks, especially sound files, will quickly use up NXT memory space 54 Loop Block Use this block to repeat sequences of code. Set the condition that will end the loop: elapsed time, the number of repetitions, a logic signal or a sensor. You can also set a loop to go on forever. If a Loop block is placed on the sequence beam, a short section of the beam will appear inside the Loop block; programming blocks dragged on top of this portion of the sequence beam will snap to it. Any new blocks dragged inside a loop that already contains programming blocks will cause the frame to expand sideways so the new blocks will fit inside the loop. This will make room for the new blocks to snap to the sequence beam automatically. 55 View the Loops video (2:41) HANDS-ON ACTIVITY SET #4 Program your robot to avoid obstacles using the touch sensor View movie describing the activity Add the touch sensor bumper attachment to the front of your robot. (Robot Educator Activity 18 has one suggested bumper design that you may want to build if you don’t have one made). Create a program called “BumpDetect” using the Motor, Loop, and Switch blocks. Program your robot to travel forward until it runs into an obstacle and then immediately stop and make a sound. BONUS ACTIVITY: Add motor blocks to have the robot make a small reverse swing turn, and then continue with the first driving action again. Make the entire program loop for 30 seconds and then stop. Hint: most of your program will need to be within the loop block, but you should configure the loop to wait for 30 seconds, then make the wheel motors stop when the 30 seconds is done, otherwise your robot will continue to loop forever. View Robot Educator Activities #17 56 Switch Block Use the Switch block to choose between two sequences of code. For example, when configured with a touch sensor, the switch block might run one series of blocks when the sensor is pressed and another when the touch sensor is not. Add blocks by dragging them over the empty spaces within the Switch block’s surrounding frame. The Switch block’s interior will expand so the block can fit and snap into place. If there are already blocks within the frame, drag any additional blocks over the desired connection point on the sequence beam and the adjacent blocks will shift sideways allowing the new blocks to snap into place. The example indicates the status of the touch sensor will cause the block to choose between the two rows of programming blocks. ● ● The upper blocks will run if the touch sensor is pressed, so the motor will run forward. The lower block will run if the touch sensor is not being pressed, so the motor will run backwards. View Switch Block video (4:30) By de-selecting the “Display Flat View” checkbox, the Switch block will use a tabbed interface to show the alternative sequences of programming blocks. By clicking on a tab, you will be able to view and edit the blocks and see which condition will cause those particular blocks to run. 57 Sensor Threshold A threshold is a “cutoff” or dividing line between two regions. One common use for thresholds is to divide the hundreds of possible sensor readings from a sensor (a Light Sensor can give a value anywhere from 0-100, for example) into two manageable categories. For the Light Sensor, this would mean setting a threshold value somewhere between 0 and 100, then declaring that all values above the threshold are now “light” while all values below the threshold are now “dark.” A light sensor reading can then be easily categorized and handled appropriately. The threshold value can be chosen in any way desired, but it is conventional to choose a value exactly halfway between two known extremes (e.g. halfway between a very dark surface and a very light one). View Thresholds explanation movie 58 Calculating & Setting Thresholds A threshold number must be set in the configuration panel for the following sensors: ● Light Sensor ● Ultrasonic Sensor ● Sound Sensor 1. 2. 3. 4. Record the maximum reading from the sensor on your robot (sound, light, distance, etc). Record the minimum reading from the sensor. Threshold numbers are usually placed around midway between the maximum and minimum readings of the sensor, so calculating the average (mean) is the typical method. Enter that calculated threshold number into the configuration panel as needed for the sensor. (the software will only accept whole numbers) 59 View Mode on NXT If you want to see exactly what a sensor is reading on your NXT, you may use the “View” mode on the NXT brick and the sensor you want information from. View movie about Light sensor View Mode Make sure the sensor is hooked up to your NXT and navigate to the main menu on your robot. Press the light grey buttons to get to “View”. Press the orange button to select the “View” mode. Use the light grey arrows to navigate to the type of sensor you want to get a reading from (rotation, degrees, reflected light, etc). Press the orange button to select that sensor type. Check the wiring of your robot & sensor, then use the light grey arrows to select the correct port number. When you press the orange button to select that port, the NXT screen will immediately start to display the sensor reading. Press the dark grey button to return to the main menu when you 60 are done. Line Tracking using Light Sensor The robot can use a light sensor to follow the edge of a dark/light line. The must be programmed to continuously turn towards the edge of the line. 1. 2. 3. 4. 5. View Line Tracking explanation Use the “View” mode on the NXT to calculate the threshold level between the light & dark sensor readings. Add a “Switch Block” to the program and set the configuration panel to your calculated threshold number. Add programming blocks to the “dark” side of the Switch Block so the robot will turn towards the light colored surface. Add programming blocks to the “light” side of the Switch Block so the robot will turn towards the dark colored surface. Place all of these programming blocks inside a “Loop Block”. 61 HANDS-ON ACTIVITY SET #5 Program your robot to follow the edge of a black line using Loop & Switch Blocks Use the View mode to test the sensor readings for a black and white table surface. (approximately 1/4” above table is usually the best height for mounting a light sensor). Calculate the threshold level you will need to use for your robot Create a program called “LineTracker” using Motor, Loop, and Switch blocks to travel exactly 10 rotations, then stop the motors. BONUS ACTIVITY: make modifications to your turns to find out how quickly your robot can follow the line without getting lost. There are several different ways to make the robot quicker and more accurate by modifying how it makes its turns using swing or curve turns of varying power levels of the motors. Hint: you may need to start out making slow & tight forward turns until you find out how your robot reacts to the curves and thickness of the black line. 62 View Robot Educator Activities #17 Parallel Sequence Beams View Yocum Tasks video You can use the starting point to create additional sequence beams that will allow your program to run simultaneous tasks. For example, you might have the main sequence beam in your program controlling a robot’s forward motion but have a second sequence beam controlling a robotic arm on the robot. To create a parallel sequence beam, move the mouse pointer over the starting point (or over the wire stub), then press and hold your mouse button while you move the mouse upwards or downwards. This will draw out a sequence beam that can be connected to programming blocks. When you download and run the program, the blocks on both sequence beams will run in parallel. You can use data wires to have the blocks on both sequence beams communicate with each other. You can also start a new sequence beam later in your program (i.e., not from the starting point). Do this by holding down the Shift key and moving your mouse pointer straight up or down from a position on the main sequence beam. 63 Display Block Use this block to display an image, display text, or draw a shape on the NXT’s display screen. The screen measures 100 pixels wide by 64 pixels high. 1. 2. 3. This icon shows whether the block is set to display an image, some text, or a drawing; or whether it will just reset the display to the default icon. You can control the Display block dynamically by connecting data wires (from other blocks’ data hubs) to the Display block’s data hub. Information can be displayed on various sections of the LCD screen by using settings located in the configuration panel. Caution: using display blocks can quickly use up NXT memory space 64 Display Block Settings Configuring the Display Block: 1. 2. Use the pull-down menu to choose whether you want to display an image, some text, or your own drawing. You can also select that you just want to reset the display. To erase the contents of the NXT’s screen, check the “Clear” checkbox. If you choose to display an image, you’ll be able to set the following additional properties: 3. The File property will you let select the image to display. Click on each name to see a preview. 4. Use your mouse to move an image, some text, or a drawing around the preview screen to position it. The X and Y input boxes let you precisely position the image. If you choose to display some text, you’ll be able to set the following additional properties: 5. The Text property will allow you to enter the text to be displayed on screen. 6. Use the pull-down menu to choose the line number that you would like your text displayed on or use the X and Y input boxes to set a precise starting location for the text. Typing zeros into both boxes will start the text at the bottom edge of the screen against the left edge. 7. For Drawing Actions: the Type property will allow you to select between drawing a dot, a line or a circle. View the Display Blocks video (2:49) 65 NXT Buttons Block If you choose “NXT” Buttons within a “Wait For block,” the program will wait for a chosen NXT buttons to be bumped, pressed, or released before moving on. If you select “NXT Buttons” within the “Sensor” block, you can select which NXT button will send out a “true” signal when activated. The block’s data hub will automatically open when the block is placed on the sequence beam. You will need to drag a data wire from the NXT Buttons block to another block that can accept a logic (true/false) signal. The configuration panel must be set using these options: Select which NXT button will send out a “true” signal when activated and cause the program to move on. Choose “Pressed” if you want the chosen button to be activated at the instant the button is pressed in. Choose “Released” if you want the chosen button to be activated at the instant the button is released. Choose “Bumped” if you want the chosen button to be activated after 66 the button is both pressed then released. Sensor Feedback Box from NXT The feedback boxes on the bottom left corner of the software window will count how many degrees or full rotations your motors turn as you manually move them if your robot is communicating with your computer View the Viewing Sensors video (7:39) To receive feedback, make sure that the motors are connected to the chosen ports and that communication has been established with the NXT either with USB cable or Bluetooth. Click on a Move, Motor, or rotation Sensor block in the program Click the reset button to return the values to zero. Manually move the motor and the computer will display real-time count on the number of degrees the motor rotates. Black numbers indicate forward rotations. Red numbers indicate reverse rotations. 67 Using Multiple Sensors (Cascading Switch Blocks) View the Cascading Switches video (3:19) By placing Switch blocks inside other SwitchCan you predict the robot behaviors? blocks, the program can be written with multiple “If-Then” choices. Place a Switch block into the program to determine the first sensor decision. Place a new switch block inside the first Switch block to make the second decision. By de-selecting the “Display Flat View” checkbox, the Switch block will use a series of tabs on the interface to show the alternative sequences of programming blocks. Click on a tab to view and edit the blocks and see what blocks will run under that sensor condition. Flat View Tab View 68 Opening Data Hubs & Creating Data Wires Open a block’s data hub by clicking the tab at the lower left edge of the block after it has been placed on the work area. Note: Sometimes data hubs will not open completely, leaving some plugs hidden. Reveal all of a data hub’s plugs by clicking again on the tab area. You can also close a data hub (or hide any unused plugs not connected to data wires) by clicking the tab area. The cursor will change shape when it hovers over or is near a data plug. If you then press the mouse button and drag to the right, a data wire will “unroll” that can then be connected to a plug on another block’s data hub Data wires carrying input information to a block are connected to the plugs on the left side of its data hub. Data wires carrying output information away from a block to another block are connected to the plugs on the right side. Each data wire carries a specific type of data between blocks. For example, if a data wire is dragged from a logic plug on a block’s data hub, it can only be connected to a logic plug on another block’s data hub. Data wires are identified with specific colors as shown in this diagram: View Data Hubs video (4:46) 69 Number To Text Block This block will take a number (like a reading from a sensor) and turn it into text that can be displayed on the NXT’s screen. The input number can be typed in or supplied dynamically by a data wire. Text is a group of characters of any length that you type in using your keyboard. Text is important because it can be displayed on the NXT’s screen. The numbers (data) generated by the NXT as it runs your program are not text; they can’t be displayed directly on the NXT’s screen. You must first convert them to text using a Number To Text block from the “Advanced” commands in the “Complete” pallet. The Number To Text block’s input number can be typed in or supplied dynamically by a data wire. The output text can only be sent out using a data wire. See the Data Hub section on page 64 for more information. When you convert a number into text, you can add it to a sentence that will be displayed on your NXT’s screen. By using a different block called a Text block, you can create sentences such as: “The motor turned 6 times” or “The light sensor reading is 35%” that can be displayed on the NXT’s screen. In these sentences, the numbers 6 and 35 were generated by the NXT (and not typed in). Those numbers (data from the NXT) had to be processed by a Number To Text block before being added to the other pieces of text. 70 Variables Block Think of a variable as a place to store a value in the NXT’s built-in memory. Other programming blocks can read the variable’s current value (and even change it) by connecting to the block with data wires. View the Variables movie (7:02) Creating a Variable To create a variable, you must first choose the Define Variable command in the Edit menu of the software. In the dialog window, give your new variable a short, easy-to-understand name and set the type of data that the variable will hold (i.e., text, number, or logic). Then drag a Variable block into your program and select the variable’s name from the list. Choose to either “read” from or “write” to the variable. Choosing to write to a variable will let you change the variable’s value over time by overwriting its current value with new information. To do this, you must wire an input data wire to the block’s data hub that will deliver the new information. You can give the variable a starting constant value by typing in the input box (or by using the radio buttons if your variable’s data type is set to logic). 71 Types of Variables Variable (programming): A “container” for a value. The programmer may choose to store a value (perhaps a sensor reading) in the variable, and use it in a later operation (display it to the screen at the end of the program, for instance). The programmer may also choose to perform mathematical operations on the stored value, such as adding 1 to it by adding a Math Block. Variable (experimental): A factor that is either manipulated or measured during the course of an experiment. Also called Independent Variable or Dependent Variable. Variable (mathematics): A stand-in for a not-yet-known value in a mathematical equation. Once a variable’s value has been found, the value can be substituted anywhere in place of the variable. 72 Math Block A Math block performs simple arithmetic operations like addition, subtraction, multiplication, and division. A Math block dropped into the work area will have an open data hub with two input plugs (on the left) and three output plugs (on the right). The input numbers for the arithmetic equation can be typed in or supplied dynamically by data wires. Output from the equation will be delivered from the bottom output plug on the right side; connect this plug using a data wire to another block’s data hub. The two output plugs opposite the input plugs allow you to pass the input numbers on to other blocks if this is necessary. Input values can be typed in or supplied dynamically by data wires. The input boxes will be grayed out when data wires are connected. The pull-down menu will let you choose from four arithmetic operations you can perform: ● Addition (+) [default] ● Subtraction (-) ● Multiplication (x) ● Division (/) 73 Logic Commands This block performs a logical operation on its inputs and sends out the true/false answer by a data wire. The inputs (which must also be “true” or “false”) can be set using the radio buttons or supplied dynamically from data wires. The Logic block uses only two possible values: “true” or “false,” for both input and output. These values are often written as the numbers “1” or “0” where any true statement is written as a 1; any false statement is written as a 0. The four logical operations that this block can perform allow you to perform a series of comparisons. The details of these operations (And, Or, Xor, and Not) are described below. With the “And” operation, if your two input values are both “true,” then the output is also equal to “true”; in all other cases the output will be “false.” With the “And” operation, if your two input values are both “true,” then the output is also equal to “true”; in all other cases the output will be “false.” With the “Xor” operation, if either one of your two input values is “true,” but not both, then the output is equal to “true.” The “Not” operation is sometimes called an “inverter.” This operation has only one input value. If this input value is “true,” the output is equal to “false”; if the input value is “false,” the output is equal to “true.” It just flips the input value. 74 Reset Motors Block The interactive servo motors have an automatic error correction mechanism that helps your robot move very precisely. However, there may be times when you want to turn this feature off. The Reset Motor block will let you do this. If you set the Next Action parameter to Brake between Move blocks, your robot will move more precisely over each step. However, your robot will not drive continuously unless you set the motors to “coast”. Errors build up when you use Coast as the Next Action because of the momentum of the robot. Tip: When you use the “Stop” command for the Motor or Move blocks, the rotations are reset automatically. 75 Calibrate Sensors Function View Yocum Light Sensor video First make sure that your NXT is connected to your computer and that it is turned on. Also, make sure that the sensors you want to calibrate are connected to the NXT. Pay particular attention to the ports they are connected to. When you are ready, select the Calibrate Sensors function from the Tools menu. The Calibrate Sensors dialog box will appear. If no NXT is connected to your computer, the dialog box will appear grayed out. Select the light sensor and the port the sensor is connected to. Then click the Calibrate button. This will download a small program to the NXT and run it automatically. On the NXT’s screen you will see text that reads “Min Value:”. Point the light sensor towards a material or spot that represents what the light sensor should measure as dark. Press the orange Enter button on the NXT. Next you will see text that reads “Max Value:”. Point the light sensor towards a material or spot that represents the brightest location the sensor will encounter during the program. Press the orange Enter button again. Calibration is complete. Note: The calibration will work for the specific sensor no matter which port you connect it to after completing the calibration process. If you calibrate the light sensor on port 3, the calibration will still remain in effect if you later connect the light sensor to port 4. 76 1. 2. Calibrate Sensor Blocks Use this block to calibrate the minimum (0%) and maximum (100%) values detected by a sound or light sensor. You will need two Calibration blocks to fully calibrate a sound or light sensor: one to set the minimum value for the sensor and another to set the maximum value. One way to fully calibrate a sound or light sensor is to set up two Calibration blocks at the beginning of your program with a Wait block (set to wait for a Touch sensor) positioned after each one. If your are calibrating a light sensor, for example, and you set the first Calibration block to calibrate the minimum value and the second Calibration block to calibrate the maximum value, the calibration procedure would happen like this: Place your robot in the darkest/quietest place it will encounter during its program and press the touch sensor. This will calibrate the minimum value. Then place your robot in the lightest/noisiest place it will encounter during its program and press the touch sensor. This will calibrate the sensor’s maximum value and your robot will continue on with its program. 77 Data Logging Configuring a Start Data Hub or Experiment You can use this block to let your NXT collect data from sensors and save it to a file on the NXT. The Experiment Configuration panel is configured in the same manner and is used to create a new experiment or modify an existing one. 1) 2) 3) 4) 5) 6) 7) Use the input box to name a log. The default name is myData Select the duration of the experiment in Seconds or Minutes and enter the value in the text field to the left. Select Unlimited to run the experiment indefinitely until it is stopped by a Stop Data Logging Block, or choose Single Measurement to take only one measurement. Select the rate at which samples will be taken in Samples per Second or Seconds between Samples and use the editable input box to the left to set the number. With "Wait for Completion" selected (default), the Start Datalog block will finish its action completely before allowing the program to move on. If you de-select "Wait for Completion," other blocks in the program can proceed while your Start Datalog block completes its action. Using the sensor pull-down menu, select the sensor(s) that you want to use. Using the Port drop-down menu, select the port on the NXT the sensor is connected to. Choose the measurement unit by clicking on the icon and toggling between the options 78 for each sensor. Data Logging Configuring a Stop Data Hub This block stops a Start Data Logging block that had been previously set to unlimited. ● ● ● Use the drop-down menu to choose the name on the Start Data Logging block you would like to stop. You can control the Stop Data Logging Block dynamically by connecting data wires (from other block’s data hubs) to the Stop Data Logging block’s data hub. You can open a block's data hub by clicking the tab at the lower left edge of the block after it has been placed on the work area. 79 Data Controller The Data Logging Controller is the interface between the Data Logging program and the NXT. The Controller allows you to open the NXT Window, download and transfer log files from the NXT, download and run experiments and stop active experiments. The Controller is inactive until you move or “hover” your mouse cursor over it, changing it from a small grey form to a larger, fully interactive version. You can do five things with the Data Logging Controller: ● ● ● ● ● NXT Window: Opens the NXT Window, allowing you to connect your computer to the NXT, view important information about your NXT, and manage NXT files. If your NXT memory becomes full while data logging, you can delete log files in the Memory tab. Download to NXT: Downloads a program to the NXT, allowing you to use the NXT remotely to run experiments and log data for Upload to the Data Logging program. Download and run: Downloads and runs the selected experiment. Stop: Allows you to stop an experiment that is currently being run on the NXT. Upload: This allows you to move data logging files from your NXT to your computer. The log files on the NXT can originate from data logging experiments and from any data logging programs on the NXT. You can run experiments and log data remotely, and then connect the NXT to the computer when you are finished. 80 Data Logging Accessing log files on the NXT A Start Data Logging block creates a log file on the NXT. ● ● ● . . To access the log file, open the NXT Window, click on the file category “Other” on the list to the left, select the log file you would like to upload from the list, then click on Upload. Then select the location on your computer where you would like to copy your log files to. Once your log files are copied to your computer, they can be opened using a text editor or spreadsheet program. You can have multiple Start Data Logging blocks create different log files. The Name on the block identifies a specific log file on the NXT. If the same name is used in more than . one block, the data will be written to the same log file. If different names are used for the Start Data Logging blocks, different log files will be created. 81 HANDS-ON ACTIVITY SET #6 Data Logging with Color Sensor Devise a method to use Data Logging to evaluate the effectiveness of using a LEGO color sensor to differentiate different colors (this can also be done with a light sensor). Use a separate piece of paper to formulate a Data Logging experiment that will test whether 2 specific colors will have enough contrast for your robot to differentiate between them using the LEGO light sensor. Have your experiment approved by your instructor. Use the chart below to predict whether 2 particular colors will have “High”, “Moderate”, or “Low” contrast with each other. Write your experiment into a working program and test it with your robot. BONUS ACTIVITY: Program your robot to utilize your collected data to navigate through an obstacle course using your color sensor data. Hint: you may need to slow the driving speed of your robot for it to collect quality data points for your specific color samples. 82 Creating a “My Block” (subroutine) A “My Block” (often called a subroutine) is used to help save NXT memory space by putting commonly repeated robot actions into a custom file that can be reused multiple times. Click and drag to highlight the code sections that you want to change into a My Block. • Click the “Create My Block” button on the toolbar at top of the page. • Type a name for your new My Block. • You can enter a description of the actions. • Click “Next” if you want to assemble icons into a custom design for your new program. • Click “Finish” to save your my Block. • View Yocum My Blocks video 83 Adding My Blocks to your program After you have created a My Block, it is saved in the Custom Pallet where it can be used multiple times in different programs. • • • • To add you’re my Block to a program, begin by opening the “Custom Pallet” by clicking on the icon with 2 teal colored bars in bottom left corner. The top block in the Custom Pallet is where your My Block programs can be located. Click & drag the My Block that you want added from the pallet area into your program. NOTE: You can modifying that My Block at any time by double clicking on it and making the new changes. However, doing so will change it in every program that you use it in. 84 My Block with Variables • My Blocks can be created so they have variables that can be edited for specific purposes after the My Block is created. • • • • • • • • Create or open an existing program with a set of commands that you want to reuse often. Change the “Wait For” in the program to be a “Logic” command and wie it to a new Sensor block. Add a Variable block to the program and wire it to the Logic block trigger point. Click and drag to highlight the code sections that you want to change into a My Block (excluding the variable). Click the “Create My Block” button on the toolbar at top of the page. Finish creating the My Block as described on page #77. You can access your new program through the “My Block” menu and reuse it for any of your programs. When you place the new My Block into any other program, it will automatically include the Variable block that you can edit without making permanent changes to the other My Block commands. View the My Blocks Advanced video (4:49) 85 HANDS-ON ACTIVITY SET #6 Create & Use a My Block for your robot Open an existing program, or write a new program that will make your robot perform a perfect 90 degree turn and then create a new “My Block” of that behavior. Create a “My Block” for your turn. Create another “My Block” for turning the other direction 90 degrees. Create a new program to navigate an obstacle course that uses each of your new “My Block” behaviors at least twice each. Test and refine it until it is 100% successful. BONUS ACTIVITY: Create additional “My Blocks” from new or existing programs. Hint: If you modify a “My Block”, you must resave the “My Block” and then redownload any program that uses that “My Block”. Any time you need to modify a “My Block”, those changes will occur on every program that uses that “My Block”.86 NXT Window (Getting Information from Your Robot) “Memory” tab contains a graphical overview of used and available memory. The different file categories (programs, sounds, graphics) that take up the NXT’s ● ● ● ● ● ● memory. Clicking on a category name will display these types of files in the list. A list of files in the currently selected category. Delete. This button deletes any selected files from the NXT. Download. This button will download files from your PC to the NXT. Upload. This button will copy any selected files from the NXT to your PC. Delete all User Files. This button deletes all user files and cleans up the NXT’s memory. Show System Files. Checking this box will reveal all factoryinstalled files on the NXT. Each NXT has an available memory of about 130.7 kilobytes. Some of this memory is used to store example programs, graphics and sound files that are preloaded on the NXT device when you first get it. This leaves about 100 kilobytes for the files you create and download. 87 Bluetooth Communication The robot and computer can communicate wirelessly with the use of Bluetooth technology. If the computer does not have built-in Bluetooth capabilities, a plug-in USB dongle can be purchased ● ● ● ● ● ● ● ● ● ● ● ● ● ● The Bluetooth option on the NXT must be turned on before it can send or receive data wirelessly. Follow these directions on the NXT Turn on the NXT or navigate to the “My Files” menu. Use the light grey arrows to navigate to the Bluetooth icon. Press the orange button to select Bluetooth. Use the light grey arrows to navigate to the “On/Off” icon. Press the orange button & then select “On”. Use the dark grey button to return to the main menu screen. A “B” Bluetooth icon will appear in the top left corner of LCD The computer must be set up to recognize the NXT Power up the NXT and open any program file on the computer. Connect the NXT to the computer with the USB cable. Click the “NXT Window” button, and then click the “Memory” tab. Rename the NXT if you are using Bluetooth on more than one NXT. Click the “Scan” button to search for all NXT’s in the Bluetooth range Select the Bluetooth NXT you want and click “Connect”. You will be guided through a series of password steps to finish connection 88 Using NXT Interface to Delete 1 File Deleting one program file at a time from the NXT Turn NXT on by pressing orange button. Open the program that you want to delete (My Files – Software Files – Program Name). Press the gray buttons to scroll to the “Delete” command (trash can) for that program. Press the orange button to select that program for deleting. The screen will prompt you to make sure you want to delete that program file. Scroll to the checkmark if you are sure and then press the orange button. If you DO NOT want to delete that file, scroll to the “X” and press the orange button, and then back out of the process by pressing the dark gray button several times. 89 Using NXT Interface to Delete files Deleting all program files from NXT at the same time Turn NXT on by pressing orange button. Use grey arrow buttons to scroll to the “Settings” command. Press the orange button to enter the Settings folder. Scroll to “Delete Files” command (trash can) and press the orange button. Scroll to “Software Files” and press orange button. The screen will prompt you to make sure you want to delete the Software Files. Scroll to the checkmark if you are sure and then press the orange button. If you DO NOT want to delete those files, scroll to the “X” and press the orange button, and then back out of the process by pressing the dark gray button several times. 90 Using NXT Window Deleting one file at a time A program must be open on the computer and the robot must be connected for this method to work. Click the “NXT Window” button in the bottom right corner of the screen. Click on the “Memory” tab to view the currently loaded programs on the NXT. Click on the word “Program” under the section labeled “NXT Memory Usage”. Click on the program that you want to delete. Click the “Delete” button to immediately remove that program from the NXT. After several seconds, the memory window will update and show the remaining programs and current memory. The files you selected will be deleted from the NXT (it will remain on your computer if it was saved properly and can be downloaded again in the future if needed). 91 Using NXT Window Deleting all files from the robot A program must be open on the computer and the robot must be connected for this method to work. Click the “NXT Window” button in the bottom right corner of the screen. Click on the “Memory” tab to view the currently loaded programs on the NXT. Click the “Delete All” button. A window will pop up to confirm that you do want to delete all of the program files from the NXT. Click “OK” to continue. After several seconds, the memory window will update and show no programs The files from the NXT will be deleted (they will remain on your computer and can be downloaded again if needed). 92 Deleting Profiles from the computer Old “Profiles” can be removed from each computer after they are not needed any more to help conserve hard drive space and help with file maintenance & organization. In the “Edit” menu, select “Manage Profiles”. Click on the Profile that you want to delete (it will also delete all of the programs within that profile). Click “Delete” to immediately remove that profile. Once you delete it, it is gone forever! Click the “Close” button to finish the process. 93 Updating Firmware (Also resets default NXT settings and files) Occasionally updated Firmware versions (robot communication language) should be downloaded to each of the NXT bricks. This will also delete all student created files from the NXT unit Firmware v1.05 is the most current release for LM-NXT v1.1 Firmware v1.26 is the most current release for LM-NXT v2.0 Firmware v1.31 is the most current release for LM-NXT v2.1 Click on “Tools” and then select “Update NXT Firmware”. Click “Check” on Online Updates to see if there is a newer version of Firmware that you should download to the computer. After the download from the Internet is complete, select the Firmware version that you want to download to your NXT and select “Download”. During the updating process, the NXT will make noises, including quiet clicking sounds, until it is done and makes they typical chime tones. The screen will say “Download Complete”. After the screen reads “Successfully Loaded Firmware”, click the “Close” button to finish the process. 94 Backing Up & Transferring All Programs Within a “Profile” From The Computer It is a good idea to copy all program files (including “My Blocks”) from a particular profile if you are concerned about keeping a back-up. This same procedure can be used to transfer all programs from one computer to another. Navigate to the location on the hard drive where the NXT software is saving your programs. (typically: My Computer > Local Disc C > My Documents> LEGO Creations > MINDSTORMS Projects > Profiles > YOUR PROFILE ) Create a copy of the profile and then put the copy into the location you want to save your back-up (flash drive, ext hard drive, CD, etc). Those files can then be transferred to a different computer by copying that entire folder into the same location on the other computer (see file path specifics from above). The files on the new computer can be opened just like they were done on the original computer. Use caution when working on more than 1 computer at a time using the same profile! Note: transfers between Windows & Mac computers may require more work to open correctly. 95 Downloading To Multiple NXTs Simultaneously This function allows you to download one or more programs to multiple NXTs. This is especially useful if you need to load a number of NXTs with the same program(s). Before using this function, make sure that all of the programs you would like to download are open in the software. When you open more than one program at the same time, the program names appear as tabs along the top of the work area. Also, make sure your bricks are "available" by pressing Scan in the NXT window. Otherwise they will not appear in the Download to Multiple NXTs window. When the programs that you would like to download are open, launch the function by choosing “Download to Multiple NXTs” in the Tools menu. This will open the Download to Multiple NXTs dialog box. Downloading to Multiple NXTs Choose the NXTs to which you would like to download by clicking in the boxes to the left of the NXT names. You can select all available NXTs by clicking the Select All button below the list. Clicking the Deselect All button deselects all of the NXTs. Then choose the programs you would like to download by clicking the boxes to the left of the program names. When your selection is complete, click the Download button below the program list. This begins the download process. 96 Technical Support Help What to do if problems occur Soft Reset of NXT (simple unlock) ● Press the reset button on the backside of the NXT brick for 1-2 seconds. Hard Reset of NXT (major problems) ● ● Press and hold the reset button for 15-20 seconds. The NXT brick will begin to “click” quietly to indicate that the Firmware has been removed from the NXT. Download Firmware back onto NXT Use a paperclip to press & hold the Reset button at the bottom of this hole for 15-20 seconds. LEGO Education Technical Support 1-866-349-5346 (1-866 FIX LEGO) 97 Open Discussion Time and Hands-On Programming & Problem-Solving 98 Bibliography / Resources LEGO Mindstorms Edu NXT (LEGO Education) http://www.legoeducation.us Robotics Engineering v1 (Carnegie Mellon University) http://www.education.rec.ri.cmu.edu/content/lego/curriculum/rev1_index.htm NXT Video Trainer (Carnegie Mellon University) http://www.education.rec.ri.cmu.edu/content/lego/curriculum/nvt2_index.htm FLL Programming 101 NXT-G (Doug Frevert) http://www.hightechkids.org/coach-library Caitlin Gabel NXT Tutorial v1.16 (Dale Yokum) http://www.ortop.org/NXT_Tutorial/html/about.html NXT Robotics Programming Resource rev 5.2 Copyright 2011 Paul R Keeney No reproduction of this material is allowed without written permission from the author © 99 Notes: ____________________________________________________________________________ ____________________________________________________________________________ ____________________________________________________________________________ ____________________________________________________________________________ ____________________________________________________________________________ ____________________________________________________________________________ ____________________________________________________________________________ ____________________________________________________________________________ ____________________________________________________________________________ ____________________________________________________________________________ ____________________________________________________________________________ ____________________________________________________________________________ ____________________________________________________________________________ ____________________________________________________________________________ ____________________________________________________________________________ ____________________________________________________________________________ ____________________________________________________________________________ ____________________________________________________________________________ 100 100 ____________________________________________________________________________ Notes: ____________________________________________________________________________ ____________________________________________________________________________ ____________________________________________________________________________ ____________________________________________________________________________ ____________________________________________________________________________ ____________________________________________________________________________ ____________________________________________________________________________ ____________________________________________________________________________ ____________________________________________________________________________ ____________________________________________________________________________ ____________________________________________________________________________ ____________________________________________________________________________ ____________________________________________________________________________ ____________________________________________________________________________ ____________________________________________________________________________ ____________________________________________________________________________ ____________________________________________________________________________ ____________________________________________________________________________ 101 101 ____________________________________________________________________________
* Your assessment is very important for improving the work of artificial intelligence, which forms the content of this project
advertisement