if-else Structures Principles of Engineering

Slides:



Advertisements
Similar presentations
ROBOTC for CORTEX While Loops Part 1
Advertisements

Variables and Functions ROBOTC Software. Variables A variable is a space in your robots memory where data can be stored, including whole numbers, decimal.
While Loops and If-Else Structures
Automation and Robotics
VEX and Robot C Chris Patterson Presented by Modified by J. Andazola.
Autonomy using Encoders Intro to Robotics. Goal Our new task is to navigate a labyrinth. But this time we will NOT use motor commands in conjunction with.
Programming – Touch Sensors Intro to Robotics. The Limit Switch When designing robotic arms there is always the chance the arm will move too far up or.
Testbed: Exercises.
ROBOTC for VEX Online Professional Development
ROBOTC Software Introduction. ROBOTC Software ROBOTC developed specifically for classrooms and competitions Complete programming solution for VEX Cortex.
ROBOTC for VEX On-Site Professional Development
Chapter 4: Decision Making with Control Structures and Statements JavaScript - Introductory.
Wall Encounter By Made easy by Dwayne Abuel.
Chapter 15 JavaScript: Part III The Web Warrior Guide to Web Design Technologies.
Lesson 4: Conditional Statements Programming Solutions.
Variables and Functions ROBOTC Software © 2012 Project Lead The Way, Inc.Principles of Engineering.
While and If-Else Loops ROBOTC Software. While Loops While loop is a structure within ROBOTC Allows a section of code to be repeated as long as a certain.
Programming 101 The Common Palette Content provided by Connor Statham (9 th Grade Student) Formatting by Shannon Sieber.
VEX and Robot C Chris Patterson Frisco ISD CTE Center Presented by.
Automation and Robotics.  First you select the platform type so that you can use Natural Language PLTW.
Decision Making: while loops and Boolean Logic. While Loops A while loop is a structure within ROBOTC which allows a section of code to be repeated as.
Sensor Information: while loops and Boolean Logic.
IST 210: PHP Logic IST 210: Organization of Data IST2101.
Copyright © 2014 Pearson Addison-Wesley. All rights reserved. 4 Simple Flow of Control.
ROBOTC for CORTEX Teacher Training © 2011 Project Lead The Way, Inc. Automation and Robotics VEX.
Programming Design ROBOTC Software Principles Of Engineering
Variables and Functions
Variables and Functions
Variables and Functions
ROBOTC for VEX Online Professional Development
ROBOTC for VEX On-Site Professional Development
Robotics Programming Using Shaft Encoders
Chapter 3 Loops Section 3.3 Slides prepared by Rose Williams, Binghamton University Kenrick Mock, University of Alaska Anchorage.
Chapter 5 Decisions. Chapter 5 Decisions ssential uestion: How are Boolean expressions or operators used in everyday life?
Automation and Robotics
Programming Design ROBOTC Software Computer Integrated Manufacturing
Variables and Functions
Movement using Shaft Encoders
Using Encoders to go Straight
Programming – Touch Sensors
Variables and Functions
Variables and Functions
LESSON 11 – WHILE LOOPS UNIT 5 – 1/10/17.
Variables and Functions
Automation and Robotics
While Loops and If-Else Structures
Variables and Functions
Line Following Behavior
Auto Straightening using VEX Shaft Encoders
While Loops and If-Else Structures
Multitasking Emergency Stop Computer Integrated Manufacturing
Three Special Structures – Case, Do While, and Do Until
Programming Design ROBOTC Software Principles Of Engineering
While Loops and If-Else Structures
While Loops and If-Else Structures
While Loops and If-Else Structures
Conditional Logic Presentation Name Course Name
Programming - Buttons Intro to Robotics.
RobotC While loop When and how to use the while loop
Automation with RobotC
Robotics Programming Using Shaft Encoders
Programming - Buttons Intro to Robotics.
Robotics Programming Using Shaft Encoders
While Loops and If-Else Structures
Automation with RobotC
Robotics Programming Using Shaft Encoders
While Loops and If-Else Structures
Programming Design ROBOTC Software Principles of Engineering
Lego MINDSTORMS EV3.
While Loops And If-Else Structures
Presentation transcript:

if-else Structures Principles of Engineering © 2012 Project Lead The Way, Inc.

Boolean logic

Boolean logic

if statements if statement in the program is evaluated by condition contained in parentheses If condition is true, commands between braces are run If condition is false, those commands are ignored Very similar to how a while loop works, but does not repeat the code

if-else statements if-else statement is an expansion of if statement if checks condition and runs appropriate commands when it evaluates to true else allows code to run when condition is false Either if or else branch is always run once

Multiple if-else statements Be careful when using two separate if-else statements, particularly if both are used to control the same mechanism One branch of each if-else statement is always run so that you may create a scenario where the two statements ‘fight’ one another

Multiple if-else statements In this example, if one of the touch sensors is pressed, the “motor” will be turned on in one if-else statement and immediately turned off in the other.

Multiple if-else statements This can be corrected by embedding the second if-else within the else branch of the first if-else. The second condition is only checked if the first condition is false.

Nested if-else statements: else if An else {if else} statement can also be represented as an else if - else

Timers Loop control Solution: Timers Presentation Name Course Name Unit # – Lesson #.# – Lesson Name Timers Loop control Where would the wait statement go if we wanted the loop to repeat for a controlled amount of time? Nowhere! We need something else. Solution: Timers Internal stopwatches (4 available) Like encoders, timers should be cleared before they are used. Be careful: Don’t clear a timer in a timed loop. Clearing timers within a loop may continually reset the timers, which may create an infinite loop.

References Carnegie Mellon Robotics Academy. (2011). ROBOTC. Retrieved from http://www.robotc.net