Sensor Information: while loops and Boolean Logic.

Slides:



Advertisements
Similar presentations
Decision Structures - If / Else If / Else. Decisions Often we need to make decisions based on information that we receive. Often we need to make decisions.
Advertisements

ROBOTC for CORTEX While Loops Part 1
While Loops and If-Else Structures
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.
RobotC For Beginners Tyler Lutz and Keaton Bonds DRSS Enterprise.
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.
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.
ROBOTC for VEX On-Site Professional Development
Python – Making Decisions Lecture 02. Control Structures A program that only has one flow is useful but limited. We can use if statements to make these.
Institute for Personal Robots in Education (IPRE)‏ CSC 170 Computing: Science and Creativity.
AUTOMATION WITH ROBOTC Starting to write and troubleshoot computer code.
ITEC 109 Lecture 11 While loops. while loops Review Choices –1 st –2 nd to ?th –Last What happens if you only use ifs? Can you have just an else by itself?
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.
ITK 168 Decisions Dr. Doug Twitchell September 20, 2005.
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.
Control Flow (Python) Dr. José M. Reyes Álamo. 2 Control Flow Sequential statements Decision statements Repetition statements (loops)
VEX and Robot C Chris Patterson Frisco ISD CTE Center Presented by.
Flow Control in Imperative Languages. Activity 1 What does the word: ‘Imperative’ mean? 5mins …having CONTROL and ORDER!
PYTHON WHILE LOOPS. What you know While something is true, repeat your action(s) Example: While you are not facing a wall, walk forward While you are.
Control Structure  What is control Structure?  Types of Controls  Use the control structure in VBScript.  Example Summery.
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.
Loops causes program to execute the certain block of code repeatedly until some conditions are satisfied. Suppose you want to execute some code/s 10 times.
IST 210: PHP Logic IST 210: Organization of Data IST2101.
ROBOTC for CORTEX Teacher Training © 2011 Project Lead The Way, Inc. Automation and Robotics VEX.
Control Flow (Python) Dr. José M. Reyes Álamo.
CHAPTER 4 DECISIONS & LOOPS
Mile-long hurdle race Suppose that we want to program Karel to run a one-mile long hurdle race, where vertical wall sections represent hurdles. The hurdles.
ROBOTC for VEX Online Professional Development
ROBOTC for VEX On-Site Professional Development
Robotics Programming Using Shaft Encoders
Chapter 5 Decisions. Chapter 5 Decisions ssential uestion: How are Boolean expressions or operators used in everyday life?
Movement using Shaft Encoders
Using Encoders to go Straight
LESSON 11 – WHILE LOOPS UNIT 5 – 1/10/17.
Automation and Robotics
CPS120: Introduction to Computer Science
CMSC 120: Visualizing Information 3/25/08
While Loops and If-Else Structures
Working with Arduino: Lesson #1: Getting Acquainted with the Kit
Sensors and Logic Switches
Scratch: selection / branching/ if / If…else / compound conditionals / error trapping by Mr. Clausen.
Line Following Behavior
While Loops and If-Else Structures
Using the sensor Lesson 5.
Three Special Structures – Case, Do While, and Do Until
While Loops and If-Else Structures
Programs as Directions
While Loops and If-Else Structures
While Loops and If-Else Structures
RobotC While loop When and how to use the while loop
if-else Structures Principles of Engineering
Automation with RobotC
Robotics Programming Using Shaft Encoders
Robotics Programming Using Shaft Encoders
While Loops and If-Else Structures
There many situations comes in real life when we need to make some decisions and based on these decisions, we decide what should we do next. Similar situations.
Introduction to Repetition
Automation with RobotC
Robotics Programming Using Shaft Encoders
Python While Loops.
Introduction to Repetition
© A+ Computer Science -
While Loops and If-Else Structures
While Loops And If-Else Structures
CPS120: Introduction to Computer Science
Presentation transcript:

Sensor Information: 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 long as a certain condition remains true. There are three main parts to every while loop.

1. The word “while” Every while loop begins with the keyword “while”.

2. The Condition The condition controls how long or how many times a while loop repeats. While the condition is true, the while loop repeats; when the condition is false, the while loop ends and the robot moves on in the program. The condition is checked every time the loop repeats, before the commands between the curly braces are run.

3. Commands to be Repeated Commands placed between the curly braces will repeat while the (condition) is true when the program checks at the beginning of each pass through the loop.

while() Loops do NOT Constantly Check their Conditions while() loops check their conditions before running the body of code After the body of code is run, the while() loop checks the condition again The condition is NOT checked while the body of code is being run

While Loop: Program Flow

Boolean Logic Decisions robots make must always based on questions which have only two possible answers: yes or no, true or false. Statements that can be only true or false are called Boolean statements, and their true-or- false value is called a truth value.

Boolean Logic

While Loop Exercise 1 Using the Line Tracker Sensor, program the LED to turn on when the lights in the room go out (or the sensor is blocked), and turn back off when the lights are turned back on, forever.

Timers More loop control please? – Question: Where would the wait statement go if we wanted the loop to repeat for a controlled amount of time? – Answer: Nowhere! We need something else. Solution: Timers – Can be thought of as internal stopwatches (4 available) – Like encoders, timers should be “cleared” anytime before they are used Watch where you clear them!

Timers In the program below, timer T1 is used as the condition for the while loop, which will run for 30 seconds:

While Loop Exercise 2 Example: Program the greenLED to repeatedly turn on for 2 seconds, then off for 2 seconds, while less than 20 seconds have elapsed. Individual: Program the greenLED to repeatedly turn on for 2 seconds, then off for 2 seconds, until the poten. Is greater than 3123.