ROBOTC Software Introduction. ROBOTC Software ROBOTC developed specifically for classrooms and competitions Complete programming solution for VEX Cortex.

Slides:



Advertisements
Similar presentations
Variables and Functions ROBOTC Software. Variables A variable is a space in your robots memory where data can be stored, including whole numbers, decimal.
Advertisements

While Loops and If-Else Structures
08/2012Tanya Mishra1 EASYC for VEX Cortex Llano Estacado RoboRaiders FRC Team 1817.
Automation and Robotics
VEX and Robot C Chris Patterson Presented by Modified by J. Andazola.
Programing Concept Ken Youssefi/Ping HsuIntroduction to Engineering – E10 1 ENGR 10 Introduction to Engineering (Part A)
© 2006 Pearson Education. All Rights Reserved Starting Out with C++: Early Objects 5/e Starting Out with C++: Early Objects 5 th Edition Chapter 2 Introduction.
Chapter 2: Introduction to C++.
Introduction to C Programming
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.
Python quick start guide
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.
CSC 125 Introduction to C++ Programming Chapter 2 Introduction to C++
Programing Concept Ken Youssefi/Ping HsuIntroduction to Engineering – E10 1 ENGR 10 Introduction to Engineering (Part A)
Programming Fundamentals. Today’s lecture Decisions If else …… Switch Conditional Operators Logical Operators.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 2-1 Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley.
CPS120: Introduction to Computer Science
Programming Design ROBOTC Software Principles of Engineering
CPS120: Introduction to Computer Science Decision Making in Programs.
Introduction to Programming with RAPTOR
AUTOMATION WITH ROBOTC Starting to write and troubleshoot computer code.
COIT29222 Structured Programming 1 COIT29222-Structured Programming Lecture Week 02  Reading: Textbook(4 th Ed.), Chapter 2 Textbook (6 th Ed.), Chapters.
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.
PROGRAM ESSENTIALS. TOKENS  SMALLEST UNITS OF A PROGRAM LANGUAGE  Special Symbols  Mathematical Operators  Punctuation  Word Symbols  Key Words.
Variables and Functions ROBOTC Software. Variables A variable is a space in your robots memory where data can be stored, including whole numbers, decimal.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 2 Introduction to C++
VEX and Robot C Chris Patterson Frisco ISD CTE Center Presented by.
Java Basics. Tokens: 1.Keywords int test12 = 10, i; int TEst12 = 20; Int keyword is used to declare integer variables All Key words are lower case java.
Automation and Robotics.  First you select the platform type so that you can use Natural Language PLTW.
1 Agenda  Unit 7: Introduction to Programming Using JavaScript T. Jumana Abu Shmais – AOU - Riyadh.
Programming Design ROBOTC Software. Behavior-Based Programming A behavior is anything your robot does –Turning on a single motor or servo Three main types.
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.
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.
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
Data Types and Expressions
Variables and Functions
Variables and Functions
Robotics Programming Using Shaft Encoders
Programming Design ROBOTC Software Computer Integrated Manufacturing
Variables and Functions
Movement using Shaft Encoders
Using Encoders to go Straight
Variables and Functions
Variables and Functions
Variables and Functions
Variables and Functions
While Loops and If-Else Structures
Variables and Functions
Auto Straightening using VEX Shaft Encoders
T. Jumana Abu Shmais – AOU - Riyadh
While Loops and If-Else Structures
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
if-else Structures Principles of Engineering
Automation with RobotC
Chapter 2: Introduction to C++.
Robotics Programming Using Shaft Encoders
While Loops and If-Else Structures
Automation with RobotC
While Loops and If-Else Structures
Programming Design ROBOTC Software Principles of Engineering
While Loops And If-Else Structures
Presentation transcript:

ROBOTC Software Introduction

ROBOTC Software ROBOTC developed specifically for classrooms and competitions Complete programming solution for VEX Cortex and several other popular robot platforms Real-time debugger Similar to industry-standard C programming

Industry Standard Coding ROBOTC programming is a key components of industry standard programming languages

Sample Program // sample comments to describe behavior task main() { startMotor(rightMotor, 63); wait(); stopMotor(rightMotor); }

Statements and Expressions Statements are the smallest complete unit of a working program. Statements primarily consist of expressions, keywords and operators Expressions may consist of keywords, operators, values, variables, etc. Example: int length = 2 * 12; // convert feet to inches

Comments Comments are used to make notes in code for the human programmers Every sample program contains comments pertaining to robot configuration, ROBOTC commands, robot behavior, etc. // Single line comment – All material after “//” is ignored by the ROBOTC compiler /* Multi-line comment*/ – All material between the “/*” and “*/” symbols is ignored by the ROBOTC compiler

