LEGO Mindstorms Class: Lesson 1

Similar documents
An Introduction to Programming using the NXT Robot:

Where C= circumference, π = 3.14, and D = diameter EV3 Distance. Developed by Joanna M. Skluzacek Wisconsin 4-H 2016 Page 1

The light sensor, rotation sensor, and motors may all be monitored using the view function on the RCX.

Lab book. Exploring Robotics (CORC3303)

Deriving Consistency from LEGOs

Hare and Snail Challenges READY, GO!

Your EdVenture into Robotics 10 Lesson plans

Robotics using Lego Mindstorms EV3 (Intermediate)

FLL Coaches Clinic Chassis and Attachments. Patrick R. Michaud

understanding sensors

Chassis & Attachments 101. Chassis Overview

Robotics Workshop. for Parents and Teachers. September 27, 2014 Wichita State University College of Engineering. Karen Reynolds

Pre-Activity Quiz. 2 feet forward in a straight line? 1. What is a design challenge? 2. How do you program a robot to move

How Do You Make a Program Wait?

FLL Programming Workshop Series

Chassis & Attachments 101. Part 1: Chassis Overview

The Nomenclature and Geometry of LEGO

Ev3 Robotics Programming 101

Nebraska 4-H Robotics and GPS/GIS and SPIRIT Robotics Projects

Erik Von Burg Mesa Public Schools Gifted and Talented Program Johnson Elementary School

the complete parts reference bricks

Line Detection. Duration Minutes. Di culty Intermediate. Learning Objectives Students will:

Appendix Course Notes MIT Course Organizers. Chapter 7: LEGO Design

Studuino Icon Programming Environment Guide

acknowledgments...xv introduction...xvii 1 LEGO MINDSTORMS NXT 2.0: people, pieces, and potential getting started with the NXT 2.0 set...

EV3 Advanced Topics for FLL

Sample Pages. Classroom Activities for the Busy Teacher: NXT. 2 nd Edition. Classroom Activities for the Busy Teacher: NXT -

A - Debris on the Track

A - Debris on the Track

Worksheet Answer Key: Tree Measurer Projects > Tree Measurer

Pre-Activity Quiz. building a robot to fight another robot by trying to push it out of a ring? in the competition? the way when racing?

e d u c a t i o n Detect Dark Line Objectives Connect Teacher s Notes

THE GREEN CLUB PROJECT

A - Debris on the Track

Parts of a Lego RCX Robot

Mindstorms NXT. mindstorms.lego.com

Chapter 14. using data wires

I.1 Smart Machines. Unit Overview:

In order to do this project you should review the following concepts:

The Robot Olympics: A competition for Tribot s and their humans

Robot Programming Manual

Line-Follower Challenge

LS Creative Learnings Pvt Ltd. STEM-Robotics Education. Report for Sep S.B. Patil Public School, Pune

Force multipliers and speed multipliers Machines can make work easier by reducing the amount of force necessary to move an object or increasing the

1-11. Mini Sumo Bot. Building Instructions. Fun Projects for your LEGO MINDSTORMS NXT! Home Projects Help Contacts. Building: Program:

Cardboard Circuit Playground Express Inchworm Robot

Dual Fidgety Art Bot. We enjoyed building our Trashy Art Bot just as much as our Fidgety Art Bot.

Welcome to Lego Rovers

Simple Machines. Contact the National Museum of the U.S. Navy for Field Trip and School Visit opportunities!

Learn about the RoboMind programming environment

FLL Robot Design Workshop

Name & SID 1 : Name & SID 2:

STOP! READ THIS FIRST

Toeing the Line Experiments with Line-following Algorithms

Note to Teacher. Description of the investigation. Time Required. Materials. Procedures for Wheel Size Matters TEACHER. LESSONS WHEEL SIZE / Overview

BY ALIEN TECHNOLOGIES CORP

Note to the Teacher. Description of the investigation. Time Required. Additional Materials VEX KITS AND PARTS NEEDED

AUDI A8 D3 REPLACING THE OUTSIDE DRIVER DOOR HANDLE

TeacherGeek Sumo Bot Vehicle Application Guide

Screw. Introduction This Rokenbok STEM-Maker lesson will use the following steps to learn about the screw. Learning Objectives. Resources.

ANATOMY OF A BIT TM how you can tell top from bottom. four on the floor!

MAKE SURE THE COLECOVISION OR ADAM IS OFF BEFORE INSERTING OR REMOVING A CARTRIDGE.

Activity Template. Subject Area(s): Science and Technology Activity Title: Header. Grade Level: 9-12 Time Required: Group Size:

Agent-based/Robotics Programming Lab II

Automatic Headlights

3. Draw a side-view picture of the situation below, showing the ringstand, rubber band, and your hand when the rubber band is fully stretched.

1 Day Robot Building (MC40A + Aluminum Base) for Edubot 2.0

