我不完全确定这是否是正确的地方问这个问题。那么,它是我想一个编程问题。为什么较低的增量会导致我的PID控制器以较低的精度进行调整?
我想在Java中创建一个简单的PID控制器模拟。
总之,有一个目标值和一个当前值。当前值由一个数字修改。您向PID控制器提供当前值,它会尝试返回一个数字,希望这个数字能够使当前值接近目标值。加班时,越多使用PID控制器,它将“学习”(使用积分和微分),并最终返回更多更准确的值。例如,通过控制轮子的运动来保持船的平衡,这是非常有用的。
PID控制器使用的公式非常一般,非常简单 - 或者我认为。在下面的示例中,由PID控制器返回的值仅添加到当前值。我认为它可以处理更复杂的应用程序(涉及乘法或除法等)。这是我的计划:
public class PID {
private static double Kp = 0.1;
private static double Kd = 0.01;
private static double Ki = 0.005;
private static double targetValue = 100.0;
private static double currentValue = 1.0;
private static double integral = 0.0;
private static double previousError = 0.0;
private static double dt = 0.5;
private static double max = 5;
private static double min = -5;
public static void main(String[] args) throws Exception {
while (true) {
Thread.sleep((long) (1000.0 * dt));
double error = targetValue - currentValue;
double derivative = 0.0;
double output = 0.0;
integral = integral + error * dt;
derivative = (error - previousError)/dt;
output = Kp * error + Ki * integral + Kd * derivative;
previousError = error;
if (output > max) output = max;
if (output < min) output = min;
// Apply the output to the current value:
System.out.println(currentValue + " + " + output + " = " + (currentValue + output));
currentValue += output;
}
}
}
如果你运行它,你会看到PID控制器最终设法使电流值是非常非常接近目标值。
这很酷。现在,我希望看到我的结果更快一些(因为我打算制作某种交互式图形),所以我决定将delta dt
更改为0.1
。
唉,结果值不再接近100!现在看起来达到105然后,很慢慢慢,减少到100.这不好!
现在想象拥有dt
在0.01
!现在达到102的速度非常慢,现在它甚至不能回到100,现在它不断增加!
所以我的问题是:为什么低三角洲造成这种情况?
我的代码是基于this PDF document,他们使用0.01
就好了。
我觉得你的问题更适合这个[网站](http://math.stackexchange.com/search?q= [控制理论] + PID +控制器)。 – user3707125