08/2012Tanya Mishra1 EASYC for VEX Cortex Llano Estacado RoboRaiders FRC Team 1817.

Slides:



Advertisements
Similar presentations
Introducing C++ Elements. CSCE 1062 Outline Main algorithms’ constructs General form of a C++ program {section 2.5} C++ language elements {section 2.1}
Advertisements

Team 5220 Roboknights. Outline  Getting Started  Hardware Setup/Wiring  Software Setup/Pragmas  Programming with RobotC  Grammar/Syntax  Basic Statements.
CS0007: Introduction to Computer Programming
Lecture 2 Introduction to C Programming
Introduction to C Programming
 2000 Prentice Hall, Inc. All rights reserved. Chapter 2 - Introduction to C Programming Outline 2.1Introduction 2.2A Simple C Program: Printing a Line.
Programing Concept Ken Youssefi/Ping HsuIntroduction to Engineering – E10 1 ENGR 10 Introduction to Engineering (Part A)
CMT Programming Software Applications
Programming Concepts (Part A) Ping Hsu. What is a program? WHITE CAKE RECIPE 1.Preheat oven to 350 degrees F (175 degrees C). 2.Grease and flour a 9x9.
CS31: Introduction to Computer Science I Discussion 1A 4/2/2010 Sungwon Yang
Introduction to Computers and Programming Class 6 Introduction to C Professor Avi Rosenfeld.
Computer Science: A Structured Programming Approach Using C1 Objectives ❏ To understand the structure of a C-language program. ❏ To write your first C.
Introduction To C++ Programming 1.0 Basic C++ Program Structure 2.0 Program Control 3.0 Array And Structures 4.0 Function 5.0 Pointer 6.0 Secure Programming.
Program A computer program (also software, or just a program) is a sequence of instructions written in a sequence to perform a specified task with a computer.
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.
ROBOTC Software Introduction. ROBOTC Software ROBOTC developed specifically for classrooms and competitions Complete programming solution for VEX Cortex.
CPS120: Introduction to Computer Science Lecture 8.
COMPUTER PROGRAMMING. Data Types “Hello world” program Does it do a useful work? Writing several lines of code. Compiling the program. Executing the program.
CIS Computer Programming Logic
EGR 2261 Unit 4 Control Structures I: Selection  Read Malik, Chapter 4.  Homework #4 and Lab #4 due next week.  Quiz next week.
Programing Concept Ken Youssefi/Ping HsuIntroduction to Engineering – E10 1 ENGR 10 Introduction to Engineering (Part A)
Conditional Statement
Chapter 4: Control Structures I (Selection). Objectives In this chapter, you will: – Learn about control structures – Examine relational operators – Discover.
CSE 1301 Lecture 2 Data Types Figures from Lewis, “C# Software Solutions”, Addison Wesley Richard Gesick.
CPS120: Introduction to Computer Science
Lec 6 Data types. Variable: Its data object that is defined and named by the programmer explicitly in a program. Data Types: It’s a class of Dos together.
Lecture #5 Introduction to C++
Data & Data Types & Simple Math Operation 1 Data and Data Type Standard I/O Simple Math operation.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Chapter 2 Chapter 2 - Introduction to C Programming.
Variables and Functions. Open your Encoder program Let’s begin by opening the “Labyrinth Auto Straight” code. Save this file as Labyrinth with variables.
Property of Jack Wilson, Cerritos College1 CIS Computer Programming Logic Programming Concepts Overview prepared by Jack Wilson Cerritos College.
Fundamental Programming: Fundamental Programming Introduction to C++
CPS120: Introduction to Computer Science Decision Making in Programs.
Programming for Beginners Martin Nelson Elizabeth FitzGerald Lecture 2: Variables & Data Types.
Chapter 7 Selection Dept of Computer Engineering Khon Kaen University.
Introduction to Java Java Translation Program Structure
BEGINNING PROGRAMMING.  Literally – giving instructions to a computer so that it does what you want  Practically – using a programming language (such.
Variables in Java x = 3;. What is a variable?  A variable is a placeholder in memory used by programmers to store information for a certain amount of.
VISUAL C++ PROGRAMMING: CONCEPTS AND PROJECTS Chapter 2A Reading, Processing and Displaying Data (Concepts)
Variables and Functions ROBOTC Software © 2012 Project Lead The Way, Inc.Principles of Engineering.
Week 4 Program Control Structure
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Chapter 2 - Introduction to C Programming Outline.
CPS120: Introduction to Computer Science Variables and Constants.
CHAPTER 2 PROBLEM SOLVING USING C++ 1 C++ Programming PEG200/Saidatul Rahah.
Controlling Program Flow with Decision Structures.
Variables and Functions ROBOTC Software. Variables A variable is a space in your robots memory where data can be stored, including whole numbers, decimal.
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.
An Introduction to Programming with C++ Sixth Edition Chapter 5 The Selection Structure.
CHAPTER 3 COMPLETING THE PROBLEM- SOLVING PROCESS AND GETTING STARTED WITH C++ An Introduction to Programming with C++ Fifth Edition.
Programming Basics - RobotC Introduction to Robotics.
CSE 110: Programming Language I Matin Saad Abdullah UB 1222.
Chapter 2 Variables and Constants. Objectives Explain the different integer variable types used in C++. Declare, name, and initialize variables. Use character.
Chapter 2 - Introduction to C Programming
Objectives Identify the built-in data types in C++
The Selection Structure
Chapter 2 - Introduction to C Programming
Movement using Shaft Encoders
Introduction to the C Language
Using variables, for..loop and functions to help organize your code
Unit 2 Programming.
Chapter 4: Control Structures I (Selection)
Chapter 2 - Introduction to C Programming
Chapter 2 - Introduction to C Programming
Programming Funamental slides
Programming Basics - RobotC
Chapter 2 - Introduction to C Programming
Chapter 2: Introduction to C++.
Chapter 2 - Introduction to C Programming
DATA TYPES There are four basic data types associated with variables:
Variables and Constants
Presentation transcript:

08/2012Tanya Mishra1 EASYC for VEX Cortex Llano Estacado RoboRaiders FRC Team 1817

08/2012Tanya Mishra2 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”.

08/2012Tanya Mishra3 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.

08/2012Tanya Mishra4 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”.

08/2012Tanya Mishra5

08/2012Tanya Mishra6 “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.

08/2012Tanya Mishra7

08/2012Tanya Mishra8 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

08/2012Tanya Mishra9 A Basic C Program #include // 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

08/2012Tanya Mishra10 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.

08/2012Tanya Mishra11 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.

08/2012Tanya Mishra12 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.

08/2012Tanya Mishra13 char(Characters): Single characters bool(Boolean): True and False values Declare a variable: int Age; float Score; string Name; char Grade; bool Pass;

08/2012Tanya Mishra14 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;

08/2012Tanya Mishra15 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.

08/2012Tanya Mishra16 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

08/2012Tanya Mishra17 Conditional Operators Comparison operators Relational OperatorExample > (Greater Than) 7 > 5 >= (Greater Than or Equal To) 7 >= 5, 7 >= 7 < (Less Than)5 < 7 <= (Less Than or Equal To)5 < 7, 7<=7 == (Equal To)7 == 7 != (Not Equal To)7 != 5 = (Assignment Operator)number = 7

08/2012Tanya Mishra18 Logical operators: Boolean Truth Table Joining two or more statements using “And” and “Or” A: Its a Sunny Day B: My Car is working Can I go out? (A and B) Can I go out? (A or B) Yes No Yes NoYesNoYes No

08/2012Tanya Mishra19 And : && Or : || Not : ! AB!AA && B A || B True FalseTrue False True FalseTrue FalseTrue False TrueFalse

08/2012Tanya Mishra20 Control Structures and Loops Control Structure IF statements: if(condition) { Instructions, if “condition” is True }

08/2012Tanya Mishra21 IF-ELSE Statements: if(condition) { // Instructions, if “condition” is true } else { // Instructions, if “condition” is false }

08/2012Tanya Mishra22 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 }

08/2012Tanya Mishra23 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 }

