PID Drive Control using Quad Encoders, easyC v5

I am trying to program PID drive loop to use for our robot.

We are using mecanum wheels, with quad encoders on the back two wheels.

easyC v5 for Cortex
v5.0.0.2

easyC includes a basic PID control function, but that only uses IMEs, and issues with IMEs have driven us (haha) to use quad encoders. Can someone guide me and possibly include sample code?

EDIT: Also, we would not like to use buttons to drive. Rather, we would like to use the analog joysticks, channel 1, 2, 3, and 4.

Thanks,
Ethan Page
Team 1961E

PID is usually used for precise autonomous driving. I’m guessing you want to drive straight when the joystick is pretty close to straight in the x or y directions. That would be just drift correction. Going sideways would require quads on both the front and back, so I would put your quads like

X |
| X
X = Quad Encoders

in order to have a directional left and right encoder.

You would probably need an if statement to check straightness. That would require a check to see if Ch1 is near 0 or if Ch2 is near 0 and run the correction program by reading the values.

Sorry, I don’t really know EasyC, but the program is basically:
1. Encoder Reset
2. (Left - Right)*CorrectionConstant
3. LeftMotor(Speed - CorrectionConstant) and RightMotor(Speed + CorrectionConstant)
4. Go to 2.

You would need to touch up on the CorrectionConstant (I’d make it a float [so that decimal value inputs are allowed], if EasyC has those).

Okay, so firstly if you ware experiencing one wheel (or set of wheels) not going as fast as another set of wheels, then you may want to first check you chasis for excess friction, this has been discussed many time before but I will reiterate it, a drift correction loop can do nothing but **slow your **robot down. Check all your motors are the same, check theres no bent shafts, check for excess friction. If that proves inconclusive, and only then should you move onto software drift correction!