I am trying to implement PID control with my line follower but I am having some trouble. It currently runs with just a big switch case that chooses which outputs to send to the motors depending on the sensor input.
Technically with 6 sensors I have 64 possible sensor combinations, but only 12 that are usuable for the purpose of line following (there would be more used combinations if I wanted to program it to deal with some of the advanced obstacles they put on some of the tracks).
It tracks the line great using what I have implemented so far. Unfortunately when I try to increase its speed, it begins oscillating and can't really track the line at that point. This is where I believe the PID control would be useful, or at least PD control. I believe the derivative would help prevent a lot of these overshots.
I was thinking to make the center position sensor output equal to zero(setpoint), and the outer sensors -5, +5. Then use the PID. Up to this point I can figure things out.
Once the PID calculates an output, I'm confused as to how to send this to the motors, since I'm using a differential drive system. I think I will have to take the PID output, and then use a switch case similar to what I'm using now and map ranges of the PID output to various output combinations for the motors. IE: PID output is -4.77, this would fall within the -4.5 to -5.0 range in my switch case and drive the motors 100% L and 20% R.
This would basically be the same as what I'm using now with the exception of using the PID equation for output. I think what I'm using right now is basically very similar to just the proportional.