robotc for vex cortex llano estacado roboraiders frc team 1817 n.
Skip this Video
Loading SlideShow in 5 Seconds..
ROBOTC for VEX Cortex Llano Estacado RoboRaiders FRC Team 1817 PowerPoint Presentation
Download Presentation
ROBOTC for VEX Cortex Llano Estacado RoboRaiders FRC Team 1817

ROBOTC for VEX Cortex Llano Estacado RoboRaiders FRC Team 1817

141 Views Download Presentation
Download Presentation

ROBOTC for VEX Cortex Llano Estacado RoboRaiders FRC Team 1817

- - - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript

  1. ROBOTC for VEX CortexLlano Estacado RoboRaiders FRC Team 1817 Tanya Mishra

  2. Tanya Mishra Humans and Machines • Machines are built to perform useful tasks. • The way a Machine works depends entirely on the way the Human build it. • Since Machines and Robots need a medium of communication, a language called “Programming Language” is used. • EASYC, ROBOTC, C++, C all are programming languages. • The instructions in the language are called “Programs” and the human that writes the instructions is called the “Programmer”.

  3. Tanya Mishra • Task of Programmer: Understand Problem, Find a solution, Write a program to solve the problem in the required Programming language. • Task of Machine: Follow the program provided. • A ROBOT is a Machine.

  4. Tanya Mishra Planning and Behavior • Behavior: Action the Robot has to take. • Big Behavior: Solving a maze • Small Behavior: Turn Left, Move Forward, etc. • Big Behavior is made up of Smaller Behaviors. • Plan a Solution to the problem. • Break down the plan into detailed smaller steps. • Each step is a behavior the robot needs to follow. • Sequence of these steps in English is called “pseudo-code”.

  5. Tanya Mishra

  6. Tanya Mishra • “Flow charts” are a visual representation of the program flow. • Start and End: “Rounded Rectangles”. They contain the word “Start” or “End”, but can be more specific such as “Power Robot Off” or “Stop All Motors”. • Actions: “Rectangles”. They act as basic commands and process steps. • Decision blocks: “Diamonds”. These typically contain Yes/No questions. Based on the choice, the next step is determined.

  7. Tanya Mishra

  8. Tanya Mishra Introduction to C Programming • EasyC is based on the the principles of C Programming. • We will cover the following concepts: 1. Basic Components of a C Program 2. Data Types and Variables 2. Conditional operators 3. Control Structures and Loops 4. Methods and Functions

  9. Tanya Mishra A Basic C Program #include<stdio.h> // Header File void main(void) // Main function { // Body of the main function } • Header file: Includes all the required words and instructions needed to write a program • Main function: Execution starts from here • Body: stepwise Instructions to the Robot

  10. Tanya Mishra • Each Instruction to the robot is also called a “Statement”. • When the list of instruction is send to the VEX cortex, it read them from top to bottom and left to right. • Different Commands use different paired Punctuations such as “[]” “{}” “()” • “{..}” defines a body of one or more instructions. Also called a “Compound Statement”. • Every instruction in the body ends with a “;”. It shows the end of a instruction.

  11. Tanya Mishra • Comments are for the programmer to understand what a particular statement does. • Two kinds of comments: 1. // This is a one line comment 2. /* This is a more than one line Comment.*/ • C language is case sensitive: Upper and lower cases are considered different.

  12. Tanya Mishra Data types and Variables • A “Variable” is a place to store a value. • A variable has a “Type” and a “Name” • “Type” deals with the type of Data the variable will hold. Type of Data: Int: Whole Numbers. Positive, Negative, Zero float(Floating Point): Decimal Point Numbers. Positive and Negative. String: Text. Letters, Spaces and characters.

  13. Tanya Mishra char(Characters): Single characters bool(Boolean): True and False values • Declare a variable: int Age; float Score; string Name; char Grade; bool Pass;

  14. Tanya Mishra Assign a variable: Age = 18; Score = 90.5; Name = “William”; Grade = 'A'; Pass = True; Declare and assign: int Age = 18; float Score = 90.5; string Name = “William”; char Grade = 'A'; bool Pass = True;

  15. Tanya Mishra Variable Naming Rules: • A variable name can not have spaces in it. • A variable name can not have symbols in it. • A variable name can not start with a number. • A variable name can not be the same as an existing reserved word. Scope of a Variable: • Local variables: Within a certain block of code or function. Cannot be accessed outside. • Global variables: Can be accessed anywhere in the code.

  16. Tanya Mishra Using Variables in a print to screen function: When printing a variable on the screen, the following syntax is used: Print to screen function(“%type”,Variable); Signed : + and - , unsigned: - , short: less range , long : more range

  17. Tanya Mishra Conditional Operators • Comparison operators

  18. Tanya Mishra • Logical operators: Boolean Truth Table Joining two or more statements using “And” and “Or”

  19. Tanya Mishra And : && Or : || Not : !

  20. Tanya Mishra Control Structures and Loops Control Structure • IF statements: if(condition) { Instructions, if “condition” is True }

  21. Tanya Mishra • IF-ELSE Statements: if(condition) { // Instructions, if “condition” is true } else { // Instructions, if “condition” is false }

  22. Tanya Mishra • ELSE-IF Statements: if(condition1) { // Instructions, if “condition 1” is true } else if(condition 2) { // Instructions, if “condition 2” is true } else { // Instructions, if “condition 1” and “condition 2” are false }

  23. Tanya Mishra • Switch Statements: switch(expression) //expression can only be an “int” or “char” { case Value-1: // Instructions, if expression = Value-1 break; case Value-2: // Instructions, if expression = Value-2 break; default: // Instructions, if expression does not match any Value }

  24. Tanya Mishra Example: char Grade = 'A'; switch(Grade) { case A: Your Grade is A; break; case B: Your Grade is B; break; default: This is the default choice }

  25. Tanya Mishra Loops • While loops: while(condition) { // Instructions, if “condition” is true } Note: Control Structures execute only once. On the other hand, while loops execute continuously until the condition is false. • If the condition in the loop is always true, the loop never ends. Such a loop is called an “Infinite Loop”. • A loop will end only when the condition is false or there is a “break” statement.

  26. Tanya Mishra Example: int count = 0; //Initialization while(count <= 2) //Condition { PrintToScreen(“ I have %d apple \n”, count); count = count + 1; //Increment } Output: I have 0 apple I have 1 apple I have 2 apple

  27. Tanya Mishra • For Loop: for(initialization; condition; increment) { // Instructions, If “condition” is true } Similar to a while loop except that the initialization and increment are all together. • Note: Initialization is done only when the loop first starts. After that it is skipped.

  28. Tanya Mishra Example: int count; for(count =0; count <= 2; count = count +1) { PrintToScreen(“ I have %d apple \n”, count); } Output: I have 0 apple I have 1 apple I have 2 apple Note: \n is called new lines. It prints the next sentence in a new line.

  29. Tanya Mishra Methods and function • Functions are named sections of code that can be called from other sections of code. • Also called subroutines. • Every executable statement in C must live in a function. • Functions have a Data type, name and input values. • Input values are called Parameters. They are the values you want the function to work with.

  30. Tanya Mishra • The function definition specifies the “return value” and the “parameters” of the function: <data type> FunctionName(<param1>, <param2>, ...) { <function body> <return type> } • Return type and Data type should be of the same kind. • Return type is “void” if nothing is to be returned. Parameters is “void” if nothing is to be passed in.

  31. Tanya Mishra Example: int addition(int x, int y) { int z; z = x+ y; return z; } void main(void) { addition(2, 3); }

  32. Tanya Mishra Some Useful terms Compiler: Turns C program into the machine language for the controller. Loader: Loads the machine language output of the compiler (along with other stuff) into the robot controller. Machine Language: What the robot controller actually understands. Found in .HEX files. 10110100 11100101 00001011

  33. Tanya Mishra Download ROBOTC • Download Link: ROBOTC for CORTEX and PIC>Download->ROBOTC 3.0 for CORTEX and PIC or

  34. Tanya Mishra ROBOTC Rules task main() { motor[port3] = 127; wait1Msec(3000); } • Important words are highlighted. • Uppercase and Lowercase matters. • White spaces and tabs are for programmer convenience • Sentences or Instructions are separated by semicolon. • Instructions are read from T – B and L-R.

  35. Tanya Mishra Error Messages • Compiler analyzes your programs to identify syntax errors, capitalization and spelling mistakes, and code inefficiency (such as unused variables). • Errors: Major issues. misspelled words, missing semicolons, and improper syntax. Errors are denoted with a Red X. • Warnings: Minor issues. These are usually incorrect capitalization or empty, infinite loops. Warnings are denoted with a Yellow X.

  36. Tanya Mishra • Information: ROBOTC will generate information messages when it thinks you have declared functions or variables that are not used in your program. These messages inform you about inefficient programming. Information messages are denoted with a “White X”.

  37. Tanya Mishra System Configurations • “Firmware” is a piece of software that accessing the operating system in the processor enabling it to perform its task. • Update firmware to make sure it is compatible with the ROBOTC and latest Vex Hardware • Update Firmware on Cortex: • Cortex Micro controller is the “Brain”

  38. Tanya Mishra • It has two separate processors inside: 1. User Processor : Handles all ROBOTC programming instructions. 2. Master Processor: Handles all lower level operations like Motor Control and VexNet Communication. • Make sure you have the following first: 1. A USB A-A cable. 2. A charged robot battery 3. The cortex Powered Off 4. Latest version of ROBOTC installed on PC

  39. Tanya Mishra • Step 1: Connect Cortex and PC using A-A cable. • Step 2: Turn Cortex ON. • Step 3: Go to ROBOTC Robot->Platform Type->Innovation First(IFI)->Vex 2.0 Cortex

  40. Tanya Mishra • Step 4: View->Select Communication Port->USB wired Cable or Vex Robotics COMM Port (if Cortex recognized) otherwise Automatic • Step 5: Robot->Download Firmware->Automatically update Vex Cortex

  41. Tanya Mishra Update Firmware on Joystick: • Make sure you have the following first: 1. A USB A-A cable. 2. Latest version of ROBOTC installed on PC • Step 1: Connect Joystick and PC using A-A cable. • Step 2: Go to ROBOTC Robot->Platform Type->Innovation First(IFI)->Vex 2.0 Cortex

  42. Tanya Mishra • Step 4: View->Select Communication Port->USB wired Cable or Vex Robotics COMM Port (if Cortex recognized) otherwise Automatic • Step 5: Robot->Download Firmware->Automatically update VexNET Joystick

  43. Tanya Mishra Download Firmware when: • You start using a particular Vex Cortex or VexNET Joystick • You update a newer version of ROBOTC.

  44. Tanya Mishra Download Sample Program • Step 1: Go to ROBOTC File->Open Sample Program->Training Samples->Motor port 3 forward.c

  45. Tanya Mishra Before Downloading, make sure: • Your cortex and VexNet remote control are paired and equipped with VexNet USB keys. • Batteries connected to remote control and cortex. • Robot propped up. • Orange programming kit connecting PC and remote control. • Turn on Remote Control and Robot. • Robot and VexNet status lights should blink green on both remote control and Robot.

  46. Tanya Mishra • Step 2: View->preferences->Detailed Preferences->Platform: Vex 2.0 Cortex and Communication Port: Prolific USB-Serial Comm port. • Step 3: Robot->Vex Cortex Communication Mode->VexNet or USB

  47. Tanya Mishra • Step 4: Robot->Compile and Download Program • Step 5:Debugger Window->Start

  48. Tanya Mishra Motors task main() { motor[port3] = 127; motor[port2] = 127; wait1Msec(3000); } • Running this program makes the Robot spin because the motors on the robot are mirrored. So making the motor on port2 move forward in the code, makes it move in reverse in real time.

  49. Tanya Mishra Reverse Motor Polarity: • Robot->Motors and Sensors Setup->Motors tab-> Port 2 reversed check box is checked.

  50. Tanya Mishra #pragma config(Motor, port2, , tmotorNormal, openLoop, reversed) • The “pragma” statement contains configuration information from the motors and sensors settings and should only be changed from the window.