Anda di halaman 1dari 4

Vex Programming with SDCC

SDCC (Small Device C Compiler) is an open source C compiler that supports several different micro-controllers. SDCC is available in most *nix ports systems including FreeBSD ports, MacPorts, Gentoo Portage, Debian packages, pkgsrc, etc. See the SDCC WEB site for instructions on installing on platforms that do not currently offer a port. The entire system described here for programming Vex with SDCC has been tested on FreeBSD, Linux, Mac OS X, and Windows (Cygwin). The OpenVex source distribution contains a collection of "robotize" scripts to help you install these tools on any of the above environments. If you're running these tools under another platform, please send me a note so I can mention it here. Vex programming under FreeBSD/KDE4.

Many thanks to Ag Primatic for his tenacity and brilliant detective work, which made the SDCC port a reality much sooner than expected.

What you'll need


1. SDCC version 2.7.0 or later in order to successfully compile for the Vex's PIC 18F8520 MCU (use sdcc -mpic16 -p18f8520 file.c). 2. A make program. BSD or GNU make work best. 3. The OpenVex API library (See below). 4. Vex programming hardware (the orange USB-serial cable, dongle, and RJ45 cable). This is included with the commercial programming kits (easyC, MPLAB, RobotC, all of which run only on Windows) but can also be purchased separately. (P/N: 276-2186) 5. An editor or IDE to write your code. I use APE (Another Programmer's Editor), which greatly speeds up the software development cycle when compared to ordinary text editors, but any editor should work. 6. A programming tool (for uploading firmware to the Vex controller). Unix/Mac/Cygwin users can use vexctl, part of the roboctl project (see below). 7. A terminal emulator. For *nix systems, including Mac, I recommend cutecom. For Windows, Bray++ Terminal is the best tool I've found. Both are described in detail below. Both are much more flexible than the terminal included with the IFI loader.

Vexctl
Programs can be uploaded to the Vex robot from *nix and Cygwin using the vexctl command, part of the roboctl project. Besides being a multi-platform program, vexctl also has the advantage of being much faster than the Windows IFI loader. Default firmware uploads typically take about 5 seconds (2280 bytes/sec) vs. the 20-30 seconds I've experienced with the Windows IFI loader. Communicating with the controller requires a serial port and driver. Modern Macs do not have serial ports. The orange USB-Serial adapter in the Vex programming kit uses the PL-2303 chip set from Prolific. There are two drivers available for the Mac. The commercial driver is available at this link. After installing the driver, plugging in the USBserial adapter will create the device node /dev/cu.usbserial. There is also a PL-2303 driver available at Sourceforge. It creates a device called /dev/cu.PL2303-0000101D. This driver is much slower, and doesn't seem to work with VirtualBox. (You may be unable to connect the USB device to Windows.) Both FreeBSD and Linux come with a driver for the Prolific adapter. Run "man vexctl" after installing roboctl for more information. You can also use a serial port directly if your PC has one. Note: Standard male DB-9 serial connectors have posts, while standard female connectors have screws. The Vex dongle has a female serial connector with posts, and hence cannot be plugged into the back of your computer of any other standard male DB-9 serial port. A serial extension cable with screws on both ends will resolve this. I have also tried a Keyspan USB to serial adapter with vexctl and it worked very well.

The OpenVex API Library (formerly LibVexBot)


The OpenVex API is an open source C library which makes it easy to program Vex robots using SDCC or Microchip's MCC18 compiler. OpenVex was developed on FreeBSD using SDCC, and MCC18 under Wine. It has also been tested on Mac (Intel and PowerPC), Ubuntu Linux, and Cygwin. It is the world's first SDCCcompatible firmware for Vex robots, and the only available option for programming the VEX from non-Windows systems. Best of all, OpenVex is FREE, and always will be. OpenVex is released and distributed under the GNU Public License.

Why OpenVex?
OpenVex is meant to be an educational tool, making it easier to get started with Vex robotics programming while teaching software engineering principles (such as abstraction, coherence, etc.) by example. Programming in OpenVex is almost as easy as EasyC, without the limitations that hamper more advanced programmers. Beginners can program Vex robots with no knowledge of the PIC processor details. Since the library is 100% open source, more advanced programmers can learn more by studying and modifying the library code. In contrast, the Vex default code is written entirely at the "bare metal" level, full of cryptic references to PIC hardware resources whose names provide no clue as to what purpose they

serve in a Vex robot. For example, to enable interrupts on the Vex interrupt port 2, the default code uses the following: INTCON2bits.INT3IP = 0; INTCON2bits.INTEDG3 = 1; INTCON3bits.INT3IE = 1; OpenVex frees you from such details by encapsulating them in API (application programming interface) functions, so you can program your Robot using simple, descriptive function calls that relate to the Vex controller as you see it. For example, to enable interrupt port 2 on the Vex using OpenVex, you would write: interrupt_enable(2); OpenVex supports all the common Vex sensors, using synchronous I/O ports or interrupts where appropriate. You can plug any sensor into any appropriate port: you need only provide the right port numbers when calling the API functions. For example: #define BUMPER1_PORT 5 #define LIGHT_SENSOR1_PORT 2 #define SONAR_INTERRUPT_PORT 1 #define SONAR_OUTPUT_PORT 6 ... io_get_digital(BUMPER1_PORT); io_get_analog(LIGHT_SENSOR1_PORT); sonar_init_async(SONAR_OUTPUT_PORT, SONAR_INTERRUPT_PORT); ... sonar_distance = sonar_read_async(SONAR_OUTPUT_PORT, SONAR_INTERRUPT_PORT); For more details, see the complete API documentation. The source code includes sample code with a complete rewrite of the VEX default code, using only OpenVex calls. The combination of OpenVex, SDCC, and the Unix platform can greatly reduce the time and frustration of the code development cycle. Unix systems such as FreeBSD and Linux run far faster than Windows on the same hardware. In addition, they don't require frequent updates, are far less vulnerable to malware, and almost never need to be rebooted. If you like to spend your time being creative, rather than installing updates, removing viruses, and rebooting, you'll love working with Unix. SDCC on FreeBSD compiles the entire OpenVex 4.4.3 suite (7,774 lines of code) in 3.5 seconds on a ThinkPad T42 (Pentium M 1.6GHz), 1.25 seconds on a desktop system with an Athlon 64 X2 2.2GHz and SATA drive.

Especially problematic are Windows machines that are not in constant use, such as student laptops. A Windows machine that has been sitting in a cabinet for a month could take an hour or more and several reboots to catch up on critical security updates, and will be essentially unusable during this time.

Anda mungkin juga menyukai