Setting-Up More Classical Feedback Controllers

Table of Contents

This tutorial explains how to setup a basic MPC controller. Again, we consider a simple actively damped quarter car model.

Implementation of a PID controller for a Quarter Car

The following piece of code sets-up a PID controller that could be used to control a quarter car:

#include <include/acado_gnuplot/gnuplot_window.hpp>
int main( )
{
// SETTING UP THE FEEDBACK CONTROLLER:
// -----------------------------------
PIDcontroller pid( 4,1,0.01 );
Vector pWeights( 4 );
pWeights(0) = 1000.0;
pWeights(1) = -1000.0;
pWeights(2) = 1000.0;
pWeights(3) = -1000.0;
Vector dWeights( 4 );
dWeights(0) = 0.0;
dWeights(1) = 0.0;
dWeights(2) = 20.0;
dWeights(3) = -20.0;
pid.setProportionalWeights( pWeights );
pid.setDerivativeWeights( dWeights );
pid.setControlLowerLimit( 0,-200.0 );
pid.setControlUpperLimit( 0, 200.0 );
Controller controller( pid,zeroReference );
// INITIALIZE CONTROLLER AND PERFORM A STEP:
// -----------------------------------------
Vector y( 4 );
y.setZero( );
y(0) = 0.01;
controller.init( 0.0,y );
controller.step( 0.0,y );
Vector u;
controller.getU( u );
u.print( "Feedback control" );
return 0;
}

First, a PID controller comprising four inputs and one output with a sampling time of 10ms is defined. In case the number of outputs equls the number of inputs, all outputs are calculated component-wise; otherwise, as in our example, the PID terms of all inputs are summed to yield the single output. Second, proportional and derivative weights are set. Third, lower and upper limits are specified for the control output, i.e. if the control signal exceed these limits, it is clipped. Finally, the controller is initialized, one step is performed and the control signal is printed.

Implementation of an LQR controller for a Quarter Car

The following piece of code sets-up an LQR controller based on the quarter car model:

#include <include/acado_gnuplot/gnuplot_window.hpp>
int main( )
{
// SETTING UP THE FEEDBACK CONTROLLER:
// -----------------------------------
Matrix K( 1,4 );
K(0,0) = -3.349222044080232e+04;
K(0,1) = -3.806600292165519e+03;
K(0,2) = 9.999999999999985e+02;
K(0,3) = -1.040810121403324e+03;
LinearStateFeedback lqr( K,0.025 );
lqr.setControlLowerLimit( 0,-200.0 );
lqr.setControlUpperLimit( 0, 200.0 );
Controller controller( pid,zeroReference );
// INITIALIZE CONTROLLER AND PERFORM A STEP:
// -----------------------------------------
Vector y( 4 );
y.setZero( );
y(0) = 0.01;
controller.init( 0.0,y );
controller.step( 0.0,y );
Vector u;
controller.getU( u );
u.print( "Feedback control" );
return 0;
}

First, the gain matrix of the LQR controller is defined (that has been calculated before-hand). Afterwards, the linear state feedback controller is defined by specifying the LQR gain matrix as well as a sampling time of 25ms. Third, lower and upper limits are specified for the control output, i.e. if the control signal exceed these limits, it is clipped. Finally, the controller is initialized, one step is performed and the control signal is printed.

Next example: Performing a Basic Closed-Loop MPC Simulation



acado
Author(s): Milan Vukov, Rien Quirynen
autogenerated on Mon Jun 10 2019 12:35:22