Programming Review

Name __________________________Date _________ Hour Review: Programming What are the digital inputs (sensors) in Vex? Bump Switch, Limit Switch, Optical Shaft Encoder, Ultrasonic Range Finder What are the digital outputs that plug into the Cortex in Vex? LED What are the analog inputs (sensors) in Vex? Light Sensor, Potentiometer, Line Follower What does it mean for a switch to be normally open or normally closed? A Normally Open Switch is off by default and the electrical pathway is broken. A normally Closed Switch is on by default. What is syntax? Syntax in computer programming means the rules that control the structure of the symbols, punctuation, and words of a programming language. What is a basic behavior? Single command to a robot Example: start a motor What is a simple behavior? Robot performs a simple task Example: fan stops when sensor is activated What is a complex behavior? Robot performs a complex task Example: automate fan control What is pseudocode? • Break down behaviors into individual actions • Do not be concerned about syntax or which commands will be used with ROBOTC • Simply describe them in short phrases • Examples – Turn a motor on for three seconds – Follow a line until it runs into a wall What are comments and how are they made? Comments are used to make notes in code for the human programmers // Single line comment – All material after “//” is ignored by the ROBOTC compiler /* Multi-line comment*/ – All material between the “/” and “/” symbol is ignored by the ROBOTC compiler What is a reserved word in Robot C and give one example. A word that has a specific meaning in Robot C and cannot be used to name variables, motors and sensors. Example: startMotor What is boolean logic? Program decisions are always based on questions • Only two possible answers – true or false • Statements that can be only true or false are called Boolean statements How do if else statements work? • 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 • Does not repeat the code

How do while statements work? • Allows a section of code to be repeated as long as a certain condition remains true • Three main parts to every while loop

  1. The word “while”

  2. The condition

  3. Commands to be repeated

How do timers work? Built in Internal Stopwatches for Robot C. They should be cleared before they are used. The timers run in milliseconds ( ex. (time1(T1) < 4000) would be used to run a loop for 4 seconds) Timer in a while loop: ClearTimer (T1); while (time1[T1] < 30000) How do variables work? • Initialize a variable by stating an initial value

• Declare and initialize are typically combined into a single statement

How do counters work?

This loop will run five times where the variable count changes as described by the following sequence: 0,1,2,3,4. How do functions work? • Functions – Group together several lines of code – Referenced many times in task main or in other functions What are the 3 parts of a function and where are they located?

  1. Function declaration (declare that a function exists and indicates its name) – located before taskmain 2. Function definition (code for the function) – located after the main program 3. Function call (where function code will run) – located in the main program What is an open loop? An open loop system is a non-feedback system. Loop depends on input only or as a timed loop. What is a closed loop? A closed loop system uses feedback (sensor) to self-correct. This loop is more accurate and predictable.