Moderators: Dave Moll, Andrew Davie, Steve Anderson
Klaas Robers wrote:Servo systems are always "Error Driven". So you need to construct an error signal. And because this is not a speed stabilizer, but a position stabilizer, your error signal is the time difference between the sync pulse from the signal, or whatever you will use in place of that, and the IR-pulse coming from the disc. You have to do whatever you can to make that error signal to go to zero.
If you want to have a certain, fixed or variable offset, you can add a positive (or negative) number to the measured timing error.
This error signal is the input for your PID. Don't try to invent the PID yourself.
Robonz wrote:Hi Andrew
First time post as I only discovered mechanical TV a few days ago and am fascinated by it. I am keen to try building one myself. I have had a bit of experience with PID and motor control. I think you may be simply missing the 4th term which is not well taught. I have always had add a 4 the term which I call i_max
It is basically a maximum allowable value for I. It is used to prevent "integrator wind" up as they call it.
e.g.
calculate i then
If i > i_max
i = i_max
if i > -i_max
I = - i_max
I am enjoying reading about your build so keep on keeping on.
byte calculatePID(double error) {
double now = ( (double) playbackAbsolute ) / singleFrame;
double timeChange = now - lastTime;
if (timeChange > 0) {
errSum += ( error * timeChange );
double dErr = ( error - lastErr ) / timeChange;
motorSpeed = kp * error + ki * errSum + kd * dErr;
if (motorSpeed > 255)
motorSpeed = 255;
if (motorSpeed < 0)
motorSpeed = 0;
lastErr = error;
lastTime = now;
}
return (byte) ( motorSpeed + 0.5 );
}
Robonz wrote:First time post as I only discovered mechanical TV a few days ago and am fascinated by it. I am keen to try building one myself.
Robonz wrote:errSum += ( error * timeChange ); <--- typically this would have some bounds which would limit integrator wind up.
e.g. if errSum > maxErrSum
errSum = maxErrSum
if errSum < -maxErrSum
errSum = -maxErrSum
Also I noticed you are using 8 bits for the motor speed. I would typically start at 10 unless there was a reason not to. It may lock in the vertical frame stability a little better, then again maybe not. I just like to use all the power if its just a matter of typing in two extra lines of code.
Andrew wrote: I try to limit calculations to a minimum
Robonz wrote:Andrew, can I ask you to try one thing? Could you set all the PID to singles instead of doubles and see if there is any difference. I am betting there will not be. This would take the PID processing down to around a quarter of the time.
Robonz wrote:I noticed you are getting really awesome video too. Are you using a camcorder that has a 12hz setting for long exposure video?
Robonz wrote:It must have taken you many hours to write all that code.
Return to Andrew Davie's Arduino Televisor
Users browsing this forum: No registered users and 1 guest