08/2012Tanya Mishra24 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 }

08/2012Tanya Mishra25 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.

08/2012Tanya Mishra26 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

08/2012Tanya Mishra27 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.

08/2012Tanya Mishra28 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.

08/2012Tanya Mishra29 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.

08/2012Tanya Mishra30 The function definition specifies the “return value” and the “parameters” of the function: FunctionName(,,...) { } 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.

08/2012Tanya Mishra31 Example: int addition(int x, int y) { int z; z = x+ y; return z; } void main(void) { addition(2, 3); }

08/2012Tanya Mishra32 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

08/2012Tanya Mishra33 Download EASYC Download Link: EASYC V2.0 for VEX

08/2012Tanya Mishra34 Updating EASYC If the website says you need to update EasyC, you can do that by going to: Help->Check for updates

08/2012Tanya Mishra35 Updating the Firmware on the Cortex Controller and Remote Controller “Firmware” is a piece of sofware that access the operating system on the processor and allows it to perform its task. Step 1: Connect the Cortex/Remote Controller and your computer using the A-A USB cable. The LED should start flashing

08/2012Tanya Mishra36 Step 2: On your computer's taskbar, goto: Start -> All Programs -> easyC v4 For Cortex -> IFI VEXNet Firmware Utility

08/2012Tanya Mishra37 Step 3: Select “SEARCH” if the response is (Upgrade required) then “BOOTLOAD” and YES

