Too many autotune objects?

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: http://playground.arduino.cc/Code/PIDLibrary
Autotune PID library: http://playground.arduino.cc/Code/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?

Looks like you are running out of ram, look in the playground for the code to check of the amount of ram being used and insert it in serup().

Mark

Hey!
Thanks for good advice! I've checked it with MemoryFree.h library, how much memory one PID Autotune library occupies.
Without any autotune declared, freeMemory=1487
With one declared, freeMemory=980
With two declared, freeMemory=473.

It it obvious, that one instance of PID Autotune takes 507, so with 473 left there is no room for another.
That it the answer to my question why. Now I have to think of solution.

Thanks again!

unsigned int aTuneLookBack=20; Try reducing this to 10 or even 5. Or get an arduino mega

Mark