Presentation is loading. Please wait.

Presentation is loading. Please wait.

Teacher/Mentor Institute Intro to easyC Programming Scott McEwen July 21-22, 2016.

Similar presentations


Presentation on theme: "Teacher/Mentor Institute Intro to easyC Programming Scott McEwen July 21-22, 2016."— Presentation transcript:

1 Teacher/Mentor Institute Intro to easyC Programming Scott McEwen July 21-22, 2016

2 Outline Installing easyC Installing easyC Programming Overview Programming Overview easyC Overview easyC Overview Creating a new program Creating a new program Debugging Tips Debugging Tips Additional easyC Training Additional easyC Training Charts for Hands-On Session: Building a Robot Intro Charts for Hands-On Session: Building a Robot Intro Additional charts in TMI Notebook Additional charts in TMI Notebook 1-hour easyC Breakout session at Kickoff for Teachers, Mentors and Students 1-hour easyC Breakout session at Kickoff for Teachers, Mentors and Students Page 2

3 Installing easyC Minimum Laptop Requirements Minimum Laptop Requirements Windows XP/Vista/Win7/Win8. Mac not supported Windows XP/Vista/Win7/Win8. Mac not supported 1024MB RAM, 512MB HDD, 1024x768 Display 1024MB RAM, 512MB HDD, 1024x768 Display Administrator Access Administrator Access 1 USB port (for Cortex programming) 1 USB port (for Cortex programming) Software & Installation Software & Installation Software provided on USB drive (v4 = 3 seats & unlimited time) or 15-day trial from http://www.intelitekdownloads.com/easyCV5/ Software provided on USB drive (v4 = 3 seats & unlimited time) or 15-day trial from http://www.intelitekdownloads.com/easyCV5/http://www.intelitekdownloads.com/easyCV5/ Installer auto runs from CD Installer auto runs from CD 4-month license begins at installation, 3 seats 4-month license begins at installation, 3 seats Enter the registration code provided by Hub Enter the registration code provided by Hub

4 Programming Overview You create a program using easyC to connect inputs to robot outputs (actions) You create a program using easyC to connect inputs to robot outputs (actions) Reads Joystick or sensor inputs Reads Joystick or sensor inputs Controls when and how motors and servos operate (outputs) Controls when and how motors and servos operate (outputs) Used to: Used to: meet the requirements of the game meet the requirements of the game improve control and efficiency of your robot improve control and efficiency of your robot

5 Traditional Syntax Traditional C syntax can be imposing Traditional C syntax can be imposing Program structure is not obvious without training Program structure is not obvious without training Page 5

6 Program Flow Flow charts can help show structure of a process or a program Flow charts can help show structure of a process or a program Program “blocks” are more intuitive than C code Program “blocks” are more intuitive than C code Page 6

7 easyC Example easyC combines both graphical and textual views of code easyC combines both graphical and textual views of code easyC is a simple user interface to the C programming language for the VEX Cortex. It is a graphical, drag and drop interface easyC is a simple user interface to the C programming language for the VEX Cortex. It is a graphical, drag and drop interface Page 7

8 easyC User Interface (IDE) Menus Function Blocks Icons Project Explorer Page 8

9 easyC User Interface – Menus Menu Usage: File Menu: New Project, Open, Save, Print Edit Menu: Undo, Edit, Copy, Paste, Find Project Menu: Project Type, Add Function, Import Function, Library Import Build and Download Menu: Compile, Build and Download, Download IFI Default Code Tools: Terminal Window, Download Window, On-Line Window Window: Block Layout, Block & C Layout Help Menu: Contents, Registration, Updates Page 9

10 easyC User Interface – Icons Icons New Project New Competition Project OpenSave Start Page Function Blocks Panel Project Explorer Panel Output Panel Controller Configuration Global Variables Compile Compile and Download Terminal Window Graphic Display On-line Window FindZoom Page 10

11 easyC User Interface – Function Blocks Program Flow Wait, If, Else, While, Timer, Assignment Inputs Limit Switch, Digital Input, Analog Input, Potentiometer Outputs Motor / Servo Module, Digital Output Joystick Tank (2 Stick), Arcade (Single Stick), Motor to Joystick, Motor to Digital (Button), Get Digital, Get Joystick Mathematics SIN, COS, TAN, Power, Random Page 11

