1 / 35

ROBOTC Software

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.

ziarre
Download Presentation

ROBOTC Software

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. ROBOTC Software Introduction

  2. 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

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

  4. Sample Program // sample comments to describe behaviortask main(){startMotor(rightMotor, 63);wait();stopMotor(rightMotor);}

  5. 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

  6. 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

  7. 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,

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

  9. Simplified Order of Operations More info: http://en.wikipedia.org/wiki/Order_of_operations *Note: this also depends on pre versus post behavior

  10. 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:intdistance = 500; // declare and set

  11. 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

  12. Variable Types

  13. 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 Assignment

  14. 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.

  15. 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”

  16. Functions • 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 • Function header (name of function) • Function definition (code in the function) • Function call (where function code will run)

  17. Function Definition • Function definitions definethe code that belongs to the function

  18. Function Call • Function calls • Call and run code from function • Placed in task main or other functions

  19. 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 • The word “while” • The condition • Commands to be repeated

  20. 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

  21. 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.

  22. Boolean Logic

  23. 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

  24. 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

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

  26. 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

  27. If-Else Statements • If-else statement is an expansion of if statement • If checks condition and runs appropriate commands when it evaluates to true • Elseallows code to run when condition is false • Either ifor elsebranch is always run once

  28. Multiple If-Else Statements • Be careful when using two separate if-elsestatements, 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

  29. Behavior-Based Programming • A behavior is anything your robot does • Turning on a single motoror servo • Three main types of behaviors • Complex behaviors – Robot performs a complex task (automated fan control) • Simple behaviors – Simple task performed by the robot (fan stops when sensor activated) • 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

  30. 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.

  31. 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.

  32. 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.

  33. 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.

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

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

More Related