Keywords Keywords are specific directives that mean something special to the ROBOTC compiler They are sometimes called reserved words because the compiler “reserves” those words and they can not be used for any other purpose. Some keywords you will see: #pragma, task,

Operators Similar in behavior to a mathematical function: Examples: or ADD(1,2) They commonly take one or more operands and produce a result Foundational to building expressions and statements

Simplified Order of Operations OrderOperator(s)Notes 1() [] ->. ::Grouping, Scope, Array increment/decrement* 3* / %Multiply, divide, modulo 4+ -Addition, subtraction 5 >=Comparison 6== !=Comparison 7&&Logical AND 8||Logical OR 9= += -= *= /= %=Assignment More info: *Note: this also depends on pre versus post behavior

Variables A variable is a special form of a label that allows you to reference a value in memory by a name instead of just a location Variables are “variable” by nature – their contents can usually be changed Variables can improve the readability and expandability of your programs To change the value of variable: int distance = 500; // declare and set

Creating a Variable Declare the variable (stating its type and its name) once at the beginning of task main: Type of data: int float Name of variable: Starts with letter Letters, numbers, and underscores are ok Not a reserved word

Variable Types Data TypeDescriptionExampleCode IntegerPositive and negative whole numbers, as well as zero -35, -1, 0, 33, 100 int Floating Point Number Numeric values with decimal points (even if the decimal part is zero) -.123, 0.56, 3.0, float BooleanTrue or false – Useful for expressing the outcomes of comparisons true, false bool CharacterIndividual characters, placed in single quotes. Not useful with POE kits. ‘L’, ‘f’, ‘8’ char StringStrings of characters, such as words and sentences placed in double quotes. Not useful with POE kits. “Hello World!”, “asdf” string

Assigning a Value to a Variable The assignment operator is the single equal sign The right-hand side of the equal sign is evaluated, and then the value is assigned to variable on the left-hand side This is not the equality from algebra! Declaration Initialization Assignment

Variable Applications Variables are needed for most programs. Here are some examples: Example #1: Repeat code 5 times Example #2: Count user’s button presses Example #3: Remember if the user EVER pushed a button Example #4: Remember a maximum value Example #5: Debug a program by remembering which branch of code has been executed.

Global vs. Local Variables Variables can have either a “global” or a “local” scope. –Global variable Can be read or changed from any task or function in your code. Its value can be seen/read globally. –Local variable Belongs only to the task or function in which it was created Value can only be read or changed from within that task or function Value can only be seen/read locally Generally the type of variable you’ll want to use, local to “main”

Functions –Group together several lines of code –Referenced many times in task main or in other functions Creating Functions Example: LED on if bumper is pressed, off if released 1.Function header (name of function) 2.Function definition (code in the function) 3.Function call (where function code will run)

Function Definition Function definitions define the code that belongs to the function

Function Call Function calls –Call and run code from function –Placed in task main or other functions

While Loops While loop is a structure within ROBOTC 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

2. The Condition Condition is an expression that controls how many times a while loop repeats –When condition is true, the while loop repeats –When condition is false, the while loop ends and the remainder of the program executes Condition is checked once every time loop repeats before commands between curly braces are run

Boolean Logic Program decisions are always based on questions Only two possible answers –yes or no –true or false Statements that can be only true or false are called Boolean statements Their true-or-false value is called a truth value.

Boolean Logic

Writing a condition: Example While the bump switch is not pressed: wait until it’s dark, then turn on light; wait until it’s light, then turn off light

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

Timers Timer T1 is used as the condition for the while loop, which will run for 30 seconds

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

Behavior-Based Programming A behavior is anything your robot does –Turning on a single motor or servo Three main types of behaviors 1.Complex behaviors – Robot performs a complex task (automated fan control) 2.Simple behaviors – Simple task performed by the robot (fan stops when sensor activated) 3.Basic behaviors – Single commands to the robot (turn on a motor) Complex behaviors can always be broken down into simple behaviors, which are then broken down into basic behaviors

Program Design Many basic behaviors generally come together to create a complex behavior. Troubleshoot basic behaviors as they come together to form a complex behavior.

Complex Behaviors Describe the task or overall goal that your program will accomplish. –A fan will run until someone needs it to stop. A safety device warning light will come on before the fan turns on. Another light will indicate that the fan has stopped. This may be described as one or more complex behaviors.

Simple Behaviors Break each complex behavior down into simple behaviors. List the behaviors line by line in the order that each should occur. Describe actions and what prompts each action to continue.

Basic Behaviors Break each simple behavior down further into basic behaviors. Think in terms of what each input and output component will be on your device.

Program Design Code and test small behaviors or sets of behaviors individually. Edit or add comments as you build code.

Program Design Continue programming while testing one behavior at a time. –Temporarily turn sections of code into comments using /* followed by */.