Programming for the Vex Robotics System

Background Information

The Vex Robotics System comes with a microprocessor that can be used to read inputs and control outputs to the robot. Some of the inputs include the receiver, which is used to communicate with joysticks, sensors for autonomous control, etc. Outputs are the PWM signals to the speed controllers for the motors, relays for the pneumatic components and other motors for the manipulator, etc. The program loaded onto the microprocessor must be able to read the inputs and decide what the outputs should be based on that information.

The Vex Starter Kit does not come with the necessary tools for programming. You will need to get a programming cable directly from the Vex website for $50 or kitsusa.net for $45.

There are 5 software options for programming the Vex controller, and there's a fairly good comparison of them on the Vex website. There are 4 shown, but there are two different libraries you can use with MPLab, the default IFI code, and WPILib. Here's a cost comparison:

Software Cost w/ Programming Cable Cost w/o Programming Cable Trial Version Available?
EasyC $99 N/A No
EasyCPro $149 N/A No
RobotC $99 $30 Yes, free 30 day trial
MPLab with C18 Compiler $99 $50 Yes, free 60 day trial

All of these can be purchased from the Vex website. The RobotC website sells RobotC for much cheaper than you can get it from the Vex website.

Instructions for Setting Up WPILib with MPLab

Getting the Software

***You must have administrator privileges to install***

  1. Download MPLab IDE 8.10 (used to write code) and install using all the default settings.
  2. Download C18 Compiler 2.40 (used to compile code) and install the microchip C18 compiler into C:\mcc18\(default) and check mark all six of the configuration options (Add MPLAB C18 to PATH variable, Update MPLAB IDE…, etc). This is the a 60-day trial student edition of the compiler.
  3. Download and install IFILoader 1.1.0 (used to load code onto the processor)
  4. Download the WPILib Library and extract to the root of your hard drive (C:\). So the path to the code should be C:\WPILib\Vex\ and there should be 5 files in that folder. These will be used in the next step.

Setting up the project, compiling, downloading

  • Open the MPLab IDE 8.10
  • Project --> Project Wizard
  • Select a device: PIC18F8520
  • Select a toolsuite: C18 Toolsuite
  • Locate all Toolsuite Contents files (4 files)
  • Name the project and save it in C:\WPILib\Vex\
  • Add the 5 files in the C:\WPILib\Vex\ folder:
    • 18f8520.lkr
    • API.h
    • BuiltIns.h
    • Vex_library.lib
    • WPILibVex.lib
  • Click “Finish” to create the project
  • If the project window is not open, View --> Project
  • Right click on “Library Files” in the Project Window, select “Library Link Order” and make sure WPILibVex.lib comes before Vex_library.lib
  • Create a new file and type the following code:

#include “API.h”

#include “BuiltIns.h”

void main(void) {

IO_Initialization();

printf(“Hello World!”);

}

  • Save the file as main.c in C:\WPILib\Vex
  • Right click on “Sources” in the Project Window, select “Add Files…” and add your main.c file.
  • Open API.h and add a line at the very top:

#define _VEX_BOARD

  • Press F10 to see if your project compiles. If it doesn't, fix the errors and try again.
  • To download to your robot, open up IFI Loader (installed earlier).
  • Browse to C:\WPILib\Vex\ yourprojectname.hex
  • Under port settings, check to see that your COM port is correct. You can check in Device Manager (Start --> Run --> devmgmt.msc), then expand the ports section.
  • Click the download button!

Using the WPILib Library

  • Open C:\WPILib\WPILib.pdf for the full documentation on the library. This document references both VEX functions and FRC functions, so make sure that you only use VEX functions in your code.
  • Once you have skimmed the pdf, you can open up API.h in your project for quick access to the full list of functions available.
  • For more information on WPILib, you can check out their website or their subforum on ChiefDelphi.
  • Good Things to Start out with:
    • Use the Tank2() and Arcade2() functions to drive the robot with the transmitter.
    • Use the GetRxInput() and SetPWM() functions to control a servo.
    • Use the TwoWheelDrive() and Drive() functions in BuiltIns.h and the Wait() function in API.h to make your robot drive for set time periods autonomously.
    • Use the GetDigitalInput() and GetAnalogInput() functions to read sensors such as light sensors, bump sensors. Make sure you initialize the IO first with the DefineControllerIO() function.
    • Make a robot that can follow a black line.

WPILib Getting Started Guide

  • Here's another presentation that goes into more detail on how to use WPILib: Guide to WPILib by Aaron Osmer

Troubleshooting Guide

  • Problem: Compiler says: “Error: Could not find library clib.lib”
  • Solution: Uninstall and reinstall C18 compiler (it needs to be installed after MPLAB is installed). And check all 6 checkboxes in the installation wizard – these options tell MPLAB how to find the compiler.
  • Problem: I can’t download my program!
  • Solution:
    • Make sure you pressed the orange button on the programmer module and the programming light on the microcontroller is flashing.
    • Ensure that Windows is recognizing the device – Go to Device Manager (Start --> Run --> devmgmt.msc), expand the ports section, and check which COM port your device is on under the ports section. Make sure this COM port in IFI Loader under Port Settings
    • Check to make sure the programming cable is plugged in! The RJ-11 jacks on the Vex controller do not always make a good connection.
    • Check battery voltage. If voltage is too low, program won’t download.
  • Problem: I downloaded my program, but it's not doing what I told it to!
  • Possible Solution: Update the firmware on your vex controller to the latest version.