Difference between revisions of "Robotino3 PI controller"

From RobotinoWiki
(Discrete PI controller)
(Discrete PI controller)
Line 11: Line 11:
  
 
e) is derived by subtracting d) from c). e) is the so called velocity form of the discretised PI controller.
 
e) is derived by subtracting d) from c). e) is the so called velocity form of the discretised PI controller.
 +
 +
==Implementation in Robotino's microcontroller==
 +
<pre>
 +
//K  - proportional gain
 +
//Ki - gain
 +
//ss - speed set-point
 +
//y  - actual speed
 +
//u  - control signal
 +
//ud - decay factor to bring u down to zero in the case that err and ss are both 0 already
 +
//up - u(t-1)
 +
//ep - err(t-1)
 +
 +
float err = ss - y;
 +
 +
float u;
 +
 +
if( 0 == Ki )
 +
{
 +
u = K * err; // There is no integral term
 +
}
 +
else
 +
{
 +
u = motor_uant[motor] + K * (err - motor_errant[motor]) + Ki * err;
 +
}
 +
 +
if( 0 == ss && 0 == err )
 +
{
 +
u *= ud;
 +
}
 +
 +
if( u < 1.0f && u > -1.0f )
 +
{
 +
u = 0;
 +
}
 +
 +
up = u;
 +
ep = err;
 +
 +
if( u > 255.0f ) u = 255.0f;
 +
else if( u < -255.0f ) u = -255.0f;
 +
</pre>

Revision as of 14:28, 1 October 2012

Discrete PI controller

Pi controller discrete formula.png

a) is the PI controller in continuous time domain form.

b) is the approximation of the integral by a discrete sum.

c) is the resulting discretised PI controller.

d) is the discretised PI control law time shift back one interval.

e) is derived by subtracting d) from c). e) is the so called velocity form of the discretised PI controller.

Implementation in Robotino's microcontroller

//K  - proportional gain
//Ki - gain
//ss - speed set-point
//y  - actual speed
//u  - control signal
//ud - decay factor to bring u down to zero in the case that err and ss are both 0 already
//up - u(t-1)
//ep - err(t-1)

float err = ss - y;

float u;

if( 0 == Ki )
{
	u = K * err; // There is no integral term
}
else
{
	u = motor_uant[motor] + K * (err - motor_errant[motor]) + Ki * err;
}

if( 0 == ss && 0 == err )
{
	u *= ud;
}

if( u < 1.0f && u > -1.0f )
{
	u = 0;
}

up = u;
ep = err;

if( u > 255.0f ) u = 255.0f;
else if( u < -255.0f ) u = -255.0f;