12 easyC User Interface – Project Explorer Advanced Capabilities: Controller Configuration Change Inputs and Output, Label Ports Macros and Constants Create Definitions (aka C #define) Global Variables Variable with Global Program Scope Block Diagram Select Between Functions Source & Header Files Create or Import.c and.h files, Write C- Code Freehand Library Files Import a easyC® library Page 12

13 Simple Program Example This simple program operates a robot’s: wheels (Arcade2), wheels (Arcade2), arm lifting motor (JoystickToMotor), arm lifting motor (JoystickToMotor), and claw (JoystickToServo) and claw (JoystickToServo) The remaining charts describe the creation of this program Page 13

14 Create a New Program File -> New Standalone Project -> Joystick Project

15 Add a “While Loop” that is always true in order for program to “loop” continuously Add a While Loop (1 of 3) Page 15 Under Function Blocks (left side of easyC), click the “+” beside Program Flow Under Function Blocks (left side of easyC), click the “+” beside Program Flow

16 While Loop (2 of 3) Page 16 Click and drag the While Loop icon; drop it on the vertical line between Variables box and End box Click and drag the While Loop icon; drop it on the vertical line between Variables box and End box In the dialog box, type a true expression such as (2<3) or 1 In the dialog box, type a true expression such as (2<3) or 1 Click OK Click OK

17 While Loop (3 of 3) This is an example of an inserted While Loop This is an example of an inserted While Loop Without the While Loop, all statements in the program will execute only once. Your robot will not move when the Cortex is turned on Without the While Loop, all statements in the program will execute only once. Your robot will not move when the Cortex is turned on Page 17

18 Typically, a robot will have a drive wheel on each side of its chassis Typically, a robot will have a drive wheel on each side of its chassis To avoid spinning in circles, the wheels need to spin in opposite directions To avoid spinning in circles, the wheels need to spin in opposite directions The wheels need to spin at the same rate to move the robot forward or backward; and spin at different rates to turn the robot The wheels need to spin at the same rate to move the robot forward or backward; and spin at different rates to turn the robot This can be achieved with the Arcade function This can be achieved with the Arcade function Add Drive Motors (1 of 6) Page 18

19 Under Function Blocks, click the “+” beside Joystick Under Function Blocks, click the “+” beside Joystick Click and drag the Arcade - 2 motor function to the vertical line between the braces {} in your While Loop Click and drag the Arcade - 2 motor function to the vertical line between the braces {} in your While Loop In the dialog box: In the dialog box: Change Forward/Reverse Channel from 2 to 3 Change Forward/Reverse Channel from 2 to 3 Change Rotate Channel from 1 to 4 Change Rotate Channel from 1 to 4 Leave left motor number (port) at 2 Leave left motor number (port) at 2 Change right motor port from 3 to 9 (to balance the load on the Cortex’s two circuit overload protectors) Change right motor port from 3 to 9 (to balance the load on the Cortex’s two circuit overload protectors) Drive Motors (2 of 6) Page 19

20 Drive Motors (3 of 6) Arcade Dialog Box Motor Ports Joystick Channels Motor Direction

21 Transmitter Joystick # is always set to 1 Transmitter Joystick # is always set to 1 Transmitter Channel links a given button or joystick stick to a given motor or servo Transmitter Channel links a given button or joystick stick to a given motor or servo We will use the left stick to operate the wheels and the right stick to raise & lower the arm with attached claw We will use the left stick to operate the wheels and the right stick to raise & lower the arm with attached claw Joystick Transmitter Channel Page 21

22 Drive Motors (4 of 6) Joystick # = 1 (always) Joystick Channels = 3 & 4 Cortex motor ports = 2 & 9 Invert direction = 0

23 Drive Motors (5 of 6) This program drives a robot using joystick channels 3 (left stick vertical) and 4 (left stick horizontal) with motors connected to motor ports 2 and 9

24 Connect Parts for Testing Note: This photo shows use of different ports than used in our example program

25 If the wheels do not move the robot properly, the direction of one motor needs to inverted (i.e., reversed) Double click on the Arcade2 icon Double click on the Arcade2 icon Below the Left Motor, click the down arrow for Invert Direction and select 1 Below the Left Motor, click the down arrow for Invert Direction and select 1 If the robot goes backwards, change Invert Direction for Left Motor to 0 and change Invert Direction for Right Motor to 1 If the robot goes backwards, change Invert Direction for Left Motor to 0 and change Invert Direction for Right Motor to 1 Click OK Click OK The motor direction may also be changed by reversing the wires to the motor The motor direction may also be changed by reversing the wires to the motor Drive Motors (6 of 6) Page 25

26 Build and Download Let’s save and test our program thus far File -> Save Project File -> Save Project Build and Download -> Build and Download Build and Download -> Build and Download

27 Add a motor (e.g. winch) to raise/lower the arm: Under Function Blocks and Joystick, click and drag the Joystick to Motor function to the vertical line between Arcade2 and the closing brace in your While Loop Under Function Blocks and Joystick, click and drag the Joystick to Motor function to the vertical line between Arcade2 and the closing brace in your While Loop Add a Motor (1 of 4) Page 27

28 Set Joystick Channel from 1 to 2 Set Joystick Channel from 1 to 2 Set motor port: Set motor port: BEST does not allow use of ports 1 or 10 BEST does not allow use of ports 1 or 10 Have already used ports 2 & 9 Have already used ports 2 & 9 Let’s use port 3 Let’s use port 3 Motor ports 1 and 10 are not permitted by BEST Motor ports 1 and 10 are not permitted by BEST Motor (2 of 4) Page 28

29 Motor (3 of 4) Joystick # = 1 (always) Joystick Channel = 2 Cortex motor port = 3 Invert direction = 0

30 Motor (4 of 4)

31 Add a servo to close the door in your robot’s claw: Under Function Blocks and Joystick, click and drag the Joystick to Servo function to the vertical line between JoystickToMotor and the closing brace in your While Loop Under Function Blocks and Joystick, click and drag the Joystick to Servo function to the vertical line between JoystickToMotor and the closing brace in your While Loop Except for the title, the Servo dialog box is identical to the Motor dialog Box Except for the title, the Servo dialog box is identical to the Motor dialog Box Let’s leave the Channel at 1 and set the Motor port to 6 Let’s leave the Channel at 1 and set the Motor port to 6 Click OK Click OK Add a Servo (1 of 2) Page 31

32 Servo (2 of 2) Servo (2 of 2)

33 Simple Program Example This simple program demonstrates most of the functionality used to control your Mini-Robot This simple program demonstrates most of the functionality used to control your Mini-Robot Kickoff includes an hour of easyC training session for your students Kickoff includes an hour of easyC training session for your students Page 33

34 Add Deadband (1 of 2) Motors often emit a high-pitch whine, due to Joystick sticks not being in the exact neutral position. This whine can be eliminated. Under Function Blocks and Joystick, click and drag the Joystick Analog Deadband function to the vertical line below the While statement Under Function Blocks and Joystick, click and drag the Joystick Analog Deadband function to the vertical line below the While statement Set Analog Channel # to 2 (for arm/winch motor) Set Analog Channel # to 2 (for arm/winch motor) Set Positive Deadband and Negative Deadband to 20 Set Positive Deadband and Negative Deadband to 20 Repeat the steps above for both drive motors (channels 3 and 4)

35 Deadband (2 of 2)

36 Our simple program with Deadband functions

37 easyC On-Line Window The easyC On-Line Window allows the user to see and control motors and sensors in real time. This can be enabled at any time. The easyC On-Line Window allows the user to see and control motors and sensors in real time. This can be enabled at any time. Note: The On-Line Window requires that a program, even blank, be downloaded to the Cortex. Note: The On-Line Window requires that a program, even blank, be downloaded to the Cortex. Page 37 Debugging Tip: Can be used to identify & correct errors with input and output assignment or wiring

38 easyC Terminal Window The easyC Terminal window allows you to see output from the PrintToScreen function to your laptop screen while the program is running on the Cortex Page 38 Debugging Tip: Printing to screen helps to provide feedback about internal state

39 easyC Graphic Display Window The easyC Graphic Display window allows you to see output from the GraphicDisplay function on your laptop while the program is running on the Cortex. The Graphic Display is a more advanced type of feedback that allows values to placed on grid instead of scrolling. See Samples –> “Graphic Display Joystick Test” for code. Page 39 Debugging Tip: Similar to printing but provides a continuous display of internal program variables, inputs, & outputs


Download ppt "Teacher/Mentor Institute Intro to easyC Programming Scott McEwen July 21-22, 2016."

Similar presentations


Ads by Google