|
本帖最後由 jason83530 於 2011-4-4 21:22 編輯
各位大大:
我是今年才踏進這個領域
在網路上看了很多有關PID控制的東西
我還是不知道怎麼把它應用到BBCar裡面
我的問題是:
1.PID可以幫我的BBCar什麼? 是車子跑起來的順暢度還是?
2.那我程式該怎麼打? 能給一些範例嗎?
例如
我讓車子轉彎:
打
DO
PLUSOUT 13, 650
PLUSOUT 12, 650
LOOP
這樣
那PID加進去有什麼好處?
怎麼加進去?
這是我想問的重點
我看官網的論壇那個程式碼
我也不知道能做什麼
如下:
' PidMathExample.bs2
' Demonstrates how a combination of proportional, integral, and
' derivative control influence error correction in a feedback loop.
' {$STAMP BS2}
' {$PBASIC 2.5}
SetPoint CON 0 ' Set point
Kp CON 10 ' Proportionality constant
Ki CON 10 ' Integral constant
Kd CON 10 ' Derivative constant
Current CON 0 ' Array index - current error
Accumulator CON 1 ' Array index - accumulated error
Previous CON 2 ' Array index - previous error
Delta CON 3 ' Array index - change in error
sensorInput VAR Word ' Sensor input variable
error VAR Word(4) ' Four different types of errors
p VAR Word ' Proportional term
i VAR Word ' Integral term
d VAR Word ' Derivative term
drive VAR Word ' Output
DO
DEBUG "Enter sensor input value: "
DEBUGIN SDEC sensorInput
' Calculate error.
error(Current) = SetPoint - sensorInput
' Calculate proportional term.
p = Kp * error(current)
' Calculate integral term.
error(Accumulator) = error(Accumulator) + error(Current)
i = Ki * error(Accumulator)
' Calculate derivative term.
error(Delta) = error(Current) - error(Previous)
d = Kd * error(delta)
' Calculate output.
drive = p + i + d
' Display values.
DEBUG CR, CR, "ERROR", CR,
SDEC ? SetPoint, SDEC ? sensorInput, SDEC ? error(Current), CR,
"PROPORTIONAL", CR,
SDEC ? Kp, SDEC ? error(Current), SDEC ? p, CR,
"INTEGRAL", CR,
SDEC ? Ki, SDEC ? error(accumulator), SDEC ? i, CR,
"DERIVATIVE", CR,
SDEC ? Kd, SDEC ? error(Delta), SDEC ? d, CR,
"OUTPUT", CR,
SDEC ? p, SDEC ? i, SDEC ? d, SDEC ? drive, CR, CR
' Save current error to previous error before next iteration.
error(Previous) = error(Current)
LOOP
請各位大大指點迷津 感謝! |
|