I'm learning control theory. I'm trying to find limits on how good a servo I can make just with a pot, a geared dc motor and an arduino. Well, some other hardware too, and a processing sketch for graphs and tuning. It works, but I believe it could be better. I can make it quite accurate for step changes, but I can't make it move slowly.
I have velocity control as inner and position control as outer loop. The potentiometer is read at 100Hz (10 ms per loop). I don't see noticeable differences if I increase the update frequency to 200Hz.
The pot measures angular position. Velocity is calculated from position change.
Here is some relevant code:
starttime = micros ();
ref = analogRead (1);
pos = analogRead (0);
err = ref - pos;
vel = pos-lastpos;
lastpos = pos;
Qo = Kp*err - Kv*vel;
Qo = constrain (Qo, -255, 255);
Output (Qo);
DebugOutput();
if (starttime-micros() < period) // period is 10 000 microseconds
{ };
So, I would like to make it possible for the servo to move accurately and slowly if needed.
Would I benefit from a 16 bit adc? Do I need a faster velocity loop?
edit:
I'm using Arduino Mega. For the motor driver I use SN754410.
Motors are similar to these: Micro Metal Gearmotor 100:1 (Sale) - ROB-08910 - SparkFun Electronics
The pot that measures angular position is mounted on the motor output shaft. I've drilled it and added just a bit of super glue.
I tried voltages from 3 to 12V. Currently testing 9V.