Roborodentia Robot: Tektronix. Sean Yap Advisor: John Seng California Polytechnic State University, San Luis Obispo June 8th, 2016

BEGINNER PROGRAMMING LESSON

Unit 4: Robot Chassis Construction

ORTOP Modular Robot v3.0 Arm Assembly

contents in detail PART I GETTING STARTED acknowledgments...xvii

FRICTION PERFORMANCE ASSESSMENT

Hatchback Wing Riser Kit

Robot Olympics: Programming Robots to Perform Tasks in the Real World

1. ASSEMBLING THE PCB 2. FLASH THE ZIP LEDs 3. BUILDING THE WHEELS

Final Review Powerpoint

SuperTrack Parts List

HTC VIVE Installation Guide

Removing and Replacing the Y-truck

Assembly Guide for Printrbot - Simple Maker s Edition 1405

Congratulations on your decision to purchase the Triquetra Auto Zero Touch Plate for All Three Axis.

A Day in the Life CTE Enrichment Grades 3-5 mblock Robotics - Simple Programs

2.4 Sensorized robots

Motorized Balancing Toy

V-MOTION LITE USER GUIDE. Rat Rig All rights reserved.

OWEN Walking Robot Install Guide

Basic Tutorials Series: Import A Photograph. RenoWorks Support Team Document #HWPRO0003

Design and Technologies: Engineering principles and systems Motion, mechanisms and motors

Let There Be Light. Opening Files. Deleting National Technology and Science Press

Easy Engineering Guide

RoboCup Sumo Workshop. Margaux Edwards July 2018

Flowcharts and Programs

DISCO DICING SAW SOP. April 2014 INTRODUCTION

Inspiring Creative Fun Ysbrydoledig Creadigol Hwyl. Kinect2Scratch Workbook

Low/High Tunnel Greenhouse Plans

Programming PIC Microchips

EMO. Service Instruction. created by Frank Weithöner. Table of contents: Special Tools Assembling Mixing Chamber

C - Underground Exploration

Activity 1 Position, Velocity, Acceleration PHYS 010

Transcription:

LEGO Mindstorms Class: Lesson 1 Some Important LEGO Mindstorm Parts Brick Ultrasonic Sensor Light Sensor Touch Sensor Color Sensor Motor Gears Axle Straight Beam Angled Beam Cable 1

The NXT-G Programming Environment 2

Write a simple program to make the brick play a sound 1. Connect the USB cable between the brick and the computer. 2. Select the Sound brick from the Action Blocks, and select a Sound file to play. The 'Play Sound' Program The Sound Block Settings 3. Select "Save" from the file menu, and save your program with the name "Play Sound". 4. Press the "Download and Run" button. Did it play? 5. Unplug your brick from the computer. See if you can find the program named "Play Sound" on the brick and play it directly from the brick. 6. Congratulations! You just wrote and ran your first NXT-G program! Change the "Play Sound" program to repeat itself 3 times using a loop 1. Select the "Loop" brick from the Flow Blocks and put it after the "Sound" block 2. Put the "Sound" block from before inside the loop, and set the loop to repeat 3 times. The Sound block inside a Loop The Loop Block settings 3. Download and play the"play Sound" program. Did it do what you expected? 3

Building a Door Alarm: The parts you'll need: Step 1: Attach connectors to the arms: Step 2: Attach the arms together, and connect them to the ultrasonic sensor and the brick: 4

Step 3: Connect a wire from the ultrasonic sensor to port 4 on the brick. Pseudocode: The Door Alarm Program: 1) Repeat forever a) Wait for Ultrasonic Sensor to detect an object closer than 16 inches i) When an object is detected repeat the following 3 times (1) Make a sound 2) Return to 1) Write the Program: 1. Start with a Loop (from the Common Blocks List). Set the Loop to run "Forever" The Loop Block The Loop Block Settings 5

2. Put a Wait Block (from the Common Blocks List) inside the loop. Set the control to "Sensor" and select "Ultrasonic Sensor" from the Sensor list. Make sure the Port is set to "4" (where the Ultrasonic Sensor is plugged in), and the Distance is set to "< 16 Inches". A Wait Block inside the Loop Block The Wait block Settings 3. Add a loop after the Wait block, and set the control to "Count" and the "Count" to "3". A loop inside the main loop The inner Loop settings 4. Put a sound block inside the inner loop and choose a sound to play when the alarm triggers The finished Door Alarm program 6

5. Save the program with the name "Door Alarm". Download and test your program. Did it work? Check with your instructors if you have any problems. If you finish the door alarm try this! (1) Pretty Tricky: Can you change the program so that the alarm makes a different sound if the object it detects is closer than 6 inches? Hint: You will have to use a "Switch" block to perform different actions if the object is closer than 6 inches, or further than 6 inches. Think carefully about where to put the Switch block, and if some of the existing program needs to go inside the Switch block. (2) Even Trickier: Can you change the program so that the screen on the brick displays the distance detected? This will require a block that will convert the distance (a number) to text (letters) to be displayed on the screen and a block to display the text. It also requires the use of data wires to carry the output data from the ultrasonic sensor to the converter block, and from the converter block to the display block. Don't worry if you can't do this one yet, we'll be covering data wires later in the class. (see your instructors for help with the answers) 7

