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.

Slides:



Advertisements
Similar presentations
What Is an Electric Motor? How Does a Rotation Sensor Work?
Advertisements

Create a Simple Game in Scratch
Getting started with LEGO NXT Mindstorms software This is intended to be a short introduction to the LEGO Mindstorms software and programming the LEGO.
How Does an Ultrasonic Sensor Work?
Robot Soccer Challenge
A CTIVITY M OVEMENT TASK USING SENSORS - HUMANS AND ROBOTS (75 MINUTES ) 1.
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?
BEGINNER EV3 PROGRAMMING Lesson
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.
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.
Control Using Sound. 1. What is sound? 2. How does the LEGO sound sensor sense sound? 2 Control Using Sound Pre-Quiz.
Don’t Bump into Me!. 1. How do bats sense distance? 2. Describe how bats sense distance in a “stimulus-sensor-coordinator-effector- response” framework.
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.
Music by Touch. 1. Provide an example “stimulus-sensor- coordinator-effector-response” framework for both your (human) sense of touch and the robotic.
What Is a Program?. What Is a Program? Pre-Quiz 1. What is a program? 2. What is an algorithm? Give an example. 2.
BEGINNER PROGRAMMING Lesson
GIRLS Robotic Camp. Let’s Begin Meet and Greet – Camp leaders introduce themselves – Students introduce themselves.
By Crystal Wettingfeld Supported by Lamar University, a Broadening Participation Grant from the National Science Foundation under Grant No , and.
Navigating a Maze. Navigating a Maze Pre-Quiz 2 1. What is the difference between a program and an algorithm? 2. About how many inches does an NXT move.
Maze Challenge Maze Challenge activity > TeachEngineering.org
Wait Program! WAIT please!. 1. Why is it often better to use conditional commands rather than program a robot to move exact distances? 2. What is the.
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*.]
Bug Session Four. Session description Objectives Session activities summary Resources Prior knowledge of sequencing instructions using Bug Bug website.
CS329e – Elements of Visual Programming Implementing Programs Mike Scott (Slides 2-2)
Motors and Sound Troubleshooting Tips. © H-CCS Problem 1 Why can’t I download my program to the RCX?
Negative Power or Negative Rotation makes robot go backwards. But if both are negative, the robot will go forward! Move Steering Block.
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.
Title Slide Progress Report Name. Goal Goal Statement – ex. design/create/fabricate … - should be clear and short Needs/Problems – clear and short Space.
Find the Mindstorms Icon on the computer.. To start a new program click go.
BEGINNER EV3 PROGRAMMING LESSON By: Droids Robotics Using Sensor Data and Port View.
BEGINNER FLL PROGRAMMING WORKSHOP BY DROIDS ROBOTICS & EV3LESSONS.
BEGINNER EV3 PROGRAMMING LESSON By: Droids Robotics Topics Covered: Touch Sensor.
ROBOTICS Jason Bell Brad Carlson
Creating a Simple Game in Scratch Barb Ericson Georgia Tech May 2009.
Forward Until Near Stop when near a wall.
How Do You Make a Program Wait?
DAY 2 – 50 minutes HOW DOES A ROBOT MOVE?
Line-Follower Challenge
BEGINNER PROGRAMMING LESSON
BEGINNER EV3 PROGRAMMING Lesson
Don’t Bump into Me! Presentation > TeachEngineering.org
What Is an Electric Motor? How Does a Rotation Sensor Work?
Understanding Communication with a Robot? Activity (60 minutes)
By Sanjay and Arvind Seshan
Follow the Light Follow the Light Presentation > TeachEngineering.org Center for Computational Neurobiology, University of Missouri.
What Is a Program? What Is a Program? lesson > TeachEngineering.org
Robot Soccer Challenge
Navigating a Maze.
How Does a Touch Sensor Work?
Loops and Switches Pre-Quiz
Music by Touch Music by Touch Presentation > TeachEngineering.org
BEGINNER EV3 PROGRAMMING Lesson
BEGINNER EV3 PROGRAMMING Lesson
BEGINNER PROGRAMMING LESSON
BEGINNER PROGRAMMING LESSON
An Introduction to VEX IQ Programming with Modkit
BEGINNER PROGRAMMING LESSON
Navigating a Maze.
An Introduction to VEX IQ Programming with Modkit
Maze Challenge Maze Challenge activity > TeachEngineering.org
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
Getting started with LEGO EV3 Mindstorms software
LEGO MINDSTORMS NXT PROGRAMMING
Presentation transcript:

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 a precise distance? 3. What is a stimulus? Can you think of a stimulus the robot could detect? What sensor would it use to detect it? 2 How Do You Make a Program Wait? Pre-Quiz

