Hell Arduino Forum!
I started my adventure with Arduino some time ago, and since now all went smoothly. I have problem with PID Autotune library written for Arduino:
PID library: Arduino Playground - PIDLibrary
Autotune PID library: Arduino Playground - PIDAutotuneLibrary
In my project I'm using Arduino UNO to conrtoll four motors. Each has its own PID controller. To help me finding the suitable parameters I wanted to use autotune library, but I encountered a problem. I narrowed down my project to the point, when it stops working. Here is the code:
#include <PID_v1.h>
#include <PID_AutoTune_v0.h>
double Setpoint[4] = {1,1,1,1}, Input[4] = {0,0,0,0}, Output[4] = {0,0,0,0}; //parameters for PID
double kp[4] = {2,2,2,2}, ki[4] = {1,1,1,1}, kd[4] = {2,2,2,2}; //next parameters for PID
//declaration of four PID controllers
PID PID0(&Input[0], &Output[0], &Setpoint[0],kp[0],ki[0],kd[0], DIRECT);
PID PID1(&Input[1], &Output[1], &Setpoint[1],kp[1],ki[1],kd[1], DIRECT);
PID PID2(&Input[2], &Output[2], &Setpoint[2],kp[2],ki[2],kd[2], DIRECT);
PID PID3(&Input[3], &Output[3], &Setpoint[3],kp[3],ki[3],kd[3], DIRECT);
double aTuneStep=2, aTuneNoise=0.05; //parameters for autotune
unsigned int aTuneLookBack=20; // parameter for autotune
//declaration of autotune for each PID separately
PID_ATune aTune0(&Input[0], &Output[0]);
PID_ATune aTune1(&Input[1], &Output[1]);
//PID_ATune aTune2(&Input[2], &Output[2]); // commented out
//PID_ATune aTune3(&Input[3], &Output[3]); // commented out
void setup() {
Serial.begin(115200);
Serial.println("Begin...");
}
void loop() {
Serial.println("It works.");
}
Above code works. Serial prints out "Begin" and "It works" in a loop. But when I uncomment line with
PID_ATune aTune2(&Input[2], &Output[2]);
that is third PID Autotune object - it doesn't respond at all - in serial monitor nothing appears. It probably doesn't reach even setup() phase. Program compiles and loads correctly, problem is with serial response. I uncommented only one line and it stopped working. I guess that two PID autotune objects are ok, but three of more - are not. Why it is so?