Hi! I am programming a Vex competion robot for Starstruck and currently have a 4 motor holonomic x-drive with a shaft encoder on each wheel axle. When testing, it seems that one motor is running a bit slower than the rest, and causing the robot to not drive straight (checked for friction problems/ weight distribution already). What I would like to do is create a system that would compensate for the error in the motor while driving, so there is no "drifting, " except I have no idea how to code this. I have been told I can use a PID loop with the encoders, but since I have never done PID or encoder code before, I would appreciate some help. I would also like help on how to use the encoders to precisely measure position during auton/programming skills. I am using PROS to program. Thanks!
This is my x-drive code as of now:
int getChannelValue(int channel) {
//Sets channel values based on joystick input
if (abs(joystickGetAnalog(1, channel))>15){
return joystickGetAnalog(1, channel);
}
else {
return 0;
}
}
void setDriveMotors(int flSpeed, frSpeed, blSpeed, brSpeed) {
motorSet(front_left_drive, flSpeed);
motorSet(front_right_drive, frSpeed);
motorSet(back_left_drive, blSpeed);
motorSet(back_right_drive, brSpeed);
delay(20);
}
//Drive Code (in opcontrol while loop)
ch4 = getChannelValue(4); //Channel 4 = Forward/Backward (Y-Component)
ch3 = getChannelValue(3); //Channel 3 = Left/Right Strafing (X-Component)
ch1 = getChannelValue(1); //Channel 1 = Left/Right Turning (Rotation)
frontLeftSpeed = ch3 + ch4 + ch1 ; //Speed of motors for the drive = Y-Component + X-Component + Rotation
frontRightSpeed = -ch3 + ch4 + ch1;
backLeftSpeed = ch3 - ch4 + ch1;
backRightSpeed = -ch3 - ch4 + ch1;
setDriveMotors(frontLeftSpeed, frontRightSpeed, backLeftSpeed, backRightSpeed);