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 DVector mean( 1 ), amplitude( 1 );
00080 mean.setZero( );
00081 amplitude.setAll( 50.0 );
00082
00083 GaussianNoise myNoise( mean,amplitude );
00084
00085 Actuator myActuator( 1,1 );
00086
00087 myActuator.setControlNoise( myNoise,0.1 );
00088 myActuator.setControlDeadTimes( 0.1 );
00089
00090 myActuator.setParameterDeadTimes( 0.2 );
00091
00092
00093
00094 mean.setZero( );
00095 amplitude.setAll( 0.005 );
00096 UniformNoise myOutputNoise1( mean,amplitude );
00097
00098 mean.setAll( 10.0 );
00099 amplitude.setAll( 50.0 );
00100 GaussianNoise myOutputNoise2( mean,amplitude );
00101
00102 Sensor mySensor( 2 );
00103 mySensor.setOutputNoise( 0,myOutputNoise1,0.1 );
00104 mySensor.setOutputNoise( 1,myOutputNoise2,0.1 );
00105 mySensor.setOutputDeadTimes( 0.2 );
00106
00107
00108 Process myProcess;
00109
00110 myProcess.setDynamicSystem( dynSys,INT_RK45 );
00111 myProcess.set( ABSOLUTE_TOLERANCE,1.0e-8 );
00112
00113 myProcess.setActuator( myActuator );
00114 myProcess.setSensor( mySensor );
00115
00116 DVector x0( 4 );
00117 x0.setZero( );
00118 x0( 0 ) = 0.01;
00119
00120 myProcess.initializeStartValues( x0 );
00121 myProcess.setProcessDisturbance( "road.txt" );
00122
00123 myProcess.set( PLOT_RESOLUTION,HIGH );
00124
00125
00126 myProcess.set( OUTPUT_PLOTTING,PLOT_REAL );
00127
00128 GnuplotWindow window;
00129 window.addSubplot( xB, "Body Position [m]" );
00130 window.addSubplot( xW, "Wheel Position [m]" );
00131 window.addSubplot( vB, "Body Velocity [m/s]" );
00132 window.addSubplot( vW, "Wheel Velocity [m/s]" );
00133
00134 window.addSubplot( F,"Damping Force [N]" );
00135 window.addSubplot( mB,"Body Mass [kg]" );
00136 window.addSubplot( R, "Road Disturbance" );
00137 window.addSubplot( g(0),"Output 1" );
00138 window.addSubplot( g(1),"Output 2" );
00139
00140 myProcess << window;
00141
00142
00143
00144
00145 VariablesGrid u( 1,0.0,1.0,6 );
00146
00147 u( 0,0 ) = 10.0;
00148 u( 1,0 ) = -200.0;
00149 u( 2,0 ) = 200.0;
00150 u( 3,0 ) = 0.0;
00151 u( 4,0 ) = 0.0;
00152 u( 5,0 ) = 0.0;
00153
00154 DVector p( 1 );
00155 p(0) = 350.0;
00156
00157 DVector pInit( 1 );
00158 pInit(0) = 300.0;
00159
00160 myProcess.init( 0.0,x0,u.getFirstVector(),pInit );
00161 myProcess.run( u,p );
00162
00163
00164 VariablesGrid xSim, ySim;
00165
00166
00167
00168
00169
00170
00171
00172 return 0;
00173 }
00174
00175
00176