08/2012Tanya Mishra38 Step 4: Then click “DOWNLOAD”

08/2012Tanya Mishra39 Step 5: Afterward you should see the following:

08/2012Tanya Mishra40 Connecting the Cortex Controller and Remote Controller Connect the two devices together and then turn on the Remote Controller or micro controller. Wait until the VEXNet LED turns solid green.

08/2012Tanya Mishra41 EASYC First Look Step 1: File -> New Standalone Project->Joystick Project(Wifi)

08/2012Tanya Mishra42

08/2012Tanya Mishra43 1. Function Block(Left): You can all the available functions and your project file information. 2. Main (Middle): Drag and Drop the functions here to see how they connect and get a visual look for the code. All You need to work with is the area between “Variables” and “End”. 3. Project Pane (Right) : See your project files and other files. 4. Build information (Bottom) : See any code building information here.

08/2012Tanya Mishra44 When running the Robot, the real time values in each port can be seen in the “Online Window” Step 1: EASYC-> Build & Download -> Online Window

08/2012Tanya Mishra45 When running the Robot, any “print to screen” values can be seen in the “Terminal Window” Step 1: EASYC-> Build & Download -> Terminal Window

08/2012Tanya Mishra46 You can open the controller configuration (Marked with a Red Arrow) and write down what you are going to plug in each port.

08/2012Tanya Mishra47 VEX Cortex Controller The VEX Cortex Micro controller has the following ports: 8 Analog ports 12 Digital ports 6 Interrupt ports 8 Motor ports

06/2012Tanya Mishra48 VEX Remote Controller Vex Remote control provides you with two joysticks (each having a x- axis and y-axis), eight buttons on the front and four additional buttons on the top.

06/2012Tanya Mishra49 Each set of buttons or a pair of joystick has an assigned channel number written next to it as shown in the figure. Each of these controls are accessed using the channel number they belong to.

06/2012Tanya Mishra50 Incorporating C Programming baics in EASYC We start by placing the needed module between the “Variables” and “End” modules. Creating a “While” loop: Step 1: Click the “+” sign next to the Program Flow on your Function Panel (Left) Step 2: Click and drag the “While loop” on to the Main panel (Middle) and place it between the two modules you need it to.

