Loops and Switches Pre-Quiz

Slides:



Advertisements
Similar presentations
Getting started with LEGO NXT Mindstorms software This is intended to be a short introduction to the LEGO Mindstorms software and programming the LEGO.
Advertisements

How Do You Make a Program Wait?. 1. What is an algorithm? 2. Can you think of a reason why it might be inconvenient to program your robot to always go.
Robot Soccer Challenge
A CTIVITY M OVEMENT TASK USING SENSORS - HUMANS AND ROBOTS (75 MINUTES ) 1.
© 2006 Carnegie Mellon Robotics Academy Designed for use with the LEGO MINDSTORMS ® Education NXT Software and Base Set #9797 Mine Mapping Choose a Sensor.
From the NXT top menu Connect desired hardware as indicated Enter a command in the box indicated from the menu provided Repeat for all 5 boxes.
© 2006 Carnegie Mellon Robotics Academy Designed for use with the LEGO MINDSTORMS ® Education NXT Software and Base Set #9797 Sentry System One-Way Communication.
EducateNXT NXT... an introduction The Kit and the Software.
Computational Neurobiology Center, College of Engineering, University of Missouri, Columbia MO DAY 2 – 50 minutes HOW DOES A ROBOT MOVE?
The NXT is the brain of a MINDSTORMS® robot. It’s an intelligent, computer-controlled LEGO® brick that lets a MINDSTORMS robot come alive and perform.
Reviewing Common Blocks for St. Agnes Elementary School Teachers by Jenny Chang Feb. 26th, 2007 USC & University Neighborhood Outreach Robotics STEM program.
LEGO Mindstorms NXT Programming We will be using the Common Palette for our Robots This is how you download your program onto the brick Drag and drop a.
Loops and Switches. 1. What kind of blocks are these? 2. Name two kinds of controls that can be specified to determine how long a loop repeats. 3. Give.
What Is a Program?. What Is a Program? Pre-Quiz 1. What is a program? 2. What is an algorithm? Give an example. 2.
GIRLS Robotic Camp. Let’s Begin Meet and Greet – Camp leaders introduce themselves – Students introduce themselves.
Programming 101 The Common Palette Content provided by Connor Statham (6 th Grade Student) Formatting by Shannon Sieber.
Maze Challenge Maze Challenge activity > TeachEngineering.org
Programming a light sensor to follow a black line.
Using Waits, Loops and Switches WAIT please!. Waits, Loops and Switches Pre-Quiz 1. In programming, what is a loop? When is a loop useful? 2. How can.
Robotics Overview of NXT-G Actuators in Mindstorms. Touch sensor Labwork: Right turn. Touch/bump. [Explore move versus Motor Move mini & motor mini. Motor*.]
GIRLS Robotics Objective of today Review last Saturday’s Lesson Create our 1 st robot.
Sentry System Multiple Sensors
Conditions and loops Day 4 Computer Programming through Robotics CPST 410 Summer 2009.
Lego MindStorm An Introduction to Blocks. Blocks Blocks are used to give instructions to your robot. There are many types of blocks You can use the blocks.
Castor Bot. Now, we will begin creating a robot Log onto your computer On your screen, click on the website labeled “castor bot” Your building instructions.
Use the book to build and mount the light sensor on your robot. This will allow the robot to remain inside the blue square (fight ring) on the tile floor.
Create a Halloween Computer Game in Scratch Stephanie Smullen and Dawn Ellis Barb Ericson October 2008.
Programming 101 The Common Palette Content provided by Connor Statham (9 th Grade Student) Formatting by Shannon Sieber.
Mindstorm NXT-G Introduction Towson University Robotics.
Lesson 1: Motors and Sound Programming Solutions.
ROBOTICS Jason Bell Brad Carlson
Lego Mindstorm Robots 9797 kit.  Students will learn how to identify how to detect a change in a condition.  Students will learn where and how to identify.
Forward Until Near Stop when near a wall.
© 2006 Carnegie Mellon Robotics Academy Designed for use with the LEGO MINDSTORMS ® Education NXT Software and Base Set #9797 Sentry System Two-Way Communication.
LOGICFUSION’S HANDS-ON ROBOTICS EV3 LEVEL 2! Welcome to.
How Do You Make a Program Wait?
DAY 2 – 50 minutes HOW DOES A ROBOT MOVE?
Create a Halloween Computer Game in Scratch
Line-Follower Challenge
Scratch for Interactivity
Don’t Bump into Me! Presentation > TeachEngineering.org
Mindstorms EV3 Programming
Understanding Communication with a Robot? Activity (60 minutes)
Follow the Light Follow the Light Presentation > TeachEngineering.org Center for Computational Neurobiology, University of Missouri.
Mindstorms EV3 Programming
What Is a Program? What Is a Program? lesson > TeachEngineering.org
Robot Soccer Challenge
How Does an Ultrasonic Sensor Work?
Navigating a Maze.
Learning to program with Logo
Mindstorms EV3 Programming
Music by Touch Music by Touch Presentation > TeachEngineering.org
Module F: Presentation Understanding Robot Fundamentals
BEGINNER PROGRAMMING LESSON
Robot Programming Computer Literacy S2.
Learn… Create… Program
INTERMEDIATE PROGRAMMING LESSON
An Introduction to VEX IQ Programming with Modkit
Holyoke Codes LEGO ROBOTICS
Line Following Behavior
Maze Challenge Maze Challenge activity > TeachEngineering.org
BEGINNER PROGRAMMING LESSON
ACTIVITY MOVEMENT TASK USING SENSORS - HUMANS AND ROBOTS (75 MINUTES)
Using Waits, Loops and Switches
Loops and Switches How Do You Make Loops and Switches? lesson > TeachEngineering.org Center for Computational Neurobiology, University of Missouri.
Creating a Simple Game in Scratch
Lego MINDSTORMS EV3.
Getting started with LEGO EV3 Mindstorms software
LEGO MINDSTORMS NXT PROGRAMMING
Presentation transcript:

