00001 /* 00002 * This file is part of ACADO Toolkit. 00003 * 00004 * ACADO Toolkit -- A Toolkit for Automatic Control and Dynamic Optimization. 00005 * Copyright (C) 2008-2014 by Boris Houska, Hans Joachim Ferreau, 00006 * Milan Vukov, Rien Quirynen, KU Leuven. 00007 * Developed within the Optimization in Engineering Center (OPTEC) 00008 * under supervision of Moritz Diehl. All rights reserved. 00009 * 00010 * ACADO Toolkit is free software; you can redistribute it and/or 00011 * modify it under the terms of the GNU Lesser General Public 00012 * License as published by the Free Software Foundation; either 00013 * version 3 of the License, or (at your option) any later version. 00014 * 00015 * ACADO Toolkit is distributed in the hope that it will be useful, 00016 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00017 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00018 * Lesser General Public License for more details. 00019 * 00020 * You should have received a copy of the GNU Lesser General Public 00021 * License along with ACADO Toolkit; if not, write to the Free Software 00022 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 00023 * 00024 */ 00025 00026 00027 00035 #include <acado_optimal_control.hpp> 00036 #include <acado_gnuplot.hpp> 00037 00038 00039 /* >>> start tutorial code >>> */ 00040 int main( ){ 00041 00042 USING_NAMESPACE_ACADO; 00043 00044 00045 // INTRODUCE THE VARIABLES: 00046 // ------------------------- 00047 00048 DifferentialState x1,x2; 00049 Control u; 00050 Parameter p; 00051 Parameter T; 00052 DifferentialEquation f(0.0,T); 00053 00054 const double t_start = 0.0; 00055 00056 00057 // DEFINE A DIFFERENTIAL EQUATION: 00058 // ------------------------------- 00059 00060 f << dot(x1) == (1.0-x2*x2)*x1 - x2 + p*u; 00061 f << dot(x2) == x1; 00062 00063 00064 // DEFINE AN OPTIMAL CONTROL PROBLEM: 00065 // ---------------------------------- 00066 OCP ocp( t_start, T, 27 ); 00067 00068 00069 // ocp.minimizeMayerTerm( T ); 00070 ocp.minimizeLagrangeTerm(10*x1*x1 + 10*x2*x2 + u*u); 00071 00072 ocp.subjectTo( f ); 00073 ocp.subjectTo( AT_START, x1 == 0.0 ); 00074 ocp.subjectTo( AT_START, x2 == 1.0 ); 00075 00076 ocp.subjectTo( AT_END , x1 == 0.0 ); 00077 ocp.subjectTo( AT_END , x2 == 0.0 ); 00078 00079 ocp.subjectTo( -0.5 <= u <= 1.0 ); 00080 00081 ocp.subjectTo( p == 1.0 ); 00082 ocp.subjectTo( 0.0 <= T <= 20.0 ); 00083 00084 00085 // VISUALIZE THE RESULTS IN A GNUPLOT WINDOW: 00086 // ------------------------------------------ 00087 GnuplotWindow window; 00088 window << x1; 00089 window << x2; 00090 window << u; 00091 window << T; 00092 00093 // DEFINE AN OPTIMIZATION ALGORITHM AND SOLVE THE OCP: 00094 // --------------------------------------------------- 00095 OptimizationAlgorithm algorithm(ocp); 00096 00097 algorithm.initializeControls("van_der_pol_controls.txt"); 00098 00099 algorithm << window; 00100 algorithm.solve(); 00101 00102 algorithm.getControls("van_der_pol_controls2.txt"); 00103 00104 return 0; 00105 } 00106 /* <<< end tutorial code <<< */ 00107 00108