1.What is an algorithm? An algorithm is a clear and specific procedure for solving a problem in a finite number of steps. 2. Can you think of a reason why it might be inconvenient to program your robot to always go a precise distance? If the distance is very far, this could take up a lot of time. Inconsistencies in the robot itself (power, battery charge) can also cause the robot to not always go the exact distance you program it. 2. What is a stimulus? Can you think of a stimulus the robot could detect? What sensor would it use to detect it? A stimulus is something that is sensed by a robot or animal and causes it to act. For the purposes of the lesson, it is sensed by the robot and this may cause it to act in a different manner. Example stimulus & sensor: The robot could detect a wall in front of it with a touch sensor or an ultrasonic sensor. 3 How Do You Make a Program Wait? Pre-Quiz

Objective To learn to use conditional commands. In today’s lesson, we will investigate: Why it is helpful to use conditional commands in programming How to use wait blocks to program a LEGO robot to respond to the presence of a stimulus 4 Day 1: Programming Using Wait Blocks (50 minutes)

An algorithm is a clear and specific procedure for solving a problem in a finite number of steps. Addition algorithm: A systematic process that always produces the correct answer when numbers are added: Do This: For worksheet question 1, try the algorithm (as above) for adding these two numbers: = _______ Did the algorithm result in the same answer for everyone? 5 Review: What is an algorithm?

Programming is designing an algorithm to solve a problem. You need to have commands that are clear and precise because the robot will follow them exactly. Each step is important. If you make an error in any step, the robot makes that same error! Do This: Write down the detailed steps for the addition algorithm you just performed. For worksheet question 2, start with step 1, “Write both numbers one above the other,” and so on. Let’s discuss what everyone has written down so we understand how the algorithm can be written down in steps so that a computer could execute them. 6 Programming as an Algorithm

Good algorithms should be flexible. Algorithms are useful because they can be used to solve many similar problems, not just a specific problem. For example, the addition algorithm gives the correct sum—no matter what numbers are added. 7 Designing Good Algorithms

So far, we have only learned about programming in terms of exact distances. Imagine we are programming the robot to go through a maze. We could achieve one step of this by saying “I want my robot to go five rotations forward then turn left.” 8 5 rotations Designing Good Algorithms (continued) But what happens if we start the robot a little too far back (at the blue circle instead of the green)? The robot will turn too early (at the blue star instead of the green)! Do This: Describe such problems on worksheet question 3.

As a result, that program is not very helpful because it will only work in one specific case. But what if we could program the robot to turn when it senses the wall? The robot could start from any distance and still make the turn at the correct time. In other words, the algorithm we design would work in a variety of situations, which means it would be far more useful. 9 Designing Good Algorithms (continued) 5 rotations

It turns out we can design this kind of algorithm by using conditional commands. A conditional command is a command whose action depends on a condition being satisfied. Many types of conditional commands exist. Example: If you see a stop sign, then stop! This is conditional because the action (stop!) depends on a condition (seeing a stop sign). 10 Conditional Commands

We will be focusing on conditional statements using until. Example: “Play at recess until you hear the bell ring. Then go back to class” Notice, that you do not have to keep track of exactly how long you can play at recess; you will know to go to class when you hear the bell ring. Do This: Write a sequence of similar steps to tell a robot to stop when it bumps into a wall. (worksheet question 4) Let’s discuss what each of you have written down Play at recess2. Wait until you hear the bell 3. Go to class Conditional Commands (continued)

Let’s do a simple demo of how it is easier to use conditional commands than specific commands. Do This: Set up a simple maze: Use tape on the floor to mark off a 2-foot wide track that ends at a wall 5 feet away. Blindfold a student volunteer to serve as the “robot.” Have another student volunteer command the “robot” through the maze, making a left turn at the end when the route terminates at the wall. 1. First try using only one of the two commands at a time: “move forward (or backward) X steps” or “turn left.” 2. Then try using only one of the two commands at a time: “move forward with your hands stretched UNTIL you sense the wall” or “turn left.” 12 Maze Demonstration Conditional Commands (continued)

As a group, discuss your thoughts: How did using the conditional command change the robot’s success with the instructions? Was the robot volunteer able to move faster with the conditional command? Note that the student volunteer used his/her sense of “touch” to navigate the maze. If he had used his “eyes” (light sensor), then the task could have been performed much faster! Likewise, a robot could use a variety of sensors to perform the same task. During the next class, we will learn about programming the LEGO taskbot using conditional commands. 13 Conditional Commands (continued) Maze Demonstration

Today, when programming your robot, use the conditional command ideas we discussed during the last class. If you want to make your robot keep moving forward and stop when it bumps into a wall, add a touch sensor to it and use the conditional command “until.” The robot should go forward until the touch sensor hits the wall. Then the robot should stop Move forward2. Wait until the touch sensor is pressed 3. Stop Notice that now the robot does not have to keep track of how far it should move forward! Next, we will develop an NXT program to implement this. Day 2: Programming with Wait Blocks (50 minutes)

