Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #include <acado_code_generation.hpp>
00027
00028 USING_NAMESPACE_ACADO
00029
00030 int main(int argc, char * const argv[ ])
00031 {
00032
00033
00034
00035
00036 DifferentialState x, y, w, dx, dy, dw;
00037 AlgebraicState mu;
00038 Control F;
00039
00040 IntermediateState c, dc;
00041
00042 const double m = 1.0;
00043 const double mc = 1.0;
00044 const double L = 1.0;
00045 const double g = 9.81;
00046 const double p = 5.0;
00047
00048 c = 0.5 * ((x - w) * (x - w) + y * y - L * L);
00049 dc = dy * y + (dw - dx) * (w - x);
00050
00051
00052
00053
00054
00055 DifferentialEquation f;
00056
00057 f << 0 == dot( x ) - dx;
00058 f << 0 == dot( y ) - dy;
00059 f << 0 == dot( w ) - dw;
00060
00061 f << 0 == m * dot( dx ) + (x - w) * mu;
00062 f << 0 == m * dot( dy ) + y * mu + m * g;
00063 f << 0 == mc * dot( dw ) + (w - x) * mu - F;
00064
00065 f << 0 == (x - w) * dot( dx ) + y * dot( dy ) + (w - x) * dot( dw )
00066 - (-p * p * c - 2 * p * dc - dy * dy - (dw - dx) * (dw - dx));
00067
00068
00069
00070
00071
00072 Function rf;
00073 Function rfN;
00074
00075 rf << x << y << w << dx << dy << dw << F;
00076 rfN << x << y << w << dx << dy << dw;
00077
00078 DMatrix W = eye<double>( rf.getDim() );
00079 DMatrix WN = eye<double>( rfN.getDim() ) * 10;
00080
00081
00082
00083
00084
00085 const int N = 10;
00086 const int Ni = 4;
00087 const double Ts = 0.1;
00088
00089 OCP ocp(0, N * Ts, N);
00090
00091 ocp.subjectTo( f );
00092
00093 ocp.minimizeLSQ(W, rf);
00094 ocp.minimizeLSQEndTerm(WN, rfN);
00095
00096 ocp.subjectTo(-20 <= F <= 20);
00097
00098
00099
00100
00101
00102 OCPexport mpc( ocp );
00103
00104 mpc.set(HESSIAN_APPROXIMATION, GAUSS_NEWTON);
00105 mpc.set(DISCRETIZATION_TYPE, MULTIPLE_SHOOTING);
00106
00107 mpc.set(INTEGRATOR_TYPE, INT_IRK_RIIA3);
00108 mpc.set(NUM_INTEGRATOR_STEPS, N * Ni);
00109
00110 mpc.set(SPARSE_QP_SOLUTION, FULL_CONDENSING);
00111
00112 mpc.set(QP_SOLVER, QP_QPOASES);
00113
00114 mpc.set(HOTSTART_QP, YES);
00115
00116
00117
00118
00119
00120
00121 mpc.set(GENERATE_TEST_FILE, NO);
00122 mpc.set(GENERATE_MAKE_FILE, NO);
00123 mpc.set(GENERATE_MATLAB_INTERFACE, YES);
00124
00125
00126
00127
00128 if (mpc.exportCode( "pendulum_dae_nmpc_export" ) != SUCCESSFUL_RETURN)
00129 exit( EXIT_FAILURE );
00130
00131 mpc.printDimensionsQP( );
00132
00133 return EXIT_SUCCESS;
00134 }