tekdemo / minipid Goto Github PK
View Code? Open in Web Editor NEWC++ PID controller designed for quickly and easily implementing stable closed loop control.
License: GNU General Public License v3.0
C++ PID controller designed for quickly and easily implementing stable closed loop control.
License: GNU General Public License v3.0
Hi, I am using this code as my autocar steering PID. Imagine I sit inside the car. My steering target is center of the road 5 meters in front me. I want to steer my car so it points to the target. I use sensor to measure my car current orientation. The different of these two, let's call it D, is how much I want to steer my car. So when I call getOuput, I should use:
steer = getOutput(D, 0)
Correct?
Hi, I am using this code as my autocar steering PID. Imagine I sit inside the car. My steering target is center of the road 5 meters in front me. I want to steer my car so it points to the target. I use sensor to measure my car current orientation. The different of these two, let's call it D, is how much I want to steer my car. So when I call getOuput, I should use:
steer = getOutput(D, 0)
Correct?
Nice project congratulation!
I would expect to be possible to acknowledge time component for outputRampRate. Now everything is cpu speed dependent - so if you can include time component - one could be sure that effect of same ramp rate limit will be on fast and slow mcus - theoretically...
So if possible it would be great if you could add dependence to time in uSec (getMicros()).
I'm trying to use MiniPID as a temperature controller. I measure the current temperature in °C, and drive a PWM (with a value between 0 and 400) relay to heat the space.
For now, I set arbitrary settings for P, I and D, just to see how the system reacts.
I initialize my pid :
pid = new MiniPID(1.0, 0.1, 0.1); pid->setOutputLimits(0.0, 400.0);
and call getOutput() in a loop:
auto out = pid->getOutput(0.0, 20.0);
The value of 'out' increases each time getOutput() is called (2.0, 4.0, 6.0,...) until it reaches the maximum value (400).
The next value will be 4, while I thought it would return 400 forever, until the current value increases (which won't happen in this example, of course).
I think it happens on line 240 of MiniPID.cpp, when errorSum is set to the current error. As the error is lower, the PID returns a lower value.
In my case, it would mean that the setting of the heater would increase up to the max value, then set to nearly 0, and increase again.
Is this behavior expected? Is my understanding of MiniPID correct? Should I use it another way?
Thanks for your help!
JF
Hi,
I like your code and documentation, but I think that you have a few problems in the calculation of your derivative output for the general PID case.
You have:
Doutput= -D*(actual-lastActual);
lastActual=actual;
Your method does provide proper feedback, but only in the case were the setpoint in a constant.
For the general PID case the derivative should be based on the change in error, not the change in sensor (actual) feedback.
It should be written (note no -D):
Doutput = D * (error - lastError);
lastError = error;
If you think about it, if the setpoint changes you want the derivative to kick in and provide more movement to the output. Say the setpoint increases, the change in error increases, therefore the Doutput increases and adds to the output, increasing the motor speed, heating element PWM on time, etc.
Gord_W
When using the setPID () method, the errorSum and maxError variables are not being updated.
This can cause problems in a situation like
m_pid = new MiniPID (10, 0, 0); // I = 0
m_pid-> setOutputLimits (-100, 100); // maxError = 0, maxIOutput = 200
m_pid-> setPID (10,10,10); // maxError continues 0
the output of term I will always be 0 due to the following line
Ioutput=I*errorSum;
.....
else if (maxIOutput! = 0) {
errorSum = clamp (errorSum + error, -maxError, maxError);
}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.