15 We already know which block to use for the first command – a move block. We want the direction to be forward, and the steering to be in the middle. But we have a problem: What should we set the duration to? We don’t know exactly how many rotations or seconds it will take the robot to hit the wall. So, let’s select “unlimited” from the drop-down menu. 1. Move forward Programming with Wait Blocks (continued)

16 2. Wait until the touch sensor is pressed For the second part of the program, we need to use a new kind of block – the wait block. Wait blocks tell the robot to wait until a specified stimulus occurs before going on to the rest of the program. A stimulus is an action that can be perceived by the robot that causes it to move on to the next part of the program. In this case, we want to wait until the wall presses in the touch sensor (when it bumps into it) and then stop the robot. So, the touch sensor being pressed is our stimulus. Programming with Wait Blocks (continued)

The wait block is orange in color and has an hour- glass icon over it. Hover the cursor over the wait block and several different types of wait blocks appear. The one that shows a finger pressing a button is the touch sensor wait block. Drag this block next to the move block. Notice that if you click on the drop-down menu, you can change the stimulus that controls the wait block to an action perceived by many other sensors. Also notice that the wait block shows the touch sensor connected to Port 1. Make sure that the touch sensor is connected to Port 1 on your robot. 17 Programming with Wait Blocks (continued)

18 Once the touch sensor has been pressed, we want the robot to stop. We can achieve this by simply dragging a move block down and setting direction to Stop. Our program is now complete: The robot will go forward for unlimited and wait until the touch sensor is pressed. When this happens, the robot will stop and the program will end. Notice that nowhere in the program did we tell the robot how far it needed to go forward until it hit the wall. 3. Stop Programming with Wait Blocks (continued)

19 Try to break each part of the task you are trying to achieve into a conditional statement using “until” followed by “then.” (In the example: The robot should go forward until the touch sensor hits the wall. Then the robot should stop.) Whatever comes before the “until” should come before your wait block. (In the example: “The robot should go forward.”) The wait block should depend on the condition following “until.” (In the example: The touch sensor hits the wall.) We program this by dragging down a wait block and selecting the correct sensor from the dropdown menu. The move block that comes before the wait block should have duration set to UNLIMITED. This makes the robot keep moving until it is told to stop or change direction. Whatever follows “then” should come after the wait block. Review: How to Use Wait Blocks

20 Do This: Complete questions 4 and 5 on the worksheet with the logic of the program and make sketches of the NXT blocks to implement it. The next task is to implement the program on the LEGO taskbot. Then complete the worksheet, including listing the program using the NXT software. Then download it to the computer and check it out. Discuss your findings as a group. Was navigating the maze much faster and accurate? Implementing the Simple Program

1. What is an algorithm? 2. Can you think of a reason why it might be inconvenient to program your robot to always go a precise distance? 3. What is a stimulus? Can you think of a stimulus the robot could detect? What sensor would it use to detect it? 21 How Do You Make a Program Wait? Post-Quiz

1.What is an algorithm? An algorithm is a clear and specific procedure for solving a problem in a finite number of steps. 2. Can you think of a reason why it might be inconvenient to program your robot to always go a precise distance? If the distance is very far, this could take up a lot of time. Inconsistencies in the robot itself (power, battery charge) can also cause the robot to not always go the exact distance you program it. 3. What is a stimulus? Can you think of a stimulus the robot could detect? What sensor would it use to detect it? A stimulus is something that is sensed by a robot or animal and causes it to act. For the purposes of the lesson, it is sensed by the robot and this may cause it to act in a different manner. Example stimulus & sensor: The robot could detect a wall in front of it with a touch sensor or an ultrasonic sensor. 22 How Do You Make a Program Wait? Post-Quiz

algorithm: A clear and specific procedure for solving a problem in a finite number of steps. conditional command: A command in which the completion of an action depends on a condition being satisfied. For example, if I see a stop sign [condition], I stop [action]. stimulus: Something that rouses or incites to activity. For the purposes of the lesson, it is an action that can be perceived by the robot that causes it to move on to the next part of the program. 23 Vocabulary

24 Slide 1: Baseball player girl waiting; source: Microsoft® clipart: us/images/results.aspx?qu=baseball+player&ex=1#ai:MP |mt:2| us/images/results.aspx?qu=baseball+player&ex=1#ai:MP |mt:2| Slide 7: Woman doing yoga stretch; source: Microsoft® clipart : us/images/results.aspx?qu=yoga&ex=1#ai:MC | us/images/results.aspx?qu=yoga&ex=1#ai:MC | Slide 10: Boy holding stop sign; source: Microsoft® clipart: us/images/results.aspx?qu=stop&ex=1#ai:MP |mt:2| us/images/results.aspx?qu=stop&ex=1#ai:MP |mt:2| Device and programming images from LEGO MINDSTORM NXT User’s Guide Screen captures and diagrams by author Images Sources