06/2012Tanya Mishra51 Step 3: In the “While loop” Window, enter the condition and click OK. NOTE: For an infinite loop, we use condition = 1.i.e. while(1), because 1 will always be 1 and so this condition will always be true. Similarly, we can do for a if statement, else-if statements, switch statements and For Loops.

06/2012Tanya Mishra52 Creating Variables: Step 1: Click on the “Variables” module in the Main panel. Step 2: Enter the details of the Variable in the next Local variables Window and click OK.

06/2012Tanya Mishra53 Step 3: The variable is now stored in the “Variables” module. If you click on it again, you can see your variable. Now, whenever trying to use the variable weather to set its value or get its value, it will appear in the drop down list of the inputs and outputs for the other control modules like sensors.

06/2012Tanya Mishra54 Creating User Functions: Creating a new Function: Step 1: Project -> Add New Function Step 2: Enter the Return type, name, Arguments/Parameter list (if any)

06/2012Tanya Mishra55 Adding an existing Function: Step 1: Project -> Add Existing Function Step 2: Enter the Details and location And a Search will be done.

08/2012Tanya Mishra56 Building and Downloading a Program After writing your program, you need to build it and download it on to the robot. Step 1: Connect your robot and your computer using the A- A USB Cable. Make sure your cortex is turned off right now as a safety precaution. Step 2: Build and Download → Build and Download

08/2012Tanya Mishra57 Step 3: Click “Yes” on the Hex file build successful message window and your code will be downloaded.

08/2012Tanya Mishra58 Drives Simple Tank Drive Tank Drive involves the use of both joysticks. Step 1: Click the “+” next to the Joystick Module in the Left Pane and drop Tank- 2 Motor in the Middle Pane.

08/2012Tanya Mishra59 Step 2: Enter the Joystick Number(Joystick 1 is your primary remote Controller, Joystick 2 is used if you are using another remote controller to control your robot), the left and right joystick channels, the left and right motor port numbers and if you need to invert a motor, change the value to 1.

08/2012Tanya Mishra60 Simple Arcade Drive Arcade Drive uses one joystick to drive the robot. Step 1: Click the “+” next to the Joystick Module in the Left Pane and drop Arcade – 2 Motor in the Middle Pane.

08/2012Tanya Mishra61 Step 2: Enter the Joystick Number(Joystick 1 is your primary remote Controller, Joystick 2 is used if you are using another remote controller to control your robot), the joystick channel (Set the Rotate Channel to 1), the left and right motor port numbers and if you need to invert a motor, change the value to 1.

08/2012Tanya Mishra62 Motor Control The buttons on you remote controller can be used to control motors on your robot. Step 1: Click the “+” next to the Joystick Module and drag and drop the Joystick Digital to motor in the middle pane.

08/2012Tanya Mishra63 Step 2: Enter the joystick number, Channel number for the button group, the button number and the motor value - 127(Backward) to 127(Forward). 0 makes the value stop. Finally, enter the motor port number.

06/2012Tanya Mishra64 Assigning Positive power Values(127) on both motors makes the robot go forward. Lower speed of robot by assigning values less than full power(127). Assigning negative power values(-127) on both motors makes the robot go reverse. Assigning zero power values(0) on both motors makes the robot stay in place. Turning of Motors

06/2012Tanya Mishra65 Point Turn: Turn in place (-63 and 63) Swing Turn: Making one motor on and the other off makes the robot swing around the stationary wheels. (0 and 63)

06/2012Tanya Mishra66 Shaft Encoders/Rotation Sensor Manual adjustments of power are not same for all robots and as the battery power drains, the robot is move shorter distances. Shaft Encoders are used to control how far the Robot Moves. Number of counts per Revolution on a axle mounted through the encoder center. Max 360 up for forward movements and 360 down for reverse movements.

