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
00033 #include <acado_code_generation.hpp>
00034
00035
00036 using namespace std;
00037 USING_NAMESPACE_ACADO
00038
00039 int main()
00040 {
00041
00042
00043
00044 DifferentialState xT;
00045 DifferentialState vT;
00046 IntermediateState aT;
00047 DifferentialState xL;
00048 DifferentialState vL;
00049 IntermediateState aL;
00050 DifferentialState phi;
00051 DifferentialState omega;
00052
00053 DifferentialState uT;
00054 DifferentialState uL;
00055
00056 Control duT;
00057 Control duL;
00058
00059
00060
00061
00062 const double tau1 = 0.012790605943772;
00063 const double a1 = 0.047418203070092;
00064 const double tau2 = 0.024695192379264;
00065 const double a2 = 0.034087337273386;
00066 const double g = 9.81;
00067 const double c = 0.0;
00068 const double m = 1318.0;
00069
00070
00071
00072
00073 DifferentialEquation f;
00074 aT = -1.0 / tau1 * vT + a1 / tau1 * uT;
00075 aL = -1.0 / tau2 * vL + a2 / tau2 * uL;
00076
00077 f << 0 == dot( xT ) - vT;
00078 f << 0 == dot( vT ) - aT;
00079 f << 0 == dot( xL ) - vL;
00080 f << 0 == dot( vL ) - aL;
00081 f << 0 == dot( phi ) - omega;
00082 f << 0 == dot( omega ) - 1.0/xL*(-g*sin(phi)-aT*cos(phi)
00083 -2*vL*omega-c*omega/(m*xL));
00084 f << 0 == dot( uT ) - duT;
00085 f << 0 == dot( uL ) - duL;
00086
00087
00088
00089
00090 OutputFcn h;
00091
00092 h << aT;
00093 h << aL;
00094
00095
00096
00097
00098
00099 cout << "-----------------------------------------\n Using an equidistant grid:\n-----------------------------------------\n";
00100
00101 SIMexport sim( 1, 0.1 );
00102
00103 sim.setModel( f );
00104 sim.addOutput( h, 5 );
00105
00106 sim.set( INTEGRATOR_TYPE, INT_IRK_RIIA5 );
00107 sim.set( NUM_INTEGRATOR_STEPS, 5 );
00108 sim.setTimingSteps( 10000 );
00109
00110 sim.exportAndRun( "crane_export", "init_crane.txt", "controls_crane.txt" );
00111
00112
00113 cout << "-----------------------------------------\n Using a provided grid:\n-----------------------------------------\n";
00114
00115 DVector Meas(5);
00116 Meas(0) = 0.0;
00117 Meas(1) = 0.2;
00118 Meas(2) = 0.4;
00119 Meas(3) = 0.6;
00120 Meas(4) = 0.8;
00121
00122 SIMexport sim2( 1, 0.1 );
00123
00124 sim2.setModel( f );
00125 sim2.addOutput( h, Meas );
00126
00127 sim2.set( INTEGRATOR_TYPE, INT_IRK_RIIA5 );
00128 sim2.set( NUM_INTEGRATOR_STEPS, 5 );
00129 sim2.setTimingSteps( 10000 );
00130
00131 sim2.exportAndRun( "crane_export", "init_crane.txt", "controls_crane.txt" );
00132
00133 return 0;
00134 }
00135