Libstock report: PID Library available for download!
Libstock's top contributor, Dany Rossel, has just released his new PID Library.
Many of you have asked for it, and we hope this is the right solution for you.
Library has intuitive function prototype, and comes in Package manager form with Help, Source, MCL files and examples.
We invite you to visit the Library page on Libstock and read Dany's blog to see whether this library is what you might need.
Libstock report: PID Library available for download!
Libstock report: PID Library available for download!
Web Department Manager
Re: Libstock report: PID Library available for download!
Hello,
thanks to Dany for his great contribution.
I took a bit of time and ported the lib to mikroBASIC. If Dany is interrested he can add my codes to his own codes on his libstock page to centralise the lib on one and unique access point.
The codes are attached as a zip to this post
thanks to Dany for his great contribution.
I took a bit of time and ported the lib to mikroBASIC. If Dany is interrested he can add my codes to his own codes on his libstock page to centralise the lib on one and unique access point.
The codes are attached as a zip to this post
Code: Select all
module PID_Lib
' ---------------------------------------------------------- '
' ---- PID library with fixed calculation time interval ---- '
' ---------------------------------------------------------- '
' Ahmed Lazreg
' ahmed.lazreg@pocketmt.com
' Translated from original mikroPascal code from D.Rossel
' D. Rosseel
' Original: 27-09-2011
' Latest update: 27-09-2011
' History:
' 29-09-2011: Translation from Pascal Code to MikroBasic
' 27-09-2011: Original Version (in mikroPascal).
' Documentation: http://en.wikipedia.org/wiki/PID_controller/ and http://brettbeauregard.com/blog/2011/04/improving-the-beginners-pid-introduction/
' interface
sub procedure Init_PID(dim Kp, Ki, Kd, MinOutput, MaxOutput as float)
' Initialises the PID engine
' Kp = the "proportional" error multiplier
' Ki = the "integrated value" error multiplier
' Kd = the "derivative" error multiplier
' MinOutput = the minimal value the output value can have (should be < 0)
' MaxOutput = the maximal value the output can have (should be > 0)
sub procedure Reset_PID
' Re-initialises the PID engine without change of settings
sub function PID_Calculate(dim Setpoint, InputValue as float) as float
' To be called at a regular time interval (e.g. every 100 msec)
' Setpoint: the target value for "InputValue" to be reached
' InputValue: the actual value measured in the system
' Functionresult: PID function of (SetPoint - InputValue),
' a positive value means "InputValue" is too low (< SetPoint), the process should take action to increase it
' a negative value means "InputValue" is too high (> SetPoint), the process should take action to decrease it
implements
dim PID_Kp, PID_Ki, PID_Kd as float
dim PID_Integrated as float
dim PID_Prev_Input as float
dim PID_MinOutput, PID_MaxOutput as float
dim PID_First_Time as boolean
sub procedure Reset_PID
PID_Integrated = 0.0
PID_Prev_Input = 0.0
PID_First_Time = true
end sub
sub procedure Init_PID(dim Kp, Ki, Kd, MinOutput, MaxOutput as float)
PID_Kp = Kp
PID_Ki = Ki
PID_Kd = Kd
PID_MinOutput = MinOutput
PID_MaxOutput = MaxOutput
PID_Integrated = 0.0
PID_Prev_Input = 0.0
PID_First_Time = true
end sub
sub function PID_Calculate(dim Setpoint, InputValue as float) as float
dim TheErr, ErrValue, DiffValue as float
TheErr = SetPoint - InputValue
' --- calculate proportional value ---
ErrValue = TheErr * PID_Kp
' --- Calculate integrated value ---
PID_Integrated = PID_Integrated + (TheErr * PID_Ki)
' limit it to output minimum and maximum
if PID_Integrated < PID_MinOutput then
PID_Integrated = PID_MinOutput
end if
if PID_Integrated > PID_MaxOutput then
PID_Integrated = PID_MaxOutput
end if
' --- calculate derivative value ---
if PID_First_Time then ' to avoid a huge DiffValue the first time (PID_Prev_Input = 0)
PID_First_Time = false
PID_Prev_Input = InputValue
end if
DiffValue = (InputValue - PID_Prev_Input) * PID_Kd
PID_Prev_Input = InputValue
' --- calculate total ---
Result = ErrValue + PID_Integrated - DiffValue ' mind the minus sign!!!
' limit it to output minimum and maximum
if Result < PID_MinOutput then
Result = PID_MinOutput
end if
if Result > PID_MaxOutput then
Result = PID_MaxOutput
end if
end sub
end.
- Attachments
-
- PID_Lib.zip
- (1.24 KiB) Downloaded 1066 times
http://www.pocketmt.com
Re: Libstock report: PID Library available for download!
do you have in mind released this library for mikroC version??
Re: Libstock report: PID Library available for download!
Octal provided also the C version now. It is available in Libstock, see http://www.libstock.com/projects/view/161/pid-library.kaniux wrote:do you have in mind released this library for mikroC version??
Kind regards, Dany.
Forget your perfect offering. There is a crack in everything, that's how the light gets in... (L. Cohen)
Remember when we were young? We shone like the sun. (David Gilmour)
Forget your perfect offering. There is a crack in everything, that's how the light gets in... (L. Cohen)
Remember when we were young? We shone like the sun. (David Gilmour)