Ok so I have a code that works fairly satisfactory. However, there is one thing that I want to be able to do.
The controller controls a heater and I see that in part of the code there is this part:
myPID.SetMode(MANUAL);
Output = 0;
Now if you look at the part of my code posted... when the button state becomes high and the PID controller starts doing auto control. I want to change one thing that happens then. Instead of the PID controller starting low and increasing till it reaches target temp, I want the first thing that happens when the "buttonState = high" and heater is first activated is for the output to be at max (255 in numerical terms) for 3000ms. So my question is... Is there some way I can put it on manual output control and have something like:
So what you want is to initialize its two initial states so that in the first moment it produces 0xFF on the output. This can be done if you have access to the states and you know the measured value.
Your second requirement is "for 3000ms". What if it initialized with 0xFF but measured value is so huge that according to PID rules the output must be decreased instantly? Your requirement for "3000ms first + PID later" is not a PID controller, but some kind of switching controller. You could tailor its anti-windup option to cause this delay but if you are not aware of the consequences I suggest switching from MANUAL to INITIAL and then to AUTO state.
Anyone know of any templates or examples a switching type controller?
Or... maybe a way to fool the PID controller into having its output at max for 3000ms?
The Output variable is just a value that the pid library calculates for you, a double apparently, see examples here Arduino Playground - PIDLibrary. Once you have it, you need to do something with it. Your code does this after pid computes the latest value for it:
analogWrite(10,Output);
You need the same thing after you set Output manually, before you start your 3s delay.
if(abs(Setpoint-Input)>150) {
myPID.SetTunings(20,2,0);
//aggressive for fast initial heatup
} else { myPID.SetTunings(4,2,0); }
//Then moderately tuned.
Think that will get me the desired effect? I've tried to do a manual output and then 3 second delay in the code... but that doesn't work.... It just keeps the output high the whole time.
And... I just tried something that kind of proved to me that the conservative values are not working... I set all the conservative values to ZERO. 0,0,0
I tried running the heater and it started heating.... then when the error got within 50 .... it still kept heating like nothing changed.... so that makes me think that its not switching between aggressive and conservative...
It is very likely that you need to set the loop to MANUAL, change the parameters, then set the loop back to AUTO.
You really need to have a deadband for changing the parameters. If gap is hovering right at 50 your loop could get into a situation where the code constantly toggles between the two parameter sets.