LEGO Mindstorms Class: Lesson 2 Build A Mindstorms Vehicle - 5 Minute Bot: (Copied from http://www.nxtprograms.com/five_minute_bot/steps.html) We will build a 3-wheeled robot vehicle with two motorized wheels, and an extra wheel that can pivot, called a "caster". It is possible to build a robot with 4 or 6 wheels, or with treads, like a tank, but the 3-wheeled robot is the easiest to program, so that's what we'll use. A robot with a caster generally runs best on very smooth, flat surfaces, so that the caster can glide easily. For rougher surfaces, 4 wheels or treads may work better. Follow the steps below to build the robot vehicle. Step 1: Attaching Wheels to the Motors 1

Step 2: Attaching Angled Beams to the Motors Step 3: Adding Wheels and Motors to the Bot 2

Step 4: The Attachment Bar 3

Step 5: The Caster 4

Step 6 - The Wiring: Use two medium length (35 cm) wires to connect the motors to ports B and C on the NXT. Make sure that the motor on each side is connected to the port on that side. That's it! You made a robotic vehicle! 5

Making the Robot Move: Move Block vs. Motor Block To make the motors turn, we can either use the Move Block or the Motor Block. There are several differences between the two blocks, but the biggest is that the Move block can control one, two, or three motors at one time, while the Motor block can only control one motor at a time. The Motor block allows you to control the motor in more detail, but for driving, you usually want to have at least two motors running two wheels at the same time. This is why we'll stick with the Move block to drive our robot. The Move Block The Move block controls one, two or three motors simultaneously. Look at the settings for the move block. Let's figure out what each one does: Port: This tells the Move block which of the A, B and C ports are connected to motors to control Direction: This determines whether the wheels turn forwards or backwards. Steering: Depending on where the slider is, this gives more power to one motor or the other (you specify which of the two motors to use). Power: This specifies how much power overall to send to the motors. More power makes the motors turn faster, less power turns them slower Duration: This determines how many turns the motors make, or how long in seconds they run for. The duration can be specified in rotations, degrees, seconds or unlimited (run forever). Next Action: Brake means the motor will stop after it is finished. Coast means it will keep turning, though without any additional power. We will almost always use Brake. Q: What happens to the vehicle if the motor on the left side runs faster than the motor on the right side 6 (assume both motors are turning forwards)? A:

Moving in a Straight Line Let's figure out how far the car will go when we input certain data to the Move Block. Create a simple program in NXT- G, consisting of a single Move Block. Save it in your folder on the S drive with the name "Move Test". Use this program to answer some of the questions below. You may need a calculator: 1. What is the circumference (distance around) of a tire on your robot (in inches)? inches 2. How far do you think the car will go (in inches) when the wheel turns one time? inches 3. Try it. How far did it go? inches 4. How far do you think the car will go (in inches) when the wheel turns 5 times? inches 5. Try it 3 times and compare your results: How far did it go? inches inches inches 6. How accurate do you think the Move block is? 7. If you want the robot to travel 20 inches, how many turns should the wheel make? turns. Try it. Did it work? 8. How many degrees correspond to one rotation of the wheel? degrees 9. How far will the car go if the wheels turn 720 degrees? inches 10. Try it. How far did the car go for at 720 degree rotation? inches Turning: The robot will always turn when its wheels spin at different rates. In most cases, it's hard to predict where it will go when both wheels are turning at different rates, so we'll focus on two kinds of turns that we can predict: Pivoting in Place, and Turning with One Motor. You can control which kind of turn you make with the steering setting. The following steering values give you the following different kinds of turns: Steering Value Steering Results 100 Pivot in place to the right 50 Turn to the right using one motor 0 Go straight -50 Turn to the left using one motor -100 Pivot in place to the left Pivoting in Place If you turn both motorized wheels in opposite directions at the same power (speed), the vehicle will pivot around a point halfway between the two powered wheels, as 7

shown in the picture below. The wheels travel around a circle whose diameter is the length of the axle. The tricky part is to figure out how many rotations the wheels need to complete a single turn. Let's do the calculation, and then compare it to real life by programming our vehicle. You will probably need a calculator: 1. What is the distance across the circle the car makes when it turns? inches 2. The circumference (distance around) the turning circle is about 3.14 x diameter = inches 3. How many rotations does the tire have to make to travel the circumference of the circle? The formula for the answer is: (Circumference of turning circle) (circumference of tire) = rotations Let's program our Move Block to test our answer. Slide the Steering slider all the way to the right to specify a right turn about the center of the vehicle. Put the number of rotations from answer 3 above into the Duration setting to specify how far around the vehicle will turn. Download and run your program. Did it work? Check with your instructor if you're not sure of the answer. Turning with One Motor If you give power to only one motorized wheel, while holding the other one still, the vehicle will pivot around the unpowered wheel. Let's do a calculation like we did above. Remember, in this case, the diameter of the circle the car makes is two times the length of the axle. 4. What is the diameter (distance across) the circle the car makes when it turns? inches 5. The circumference (distance around) the turning circle is about 3.14 x diameter = inches 6. How many rotations does the tire have to make to travel the circumference of the circle? The formula for the answer is: (Circumference of Circle) (Circumference of Tire) = rotations Let's program our Move Block to test our answer. Slide the Steering slider to value 50 to specify a turn to the right using one motor. Put the number of rotations from answer 6 above into the Duration setting to specify how far around the vehicle will turn. Download and run your program. Did it work? Check with your instructor if you're not sure of the answer. 8

Commenting your program: Now that you know how to go straight and turn, you can combine a series of move blocks in a row to make your robot follow a certain path. When you have a lot of Move blocks in a row that look similar, it is a good idea to place comments near each move block so that you know what it's doing. That way if you have to make any changes, it's easy to find the right place. You can add comments to your program using the comment tool window. An example of a commented program is below: at the top of the NXT Challenges for You (1) Can you write a program to make the Robot travel in a 12 inch square, using only 2 move blocks? (2) Your instructor has set up a maze lined by blocks. Can you program your robot to navigate the maze without knocking over any blocks? Note: Before you start programming, measure the distances in the maze to predict where you want your robot to go. You will probably have to adjust your program afterwards, but you will have a good starting point. (3) Your instructor has set up a "parking garage" made of blocks. Can you drive your vehicle from the starting point to park in the garage, without knocking over any of the blocks? 9

LEGO Mindstorms Class: Lesson 3 Why Use Sensors? 1: Keep the Robot on Track: In Lesson 2 we saw that it can be difficult to get the robot to navigate around its environment by just telling it where it needs to go. Part of the problem is that small variations in its path can become really big errors once the robot has travelled a long distance. For example, if you are trying to get your robot to move straight ahead, and it is angled off path by just a little, it may only be a small amount off course after a few inches, but will be much further off course after it has travelled a few feet. You can see this in the picture below. 1) Starting off course by a small amount can grow to a big error in a short while. We can fix some of this inaccuracy by having the robot get information about its surroundings via sensors. This allows the robot to find out where it is by "seeing" what is around it, figure out if it is on the right path, and make corrections if needed. 2: Allow the Robot to interact with users and its environment Sometimes you want the Robot to respond to a person or thing that it meets, or to give you information about the outside world. A robot will only know about its environment if it can sense it in some way. With the right sensors, a robot can tell if it has come across a dangerous object or what the conditions around it are like (for example how hot or cold it is). For example, sensors allowed the Mars Rover, a robot that landed on the surface of Mars, to drive around the surface of the planet, without falling into a deep hole, or running into a big rock. Sensors also allowed the robot to detect and communicate the conditions on Mars back to scientists on Earth. 1

