Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Start the pid with initial value ? #1

Open
ewok2 opened this issue Jun 2, 2024 · 4 comments
Open

Start the pid with initial value ? #1

ewok2 opened this issue Jun 2, 2024 · 4 comments

Comments

@ewok2
Copy link

ewok2 commented Jun 2, 2024

Hello
I use the pid to filter a temperature and wich a the first iteration to start with initial value.
Is it possible to set the PID so that the first iteration is not zero but the initial value?
=> doesit have any sens?
Maybe by setting

       self._pid_out 
       self._pid_out_prev 

to a intila value?

@mkner
Copy link
Owner

mkner commented Jun 3, 2024

it depends on which initial values you want to set: you can set the gains to initial values before beginning time-step iterations, or if you want to set an initial value for the control signal you are sending to some device or process plant then you can use BasicPid in iterative mode (instead of integrative mode) and handle the time-step integrations manually in a loop see some examples in RTD for BasicPid for more @ https://basic-pid.readthedocs.io/en/latest/examples.html

@ewok2
Copy link
Author

ewok2 commented Jun 4, 2024

I just had to change the pid.py file to achieve my goal :-)
I just add the folowing function :

     def setInit(self,initial):
         # set initial value
         # keeps gains intact
         self._P = 0
         self._I = 0
         self._D = 0
         self._e_prev = 0 # previous error (t-1)
         self._e_prev_prev = 0 # prev-previous error (t-2)
         self._pid_out = initial
         self._pid_out_prev = initial

just befor the reset function, and it works

I just have to call "pid.setInit(initalvalue)" befor the loop

@mkner
Copy link
Owner

mkner commented Jun 6, 2024

yep, you got it! just jump start the 1st iteration with initial PID evaluation (output) values. Did you then just run PID in integrate mode? I designed & coded BasicPID to be clean & logical so can be relatively easy to modify & customize. I was going to put in an interface function for setting initial values but left it for the first stable release. I will put it in for the next. thanks for asking about this. any feedback is welcome.

@ewok2
Copy link
Author

ewok2 commented Jun 7, 2024

The only feedback is : wonderful job
The code is clear and it was easy to add a new input point.
Wonderful if you add this functionality in next release. I will pug on it when avalaible

Many Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants