More switches, Comparison Day 7 Computer Programming through Robotics CPST 410 Summer 2009.

Slides:



Advertisements
Similar presentations
Introduction to Programming
Advertisements

EducateNXT Follow the Leader Using Bluetooth communication, one robot can be made to follow the actions of a second robot. Features in this presentation:
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.
NXT Basics: Technic Building and NXT-G Erin Cejka Riecker Center for Engineering Educational Outreach Tufts University.
© 2006 Carnegie Mellon Robotics Academy Designed for use with the LEGO MINDSTORMS ® Education NXT Software and Base Set #9797 Automated Mining Project.
Programing Concept Ken Youssefi/Ping HsuIntroduction to Engineering – E10 1 ENGR 10 Introduction to Engineering (Part A)
More switches Day 6 Computer Programming through Robotics CPST 410 Summer 2009.
Chapter 8 and 9 Review: Logical Functions and Control Structures Introduction to MATLAB 7 Engineering 161.
True or false A variable of type char can hold the value 301. ( F )
C++ Programming: From Problem Analysis to Program Design, Third Edition Chapter 4: Control Structures I (Selection)
Aalborg Media Lab 23-Jun-15 Software Design Lecture 6 “Conditionals and Loops”
Tutorial 4 Decision Making with Control Structures and Statements Section A - Decision Making JavaScript Tutorial 4 -Decision Making with Control.
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.
Robotics Catchup/Review: switch, arithmetic, range, loop Bluetooth Lab: Finish parallel parking. Next: Use Bluetooth communication for calculate & send.
What is RobotC?!?! Team 2425 Hydra. Overview What is RobotC What is RobotC used for What you need to program a robot How a robot program works Framework.
Visual Basic Chapter 1 Mr. Wangler.
Encapsulation Day 11 Computer Programming through Robotics CPST 410 Summer 2009.
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.
Unit 5 – “Watch Out!”. Introduction New Topics Case Structures New Functions Less? Comparison Function Ultrasonic Sensor.
ADVANCED EV3 PROGRAMMING LESSON
Programming Fundamentals. Today’s lecture Decisions If else …… Switch Conditional Operators Logical Operators.
More on Input Output Input Stream : A sequence of characters from an input device (like the keyboard) to the computer (the program running). Output Stream.
COMPUTER PROGRAMMING. Control Structures A program is usually not limited to a linear sequence of instructions. During its process it may repeat code.
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 Light sensor. Calibration. Reverse engineering challenge. Lab work: Create and show your program. Add light sensor (different orientations). Robot.
Application of Data Programming Blocks. Objectives  Understand the use of data programming blocks and their applications  Understand the basic logic.
Flow of Control Part 1: Selection
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.
PROBLEM SOLVING & ALGORITHMS CHAPTER 5: CONTROL STRUCTURES - SELECTION.
1 COMS 261 Computer Science I Title: C++ Fundamentals Date: September 21, 2005 Lecture Number: 10.
Chapter 05 (Part III) Control Statements: Part II.
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.
Visual Basic 2010 How to Program © by Pearson Education, Inc. All Rights Reserved.1.
Comparison the RANGE block Day 8 Computer Programming through Robotics CPST 410 Summer 2009.
Lecture 2 Conditional Statement. chcslonline.org Conditional Statements in PHP Conditional Statements are used for decision making. Different actions.
Chapter 4 Control Structures I. Chapter Objectives Learn about control structures Examine relational and logical operators Explore how to form and evaluate.
Sections © Copyright by Pearson Education, Inc. All Rights Reserved.
Visual Basic 2010 How to Program © by Pearson Education, Inc. All Rights Reserved.1.
Programming 101 The Common Palette Content provided by Connor Statham (9 th Grade Student) Formatting by Shannon Sieber.
Data Hubs and Wires. Begin by adding a basic Move block, 5 rotations 75% power.
Controlling Program Flow with Decision Structures.
Mindstorm NXT-G Introduction Towson University Robotics.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Extended Prelude to Programming Concepts & Design, 3/e by Stewart Venit and.
Visual Basic.NET Comprehensive Concepts and Techniques Chapter 5 Decision Making.
Dr. Sajib Datta Jan 23,  A precedence for each operator ◦ Multiplication and division have a higher precedence than addition and subtraction.
Vex Robotics program three: using motors and sensors together.
Conditional Statements A conditional statement lets us choose which statement will be executed next Conditional statements give us the power to make basic.
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.
Computer Science Up Down Controls, Decisions and Random Numbers.
 Very often when you write code, you want to perform different actions for different decisions. You can use conditional statements in your code to do.
Sequence, Selection, Iteration The IF Statement
Decisions Chapter 4.
fischertechnik® RoboPro Software for Gateway To Technology® RoboPro
Microsoft Visual Basic 2005 BASICS
Displaying sensor values while a robot is running
INTERMEDIATE PROGRAMMING LESSON
INTERMEDIATE PROGRAMMING LESSON
Items, Group Boxes, Check Boxes & Radio Buttons
Introduction to Problem Solving and Control Statements
Chapter 4: Control Structures I (Selection)
Control Structures Part 3
Chapter 3: Selection Structures: Making Decisions
Chap 7. Advanced Control Statements in Java
LEGO MINDSTORMS NXT PROGRAMMING
Presentation transcript:

More switches, Comparison Day 7 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.

Review