The Touch Sensor and Bumper: Today's lesson focuses on the touch sensor. It is a simple device that can detect whether someone or something touches, releases or "bumps" the orange button on its front. The button on the touch sensor is rather small, however, and it can be hard to press unless your robot is lined up perfectly with its target. To make the sensor easier to use, we will build and attach a "bumper" to it. The bumper simply consists of a bar which will trigger the touch sensor when any part of it is pushed. That way an object doesn't have to be touching the orange button directly to trigger the touch sensor. 2) The Touch Sensor 3) The Touch Sensor with a Bumper Programming with the Touch Sensor: The touch sensor can detect three different conditions. It can notice if it has been: [1] pressed (the orange button has been pushed inwards) [2] released (the orange has moved from being pushed in to its original position) [3] bumped (the orange button was pushed and released in a short period of time) There are two main ways to program with the touch sensor. The Touch Sensor block, checks in with the sensor, and waits to see if it has been triggered. 4) The Touch Sensor Block The Wait for Touch Sensor will not do anything until the action specified (pressed, released or bumped) happens. 5) The Wait for Touch Sensor Block 2

Now that we know how it works, let's add a touch sensor to our 5 Minute Bot from the last lesson, and program it to perform some tasks Adding a Touch Sensor to "5-Minute Bot" to make "Bumper Bot": We Start with 5-minute Bot from last time. (The motor wires have been removed to make it easier to see) Attach the Touch Sensor to a Bumper: Step 1: 3

Step 2: 4

5

Attach rails to 5-minute Bot: 6

Attach the Bumper to the 5-Minute Bot: 7

Attach the Wires (Connect the Touch Sensor to Port 1): You're done with Bumper Bot! 8

