The problem is you declare static float sum_e in PI_1 function. The value of will increase everytime PI_1 function is called. In 1 loop, you call PI_1 two times, resulting first call always smaller than second call because of the value of sum_e. Sum of error should be declared as global variable, and each controller has its own "sum" variable.
Declare as global :
float sum_e_1,sum_e_2;sum_e[100]; //for 100 controller.
Your function
float PI_1(float r, float y){
float e;
float vi;
float kp=2.00;
float ki=10.00;
e = r - y;
sum_e_1 = sum_e_1 + e; //integrator for controller 1
vi = kp * e + ki * sum_e;
return vi;
}
//--------------------------------------------
float PI_2(float r, floatint ynumber){
float e;
float vi;
float kp=2.00;
float ki=10.00;
e = r - y;
sum_e_2sum_e[number] = sum_e_2sum_e[number] + e; //integrator for controller 2number
vi = kp * e + ki * sum_e;sum_e[number];
return vi;
} }
function call
vi_1 = PI_1(r_o_1, y_o_1,1);
vi_2 = PI_2PI_1(r_o_2, y_o_2,2);
Here is the rough example. There are lot more efficient ways than this, but this should gives you some idea. You can reduce the code yourself since the values should be correct already.