The standard Arduino PID library is pretty simple and the Author Brett Beauregard wrote an article explaining it: improving-the-beginners-pid
Are you sure of this? Sound like your hydraulic system cannot maintain a constant pressure.
Paul
I have to admit it's not in optimum condition, nevertheless I was partly successful already and figured that a pid controller would compensate for the suboptimal condition the system is in.
now that I understood the function I figured it's exactly what I'm doing already with my code.
I'm gonna try to describe the behavior I want to achieve. if the error exceeds the "deadband" I want the output to pretty much reach the maximum or minimum dependent on the direction of the error, but once the error gets smaller the output should slowly proximate 2047 again.
the above suggests the following, where the x-axis is the tilt angle and the y-axis the PWM output to the directional valve
suggests
the response time of the affect of the directional valve on the tilt angle is unknown. lag can result in overshoot. i assume at some value the directional valve has less affect.
How much time will your hydraulic system operate? If for very long, the hydraulic fluid will heat and cause all you nice parameters to change.
Paul
it's an irregular on off situation, so sometimes it operates for 1 - 2 minutes constantly and the then it does nothing for like 1 - 5 minutes. the hydraulic system has a huge tank and a cooling system, so once the fluid reaches operation temperatures it's very stable temperature wise.
@gcjr the last diagram is the most suitable
But, is it constantly circulating and being cooled?
Paul
yes it is, the whole system circulates like 400 liters per minute with a overall capacity of approx 800 liters of hydraulic fluid.
Then you need to tap the system where there is constant pressure. If there is no such location, you need to make one with a pressure regulator.
Paul
Now I got myself pretty familiar with the PID_v2 library by Brett Beauregard.
The only thing I can't find is how to set the initial output value. Can anyone give me a hint, cause I'll get 255 as output value whenever start the PID controller.
here's my code, I hooked up an encoder to simulate a changing input and spit the output out via serial terminal.
#define encoder_A_pin 3 // physical pin has to be 2 or 3 to use interrupts (on mega e.g. 20 or 21), use internal pullups
#define encoder_B_pin 2 // physical pin has to be 2 or 3 to use interrupts (on mega e.g. 20 or 21), use internal pullups
#define ENCODER_OPTIMIZE_INTERRUPTS //Only when using pin2/3 (or 20/21 on mega)
#include <Encoder.h> //for Encoder Download: https://github.com/PaulStoffregen/Encoder
#include <PID_v2.h>
int8_t input = 0;
double Kp = 10, Ki = 5, Kd = 1;
PID_v2 myPID(Kp, Ki, Kd, PID::Direct);
Encoder ENCODER(encoder_A_pin, encoder_B_pin);
void setup() {
pinMode(encoder_A_pin , INPUT_PULLUP);
pinMode(encoder_B_pin , INPUT_PULLUP);
Serial.begin(9600);
myPID.Start(input, // input
4095, // current output
0); // serpoint
myPID.SetOutputLimits(0, 4095);
}
void loop() {
int8_t EncoderPosition = ENCODER.read();
if(EncoderPosition <= -3)
{
input = input + 1;
ENCODER.write(EncoderPosition+4);
EncoderPosition += 1;
}
else if(EncoderPosition >= 3)
{
input = input -1;
ENCODER.write(EncoderPosition-4);
EncoderPosition -= 1;
}
const double output = myPID.Run(input);
Serial.println(output);
Serial.println(input);
}
The output is calculated by the PID - you don't set it and I'm not sure why you would want to. Of course, you can decide to ignore it when it's at that level - what you do with the output is your business.
easy answer, I'm not using the output with PWM, but rather send it to a 12 bit DAC, the voltage output of the DAC is scaled to +10 to -10 volts. that voltage is the control signal for a proportional hydraulic valve and I want to make sure that the pid controller starts off at the center so the valve starts in the idle position. at the moment the PID output starts at 255, that would result in a relatively high negative voltage and the valve would bring the attached platform out of balance until the PID went through a few cycles and finally settles.
I'm not sure what's happening with your input, but I wonder if you could start it at a higher value (128). It looks like the output is going super high because you start it at zero.
what do you mean with I start it at zero? if I monitor the output the first value it throws is 255, since I use an encoder to stimulate the input it stays there until I turn the encoder.
I set the output limits to 0 and 4095, which the output eventually reaches when I turn the encoder, but I don't understand why it starts off at 255?
Input starts at zero, which I assume is telling the PID that it's way off where it needs to be, so it reacts with a large number on the output.
I don't think so, since my setpoint is zero as well, that should result in no change in output and that's exactly what it does.
but my problem is that it doesn't change the initial value of 255. I want the initial value to be 2047 instead of 255, that's all.
255 is the default maximum range. I think you should set the output range before you start the PID.
Setpoint is zero, input is zero, so there should be no change to output as you said, so pass 2047 at startup.
many thanks @wildbill I completely overlooked that!
Now it works exactly as expected!
This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.