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
00027
00035 #include <acado_toolkit.hpp>
00036 #include <acado_gnuplot.hpp>
00037
00038
00039 int main( ){
00040
00041 USING_NAMESPACE_ACADO
00042
00043
00044
00045 DifferentialState x;
00046 DifferentialState l;
00047 AlgebraicState z;
00048 Control u;
00049 DifferentialEquation f;
00050
00051
00052
00053
00054
00055 f << dot(x) == -x + 0.5*x*x + u + 0.5*z ;
00056 f << dot(l) == x*x + 3.0*u*u ;
00057 f << 0 == z + exp(z) - 1.0 + x ;
00058
00059
00060
00061
00062 OCP ocp( 0.0, 5.0, 10 );
00063 ocp.minimizeMayerTerm( l );
00064
00065 ocp.subjectTo( f );
00066
00067
00068
00069
00070
00071 OutputFcn identity;
00072 DynamicSystem dynamicSystem( f,identity );
00073
00074 Process process( dynamicSystem,INT_BDF );
00075
00076
00077
00078
00079
00080
00081
00082 RealTimeAlgorithm alg( ocp,0.5 );
00083
00084 StaticReferenceTrajectory zeroReference;
00085 Controller controller( alg,zeroReference );
00086
00087
00088
00089
00090 SimulationEnvironment sim( 0.0,15.0,process,controller );
00091
00092 DVector x0(2);
00093 x0(0) = 1;
00094 x0(1) = 0;
00095
00096 sim.init( x0 );
00097 sim.run( );
00098
00099
00100
00101
00102 VariablesGrid diffStates;
00103 sim.getProcessDifferentialStates( diffStates );
00104 diffStates.printToFile( "diffStates.txt" );
00105 diffStates.printToFile( "diffStates.m","DIFFSTATES",PS_MATLAB );
00106
00107 VariablesGrid sampledProcessOutput;
00108 sim.getSampledProcessOutput( sampledProcessOutput );
00109 sampledProcessOutput.printToFile( "sampledOut.txt" );
00110 sampledProcessOutput.printToFile( "sampledOut.m","OUT",PS_MATLAB );
00111
00112 VariablesGrid feedbackControl;
00113 sim.getFeedbackControl( feedbackControl );
00114 feedbackControl.printToFile( "controls.txt" );
00115 feedbackControl.printToFile( "controls.m","CONTROL",PS_MATLAB );
00116
00117 VariablesGrid algStates;
00118 sim.getProcessAlgebraicStates( algStates );
00119 algStates.printToFile( "algStates.txt" );
00120 algStates.printToFile( "algStates.m","ALGSTATES",PS_MATLAB );
00121
00122
00123 GnuplotWindow window;
00124 window.addSubplot( diffStates(0), "DIFFERENTIAL STATE: x" );
00125 window.addSubplot( diffStates(1), "DIFFERENTIAL STATE: l" );
00126 window.addSubplot( algStates(0), "ALGEBRAIC STATE: z" );
00127 window.addSubplot( feedbackControl(0), "CONTRUL: u" );
00128 window.plot( );
00129
00130
00131 return 0;
00132 }
00133
00134
00135