So, my autonomous sometimes veers to the left and sometimes veers to the right. I have two shaft encders, one on the left and one on the right. I’ve been thinking about adding an “autocorrect” that if one encoder is greater than the other, the side slows down to make up for the difference. I don’t know how to execute this idea. Can anyone help?
What you need to do is first figure out the difference in speed between the two and then try and get the one side to slow down to the other one.
Or you could try statically slowing one side down something like 20% slower. That generally works.
Be careful though, if you loop too fast you could slow the one side way too much before it really has time to react.
You can also look at how people controlled flywheels last year and use take back half to get the one to be the same speed as the other.
Generally, this is done with PID control. You have one PID controller for overall distance, and another for the difference between your left and right sides. Then you can subtract the output of the angle PID from the distance PID and correct on the fly. Take a look at this for an example. In short, the left side of your drive train gets distance PID output + angle PID output, and the right side gets distance PID output - angle PID output.