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
00036 #include <acado_toolkit.hpp>
00037 #include <acado_gnuplot.hpp>
00038
00039
00040 int main( )
00041 {
00042 USING_NAMESPACE_ACADO
00043
00044
00045
00046
00047 DifferentialState xB;
00048 DifferentialState xW;
00049 DifferentialState vB;
00050 DifferentialState vW;
00051
00052 Disturbance R;
00053 Control F;
00054
00055 Parameter mB;
00056 double mW = 50.0;
00057 double kS = 20000.0;
00058 double kT = 200000.0;
00059
00060
00061
00062
00063 DifferentialEquation f;
00064
00065 f << dot(xB) == vB;
00066 f << dot(xW) == vW;
00067 f << dot(vB) == ( -kS*xB + kS*xW + F ) / mB;
00068 f << dot(vW) == ( kS*xB - (kT+kS)*xW + kT*R - F ) / mW;
00069
00070 OutputFcn g;
00071 g << xB;
00072 g << 500.0*vB + F;
00073
00074 DynamicSystem dynSys( f,g );
00075
00076
00077
00078
00079 Process myProcess;
00080
00081 myProcess.setDynamicSystem( dynSys,INT_RK45 );
00082 myProcess.set( ABSOLUTE_TOLERANCE,1.0e-8 );
00083
00084 DVector x0( 4 );
00085 x0.setZero( );
00086 x0( 0 ) = 0.01;
00087
00088 myProcess.initializeStartValues( x0 );
00089 myProcess.setProcessDisturbance( "road.txt" );
00090
00091 myProcess.set( PLOT_RESOLUTION,HIGH );
00092
00093 GnuplotWindow window;
00094 window.addSubplot( xB, "Body Position [m]" );
00095 window.addSubplot( xW, "Wheel Position [m]" );
00096 window.addSubplot( vB, "Body Velocity [m/s]" );
00097 window.addSubplot( vW, "Wheel Velocity [m/s]" );
00098
00099 window.addSubplot( F,"Damping Force [N]" );
00100 window.addSubplot( mB,"Body Mass [kg]" );
00101 window.addSubplot( R, "Road Disturbance" );
00102 window.addSubplot( g(0),"Output 1" );
00103 window.addSubplot( g(1),"Output 2" );
00104
00105 myProcess << window;
00106
00107
00108
00109
00110 VariablesGrid u( 1,0.0,1.0,6 );
00111
00112 u( 0,0 ) = 10.0;
00113 u( 1,0 ) = -200.0;
00114 u( 2,0 ) = 200.0;
00115 u( 3,0 ) = 0.0;
00116 u( 4,0 ) = 0.0;
00117 u( 5,0 ) = 0.0;
00118
00119 DVector p( 1 );
00120 p(0) = 350.0;
00121
00122 myProcess.init( 0.0 );
00123 myProcess.run( u,p );
00124
00125
00126 VariablesGrid xSim, ySim;
00127
00128 myProcess.getLast( LOG_SIMULATED_DIFFERENTIAL_STATES,xSim );
00129 xSim.print( "Simulated Differential States" );
00130
00131 myProcess.getLast( LOG_PROCESS_OUTPUT,ySim );
00132 ySim.print( "Process Output" );
00133
00134
00135 return 0;
00136 }
00137
00138
00139