|
|
View previous topic :: View next topic |
Author |
Message |
Zek_De
Joined: 13 Aug 2016 Posts: 100
|
PID integral term |
Posted: Fri Feb 10, 2017 10:58 am |
|
|
Hello friends,
I couldn't understand how to do integral term limits. These are my codes, and 20.000 max pwm to max power. Where is my mistake?
Code: |
int16_t Constrain(float test, int16_t a, int16_t b)
{
if(test < a) return a;
else if(test > b) return b;
else return (int16_t)lroundf(test);
}
//##########################################
uint16_t PIDX(uint16_t value, float target, float current)
{
error = (target - current);
integral = (float)Constrain((integral + error*deltaT), -19000, 19000);
derivative = (error - previousError) / deltaT;
previousError = error;
return (Constrain(value + Kp*error + Ki*integral + Kd*derivative, 0, 19999));
} |
|
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9226 Location: Greensville,Ontario
|
|
Posted: Fri Feb 10, 2017 11:18 am |
|
|
to my old eyes, it's using floating point numbers...
or...it could be lack of casting or other math related confusion,like braces.
When doing math like this, you should print out(display) ALL of the interim terms and use KNOWN input values, compare what the PIC says vs what YOU have done the math on.
I didn't use them 20 years ago with 16F877s and realtime helicopters...
..no need for them and they take a HUGE amount of time to compute.
Jay |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19513
|
|
Posted: Fri Feb 10, 2017 11:52 am |
|
|
Yes. The idea of 'PID', and 'floating point', don't really go together on a PIC, unless you are controlling something really slow. I've successfully done some quite fast PID's using 24bit integers, with the last byte treated as the fractional part. 1.0000, then is stored as 256.... |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|