Programming Exercises: Exercise 1: Write a simple program to say "ouch" when the touch sensor is pressed and "hooray" when it is released. The pseudocode (program steps written in plain language) for this program looks like this: Wait for touch sensor to get pressed. Say "ouch". Wait for touch sensor to get released. Say "hooray". Repeat from the beginning. 1) We will want our program to repeat itself so that it can say "ouch"/"hooray" over and over again. Most of the time when you repeat actions inside a program it's a good idea to use a loop. 2) Wait for the touch sensor to get pressed. 3) Make an "ouch" sound. 4) Now wait for the touch sensor to get released 9

5) Say "hooray", and the loop will return you to the beginning of the cycle Exercise 2: Write your own program to have the "Bumper Bot" drive until the bumper hits something, then stop, back up about 6 inches, turn right and start over again. The pseudocode would look something like this: Start driving forward Wait until the bumper is touched Stop Back up about 6 inches Turn right Repeat from the beginning Challenges for You Challenge 1: See if you can get Bumper Bot drive up to a block, and stop when it touches it without knocking the block over. Challenge 2: Use the touch sensor to get Bumper Bot to knock a block off the edge of a low platform (your instructors will set one up for you) without falling over the edge of the platform itself. Challenge 3: (Advanced!): Have Bumper Bot travel to a wall, stop when it hits it and then travel backwards to the exact same starting place. You need to use the rotation sensor and data wires to do this. 10

LEGO Mindstorms Class: Lesson 4 The Light Sensor: The light sensor allows a Mindstorms robot to "see" the difference between light and dark. It detects light and dark surfaces by shining a light on the surface, and seeing how much of the light bounces back to the detector. Light surfaces reflect more light, and dark surfaces reflect less light. You can also turn off the light bulb in the light sensor, and then the sensor will detect the amount of light around it. We'll work with reflected light, and use the light sensor attached to 5-Minute Bot to detect dark and light surfaces that it drives over. Because lighting conditions differ depending on where you are or what time of day it is, the light sensor needs to be calibrated every time you use it under different lighting conditions (for example if you move from a dark room to a brightly lit room, or take your robot outside). What looks to be one color in a dark room may look different in bright sunlight. You have to tell the light sensor what you mean by "dark" and what you mean by "light". When you write a program that checks the light sensor, the sensor returns a value between 0 and 100. 0 is the darkest and 100 is the lightest. When you calibrate the sensor, it asks you to show it the darkest color it will be detecting, and it sets that as the 0 value. Similarly, it asks to see the lightest color you will be detecting, and it sets that value to 100. We'll see how to calibrate the sensor later on. Let's attach a light sensor to our robot. Attaching the Light Sensor to the 5-minute Bot: Take off the touch sensor from the last lesson so you are only left with the 5-minute Bot (below) 1

You will need these parts: Now we can assemble and attach the light sensor: 2

Attach the light sensor to the underside of 5-minute-Bot Connect the light sensor to Port 3 on the Brick. This is the default light sensor port. That's it! You're ready to follow the light! Calibrating the Light Sensor: You can calibrate the light sensor directly from the NXT-G programming environment, or write your own program to do it. If you use the NXT programming environment directly, your brick needs to be plugged in to the computer for calibration. Since we're using laptops, and can move them around easily, we'll use that method. 3

Exercises: Exercise 1: Calibrating the light sensor in the NXT-G programming environment 1) Plug the brick into your computer. Be sure it is turned on. 2) Select "Calibrate Sensors" from the "Tools" menu in the NXT-G window. 3) From the pop-up window (shown below), select light sensor, port 3, and click the "Calibrate" button. 4) Look at the screen on the brick. It is asking you to hold the light sensor over the darkest surface it will be scanning. The changing numbers you see are the "raw" unprocessed output from the light sensor, and they range from 0 to about 1000. Move the sensor around to surfaces with different lightness/darkness, and watch how the numbers change. After you calibrate the sensor and use it in a program, the NXT-G program environment will convert the numbers to a value between 0 and 100. 5) Place the light sensor so that it is completely over a dark line on the paper your instructors have set up, then press "Enter" (the orange button). 6) The screen is now asking you to hold the light sensor over the lightest surface it will be scanning. Place the light sensor over the white part of the paper your instructors have set up, then press "Enter". 7) Your light sensor is now calibrated. The brick will remember these calibration settings until the next time you recalibrate it. You will only need to recalibrate if you are using the light sensor in a place with different lighting conditions. Exercise 2: Write a program to display the final light sensor readings Let's write a program to view the output from the calibrated light sensor. We're using some advanced concepts here, including data wires, which carry information from one NXT programming block to another. Data wires will let us take the numbers that are output by the light sensor block, and use them as input to the display block. To input and output data to a NXT-G programming block, many blocks have what is called a data "hub" which clicks in and out of the data block. You can click on the hub to make it slide in and out. Below is a picture of the Display Block with the data hub closed, and opened. The ports on the data hub are for taking in and putting out different kinds of data, such as numbers, text and images. 4

A Display Block with the data hub closed: To open the Data Hub, click on the line at the lower left of the Display Block. A Display Block with the data hub open: Each port is for inputting and outputting a different kind of information, such as text, start position, end position, etc. You will need to know how to display written information on the NXT brick's screen. The screen can write almost anything you tell it to, but it only understands numbers in "text" format. Letters and words are automatically "text", but numbers are not. To put the numerical (number) output from the light sensor into a form that the display block can understand, we will have to convert it to text. Create a program named "showlight.rbt" in the NXT-G programming window (be sure to save it to the shared drive!), and follow the steps below to write it. 1) We will want to run this program repeatedly, so set up a forever loop: 2) Add a Light Sensor Block (from the Sensor Menu), and make sure that it reads Port 3 3) Add a Number to Text Block (from the Advanced Menu) 5

4) Now move the cursor to the plug sticking out of the bottom of the Light Sensor Block. It will turn into a picture of a little spool of wire. Click on the plug, and drag the cursor over to the plug to the left of the "#" plug at the bottom of the Number to Text Block. When you let go, you will create a yellow Data Wire connecting the output of the light sensor block to the input of the Number to Text Block. 5) Add a Display Block, and click on the data hub to make sure it pops out. 6) Connect a data wire from the output of the Number to Text box to the capital letter "T" (for Text) on the Display Block data hub. 6

Set the Display block to display the input Text: 7) Add a Wait block, and set it to wait for 0.2 seconds before repeating 8) Now let's test out our program. o Run "showlight.rbt", and move the sensor around over different dark and light areas. Do you see the readout change? When is the readout higher, and when is it lower? Is that what you expected? o Try rolling your robot over the dark lines on the paper that your instructors set up. Watch the values change as the sensor starts to move over the line. Do the values make sense? 7

Challenges: Challenge 1: Write a program to make the robot drive until it detects a dark line and then stop. Use the paper that your instructors have provided, with electrical tape to make the dark lines. Before you attempt this challenge, think about what it means for your robot to detect a dark line. Think about what the sensor readings will be as the sensor approaches the line. When the light sensor is over the white paper, the readings will be pretty high. When the sensor is just a little bit over the black line, less light will get reflected, so the light sensor values will start to drop. The more of the sensor that is over the black line, the lower the light sensor values will be. Hint 1: Use the Wait for Sensor Block to let your robot keep moving until the value of the Light Sensor has dropped past a certain value. Think about what a reasonable value might be to indicate that the sensor is over the black line. Hint 2: Make sure that the first Move Block in your program uses the unlimited setting, so that your program will check the light sensor while the robot is still driving. Otherwise, the robot will finish running the move block before it checks the light sensor. Challenge 2: Your instructors have created a "ring" out of dark electrical tape on white paper. The ring has a hole in it, large enough for your robot to drive through. Write a program that allows your robot to find its way out of the ring without crossing over a black line. Hint: When you encounter a black line, you will want the robot to stop, turn, and travel in a different direction. So the pseudocode (description of your program in words) would look something like this: 1. Start driving forward. 2. If you come across a black line, stop. 3. Back up a few inches (you decide how many) 4. Turn (you decide how far the robot should turn - try different values and see what works best!) 5. Return to the start Remember, each line in pseudocode corresponds to one instruction for the robot (and one programming "block" in NXT- G) Once you get the program working, experiment with different values for the turn. See which value works best for getting your robot out of the "ring" the fastest. Challenge 3: (Advanced!) Your instructor has provided paper with dark parallel lines. Write a program that lets the robot drive over two black lines, and stop on the third. There are many ways to solve this problem. See how creative you can be! Talk to your instructors and see if your solution matches theirs. 8

LEGO Mindstorms Class: Lesson 5 Line Following with the Light Sensor: In the last class we used the Light Sensor to detect when our robot encountered a dark line. In this class, we're going to use the Light Sensor to help our robots follow along a dark line. Specifically, we will follow the edge of the line. Let's say we want our robot to follow a dark line on white paper. Remember, if we calibrated it, the light sensor will output a value from 0 to 100 depending on how much of the sensor is over the dark line. 0 means the sensor is totally over the line. 100 means the sensor is only over the white paper. Imagine what the sensor would see if it moved from left to right over a dark line (see picture below): Before we work with the line sensor, we'll need to calibrate it for the lighting conditions in the class today. Last week you loaded a program onto your robot called "Calibrate.rbt". Run it by holding the light sensor completely over the black line, and pressing the orange button on the brick, then holding the robot over the white paper and pressing the orange button again. You can test the calibration by viewing the output of the light sensor in a Light Sensor Block in the NXT-G window. Ask your instructors for help if you don't remember how to do this. Exercise 1: Write a line following program We're going to tell our robot to follow the left edge of the line. In the picture above, we see that the sensor reading is high (> 50) if the sensor is mostly over the paper, and the sensor reading is low (< 50) if the sensor is mostly over the line. We can use this fact to keep the sensor lined up with the left edge of the line while the robot moves forward. Let's write some pseudocode that does this: Get output from the sensor If the light sensor output is greater than ( > ) 50, we must be left of the line's edge o Move forward and turn slightly to the right If the output is less than ( < ) 50, we must be right of the line's edge o Move forward and turn slightly to the left Repeat from the beginning 1

