Hello,
I am using a PID controller to stabilize a ball on plate system, I have the setpoint and the position feedaback, thus, The position error e(t) = setpoint - actuall ball position, I want to calculate the position error rate e*(t), does anyone have an idea about it's calculation?
I know that the change in error is the actual error - the precedent error but I need to calculate e*(t) not only the change in error.
I hope that it is clear!
I'd say that for a rate I'd want to use time, for an Uno time can be millis() or micros(). Then I'd store a starting point value at a time, over time record the error change, and at the end of the time produce a rate of change.
are you sure you want the error rate?
doesn't PID need velocity which is the change in position vs time?
For the PID "D" term, during each iteration of the loop you subtract the last error from the current error, then copy the current error into last error.
In principle you must divide by deltaT, but since the sample rate should be constant anyway (as assumed by the standard PID algorithm), deltaT can be absorbed into the Kd term.
Actually, I am using PID but I am trying to get the error and the change in error e*(t) to use it for fuzzy logic controller
Can you elaborate the idea please?
Actually, I am using pid_v1 library, thus, how to do that?
If you mean this Arduino PID library, all you do is set Kd appropriately.
https://playground.arduino.cc/Code/PIDLibrary/
That controls the already built in error rate of change term.
PID_vi uses "Derivative on Measurement", so you'll need to change the sign (for derivative on error). I'm not sure what happens when you change the setpoint. Check this reference
QuickPID has an option to change the derivative mode.
You'll need to do this when instantiated, check this example.
(I'll be adding a new function to do this in the next version)
yes this one, actually I am only using PID for another purpose, I am trying to the error change rate to use as input for a fuzzy logic controller ! So, I am trying to figure out how to calculate it !
Actually, I am using PID for another purpose, I want to caclulate the error change rate to use it as input for fuzzy logic controller!
see PID Controller
err [t] = pos [t] - targ;
dErr [t] = (err [t] - err [t-1]) / dT
= ((pos [t] - targ) - (pos [t-1] - targ) ) / dT
= (pos [t] - (pos [t-1]) / dT
- vel [t]
what is dT? how to get it ?
the time difference between t and t-1
Calculated using milis()?
if the code uses millis() to update the PID periodically, then dT is that period.
if PID is updated aperiodically, then millis/micro() need to capture a timestamp for each measurement of pos [t] and calculate dT for that measurement as the difference between the last 2 timestamp
can you explain how you intend to use PID with fuzzy logic?
Actually, How can figure out if milis() is used or not ? I am using PID to control the ball on plate, since the ball is on moving on plate I can control get the error and calculate the correspondant change in error to use them as input for another controller which is fuzzy logic! I hope this is clear!
if millis() is not precise enough, you'll need to use micros () to determine dT
Like that?
float ErX=SetpointX-InputX; //InputX is the actual position while setpointX is the desired pos
Serial.println(ErY);
myTime2 = micros();
Tv=myTime2-myTime1;
myTime1=myTime2;
float ErT=ErX/Tv;```
isn't it dErr that depends on dT
unsigned long usec = micros ();
float pos = analogRead (Pin);
unsigned long dT = usec - usecLst;
float err = pos - setPoint;
float dErr = (err - errLst) / dT;
posLst = pos;
errLst = err;