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 using namespace std;
00039
00040 USING_NAMESPACE_ACADO
00041
00042 int main( )
00043 {
00044
00045
00046 DifferentialState xB;
00047 DifferentialState xW;
00048 DifferentialState vB;
00049 DifferentialState vW;
00050
00051 Control R;
00052 Control F;
00053
00054 double mB = 350.0;
00055 double mW = 50.0;
00056 double kS = 20000.0;
00057 double kT = 200000.0;
00058
00059
00060
00061
00062 DifferentialEquation f;
00063
00064 f << dot(xB) == vB;
00065 f << dot(xW) == vW;
00066 f << dot(vB) == ( -kS*xB + kS*xW + F ) / mB;
00067 f << dot(vW) == ( kS*xB - (kT+kS)*xW + kT*R - F ) / mW;
00068
00069
00070
00071
00072 Function h;
00073
00074 h << xB;
00075 h << xW;
00076 h << vB;
00077 h << vW;
00078
00079 DMatrix Q(4,4);
00080 Q.setIdentity();
00081 Q(0,0) = 10.0;
00082 Q(1,1) = 10.0;
00083
00084 DVector r(4);
00085 r.setAll( 0.0 );
00086
00087
00088
00089
00090 const double t_start = 0.0;
00091 const double t_end = 1.0;
00092
00093 OCP ocp( t_start, t_end, 20 );
00094
00095 ocp.minimizeLSQ( Q, h, r );
00096
00097 ocp.subjectTo( f );
00098
00099 ocp.subjectTo( -500.0 <= F <= 500.0 );
00100 ocp.subjectTo( R == 0.0 );
00101
00102
00103
00104
00105
00106 OutputFcn identity;
00107 DynamicSystem dynamicSystem( f,identity );
00108
00109 Process process( dynamicSystem,INT_RK45 );
00110
00111
00112
00113 RealTimeAlgorithm alg( ocp,0.05 );
00114 alg.set( MAX_NUM_ITERATIONS, 2 );
00115
00116 StaticReferenceTrajectory zeroReference;
00117
00118 Controller controller( alg,zeroReference );
00119
00120
00121
00122
00123 SimulationEnvironment sim( 0.0,3.0,process,controller );
00124
00125 DVector x0(4);
00126 x0(0) = 0.01;
00127 x0(1) = 0.0;
00128 x0(2) = 0.0;
00129 x0(3) = 0.0;
00130
00131 if (sim.init( x0 ) != SUCCESSFUL_RETURN)
00132 exit( EXIT_FAILURE );
00133 if (sim.run( ) != SUCCESSFUL_RETURN)
00134 exit( EXIT_FAILURE );
00135
00136
00137
00138 VariablesGrid sampledProcessOutput;
00139 sim.getSampledProcessOutput( sampledProcessOutput );
00140
00141 VariablesGrid feedbackControl;
00142 sim.getFeedbackControl( feedbackControl );
00143
00144 GnuplotWindow window;
00145 window.addSubplot( sampledProcessOutput(0), "Body Position [m]" );
00146 window.addSubplot( sampledProcessOutput(1), "Wheel Position [m]" );
00147 window.addSubplot( sampledProcessOutput(2), "Body Velocity [m/s]" );
00148 window.addSubplot( sampledProcessOutput(3), "Wheel Velocity [m/s]" );
00149 window.addSubplot( feedbackControl(1), "Damping Force [N]" );
00150 window.addSubplot( feedbackControl(0), "Road Excitation [m]" );
00151 window.plot( );
00152
00153 return EXIT_SUCCESS;
00154 }
00155
00156
00157