06/2012Tanya Mishra67 Encoders need to be set to zero before you use them. Clear the encoders for better consistency and precision on your robots movements. Step 1: You can find the Quadrature encoder modules by clicking the “+” next to the inputs modules in the left panel.

08/2012Tanya Mishra68 The corresponding text functions for the Quadrature modules are as follows: Start the Encoder: StartQuadEncoder(port number) It is good practice to preset the value of encoder to 0 before use. PresetQuadEncoder(port number, 0) Get the number of ticks passed: ticks = GetQuadEncoder(port number)

08/2012Tanya Mishra69 Limit Switch Limit Switch is a Digital Sensor(0 and 1) When pressed, it provides a sensor value 1, when released, it provides a sensor value 0. Step 1: The limit switch module is in the Inputs modules in the left panel. ?? = GetDigitalInput(port number)

08/2012Tanya Mishra70 Potentiometers: A potentiometer is a Analog Sensor. It measures rotation between 0 to 250 (not 360 due to internal mechanical stops) degrees and return value ranging from 0 to approximately ?? = GetAnalogInput(port number)

08/2012Tanya Mishra71 Ultrasonic Range Finder Ultrasonic Range Finder allows us to sense obstacles in the path of the robot and avoid bumping into them.

08/2012Tanya Mishra72 It measures distance to the obstacle using sound waves. It calculates the Distance depending on how long it takes for the sound wave to bounce back. Distance = Speed * Time / 2 Step 1: Click the “+” next to the inputs and drag and drop the Ultrasonic sensor in the middle panel.

08/2012Tanya Mishra73 Step 2: Choose if you want to start or stop the sensor or get its value. Enter the interrupt port and the digital output port.

08/2012Tanya Mishra74 The corressponding text functions will be as follows: StartUltrasonic(interrupt port numer, digital port number) ?? = GetUltrasonic((interrupt port numer, digital port number)

08/2012Tanya Mishra75 Timers Timers are like “Stopwatches”. Used in competition to know how long the robot has been working. You have access to 6 software Timers. The time is in Microseconds (1 sec = 1000 ms) Step 1: Click the “+” next to the Program Flow module and drag and drop the Timer module.

08/2012Tanya Mishra76 Step 2: Choose if you want to start, preset, get a value or stop the Timer. It is a good practice to Clear the Timer before use.

08/2012Tanya Mishra77 Wait When Wait is used, the program execution is sidle for that period of time. Step 1: Click the “+” next to the Program flow and Drag and drop the wait module. The wait module takes time in Microseconds.

08/2012Tanya Mishra78 Line Tracking Sensors Below is shown a set of three Line tracking Sensors. Line tracking sensors work on the bases of Infrared Light. Each sensor has an Infrared LED and an Infrared Light sensor.

08/2012Tanya Mishra79 The LED emits light and the sensor detects the amount the light reflected back. Light Surfaces = Low Sensor Reading Dark Surfaces = High Sensor Reading

08/2012Tanya Mishra80 The cortex gives a Sensor reading from 0 to The value does not correspond to any unit of measurement. Thus it is important to take care of lighting conditions around the robot and the height at which the sensors are placed in order to determine the threshold of reading.

08/2012Tanya Mishra81 Using all three sensors allows us to detect the line as well as border of the line, corners and intersections, which is not possible if you use just one line tracking sensor.

08/2012Tanya Mishra82 Step 1: The Line tracking Module is present in the Input modules in the Left panel. Set the Analog Input and retrieve the value returned by the Line follower.

08/2012Tanya Mishra83 Create Competition Code Step 1: File->New Competition Project->Timed Competition Project

08/2012Tanya Mishra84 The Autonomous Time and operator controlled time are in seconds. Each define the number of seconds the Autonomous code and the Operator control will run for. Put down your autonomous and operator controlled code in the corresponding file modules. You can also change the running times for the autonomous and operator control mode by clicking on the modules.

08/2012Tanya Mishra85

08/2012Tanya Mishra86 That's all for EasyC for Cortex programming. Thank you!