-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Allow to set resolution and to compute every time the function is called #9
base: master
Are you sure you want to change the base?
Conversation
if (SampleTime > 0) | ||
ratio = (double)NewSampleTime/(double)SampleTime; | ||
else | ||
ratio = (double)NewSampleTime/(double)timeChange; // We will assume the user is calling Compute at a regular interval |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is needed to prevent division with 0.
if you want to get consistent behavior from the PID, you cannot calculate every time the function is called |
Not sure if this is the issue lauszus is trying to solve, but I had a similar one with my balancing robot. The robot needs to sample an imu and run the pid every 10ms. The main loop is already setup to run at that rate. If you let the pid decide when to run using its internal timer it will get out of sync with the main loop and not always run. So I changed the pid to run every time it is called, set time interval to 10ms and let the main loop sample the imu and run the pid every 10 ms |
did you try set time smaller than 10ms? In this case, the PID is synchronized. |
@enjoyneering actually that doesn't work, the loop will execute every 10ms so the PID will always run, but the time constants INSIDE the PID will be set to 9ms so the calculations will be off. |
I agree it will be off, because the sample time is hard-coded to Ki & Kd gains
so in your case you still have to set up sample time to 10
and then bypass sample time check in the "compute()" function. Am I right? |
Major update
First of all. Thanks for a great library. I just started to use it for my balancing robot: https://github.com/TKJElectronics/Balanduino/tree/dev/Firmware/Balanduino, but I wanted to change it a bit for my needs.
This is the changes I have done:
Also do you mind if I fix the indent of the source code?