Now let's turn this pseudocode into an actual NXT-G program. Create a program called linefollow.rbt, and save it to your folder. 1. Since the program repeats, we'll need a loop 2. Now notice we have an "If" statement in our pseudocode. This means we have to make a decision based on the output of the light sensor. We'll use the "Switch" block (from the Common menu) for this. Select the settings on the switch block to use the light sensor output, and make a decision based on whether it is greater than or less than 50. 2

3. First fill in the top part of the switch statement. This is what will happen if the light sensor value is greater than 50 (see that the "light symbol" looks bright). Remember that a value greater than 50 means that the robot is positioned left of the line. We want to make the robot move forward, and slightly to the right to get closer to the line. Instead of using a Move Block, we are going to use two Motor Blocks to do this. The motor blocks give the robot a little more control over the turn, and make the movement smoother. Notice we have one motor block for motor B, and one for Motor C. Since Motor B is on the left and Motor C is on the right, if motor B spins faster (has more power) than Motor C, the robot will move to the right. Set the power for Motor B to 50 and the power for Motor C to 10. 4. Now let's fill in the bottom part of the switch statement. This is what we do if the light sensor returns a value less than 50. When the value is less than 50, the light sensor is mostly over the line. Since we want the robot to follow the left edge of the line, we'll want it to move forward, and slightly to the left. In this case, we'll want Motor C to have more power than Motor B. Add two motor blocks like we did in step 3, but set the power for Motor B to 10 and the power for Motor C to 50. That's the whole program! Your instructor has made a course out of paper and electrical tape. Try placing the robot near the left edge of the line and seeing if it can follow the course. 3

Challenges: Challenge 1: The need for speed! Your instructors have set up a course mapped out in electrical tape. Time how long it takes your robot to complete the course. Can you think of ways to make it go faster without losing its way? Hint: Try completing Challenge 2 below for one method to make your robot a speedier line follower. Challenge 2: Write a 3-state line following program The line following program we just wrote works best following a line where the curves aren't too sharp. If you try to get the robot to follow a sharply angled turn, it may lose the line entirely. The robot also moves pretty slowly, since it has to spend so much time turning left and right to find the edge of the line. Let's try a method to make the robot move faster and more accurately. Instead of telling the robot what to do based on whether it is left or right of the line (two different states), let's make it more sensitive to its position. We will let the robot travel straight if it is close to the edge of the line, and only turn left or right when it moves away from the edge it is trying to follow. Since it reacts differently to three different conditions (left of edge, right of edge, close to edge) this is called a 3-State Program. Here is the pseudocode we want to follow: Get output from the sensor If the light sensor output is greater than ( > ) 60, we must be left of the line's edge o Move forward and turn slightly to the right Otherwise the light sensor output must be less than (<) 60 o If the light sensor is less than 60 but greater than 40, we must be close to the edge Move straight forward o Otherwise the light sensor is less than 40 and we are right of the line's edge Move forward and turn slightly to the left Repeat from the beginning The code may look tricky because it has an "if" statement inside another "if" statement, but if you think carefully, you will see how to write the program. You will need to use more than one switch statement to get it to work. Ask your instructors if you need help. 4

An example of a 3-state line following program. 5

Lesson 6: No formal lesson - just built two lines with electrical tape. Placed a ball on a ring at the end, and two loops along the way. Challenged the kids to design a robot to collect all 3 objects and bring them back to base.

LEGO Mindstorms Class: Lesson 8 Gears: The LEGO Mindstorms Set comes with all sorts of gears, but up to this point we haven't explored how to use them. Today we're going to see how gears work, and how they can be useful in building robots and other devices. Below is a picture of some of the basic gears that come with the Mindstorms set, as well as a definition of some of the different gear types that are included. The different shaped gears have different purposes, but we'll focus on the spur gears. Some Different Gear Types Spur Gears - Have straight teeth, and their axles are parallel (lined up) with each other. They are the most common type of gear. Bevel Gears - Can change the direction the axle is rotating by an angle (usually 90 degrees) Rack and Pinion Gears - Combine the motion of a round gear with a flattoothed platform. This lets you convert circular motion to straight-line motion. Worm Gear - This gear consists of a cylinder with a spiral groove (like a screw) that turns. Each time it turns around once, the round gear moves forward by one tooth. The cylinder can turn the round gear, but turning the round gear does not move the cylinder. LEGO Mindstorm Gears (spur gears are underlined in red)