7/1/09Harry Howard, CPST 410, Tulane University4 More than two choices  Tribot, when I press the left NXT button, pick a number from 1 to 3.  If the number is 1, display an image.  If the number is 2, beep.  If the number is 3, play a sound.

7/1/09Harry Howard, CPST 410, Tulane University5 Switch3.rbt

7/1/09Harry Howard, CPST 410, Tulane University6 Switches in NXC  A switch statement can be used to execute one of several different blocks of code depending on the value of an expression.  It has the following syntax:  switch (expression) body

7/1/09Harry Howard, CPST 410, Tulane University7 Case labels  One or more case labels precede each block of code.  The labels are not statements in themselves - they are labels that precede statements.  They have the following syntax:  case constant_expression :  default :

7/1/09Harry Howard, CPST 410, Tulane University8 Example the number of each case is a value of x int x; … switch(x) { case 1: // do something when x is 1 break; case 2: case 3: // do something else when x is 2 or 3 break; default: // do this when x is not 1, 2, or 3 break; }

7/1/09Harry Howard, CPST 410, Tulane University9 More on case labels  Each case must be a constant and unique within the switch statement.  The switch statement evaluates the expression then looks for a matching case label.  It will then execute any statements following the matching case until either a break statement or the end of the switch is reached.  A single default label may also be used - it will match any value not already appearing in a case label.

7/1/09Harry Howard, CPST 410, Tulane University10 So now do the task in NXC  Tribot, when I press the left NXT button, pick a number from 1 to 3.  If the number is 1, display an image.  If the number is 2, beep.  If the number is 3, play a sound.

7/1/09Harry Howard, CPST 410, Tulane University11 First try: just the switch int num; task main() { num = Random(3); // Random starts at 0 switch(num) { case 0: GraphicOut( “ Smile 01.ric ” ); Wait(1000); break; case 1: PlayTone(440, 500): Wait(500); break; case 2: PlayFile( “ Laughing 02.rso ” ): Wait(500); break; }

7/1/09Harry Howard, CPST 410, Tulane University12 The switch in a while loop int num; task main() { while (SensorBoolean(S1) == true) // touch sensor on port S1 { num = Random(3); switch(num) { // Random starts at 0 case 0: GraphicOut( “ faceopen.ric ” ); Wait(1000); ResetScreen(); // otherwise graphic never goes away break; case 1: PlayTone(440, 500); Wait(500); break; case 2: PlayFile( “ Laughing 02.rso ” ); Wait(500); break; }

Comparison Kelly §15

7/1/09Harry Howard, CPST 410, Tulane University14 The challenge  Tribot, 1. choose two numbers randomly between 0 and 9 (call them A and B), 2. and display them on the screen. 3. Then, if A is greater than B, display “true”; otherwise, display “false”.

7/1/09Harry Howard, CPST 410, Tulane University15 ComparisonTest1.rbt

7/1/09Harry Howard, CPST 410, Tulane University16 Combining text  We now have two numbers to display, but a DISPLAY block can only display one at a time.  Thus the two numbers have to be combined or concatenated into a single bit of text.  The TEXT block does this.

7/1/09Harry Howard, CPST 410, Tulane University17 The TEXT block  Drag a TEXT block out of the Advanced palette - it has the icon “a”.  Pull out its hub all the way:  It has inputs for 3 pieces of text,  or text can be written in the settings windows.

7/1/09Harry Howard, CPST 410, Tulane University18 Display the two numbers  Drop a TEXT block at the end.  Plug textualized number A into TEXT plug A.  Plug textualized number B into TEXT plug C.  Enter ” > " into the text box of TEXT plug B.  Drop a DISPLAY block after the TEXT block.  Connect the TEXT block to it via the Text plugs.  Raise the text to line 3.  Don’t forget to WAIT for the display!  Test the program.

7/1/09Harry Howard, CPST 410, Tulane University19 ComparisonTest2.rbt

7/1/09Harry Howard, CPST 410, Tulane University20 Now, the comparison  This program gives a dumb result whenever A is less than or equal to B.  As a first step towards making it less dumb, let us examine the COMPARE block.

7/1/09Harry Howard, CPST 410, Tulane University21 The COMPARE block  Pull out a COMPARE block (it has > = <) from the Data part of the Complete palette.  It has three operations:  less than,  greater than,  equals.  And two input hubs.

7/1/09Harry Howard, CPST 410, Tulane University22 Adding the comparison  Drop a COMPARE block at the end of the sequence bar.  Set it to ‘>’.  Where should its inputs come from?  From the number outputs of the two Number to Text blocks.  see the next slide

7/1/09Harry Howard, CPST 410, Tulane University23 ComparisonTest3.rbt

7/1/09Harry Howard, CPST 410, Tulane University24 Now, a decision  But we want to display "True" if the comparison is true, and "False" otherwise.  How do we do that?  Drop a SWITCH block at the end of the sequence bar.  Set it to tabbed view, for convenience.  Set Control to Value.  Run a wire from the COMPARE Logic plug to the SWITCH input plug.  Now fill in each condition with a DISPLAY block with the appropriate text on line 6, and don’t clear the screen.  Don’t forget to add a WAIT at the end!

7/1/09Harry Howard, CPST 410, Tulane University25 ComparisonTest4.rbt

Play with it

7/1/09Harry Howard, CPST 410, Tulane University27 Next time  Comparison in NXC.  The RANGE and LOGIC blocks.