I currently have a PID driving program that uses base sensors as the input device. I also currently have a gyro PID Turning system. When one is running the other one is not. Sometimes my base while driving straight tends to shift s little in auton. What is some pseudo code that can correct this while driving forward and using the gyro.
motor[leftSide] = value + SensorValue[gyro] * Kg;
motor[rightSide] = value - SensorValue[gyro] * Kg;
Where value is whatever speed you would normally set it to, and Kg is some sort of constant that makes sure the gyro doesn’t affect it too much. I have mine set to 0.5, although I’ve tried it anywhere from 0.1 to 1, and it’s worked pretty well at either end of the spectrum.
If you look closer, this is essentially a P loop. As your gyroscope reading increases, the left side motors increase more and more, the right motors doing vice versa. As the reading decreases, the opposite occurs.
1 Like