Conditions and loops Day 4 Computer Programming through Robotics CPST 410 Summer 2009.

Slides:



Advertisements
Similar presentations
Intermediate Robotics Getting to the Next Level Guiding Question: How might I move the robot consistently, accurately, and predictably? –Review basics.
Advertisements

Robofest 2005 Introduction to Programming RIS 2.0 RCX Code.
Jason Howard. Agenda I. How to download robotc II. What is tele-op used for? III. How to build a basic tele-op program IV. Getting the robot to drive.
Add and Use a Sensor & Autonomous For FIRST Robotics
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.
NXT Basics: Technic Building and NXT-G Erin Cejka Riecker Center for Engineering Educational Outreach Tufts University.
Automation and Robotics
Using the NXT Light Sensor. 2 Connect One Light Sensor – 1 From My Files use Left / Right NXT buttons and get to View menu and push Orange button. From.
More switches Day 6 Computer Programming through Robotics CPST 410 Summer 2009.
EIGHTH GRADE ROBOTICS KITTATINNY REGIONAL HIGH SCHOOL MR. SHEA Introduction to Programming
Introduction to NXT Software and Functionality Bot’oberfest October 15, 2007.
1 ©2006 INSciTE Lab Two Task: Make the program from Lab One (Move forward 5 rotations and turn right 90 degrees) into a MyBlock.
Reviewing Common Blocks for St. Agnes Elementary School Teachers by Jenny Chang Feb. 26th, 2007 USC & University Neighborhood Outreach Robotics STEM program.
Variables, logic and sensors Day 3 Computer Programming through Robotics CPST 410 Summer 2009.
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.
Robotics Catchup/Review: switch, arithmetic, range, loop Bluetooth Lab: Finish parallel parking. Next: Use Bluetooth communication for calculate & send.
Introduction to the course Computer Programming through Robotics CPST 410 Summer 2009.
1 Oregon Robotics Tournament and Outreach Program Programming Techniques Workshop for Mindstorms  NXT 2012 Opening doors to the worlds of science and.
Encapsulation Day 11 Computer Programming through Robotics CPST 410 Summer 2009.
Robotics Abstractions: Levels of language, world view
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.
LabVIEW Basics Review LabVIEW Robotics Fundamentals.
More switches, Comparison Day 7 Computer Programming through Robotics CPST 410 Summer 2009.
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*.]
2 3  A machine  Built to help us  Autonomous (not remote control)  If we want robots to do things for us, we have.
A tiny turtle robot DEI The University of Padova.
The LOGIC and MATH blocks Day 9 Computer Programming through Robotics CPST 410 Summer 2009.
NXT Basics: Technic Building and NXT-G Erin Cejka Riecker Center for Engineering Educational Outreach Tufts University.
Motors and Sound Troubleshooting Tips. © H-CCS Problem 1 Why can’t I download my program to the RCX?
A note on oral presentations These are the progress report presentations. Please note that the individual presentations should be ~8 min long. Since the.
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.
Comparison the RANGE block Day 8 Computer Programming through Robotics CPST 410 Summer 2009.
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.
Robotics NXT-G: variables, file Rotation sensor Lab: Use buttons to hit specific ball. Homework: Postings. Start planning mapping the room.
LEGO® MINDSTORMS® NXT Move Block.
Programming 101 The Common Palette Content provided by Connor Statham (9 th Grade Student) Formatting by Shannon Sieber.
1 ©2006 INSciTE Common Blocks. 2 ©2006 INSciTE Common Blocks Common blocks are full featured actions Like English statements Move Wait for an action Display.
Introduction to Computer Programming - Project 2 Intro to Digital Technology.
Mindstorm NXT-G Introduction Towson University Robotics.
BEGINNER FLL PROGRAMMING WORKSHOP BY DROIDS ROBOTICS & EV3LESSONS.
Lesson 1: Motors and Sound Programming Solutions.
Automation and Robotics.  First you select the platform type so that you can use Natural Language PLTW.
MEH108 - Intro. To Engineering Applications KOU Electronics and Communications Engineering.
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.
1 ©2006 INSciTE Lab Three Task: Move forward for 2 feet, turn right 90º repeat to complete a square path. End up exactly where you started.
How Do You Make a Program Wait?
Robotics Abstractions: Levels of language, world view
Introduction to Programming in RobotC
NXT Mindstorms Kit Programming
Mindstorms EV3 Programming
Robotics Abstractions: Levels of language, world view
Mindstorms EV3 Programming
Introduction To Programming with LEGO NXT 2
Mindstorms EV3 Programming
Loops and Switches Pre-Quiz
Music by Touch Music by Touch Presentation > TeachEngineering.org
Module F: Presentation Understanding Robot Fundamentals
Forward Until Touch Robot goes forward until it hits a wall.
Lego EV3 Mindstorms SW Programming Blocks.
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.
Lego MINDSTORMS EV3.
LEGO MINDSTORMS NXT PROGRAMMING
Presentation transcript:

