Пробовал ввести отрицательную обратную связь (negative feedback).
Не работает Input2, все время имею Input2=0.00.
Input=Input-Output; // - ЗДЕСЬ ОШИБКА, Input остался без изменения, нет вычитания
Input2=Input;
Возможно ошибка data.type?
Смотрите приатаченую распечатку промежуточных точек программы на каждой итерации программіі
#include <PID_v1.h>
#define PIN_INPUT 0
#define PIN_OUTPUT 3
double Setpoint, Input, Output;
double aKp=45, aKi=0.2, aKd=1;
double Kp=0, Ki=1.0, Kd=0; //0.05, Kd=0;
double Delta;
int i1=1;
int Output1;
int Delta1;
float Input1;
float Input2;
PID myPID(&Input, &Output, &Setpoint, Kp, Ki, Kd, DIRECT);
void setup()
{
Serial.begin(115200);
Input=analogRead(0);
Setpoint = 200;
myPID.SetMode(AUTOMATIC);
}
void loop()
{
Input = 0.5*analogRead(0);.// маштабирую
Input1=Input;
if (i1=1)
{
}
else
{
Input=Input-Output;// ПИД обратная отрицательная связь с входным сигналом
Input2=Input;//=0.00, data type ???
}
myPID.Compute();
analogWrite(PIN_OUTPUT, Output);
Serial.println(i1);
Serial.print(" Input1=");
Serial.print(Input1);
Serial.print(" Input=");
Serial.print(Input);
Serial.print(" Input2=");
Serial.print(Input2);
Serial.print(" Setpoint=");
Serial.print(Setpoint);
Serial.print(" Output=");
Serial.println( Output);
delay(2000);
i1++;
} //void loop()