Presentation is loading. Please wait.

Presentation is loading. Please wait.

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

Similar presentations


Presentation on theme: "08/2012Tanya Mishra1 EASYC for VEX Cortex Llano Estacado RoboRaiders FRC Team 1817."— Presentation transcript:

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

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

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

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

5 08/2012Tanya Mishra5

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

7 08/2012Tanya Mishra7

8 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

9 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

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

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

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

13 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;

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

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

16 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

17 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

18 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

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

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

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

22 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 }

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

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

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

26 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

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

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

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

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

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

32 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. 10110100 11100101 00001011

33 08/2012Tanya Mishra33 Download EASYC Download Link: EASYC V2.0 for VEX http://www.intelitekdownloads.com/easyCV4/

34 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

35 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

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

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

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

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

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

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

42 08/2012Tanya Mishra42

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

44 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

45 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

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

47 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

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

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

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

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

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

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

54 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)

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

56 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

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

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

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

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

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

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

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

64 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

65 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)

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

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

68 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)

69 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)

70 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 4095. ?? = GetAnalogInput(port number)

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

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

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

74 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)

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

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

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

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

79 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

80 08/2012Tanya Mishra80 The cortex gives a Sensor reading from 0 to 4095. 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.

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

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

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

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

85 08/2012Tanya Mishra85

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


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

Similar presentations


Ads by Google