I have wheel encoders on my 2 wheel robot car. They work fine through interrupts. Reading some values I get from the interrupts gives a perfect measurement of the speed. But what would be the best method to actually control the speed?
Is a PID system overkill? I haven't done that, but the net is full of examples.
Before diving into PID, I found myself inventing the wheel (I'm the founder of The Wheel Re-Inventors' Society). But perhaps this is overkill, too. In my main loop, I continuously update the motor power as long as I want to remain one speed, until I want to change the speed. My algo goes like this:
On the first loop with a new target_speed value, the motor_power is set according to a lookup table.
On the second loop with the new target_speed value, the measured_speed/motor_power ratio is used to adjust the motor_power to fit the target_speed. Simple line going through zero.
On the following loops with the same target_speed, new (measured_speed, motor_power) points are recorded. To adjust the motor_power, the two last points are used for interpolation or extrapolation (same difference). When a fairly stable speed is reached, the lookup table used in step 1 is updated.
Say that I want a speed of 300 mm/s. I set motor power to 150 (let's just assume I have a very bad lookup table). I get a speed measure of 224 mm/s. My second step calculates a new power using a linear model with two points (0, 0) and (224, 150). That model would give motor power 201. So I set that as the motor power and measure the speed in my third step. Has my algo gone completely wrong already?
I don't expect motor power 201 to give the final 300 mm/s yet. Say I measured 312 mm/s. Or I measured 278 mm/s. Whatever I measured, I have a new pair of points. Let's go with the 312 mm/s. I have points (224, 150) and (312, 201). These two points would tell me that 300 mm/s would require motor power 194. I set motor power to 194 and measure the speed again.
What I hope is that looping the last step, always using the last two measurements would get me to the target speed. Possible oscillation would maybe stay in a very small intervall.
You're probably right. Without load, my motors seemed to run with a very constant speed. But as soon as I put the car on the floor, it went absolutely crazy. I shall run a few tests before I close the case, then I switch to full PID.