Our drive code was such that 3/54 teams approached us specifically asking how we get such fine control of our robot.
I know this is a lot of code, and it's not very advanced, but man does it work well.
Code:
int driveScaleFactor = 3;
void Left(int speed) {
pwm03 = Safe_Values(speed);
}
void Right(int speed) {
pwm04 = Safe_Values(254-speed);
}
int Safe_Values(int roughValue) {
int toReturn = roughValue;
if(toReturn> 254) {
toReturn = 254;
} else if(toReturn < 1) {
toReturn = 1;
}
return toReturn;
}
int Scale_Offset(int roughValue, int scaleFactor) {
int toReturn = roughValue;
toReturn = ((toReturn-127)/scaleFactor) + 127;
return toReturn;
}
//// later, in Process_Data_From_Master_uP()
if(p1_sw_trig && p2_sw_trig) {
Left(p1_y);
Right(p2_y);
} else {
Left(Scale_Offset(p1_y,driveScaleFactor));
Right(Scale_Offset(p2_y,driveScaleFactor));
}
The advantage of having a function to assign pwm values instead of assigning them inline, is, obviously, you can add other functions like the one I did. Let me know if you use this!
I will eventually post code that uses PD control with encoders to drive in a straight line autonomously.