Question: How do I make my robot drive the way I want in autonomous mode?
Answer: This is one of the most non obvious and intricate questions there is in Vex. How do I make my robot drive the way I want? After participating in over 20 competitions over the course of many years, I have concluded that the best approach is a gyro + an encoder wheel + PID control. I’m going to break these down one by one to explain how to make your robot drive the way you want in autonomous mode.
Gyro: This sensor tracks rotation along an axis. It is notorious for drift, but mounting it on green rubber links or friction pad can greatly reduce this problem. The gyro is the most direct and one of the most accurate sensors there is, and it has precision down to a 10th of a degree. By using PID control in conjunction with the gyro, you can achieve very precise and consistent turning regardless of battery voltage.
Encoder wheel: This is a high precision method of tracking your forwards and backwards position. The wheels on your robot most likely skid when you come to a stop or temporarily lift off the ground when the robot rocks, but an encoder wheel does not skid or rock. To build an encoder wheel, you should mount a small wheel on a shaft that goes through a red encoder, and then put this assembly on a screw joint and rubber band it downwards. Ideally, the encoder wheel would be at the center of your robot, but moving it towards the front or back as long as it remains centered from side to side is not a problem. This way, if the robot lifts off the ground a fraction of an inch, the rubber bands will continue to push the wheel into the ground, preventing any loss of accuracy. And, because this wheel is not driven, it never skids.
PID Control: This is probably the most intricate part of the process. However, without at least P or PI control, you will lose critical accuracy. To implement P, PI, or PID control, see the various resources on the forums and Wikipedia. The scope of this post is simply how to integrate a gyro and an encoder wheel into PID control once you know the basics. Essentially, you should create 2 separate variables: the desired drive (forwards and backwards) value and the desired turn (left and right) value. You can set these in 1 function with something like this:
void setDrive(int drive, int turn){
desiredTurn = desiredTurn + turn;
desiredDrive = desiredDrive + drive;
}
And to set the drive- say you want 1000 tics forward with no turning- you would say
setDrive(1000, 0);
By setting the new value to the old value plus whatever your target value is, you ensure that any error from the previous step will be corrected in the next step. Then, in your PID loop, you should calculate the forward speed based on the desiredDrive error, the turn speed based on the desiredTurn error, and set the motors based on these values. To set the motors based on these values, you should set one side of the drive to the drive speed plus the turn speed and the other side to the drive speed minus the turn speed. For example, if your drive speed is 50 and your turn speed is 70, one side of the drive base would go at speed 120 while the other went at -20. This would yield both forwards backwards and side to side movement in the intended direction.
I hope this post helps at least one person achieve an accurate autonomous mode driving program.