RobotC While loop When and how to use the while loop

Slides:



Advertisements
Similar presentations
ROBOTC for CORTEX While Loops Part 1
Advertisements

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.
If Statements Sections 1.25, Control Structures o All code thus far executes every line of code sequentially o We want to be able to repeat,
RobotC For Beginners Tyler Lutz and Keaton Bonds DRSS Enterprise.
Testbed: Exercises.
ROBOTC Software Introduction. ROBOTC Software ROBOTC developed specifically for classrooms and competitions Complete programming solution for VEX Cortex.
Unit 5 – “Watch Out!”. Introduction New Topics Case Structures New Functions Less? Comparison Function Ultrasonic Sensor.
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.
Control Structures – Selection Chapter 4 2 Chapter Topics  Control Structures  Relational Operators  Logical (Boolean) Operators  Logical Expressions.
PAGES:51-59 SECTION: CONTROL1 : DECISIONS Decisions.
1. We’ve learned that our programs are read by the compiler in order, from top to bottom, just as they are written The order of statement execution is.
Four Fundamental Pieces Instruction Control Structure Function Expression.
Variables and Functions. Open your Encoder program Let’s begin by opening the “Labyrinth Auto Straight” code. Save this file as Labyrinth with variables.
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.
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.
Vex Robotics program three: using motors and sensors together.
Control Flow (Python) Dr. José M. Reyes Álamo. 2 Control Flow Sequential statements Decision statements Repetition statements (loops)
Bot Shop Jane Taylor Dee Wallace Robot C For Vex.
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.
Robotics Programming Wall Follow Line tracking for a set amount of time Line tracking for a distance.
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.
Python Programming Module 4 Sensors and Loops Python Programming, 2/e1.
Sensor Information: while loops and Boolean Logic.
IST 210: PHP Logic IST 210: Organization of Data IST2101.
Variables. A variable is a space in your robot’s memory where you can store data, such as whole numbers, decimal numbers, and words. Variable names follow.
ROBOTC for CORTEX Teacher Training © 2011 Project Lead The Way, Inc. Automation and Robotics VEX.
Introduction To Robot Sensors
VEX IQ Mix & Match Curriculum
ROBOTC for VEX Online Professional Development
Robotics Programming Using Shaft Encoders
Programming – Using a Range Finder
ROBOTC for VEX Online Professional Development
Introduction To Robot Sensors
RobotC Sensors.
Movement using Shaft Encoders
Using Encoders to go Straight
Autonomy using Encoders
Programming – Touch Sensors
Introduction To Robot Decision Making
Control Structures – Selection
RobotC Sensors.
Programming – Using a Range Finder
Using variables, for..loop and functions to help organize your code
While Loops and If-Else Structures
Sensors and Logic Switches
Scratch: selection / branching/ if / If…else / compound conditionals / error trapping by Mr. Clausen.
Auto Straightening using VEX Shaft Encoders
While Loops and If-Else Structures
IPC144 Introduction to Programming Using C Week 3 – Lesson 2
An Introduction to VEX IQ Programming with Modkit
While Loops and If-Else Structures
While Loops and If-Else Structures
Introduction To Robot Decision Making
While Loops and If-Else Structures
Programming - Buttons Intro to Robotics.
if-else Structures Principles of Engineering
Robotics Programming Using Shaft Encoders
Programming - Buttons Intro to Robotics.
Robotics Programming Using Shaft Encoders
While Loops and If-Else Structures
Robotics Programming Review and Quiz.
Robotics Programming Using Shaft Encoders
While Loops and If-Else Structures
Lego MINDSTORMS EV3.
While Loops And If-Else Structures
Flow of Control Flow of control is the order in which a program performs actions. Up to this point, the order has been sequential. A branching statement.
Is there an alternative to copy-paste for repeating code?
Presentation transcript:

RobotC While loop When and how to use the while loop Get out your notes: Head the paper Your Name While / Conditions / Calculating Distances RobotC While loop When and how to use the while loop Setting up and understanding conditions Calculating Distances using the Shaft Encoder

What does this program do? SensorValue(touchSensor) == 1 means pushed, ==0 when not pushed.

While loop When to use it: Examples When you want to repeat something an unknown number of times AND It might not occur at all Examples Going forward while on a white line Repeating something forever, while (true)

How it works while (condition) { } //Commands When the compiler gets to the ‘while’ line, it checks to see if the condition is true. If the condition is true, it repeats the commands, if it is false, it leaves the while loop.

Conditions Conditions are either true or false (boolean) ROBOTC control structures that make decisions about which pieces of code to run, such as while loops and if-else conditional statements, always depend on a (condition) to make their decisions. ROBOTC (conditions) are always Boolean statements.

Conditions Sample

Conditions: Always True

Include an example of each RobotC symbol in your notes. Comparison Operators Include an example of each RobotC symbol in your notes.

Evaluating Conditions

Logical Operators

Include these RobotC symbols and their meaning. && and II Include these RobotC symbols and their meaning.

Your turn: true, false, or crash? Let x = 10, y = 5 and z = 30 for the following examples. ( 5 > 10) (8 < 3) || (9 >=6) ((6-2) > 1) && (5*3 <30)) (1 == 1) (12 > 15) || ((6<10) && (5>2) ) (20 > x > 5) (x < y) and (z >2) (x>z ) && (x < y) Number 1-8 in your notes and copy the condition and the result

Your turn: Write the condition Include your answers to the conditions in your notes. True if SensorValue[leftEncoder] gives a value less than 30. True if SensorValue[rightEncoder] is not zero. True if SensorValue[leftEncoder] is in the range 50 to 90. True if SensorValue(rightEncoder] is greater than 40 and SensorValue[leftEncoder] is less than 30.

What does the following program do? SensorValue(touchSensor) == 1 means pushed, ==0 when not pushed.

How far will this robot move if it has 4. 7 cm radius wheels How far will this robot move if it has 4.7 cm radius wheels? (Same as the clawbot) SensorValue[rightEncoder] = 0; while(SensorValue[rightEncoder] < 360) { motor[rightMotor] = 63; motor[leftMotor] = 63; } motor[rightMotor] = 0; motor[leftMotor] = 0;

What do you recall about the following? < > <= >= == && || condition while if else Shaft encoder int motor[] SensorValue[] wait1Msec() Going straight.

Today Complete the Encoder Going Straight Activities Work on the practice quiz. On Wednesday there is an open noted quiz.