Download presentation
Presentation is loading. Please wait.
1
Introduction to Programing the Cortex for BEST
SA BEST Kickoff
2
Presentation Goals Primary Goals – understand how to: Secondary Goals
Get and install software. Connect the Cortex for programming. Compile, link, and download the default program to the Cortex. Secondary Goals Components of the default program. Physical connections to Cortex. Joystick interface.
3
BEST Software Options RobotC for Cortex from VEX Robotics
“Standard” C programming by writing text. Used in a number of competitions/products, so teams may have familiarity with this. Simulink from MathWorks Visual block programming. BEST specific online training available. EasyC from Intelitek Menu driven C programming Visual blocks with code – drag, drop, and configure. All options provide simple interfaces to motors, servos, switches, etc that are included in the BEST return kit.
4
easyC Software Installation
Either download from link provided in “Software Access Instructions” or use the file provided on the USB drive to install the software. (Administrative access is needed). A license key is provided on the USB drive that will need to be used to activate the software when it is first started. The computer must have internet access to validate the license key. The licenses key can be copied to the clipboard from the text file on the USB drive, and then pasted into the activation form using the paste button on the form.
5
Connect the Cortex to the Computer
The simplest way to connect the Cortex to the PC is directly with an A-A USB cable. The USB port powers the Cortex, so no battery is needed. Motors and servos cannot be used when connected this way. Refer to the return Kit information for other ways to connect. When connected properly: Robot light: Red/flashing Vexnet light: Green
6
Programming Vocabulary
Compile – changes your C program into object code that the linker understands. Link – combines your program’s object code with library functions to create code that is executable on the Cortex processor. Download – transfers the machine code version of your program from the PC to the Cortex where it will execute (the IFI/Intelitek Loader will perform the transfer via the PC USB cable).
7
Programming Flow or 1. Write It. 2. Save It. 3. Compile & Link.
(aka Build) 4. Download It. 5. Test It. Block-based Drag & Drop (Menu Cfg) Project Files Integrated Design Environment (IDE) Target (Cortex) or easyC V6 for Cortex User Created C Program easyC Project From Scratch Libraries (C Functions)
8
easyC Start Page EasyC supports other controllers so make sure it’s set to the Cortex To set the controller: Select: Tools-> controller
9
Open BEST Default Project
10
Build and Download
11
Compile and Link If build is successful, the option to download is provided. Shows status while compiling and linking. Errors will show up here.
12
Download the File to the Cortex
Tip: It’s very common for teams to forget to download the code to the Cortex once they get code to compile without any errors.
13
VEX Cortex Connections
Gnd (Blk) +5v (Red) Sig (Wht) USB 1 Analog in 8 1 1 2 Do not use Digital in/out 3-wire PWM servo/motor ctrl 12 9 10 Speaker Out SP Do not use Sig (Wht) +5v (Red) Gnd (Blk) Config Button Battery On/Off Switch
14
Joystick Controls and Values
Channels numbers are labeled on joystick. Joysticks (1-4) return values between -127 and +127 in proportion to the stick position. Buttons (5-8) U/D/L/R return 1 when pressed and 0 when not pressed. Two channels of accelerometers provide values between -127 and in proportion to the angle(s) at which the joystick is being held (tilted forward/back or left/right). 7 8 3-4 1-2 6 5
15
BEST Default Program Function
Right Joystick Connected by program Cortex Channel Physical Connection 1 2 Motor 2 Motor 9 Right Drive Motor Left Drive Motor Left Joystick 3 Motor 5 “Claw” Servo 4 Motor 6 “Arm” Motor
16
BEST Default Code Outside the body of the program
Declares global variables Defines names for constants to help make code easier to read.
17
Config block detail
18
Globals Block Detail
19
BEST Default Code “main” is the name of the function that is executed when the program is compiled. The main function includes everything between the matched curly braces {} The END label and indenting makes it easy to see the extent.
20
BEST Default Code Sets up region around center position of joysticks where there is no output. Eliminates the problem of having motors move when you really don’t want them to. Statements prior to the while loop are executed once.
21
Joystick Analog Deadband Configuration Screen
Joystick positions of ±4 are output as zero.
22
BEST Default Code while (1) creates a loop where everything between the {} is repeated as “forever.” There should be no statements inside the while loop that require an external action before the next statement is executed. (More about this later.)
23
BEST Default Code The text in green are comments to help document the program. The “arcade2” function maps the right joystick channels to the driver motors.
24
Arcade -2 motor Configuration Screen
25
BEST Default Code “JoystickToServo” and “JoysticktoMotor” do essentially the same thing in mapping a joystick movement to a motor/servo output channel. The first statement includes an “invert” function that reverses the direction of the mapping.
26
Joystick to Servo Configuration Screen
27
Programming (step-by-step)
Create a new project. Select “New Standalone Project” from the File menu Select “Joystick Project (wifi)” from the popup window Create your program; save your program. Drag & drop programming blocks to create your program Build (i.e.,compile and link) the code. Use the “Build and Download” option from the Build and Download Menu Errors will be reported in the “Outputs & Tasks” window Download the program to the Cortex Automatic if using the “Build and Download” option IFI/Intelitek Loader window will popup showing progress
28
Drag and Drop Blocks Configure block parameters by double clicking on icon. Drag blocks from here into program.
29
Example of bad while function use
This section of code will prevent the statements below from being executed until the button is pressed. This means that the joystick values are not being read, and the other motors are not being controlled. Don’t make this mistake!
30
Do this instead … This just reads the button and then performs a function based on the state of the button. Without the “else” statement, the motor would turn on the first time the button is pressed and would never turn off.
31
Some other tips Use the BEST default program/project as a starting place for your robot program. Use the “Save As” function to save a copy of the project at different stages of development. This will make it easy to take a step backwards if you create a problem in the code. Make sure you name the different versions in a way to keep them straight (version numbers are good). Make sure to use the right version on game day!
32
… yeah, but that’s not enough.
There are tutorials and examples built into easyC. . Forums on bestrobotics.org and vexforum.com and other forums. Be aware that non-BEST-specific forums may discuss capabilities that we don’t have. Try things: you can always go back to the default code or some other simplified version of the code if things stop working.
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.