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_optimal_control.hpp>
00036 #include <acado_gnuplot.hpp>
00037
00038
00039 int main( ){
00040
00041 USING_NAMESPACE_ACADO
00042
00043
00044
00045
00046 DifferentialState xBody;
00047 DifferentialState xWheel;
00048 DifferentialState vBody;
00049 DifferentialState vWheel;
00050
00051 Disturbance roadExcitation;
00052
00053 Control dampingForce;
00054
00055 double mBody = 350.0;
00056 double mWheel = 50.0;
00057 double kSpring = 20000.0;
00058 double kTire = 200000.0;
00059
00060
00061
00062
00063 DifferentialEquation f;
00064
00065 f << dot(xBody) == vBody;
00066 f << dot(xWheel) == vWheel;
00067 f << dot(vBody) == ( -kSpring*xBody + kSpring*xWheel + dampingForce ) / mBody;
00068 f << dot(vWheel) == ( -kTire*xBody - (kTire+kSpring)*xWheel + kTire*roadExcitation - dampingForce ) / mWheel;
00069
00070
00071
00072
00073 Function h;
00074
00075 h << xBody;
00076 h << xWheel;
00077 h << vBody;
00078 h << vWheel;
00079
00080 DMatrix S(4,4);
00081 DVector r(4);
00082
00083 S.setIdentity();
00084 S(0,0) = 10.0;
00085 S(1,1) = 10.0;
00086
00087 r.setAll( 0.0 );
00088
00089
00090
00091
00092 const double t_start = 0.0;
00093 const double t_end = 1.0;
00094
00095 OCP ocp( t_start, t_end, 20 );
00096
00097 ocp.minimizeLSQ( S, h, r );
00098
00099
00100 ocp.subjectTo( f );
00101
00102 ocp.subjectTo( AT_START, xBody == 0.01 );
00103 ocp.subjectTo( AT_START, xWheel == 0.0 );
00104 ocp.subjectTo( AT_START, vBody == 0.0 );
00105 ocp.subjectTo( AT_START, vWheel == 0.0 );
00106
00107 ocp.subjectTo( -500.0 <= dampingForce <= 500.0 );
00108 ocp.subjectTo( roadExcitation == 0.0 );
00109
00110
00111
00112 GnuplotWindow window1;
00113 window1.addSubplot( xBody, "Body Position [m]" );
00114 window1.addSubplot( xWheel,"Wheel Position [m]" );
00115 window1.addSubplot( vBody, "Body Velocity [m/s]" );
00116 window1.addSubplot( vWheel,"Wheel Velocity [m/s]" );
00117
00118 window1.addSubplot( dampingForce,"Damping Force [N]" );
00119 window1.addSubplot( roadExcitation,"Road Excitation [m]" );
00120
00121
00122
00123
00124 OptimizationAlgorithm algorithm(ocp);
00125
00126 algorithm << window1;
00127
00128
00129
00130 algorithm.set( HESSIAN_APPROXIMATION, GAUSS_NEWTON_WITH_BLOCK_BFGS );
00131
00132
00133 algorithm.set( KKT_TOLERANCE, 1e-6 );
00134
00135
00136
00137 algorithm.solve();
00138
00139
00140 return 0;
00141 }
00142
00143
00144