Conditions and loops Day 4 Computer Programming through Robotics CPST 410 Summer 2009

7/1/09Harry Howard, CPST 410, Tulane University2 Course organization  Course home page Course home page  (  Lab (Newcomb 442) will be open for practice with 3-4 Macs, but you can bring your own laptop and all robots.

Sound in NXT-G Kelly §6 Make some noise!

7/1/09Harry Howard, CPST 410, Tulane University4 The SOUND block 1. This icon shows whether the block will play a sound file or a tone. 2. This icon shows whether the block will start or stop playing a sound. 3. This icon shows the block’s volume. An icon with four orange bars is set to the loudest volume. 4. You can drag data wires from other blocks to this block’s data hub that will affect the Sound block’s properties.

7/1/09Harry Howard, CPST 410, Tulane University5 Kelly's example, reversed  Spot, move forward 1 rotations at 50% power coasting to a stop and then play me a C note for 2 seconds at 75% volume.

7/1/09Harry Howard, CPST 410, Tulane University6 MoveSound.rbt

Sound in NXC

7/1/09Harry Howard, CPST 410, Tulane University8 Two useful sound functions  Definitions  PlayTone(frequency, duration)  PlayFile(filename)  Examples  PlayTone(440, 500); Wait(500);  PlayFile(“Startup.rso”);  Note that PlayTone executes immediately, so that all by itself, it does not play for 500 ms; it relies on Wait to actually extend the duration to the one specified.

7/1/09Harry Howard, CPST 410, Tulane University9 Do Kelly's example in NXC  TRIBOT, move forward 1 rotation at 50% power coasting to a stop and then play me a C note for 2 seconds at 75% volume.

7/1/09Harry Howard, CPST 410, Tulane University10 MoveSound.nxc task main() { RotateMotor(OUT_AC, 75, 360); PlayTone(1047,2000); Wait(2000); }

Waiting Kelly §10 Wait for it!

7/1/09Harry Howard, CPST 410, Tulane University12 Waiting  The robot is almost always waiting to do something, even when it is already doing something:  TRIBOT is moving towards a black line, waiting for the Light sensor to detect it.  TRIBOT is preparing to throw a ball at a target, waiting for the Touch sensor to be pressed and released.  TRIBOT is rolling towards the wall, waiting for the Ultrasonic sensor to detect it.  TRIBOT is sitting at the start line, waiting for the Sound sensor to hear me yell “Go!”.

7/1/09Harry Howard, CPST 410, Tulane University13 Conditions  The WAIT block will stop waiting when specific conditions are met.  The conditions are usually given by some kind of sensor feedback.  The blocks for each condition can be found in two ways:  Common palette > Wait.  By changing the setting from Time to Sensor on the Time WAIT block.

7/1/09Harry Howard, CPST 410, Tulane University14 The conditions  Time wait  Touch sensor wait  Light sensor wait  Ultrasonic sensor wait  NXT Buttons wait  Rotation sensor wait  Receive Message wait

7/1/09Harry Howard, CPST 410, Tulane University15 A simple test of a condition  TRIBOT, move forward for an unlimited duration at a power of 50 until the Touch sensor is pressed.

7/1/09Harry Howard, CPST 410, Tulane University16 MoveTilTouch.rbt

7/1/09Harry Howard, CPST 410, Tulane University17 A more complex example  SPOT, move forward for 1 rotation at 50% power, brake, and beep. If your Light sensor detects a light level greater than 30, move backward 1/2 rotation at 50% power, coasting to a stop.

7/1/09Harry Howard, CPST 410, Tulane University18 MoveTilLight.rbt

Conditions in NXC

7/1/09Harry Howard, CPST 410, Tulane University20 A complication  The sensor functions in NXC do not include this ability to wait; all they do is read sensor values.  So you have to add the condition that the sensor value is supposed to meet, yourself.

7/1/09Harry Howard, CPST 410, Tulane University21 If  There are two options if (condition) consequence if (condition) consequence else alternative  Examples if (x == 1) y = 2; if (x == 1) { y = 2; z = 3; } if (x == 1) y = 3; else y = 4;

7/1/09Harry Howard, CPST 410, Tulane University22 We can’t do the simple test  TRIBOT, move forward for an unlimited duration at a power of 50 until the Touch sensor is pressed.  PROBLEM: there is no ‘unlimited’ parameter for any of the NXC movement functions, so we skip this task, though the next slide shows what we would want the program to look like.

7/1/09Harry Howard, CPST 410, Tulane University23 MoveTilTouch.nxc task main() { OnFwd(OUT_AC, 50); if (Sensor(S1) == 1) { Off(OUT_AC); }

7/1/09Harry Howard, CPST 410, Tulane University24 The more complex example  TRIBOT, move forward for 1 rotation at 50% power, brake, and beep. If your Light sensor detects a light level greater than 30, move backward 1/2 rotation at 50% power, coasting to a stop.

7/1/09Harry Howard, CPST 410, Tulane University25 MoveTilLight.rbt task main() { RotateMotor(OUT_BC, 50, 360); PlayTone(1047, 500); Wait(500); if (Sensor(S3) > 30) { RotateMotor(OUT_BC, 50, -180); }

Loops Kelly §11 Round and Round

7/1/09Harry Howard, CPST 410, Tulane University27 How would you do this?  TRIBOT, display the output of the Light sensor briefly (500ms) 10 times.

7/1/09Harry Howard, CPST 410, Tulane University28 The LOOP block  The LOOP block repeats what is inside it until a condition is met.  The loop break conditions are the same as the WAIT conditions.  You drop a block inside a loop by grabbing the block, holding down the mouse button, and dropping it inside when the loop expands.

7/1/09Harry Howard, CPST 410, Tulane University29 Go ahead and do it  TRIBOT, display the output of the Light sensor briefly (1s) 10 times.

7/1/09Harry Howard, CPST 410, Tulane University30 DisplaySensorLoop.rbt

Loops in NXC

7/1/09Harry Howard, CPST 410, Tulane University32 REPEAT  The repeat command, repeat(t) {}, repeats what is in the curly brackets for the number of times given by t.

7/1/09Harry Howard, CPST 410, Tulane University33 Convert the example to NXC  TRIBOT, display the raw output of the Light sensor briefly (1s) 10 times.

7/1/09Harry Howard, CPST 410, Tulane University34 DisplaySensorLoop.nxc int light; string text_light; task main() { repeat(10) { light = Sensor(S3); txt_light = NumToStr(light); TextOut(0, LCD_LINE4, txt_light); Wait(1000); }

More practice Program each bit of pseudocode in NXT-G and then in NXC. My suggestion follows each bit of pseudocode, so don’t look ahead until you are finished with your program!

7/1/09Harry Howard, CPST 410, Tulane University36 Follow up  TRIBOT, display the output of the Light sensor briefly (1s) 10 times and beep after each display. Laugh when you are finished.

7/1/09Harry Howard, CPST 410, Tulane University37 SensorLoopSound.rbt

7/1/09Harry Howard, CPST 410, Tulane University38 SensorLoopSound.nxc int light; string text_light; task main() { repeat(10) { light = Sensor(S3); txt_light = NumToStr(light); TextOut(0, LCD_LINE4, txt_light); Wait(1000); PlayTone(1047,500); Wait(500); } PlayFile(“Laughing 02.rso”); Wait(1000); }

7/1/09Harry Howard, CPST 410, Tulane University39 Epilog on scope  Note the difference being in the loop versus being out of the loop makes. PlayTone is played 10 times, because it is in the loop. PlayFile is only played once, because it is not in the loop.  The effect of an expression like repeat is known as its scope, and in NXC the scope of an expression is stated explicitly by means of the curly brackets.

7/1/09Harry Howard, CPST 410, Tulane University40 Thought experiment  How would you make TRIBOT move forward and then turn right -- four times?  By dropping in 8 MOVE blocks, each with the same settings (one for each forward move, and one for each turn).  Does this sound like a good usage of your time?  No!

7/1/09Harry Howard, CPST 410, Tulane University41 The pseudocode  TRIBOT, move forward for 0.5 s at 50% power and then make a 90° turn for 0.65 s also at 50% power. Do this 4 times.

7/1/09Harry Howard, CPST 410, Tulane University42 RepeatTurn.rbt

7/1/09Harry Howard, CPST 410, Tulane University43 Turning in NXC  You may have noticed that the NXC movement functions do not have the nice ‘steering wheel’ ability that NXT-G has.  The trick to turning in NXC is to reverse a motor. I’ll leave it up to you to figure out which one.

7/1/09Harry Howard, CPST 410, Tulane University44 RepeatTurn.nxc task main() { repeat(4) { OnFwd(OUT_BC, 50); Wait(500); OnRev(OUT_C, 50); Wait(650); }

7/1/09Harry Howard, CPST 410, Tulane University45 Mix them up  TRIBOT, move forward for 1 rotation at 50% power and coast. If your Light sensor detects a level greater than 20, beep and move backward 1/2 rotation at 50% power, coasting to a stop. Do this 3 times, then say the number ‘three’.

7/1/09Harry Howard, CPST 410, Tulane University46 MoveLightLoop.rbt

7/1/09Harry Howard, CPST 410, Tulane University47 MoveLightLoop.nxc task main() { repeat(3) { RotateMotor(OUT_BC, 50, 360); if (Sensor(S3) > 20) { PlayTone(1047,500); Wait(500); RotateMotor(OUT_BC, 50, -180); } PlayFile(“03.rso”); Wait(1000); }

7/1/09Harry Howard, CPST 410, Tulane University48 Next time  Quiz 1  This will just be a quiz on the blocks.  More loops, switching.  Random numbers.  'Line Follower' - project done in class