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
00046 DifferentialState xB;
00047 DifferentialState xW;
00048 DifferentialState vB;
00049 DifferentialState vW;
00050
00051 Control F;
00052 Disturbance R;
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 h << F;
00079
00080 DMatrix Q(5,5);
00081 Q(0,0) = 10.0;
00082 Q(1,1) = 10.0;
00083 Q(2,2) = 1.0;
00084 Q(3,3) = 1.0;
00085 Q(4,4) = 1.0e-8;
00086
00087 DVector r(5);
00088 r.setAll( 0.0 );
00089
00090
00091
00092
00093 const double tStart = 0.0;
00094 const double tEnd = 1.0;
00095
00096 OCP ocp( tStart, tEnd, 20 );
00097
00098 ocp.minimizeLSQ( Q, h, r );
00099
00100 ocp.subjectTo( f );
00101
00102 ocp.subjectTo( -200.0 <= F <= 200.0 );
00103 ocp.subjectTo( R == 0.0 );
00104
00105
00106
00107
00108 RealTimeAlgorithm alg( ocp,0.025 );
00109 alg.set( MAX_NUM_ITERATIONS, 1 );
00110 alg.set( PLOT_RESOLUTION, MEDIUM );
00111
00112 GnuplotWindow window;
00113 window.addSubplot( xB, "Body Position [m]" );
00114 window.addSubplot( xW, "Wheel Position [m]" );
00115 window.addSubplot( vB, "Body Velocity [m/s]" );
00116 window.addSubplot( vW, "Wheel Velocity [m/s]" );
00117 window.addSubplot( F, "Damping Force [N]" );
00118 window.addSubplot( R, "Road Excitation [m]" );
00119
00120 alg << window;
00121
00122
00123
00124
00125 StaticReferenceTrajectory zeroReference( "ref.txt" );
00126
00127 Controller controller( alg,zeroReference );
00128
00129 DVector y( 4 );
00130 y.setZero( );
00131 y(0) = 0.01;
00132
00133 if (controller.init( 0.0,y ) != SUCCESSFUL_RETURN)
00134 exit( 1 );
00135 if (controller.step( 0.0,y ) != SUCCESSFUL_RETURN)
00136 exit( 1 );
00137
00138 return EXIT_SUCCESS;
00139 }
00140
00141
00142