Skip to main content
deleted 265 characters in body
Source Link
duck
  • 1.3k
  • 10
  • 27

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.

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;

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, float y){

float e;
float vi;
float kp=2.00;
float ki=10.00;

e = r - y;
sum_e_2 =  sum_e_2 + e;   //integrator for controller 2
vi = kp * e + ki * sum_e;

return vi;
}      

function call

vi_1 = PI_1(r_o_1, y_o_1);
vi_2 = PI_2(r_o_2, y_o_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.

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[100]; //for 100 controller.

Your function

float PI_1(float r, float y,int number){

float e;
float vi;
float kp=2.00;
float ki=10.00;

e = r - y;
sum_e[number] =  sum_e[number] + e;    //integrator for controller number
vi = kp * e + ki * sum_e[number];

return vi;
    } 

function call

vi_1 = PI_1(r_o_1, y_o_1,1);
vi_2 = PI_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.

added 755 characters in body
Source Link
duck
  • 1.3k
  • 10
  • 27

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;

Your function

float PI_1(float r, float y){

float e;
static float sum_e=0;
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, float y){

float e;
static float sum_e=0;
float vi;
float kp=2.00;
float ki=10.00;

e = r - y;
sum_e_2 =  sum_e_2 + e;   //integrator for controller 2
vi = kp * e + ki * sum_e;

return vi;
}      

function call

vi_1 = PI_1(r_o_1, y_o_1);
vi_2 = PI_2(r_o_2, y_o_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.

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.

float PI_1(float r, float y){

float e;
static float sum_e=0;
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, float y){

float e;
static float sum_e=0;
float vi;
float kp=2.00;
float ki=10.00;

e = r - y;
sum_e_2 =  sum_e_2 + e;   //integrator for controller 2
vi = kp * e + ki * sum_e;

return vi;
}      

Here is the rough example. There are lot more efficient ways than this, but this should gives you some idea.

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;

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, float y){

float e;
float vi;
float kp=2.00;
float ki=10.00;

e = r - y;
sum_e_2 =  sum_e_2 + e;   //integrator for controller 2
vi = kp * e + ki * sum_e;

return vi;
}      

function call

vi_1 = PI_1(r_o_1, y_o_1);
vi_2 = PI_2(r_o_2, y_o_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.

added 755 characters in body
Source Link
duck
  • 1.3k
  • 10
  • 27

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.

float PI_1(float r, float y){

float e;
static float sum_e=0;
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, float y){

float e;
static float sum_e=0;
float vi;
float kp=2.00;
float ki=10.00;

e = r - y;
sum_e_2 =  sum_e_2 + e;   //integrator for controller 2
vi = kp * e + ki * sum_e;

return vi;
}      

Here is the rough example. There are lot more efficient ways than this, but this should gives you some idea.

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

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.

float PI_1(float r, float y){

float e;
static float sum_e=0;
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, float y){

float e;
static float sum_e=0;
float vi;
float kp=2.00;
float ki=10.00;

e = r - y;
sum_e_2 =  sum_e_2 + e;   //integrator for controller 2
vi = kp * e + ki * sum_e;

return vi;
}      

Here is the rough example. There are lot more efficient ways than this, but this should gives you some idea.

Source Link
duck
  • 1.3k
  • 10
  • 27
Loading