EasyC OI Inputs?

What is up with how EasyC handles input from the OI? I was trying to reprogram our 2005 bot for drivers to practice, and I decided to use EasyC to get familiar with it and because our programming team was considering using it.

[edit] aha! EasyC doesn’t yell at you if you are using a “char” instead of an “unsigned char” to store motor data, probably because WPILib bases its drive code on a -127 to 127 range instead of the usual 0-255. This means that sometimes “0” is the ‘neutral’ value and other times it’s 127. The other functions from WPILib (the “drive” library, anyways) appeare to be based on a -127 to 127 scale. When I looked I couldn’t find this in the documentation, so made an educated guess the wrong way.

Why does the “drive” library use a different metaphor than the rest of the program? I find this rather confusing. [/edit]

I wasn’t able to figure out what was going on, so I just went back to MPLAB and reprogrammed the robot there. Tried and true, I suppose

Worked fine for me today.

Although I started off trying to use pwm14 and pwm15 for motor outputs, then found that only pwm1-12 are supported.

Are you having a conflict with int (signed) and unsigned char - whether in your variables to hold raw joystick values, or the printf?

It would have been nice if everything worked using the -127 - +127 metaphor since it makes much more sense than having an arbitrary value of 127 for stopped. The reason the rest of the code doesn’t do that is because of easyC compatibility. It had the SetPWM functions that did the 0-255 thing.

But the drive library make some things incredibly easy to do, especially around control problems. For example, you can use a gyro to drive in a straight line with this fairly simple program:

void main(void)
    int heading;
    InitGyro(1);             // initialize gyro on port 1
    TwoWheelDrive(2,1);      // Setup 2 motor drive robot (ports 1 & 2)
    StartGyro(1);             // start gyro sampling
    while (1)
        heading = GetGyroAngle(1); // get the current heading
        Drive(80, heading/2); // turn towards the error

And that’s the whole program, no other files required.

So we use the drive stuff, but it isn’t necessary. It helps with the bookkeeping of remember which way all the motors need to go and basically decouples the driving and turning values so you can think of them independently.


I tried including the WPILib downloaded from Internet (I did run the setup script that came with that).

Following the EasyC tutorial to “Add a Library”, we found that the Add Library failed in EasyC due to a pre-existing definition for TwoWheelDrive() in API.H.

As a result, there is no Drive() function available.

Any suggestions?

The problem is that the easyC guys added an identical set of functions as block code. And it’s documented all over the place in the help file and examples so they didn’t want to change/remove it. So if you’re using easyC you can use their functions and if you’re using WPILib with some other development environment (MPLab or eclipse) you can use the ones built in.

The way I resolved the name conflicts was to add the file “BuiltIns.h” which only contain definitions for the Drive functions, then include “API.h” which has everything else. So use “BuiltIns.h” if you are using MPLab and “API.h” if you are using easyC and plan on importing the block-code versions of the functions.