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
00034 #include <acado_toolkit.hpp>
00035 #include <acado_gnuplot.hpp>
00036
00037
00038 int main( )
00039 {
00040 USING_NAMESPACE_ACADO
00041
00042
00043
00044
00045 DifferentialState xB;
00046 DifferentialState xW;
00047 DifferentialState vB;
00048 DifferentialState vW;
00049
00050 Disturbance R;
00051 Control F;
00052
00053 double mB = 350.0;
00054 double mW = 50.0;
00055 double kS = 20000.0;
00056 double kT = 200000.0;
00057
00058
00059
00060
00061 DifferentialEquation f;
00062
00063 f << dot(xB) == vB;
00064 f << dot(xW) == vW;
00065 f << dot(vB) == ( -kS*xB + kS*xW + F ) / mB;
00066 f << dot(vW) == ( kS*xB - (kT+kS)*xW + kT*R - F ) / mW;
00067
00068
00069
00070
00071 OutputFcn identity;
00072 DynamicSystem dynamicSystem( f,identity );
00073
00074 Process process( dynamicSystem,INT_RK45 );
00075
00076 VariablesGrid disturbance; disturbance.read( "road.txt" );
00077 if (process.setProcessDisturbance( disturbance ) != SUCCESSFUL_RETURN)
00078 exit( EXIT_FAILURE );
00079
00080
00081
00082
00083 PIDcontroller pid( 4,1,0.01 );
00084
00085 DVector pWeights( 4 );
00086 pWeights(0) = 1000.0;
00087 pWeights(1) = -1000.0;
00088 pWeights(2) = 1000.0;
00089 pWeights(3) = -1000.0;
00090
00091 DVector dWeights( 4 );
00092 dWeights(0) = 0.0;
00093 dWeights(1) = 0.0;
00094 dWeights(2) = 20.0;
00095 dWeights(3) = -20.0;
00096
00097 pid.setProportionalWeights( pWeights );
00098 pid.setDerivativeWeights( dWeights );
00099
00100 pid.setControlLowerLimit( 0,-200.0 );
00101 pid.setControlUpperLimit( 0, 200.0 );
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116 StaticReferenceTrajectory zeroReference;
00117
00118 Controller controller( pid,zeroReference );
00119
00120
00121
00122
00123
00124 SimulationEnvironment sim( 0.0,2.5,process,controller );
00125
00126 DVector x0(4);
00127 x0.setZero();
00128
00129 if (sim.init( x0 ) != SUCCESSFUL_RETURN)
00130 exit( EXIT_FAILURE );
00131 if (sim.run( ) != SUCCESSFUL_RETURN)
00132 exit( EXIT_FAILURE );
00133
00134
00135
00136 VariablesGrid diffStates;
00137 sim.getProcessDifferentialStates( diffStates );
00138
00139 VariablesGrid feedbackControl;
00140 sim.getFeedbackControl( feedbackControl );
00141
00142 GnuplotWindow window;
00143 window.addSubplot( diffStates(0), "Body Position [m]" );
00144 window.addSubplot( diffStates(1), "Wheel Position [m]" );
00145 window.addSubplot( diffStates(2), "Body Velocity [m/s]" );
00146 window.addSubplot( diffStates(3), "Wheel Velocity [m/s]" );
00147 window.addSubplot( feedbackControl, "Damping Force [N]" );
00148 window.addSubplot( disturbance, "Road Excitation [m]" );
00149 window.plot( );
00150
00151 return EXIT_SUCCESS;
00152 }
00153
00154
00155