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
00036 #include <acado_toolkit.hpp>
00037 #include <acado_gnuplot.hpp>
00038
00039
00040 int main( ){
00041
00042 USING_NAMESPACE_ACADO;
00043
00044
00045
00046 DifferentialState x;
00047 DifferentialState v;
00048 DifferentialState phi;
00049 DifferentialState dphi;
00050
00051 Control ax;
00052 Disturbance W;
00053
00054 double L = 1.0 ;
00055 double m = 1.0 ;
00056 double g = 9.81;
00057 double b = 0.2 ;
00058
00059
00060
00061
00062 DifferentialEquation f, fSim;
00063
00064 f << dot(x) == v;
00065 f << dot(v) == ax;
00066 f << dot(phi ) == dphi;
00067 f << dot(dphi) == -g/L*sin(phi) -ax/L*cos(phi) - b/(m*L*L)*dphi;
00068
00069 L = 1.2;
00070
00071 fSim << dot(x) == v;
00072 fSim << dot(v) == ax + W;
00073 fSim << dot(phi ) == dphi;
00074 fSim << dot(dphi) == -g/L*sin(phi) -ax/L*cos(phi) - b/(m*L*L)*dphi;
00075
00076
00077
00078
00079 Function h;
00080
00081 h << x;
00082 h << v;
00083 h << phi;
00084 h << dphi;
00085
00086 DMatrix Q(4,4);
00087 Q.setIdentity();
00088
00089 DVector r(4);
00090
00091
00092
00093
00094 const double t_start = 0.0;
00095 const double t_end = 5.0;
00096
00097 OCP ocp( t_start, t_end, 25 );
00098
00099 ocp.minimizeLSQ( Q, h, r );
00100 ocp.subjectTo( f );
00101 ocp.subjectTo( -5.0 <= ax <= 5.0 );
00102
00103
00104
00105
00106 OutputFcn identity;
00107 DynamicSystem dynamicSystem( fSim,identity );
00108
00109 Process process( dynamicSystem,INT_RK45 );
00110
00111 VariablesGrid disturbance; disturbance.read( "dist.txt" );
00112 if (process.setProcessDisturbance( disturbance ) != SUCCESSFUL_RETURN)
00113 exit( EXIT_FAILURE );
00114
00115
00116
00117
00118 RealTimeAlgorithm alg( ocp,0.1 );
00119
00120
00121
00122 StaticReferenceTrajectory zeroReference;
00123
00124 Controller controller( alg,zeroReference );
00125
00126
00127
00128
00129 SimulationEnvironment sim( 0.0,20.0,process,controller );
00130
00131 DVector x0(4);
00132 x0.setZero();
00133 x0(3) = 5.0;
00134
00135 if (sim.init( x0 ) != SUCCESSFUL_RETURN)
00136 exit( EXIT_FAILURE );
00137 if (sim.run( ) != SUCCESSFUL_RETURN)
00138 exit( EXIT_FAILURE );
00139
00140
00141
00142 VariablesGrid diffStates;
00143 if (sim.getProcessDifferentialStates( diffStates ) != SUCCESSFUL_RETURN)
00144 exit( EXIT_FAILURE );
00145
00146 VariablesGrid feedbackControl;
00147 if (sim.getFeedbackControl( feedbackControl ) != SUCCESSFUL_RETURN)
00148 exit( EXIT_FAILURE );
00149
00150 GnuplotWindow window;
00151 window.addSubplot( diffStates(0), "POSITION OF THE TROLLEY" );
00152 window.addSubplot( diffStates(1), "VELOCITY OF THE TROLLEY" );
00153 window.addSubplot( diffStates(2), "PHI" );
00154 window.addSubplot( diffStates(3), "DPHI" );
00155 window.addSubplot( feedbackControl, "Accelaration [m/s^2]" );
00156
00157 window.plot();
00158
00159 diffStates.print( "diffStates.txt" );
00160
00161
00162 return EXIT_SUCCESS;
00163 }
00164
00165