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( void )
00031 {
00032
00033
00034
00035
00036 double Ts = 0.01;
00037
00038 int N = 20;
00039
00040 int Ni = 1;
00041
00042
00043
00044
00045 DifferentialState xT;
00046 DifferentialState vT;
00047 IntermediateState aT;
00048
00049 DifferentialState xL;
00050 DifferentialState vL;
00051 IntermediateState aL;
00052
00053 DifferentialState phi;
00054 DifferentialState omega;
00055
00056 DifferentialState uT;
00057 DifferentialState uL;
00058
00059 Control duT;
00060 Control duL;
00061
00062
00063
00064
00065 const double tau1 = 0.012790605943772;
00066 const double a1 = 0.047418203070092;
00067 const double tau2 = 0.024695192379264;
00068 const double a2 = 0.034087337273386;
00069 const double g = 9.81;
00070
00071
00072
00073
00074
00075
00076 DifferentialEquation f;
00077 aT = -1.0 / tau1 * vT + a1 / tau1 * uT;
00078 aL = -1.0 / tau2 * vL + a2 / tau2 * uL;
00079
00080 f << dot(xT) == vT;
00081 f << dot(vT) == aT;
00082 f << dot(xL) == vL;
00083 f << dot(vL) == aL;
00084 f << dot(phi) == omega;
00085 f << dot(omega)
00086 == -(g * sin(phi) + a1 * duT * cos(phi) + 2 * vL * omega) / xL;
00087 f << dot(uT) == duT;
00088 f << dot(uL) == duL;
00089
00090
00091
00092
00093 OCP ocp(0.0, N * Ts, N);
00094
00095 ocp.subjectTo( f );
00096
00097
00098 Function h;
00099
00100 h << xT << xL << phi << uT << uL << duT << duL;
00101
00102
00103 DMatrix W = eye<double>( 7 );
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113 Function hN;
00114 hN << xT << xL << phi << uT << uL;
00115
00116 DMatrix WN = eye<double>( 5 );
00117 WN(0, 0) = W(0, 0);
00118 WN(1, 1) = W(1, 1);
00119 WN(2, 2) = W(2, 2);
00120 WN(3, 3) = W(3, 3);
00121 WN(4, 4) = W(4, 4);
00122
00123 ocp.minimizeLSQ(W, h);
00124 ocp.minimizeLSQEndTerm(WN, hN);
00125
00126 OCPexport mhe( ocp );
00127
00128 mhe.set(INTEGRATOR_TYPE, INT_RK4);
00129 mhe.set(NUM_INTEGRATOR_STEPS, N * Ni);
00130
00131 mhe.set(HESSIAN_APPROXIMATION, GAUSS_NEWTON);
00132 mhe.set(DISCRETIZATION_TYPE, MULTIPLE_SHOOTING);
00133
00134 mhe.set(HOTSTART_QP, YES);
00135
00136
00137 mhe.set(SPARSE_QP_SOLUTION, CONDENSING);
00138 mhe.set(FIX_INITIAL_STATE, NO);
00139
00140
00141
00142 if (mhe.exportCode("crane_kul_mhe_export") != SUCCESSFUL_RETURN)
00143 exit( EXIT_FAILURE );
00144
00145 mhe.printDimensionsQP( );
00146
00147 return EXIT_SUCCESS;
00148 }