Question 1: In the pictures below, what types of gears are being used in the hand mixer and the electric mixer? Write the answers in the spaces below the pictures: Gear Type: Gear Type To make the Mindstorms robot move, motors provide power to turn the wheels. We use gears for three main reasons: 1. Changing the speed of the wheels 2. Changing the power going to the wheels 3. Change the direction the axles are turning Let's see how that works. Gears have "Teeth" that mesh together, so when one gear turns, it makes the other gear turn, too. Notice that the gears turn in opposite directions. The driver gear is the one that provides the power, and the follower gear gets turned by the driver. The gears in the first picture below are the same size, so each time the driver completes one turn, the follower completes one turn. Two Gears Turn in Opposite Directions With Three Gears, the Driver and Follower Turn in the Same Direction Gearing down and Gearing Up: When you use two gears of different sizes, you will find that they turn at different rates. The picture on the left below below show a gear with 8 teeth turning a gear with 24 teeth. Because the small gear (the driver) goes around three times (8 x 3 = 24) for every one time the follower gear goes around, this means that a wheel attached to the follower axle will go three times more slowly than the driver gear. Similarly in the picture on the right, for every time the driver gear turns once, the follower gear will go around three times. Therefore the follower axle is turning three times as fast as the driver axle.

Gearing Down (8 Tooth Gear Drives a 24 Tooth Gear) Gearing Up (24 Tooth Gear Drives an 8 Tooth Gear) The follower axle turns more slowly than the driver but has more power. The follower axle turns more quickly than the driver but has less power. Making a LEGO Gear Chain: You can take advantage of gear ratios to put together a set of gears where the follower goes much more quickly than the driver (or vice versa). An example of a gear chain is shown below. The because the big gears have 40 teeth, and the small gears have 8 teeth, the small gears turn around 5 times for every turn of the big gear (5 x 8 = 40). That means, if we are gearing up, each set of gears increases the speed of the axle by a factor of 5. Since we have geared up twice, we have increased the speed by a factor of 5 x 5 = 25 times! Picture 1: A gear train. Picture 2: The same gear train, built a different way. As we said above, turning the rightmost crank in each picture, makes the leftmost crank turn 25 times faster. There is a trade-off for this increased speed, however. The faster crank will have a factor of 25 times less power. Exercise 1: Build a gear chain similar to the pictures above, and see if you can feel the difference in power that you get when turning each handle. You can feel this with your hands by trying to hold one handle still while trying to turn the other. You will notice that one of the handles will be harder to turn than the other one. Exercise 2: Can you build a gear chain so that the follower gear goes more than 100 times faster than the driver gear? Try it!

Question 2: In the picture below, if gear A is turning clockwise, as shown, what direction are each of the other gears going (clockwise or counter-clockwise)? Which gear is turning the slowest? Gear A: Clockwise Gear B: Gear C: Gear D: Slowest Gear? Exercise3: Build a "Gear-Bot" This is an engineering challenge. Can you build a robot that uses gear ratios to increase its speed? Your instructor has a geared robot that you can use as an example. How fast can you get your robot to go?

LEGO Mindstorms Class: Tug-of-War Challenge! This class we will build robots which will compete against each other in a game of Tug-of-War. Two robots will be connected by a string with a paperclip on each end. When the referee says "start", the robots must wait (at least) 3 seconds, then start pulling. The winner is the robot which is able to pull its opponent over the line that is initially halfway between them. Rules: 1. No part of the robot may extend past the paperclip attached to the string. This means that the string can't wrap around your robot. It must be attached to a part of your robot that is facing its opponent. 2. Robots must wait 3 seconds after the referee says "start" to start pulling. Put this delay in the program you write for your robot. 3. If any part of a robot comes off during the pulling, that robot has lost the match. Build a sturdy structure, so your robot won't break. 4. The robot that pulls any part of its opponent over the midline is the winner. 5. Robots must have wheels, and pull their opponents by turning their wheels (you can't make a very heavy brick that the opponent has to drag) 6. The total weight of the robot must be less than 1 Kilogram (about 2.2) pounds. Your instructor has a scale so that you may check your robot's weight. Strategies: Weight - Heavier robots are harder to pull, but you must keep total weight under 1 Kilogram. Gears - Remember, gearing UP (connecting the drive axle gear to a larger gear, which is connected by an axle to the wheel), will increase your power. Traction (multiple tires) - We don't have treads available, but adding tires may help increase traction (the ability of your robot not to slip) on the ground. Angle of pull - You may find yourself at an advantage if you try to pull up on your opponents robot, causing it's wheels to lift up off the ground. Of course, this means that you will need a tall robot, and you will need to find a way to keep it from tipping over. If you don't know where to start, ask your instructor for directions to building a simple robot car. You can make additions to your robot from there.