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
00047 DifferentialState phi;
00048 DifferentialState dphi;
00049
00050 Parameter l;
00051 Parameter alpha;
00052 Parameter g;
00053
00054 Control F;
00055
00056
00057
00058 double const m = 1.0;
00059
00060
00061
00062
00063
00064 DifferentialEquation f;
00065
00066 f << dot(phi ) == dphi;
00067 f << dot(dphi) == -(g/l)*sin(phi) - alpha*dphi + F/m;
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079 Function h;
00080 h << phi;
00081
00082
00083
00084
00085 DMatrix S(1,1);
00086 S(0,0) = 1.0/pow(0.1,2);
00087
00088
00089
00090
00091
00092
00093
00094 VariablesGrid measurements;
00095 measurements.read( "parameter_estimation_data2.txt" );
00096
00097 if( measurements.isEmpty() == BT_TRUE )
00098 printf("The file \"parameter_estimation_data2.txt\" can't be opened.");
00099
00100
00101
00102
00103
00104
00105 VariablesGrid F_reference;
00106 F_reference.read( "parameter_estimation_controls.txt" );
00107
00108 if( F_reference.isEmpty() == BT_TRUE )
00109 printf("The file \"parameter_estimation_controls.txt\" can't be opened.");
00110
00111
00112
00113
00114
00115 OCP ocp( measurements.getTimePoints() );
00116
00117 ocp.minimizeLSQ( S, h, measurements );
00118 ocp.subjectTo( f );
00119
00120 ocp.subjectTo( 0.0 <= alpha <= 4.0 );
00121 ocp.subjectTo( 0.0 <= l <= 2.0 );
00122
00123 ocp.subjectTo( F == F_reference(0) );
00124 ocp.subjectTo( g == 9.81 );
00125
00126
00127
00128
00129 GnuplotWindow window( PLOT_NEVER );
00130
00131 window.addSubplot( phi, "The angle phi" );
00132 window.addSubplot( dphi, "The angular velocity dphi " );
00133 window.addSubplot( l, "The length of the pendulum l" );
00134 window.addSubplot( alpha,"Frictional constant alpha " );
00135 window.addSubplot( F, "Control input (force) F" );
00136
00137
00138
00139
00140 ParameterEstimationAlgorithm algorithm(ocp);
00141
00142 algorithm << window;
00143 algorithm.initializeDifferentialStates( "parameter_estimation_data2.txt" );
00144 algorithm.set(LEVENBERG_MARQUARDT, 1e-5);
00145
00146 algorithm.solve();
00147
00148
00149
00150
00151 VariablesGrid parameters;
00152 algorithm.getParameters( parameters );
00153
00154
00155 printf("\n\nResults for the parameters: \n");
00156 printf("-----------------------------------------------\n");
00157 printf(" l = %.3e \n", parameters(0,0) );
00158 printf(" alpha = %.3e \n", parameters(0,1) );
00159 printf(" g = %.3e \n", parameters(0,2) );
00160 printf("-----------------------------------------------\n\n\n");
00161
00162
00163
00164
00165 algorithm.getPlotWindow( window );
00166
00167 window.addData( 0, measurements(0) );
00168
00169 window.plot( );
00170
00171 return 0;
00172 }
00173
00174
00175