PID general question
Hello folks,
I have been recently working on implementing a PID controller into my project. I believe I understand the theory behind it but I have trouble understanding the scaling at the very end.
My scenario is as follows:
-let us say the setpoint is zero
-range for sensor input is between -90 and 90
The problem is that I need an output to be between 1000-2000 in order to run a servo. I am only using the proportional gain right now
and have linearized my data so the output works with what I have. (similar to adding a constant to the Kp term in order to control my motors)
Did I implement the proportional term correctly? it seem to always overshoot past 2000 if I increase the Kp gain a little.. I guess this is supposed to happen
and the only thing to do is to limit the upper and lower values using max and min.. <# and #> ....
Many Thanks!
Robert
I have been recently working on implementing a PID controller into my project. I believe I understand the theory behind it but I have trouble understanding the scaling at the very end.
My scenario is as follows:
-let us say the setpoint is zero
-range for sensor input is between -90 and 90
The problem is that I need an output to be between 1000-2000 in order to run a servo. I am only using the proportional gain right now
and have linearized my data so the output works with what I have. (similar to adding a constant to the Kp term in order to control my motors)
Did I implement the proportional term correctly? it seem to always overshoot past 2000 if I increase the Kp gain a little.. I guess this is supposed to happen
and the only thing to do is to limit the upper and lower values using max and min.. <# and #> ....
PRI PwmMonitor | upper, lower, angleupper, anglelower
'PID Algorithm
'Kp = 1.0
upper := 2000.0 'upper limit for esc control
lower := 1000.0 'lower limit for esc control
angleupper := 90.0 'max sensor data
anglelower := 0.0 'min sensor data
'linearize data by calculating m and b in y=mx+b
slope := math.FDiv(math.FSub(upper,lower),math.FSub(angleupper,anglelower))
b := math.FAdd(math.FMul(slope,-anglelower),lower)
repeat
sensorInputP := imu.get_angle_Pitch
sensorInputR := imu.get_angle_Roll
errorP := math.FSub(setpointP, sensorInputP)
errorR := math.FSub(setpointR, sensorInputR)
' Calculate proportional term.
pP := math.FMul(Kp, errorP)
pR := math.FMul(Kp, errorR)
' Calculate output y=mx+b
' Pitch
pwm1 := math.FAdd(math.FMul(slope,pP),b) #> 1000.0
pwm4 := math.FAdd(math.FMul(slope,math.FNeg(pP)),b) #> 1000.0
' Roll
pwm3 := math.FAdd(math.FMul(slope,pR),b) #> 1000.0
pwm2 := math.FAdd(math.FMul(slope,math.FNeg(pR)),b) #> 1000.0
pwm1f := math.FRound(pwm1)
pwm4f := math.FRound(pwm4)
pwm3f := math.FRound(pwm3)
pwm2f := math.FRound(pwm2)
Many Thanks!
Robert

Comments
Robert
Proportional
Integral (Accumulate Rate: how slow or fast to get to Max)
Derivative (often not needed)
Output Max (and/or Min if required)
Deadband Range (in a case of using an encoder, may be useful to stop oscillation when stopped)