Loops and Switches Pre-Quiz 1. What kind of blocks are these? 2. Name two kinds of controls that can be specified to determine how long a loop repeats. 3. Give an example of a program you could write that would use a switch. Center for Computational Neurobiology, University of Missouri

What are loops and switches? (50 minutes) Objective Loops and switches are two of the most important tools used in programming. Loops allow us to repeat segments of a program indefinitely or until some condition is met Switches allow a program to respond differently to different conditions In today’s lesson, we: Investigate how loops and switches work Learn how to use loops and switches when we program using the LEGO MINDSTORMS NXT software Learn to use switches and loops in unison to expand the functions of the programs we will make

Loops: What Are They? In programming, a loop is an operator that allows us to repeat a set of commands indefinitely. In many factories, a machine performs the same simple task thousands of times in a day Watch a video clip of an assembly machine www.youtube.com/watch?v=AwJflkd6Y_o (1:41 minutes) As a programmer, you don’t want to have to copy instructions for repeating that same simple task thousands of times… So, instead, you write commands for the simple task once, and then enclose those commands in a loop, which can be repeated as many times as you want. Center for Computational Neurobiology, University of Missouri

Programming with Loops Suppose we want to make a robot move once around in a square. A program to do that has 8 blocks and would look like this: start/stop at this corner 

Programming with Loops (continued) Programming this task becomes a lot easier if you use “loops.” Notice that the 8 commands we would use to do this (forward, right, forward, right, forward, right, forward, right) are really just the same 2 commands repeated 4 times So. what we really want to program is simply: Repeat (1. go forward; 2. turn right) 4 times. In the LEGOMINDSTORMS NXT software, the loop block icon looks like this  Drag this block down to the main line of your program as shown:

Programming with Loops (continued) When you highlight the loop block, notice the drop- down menu next to “Control.” The Control options enable you to tell a robot how long to keep looping the commands inside the loop. Selecting “Forever” repeats those commands indefinitely. Selecting “Sensor” repeats those commands until a sensor detects a stimulus (for example, until the touch sensor is pressed). Selecting “Time” repeats those commands until a certain amount of time has expired (for example, 5 minutes).

Programming with Loops (continued) Selecting “Count” repeats those commands some specific number of times. We won’t discuss selecting “Logic” at this time, because it is a bit too complicated for our application. In this case, what do we choose? Since we want the commands (go forward, turn right) to be repeated 4 times, we select “Count” and set “count” to 4.

Programming with Loops (continued) Next, we need to drag the commands we want to be repeated INSIDE the loop. The final program looks like this:  Notice that instead of 8 blocks, we only need 2 blocks, surrounded by a loop.

Mini-Activity 1 Do This: Program the robot to: Go forward until it hits a wall, then back up one rotation and turn left Repeat these instructions until detecting a sound Then stop

Day 2: What Is a Switch? In programming, a switch is an object that gives different commands depending on which state it is in. A light switch for example, has 2 states: up and down. When the light switch is in the “up” position, the switch directs the light it controls to turn on. When the light switch is in the “down” position, the switch directs the light it controls to turn off.

Programming with Switches Suppose we want to program a robot to end up exactly 24 inches from a wall no matter where it starts. This means that the robot will always be in one of two states: closer than 24 inches to the wall or farther than 24 inches from the wall We can best deal with this situation by using a switch. To do this, click on the switch icon: and drag it down to the program line.

Programming with Switches (continued) When you highlight the switch block, notice that you can indicate the sensor used. In this case, we are interested in how far away the robot is from the wall, so we select the ultrasonic sensor from the drop-down menu. Because we want the state of the switch to depend on the distance the robot is initially away from the wall, we also need to set the distance to 24 inches.

Programming with Switches (continued) If the condition specified is satisfied, the program will execute the commands in the top half of the switch. This means the robot is less than 24 inches from the wall and we need the robot to back up until it is at least 24 inches away from the wall. We can achieve this by using a backward move block with unlimited duration followed by a wait block as shown below.

Programming with Switches (continued) If the condition specified is not satisfied, the program will execute the commands in the bottom half of the switch. This means the robot is more than 24 inches from the wall and we need the robot to go forward until it is closer than 24 inches from the wall. We can achieve this by using a forward move block with unlimited duration followed by a wait block as shown below.

Mini-Activity 2 Do This: On a piece of paper, write out the program we just discussed in WORDS, that is, as an algorithm, and understand it fully. Then, write the NXT program, download it onto the LEGO taskbot and verify that it works correctly. Note that all the blocks for this program are provided on the previous slides.

Mini-Activity 3 Do This: Program the robot so that: It moves forward until it hears a sound. If the touch sensor is pressed when it hears a sound, turn left. If the touch sensor is not pressed when it hears a sound, turn right.

Loops and Switches Post-Quiz 1. What kind of blocks are these? 2. Name two kinds of controls that can be specified to determine how long a loop repeats. 3. Give an example of a program you could write that would use a switch. Center for Computational Neurobiology, University of Missouri