crane_nbi.cpp
Go to the documentation of this file.
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 
00034 #include <acado_optimal_control.hpp>
00035 #include <acado_gnuplot.hpp>
00036 
00037 
00038 /* >>> start tutorial code >>> */
00039 int main( ){
00040 
00041     USING_NAMESPACE_ACADO
00042 
00043 
00044     // INTRODUCE THE VARIABLES:
00045     // -------------------------
00046     DifferentialState     x  , dx  ;   // the position of the mounting point and its velocity
00047     DifferentialState     L  , dL  ;   // the length of the cable and its velocity
00048     DifferentialState     phi, dphi;   // the angle phi and its velocity
00049     DifferentialState     P0,P1,P2 ;   // the variance-covariance states
00050 
00051     Control               ddx, ddL ;   // the accelarations
00052     Parameter                    T ;   // duration of the maneuver
00053     Parameter                gamma ;   // the confidence level
00054 
00055     double const           g = 9.81;   // the gravitational constant
00056     double const           m = 10.0;   // the mass at the end of the crane
00057     double const           b = 0.1 ;   // a frictional constant
00058 
00059     DifferentialEquation   f(0.0,T);
00060 
00061     const double F2 = 50.0;
00062 
00063 
00064     // DEFINE A DIFFERENTIAL EQUATION:
00065     // -------------------------------
00066     f << dot(x   )  == dx   + 0.000001*gamma; // small regularization term
00067     f << dot(dx  )  == ddx ;
00068     f << dot(L   )  == dL  ;
00069     f << dot(dL  )  == ddL ;
00070     f << dot(phi )  == dphi;
00071     f << dot(dphi)  == -(g/L)*phi - ( b + 2.0*dL/L )*dphi - ddx/L;
00072 
00073     f << dot(P0)    == 2.0*P1;
00074     f << dot(P1)    == -(g/L)*P0 - ( b + 2.0*dL/L )*P1 + P2;
00075     f << dot(P2)    == -2.0*(g/L)*P1 - 2.0*( b + 2.0*dL/L )*P2 + F2/(m*m*L*L);
00076 
00077 
00078     // DEFINE AN OPTIMAL CONTROL PROBLEM:
00079     // ----------------------------------
00080     OCP ocp(  0.0, T, 20 );
00081     ocp.minimizeMayerTerm( 0, T       );
00082     ocp.minimizeMayerTerm( 1, -gamma  );
00083 
00084     ocp.subjectTo( f );
00085 
00086     ocp.subjectTo( AT_START, x    ==    0.0 );
00087     ocp.subjectTo( AT_START, dx   ==    0.0 );
00088     ocp.subjectTo( AT_START, L    ==   70.0 );
00089     ocp.subjectTo( AT_START, dL   ==    0.0 );
00090     ocp.subjectTo( AT_START, phi  ==    0.0 );
00091     ocp.subjectTo( AT_START, dphi ==    0.0 );
00092 
00093     ocp.subjectTo( AT_START, P0   ==    0.0 );
00094     ocp.subjectTo( AT_START, P1   ==    0.0 );
00095     ocp.subjectTo( AT_START, P2   ==    0.0 );
00096 
00097     ocp.subjectTo( AT_END  , x    ==   10.0 );
00098     ocp.subjectTo( AT_END  , dx   ==    0.0 );
00099     ocp.subjectTo( AT_END  , L    ==   70.0 );
00100     ocp.subjectTo( AT_END  , dL   ==    0.0 );
00101 
00102     ocp.subjectTo( AT_END  , -0.075 <= phi - gamma*sqrt(P0)           );
00103     ocp.subjectTo( AT_END  ,           phi + gamma*sqrt(P0) <= 0.075  );
00104 
00105     ocp.subjectTo( gamma >= 0.0 );
00106 
00107     ocp.subjectTo( 5.0 <=  T  <=  17.0 );
00108 
00109     ocp.subjectTo( -0.3 <= ddx <= 0.3 );
00110     ocp.subjectTo( -1.0 <= ddL <= 1.0 );
00111 
00112     ocp.subjectTo( -10.0 <= x   <=  50.0 );
00113     ocp.subjectTo( -20.0 <= dx  <=  20.0 );
00114     ocp.subjectTo(  30.0 <= L   <=  75.0 );
00115     ocp.subjectTo( -20.0 <= dL  <=  20.0 );
00116 
00117 
00118     // DEFINE A MULTI-OBJECTIVE ALGORITHM AND SOLVE THE OCP:
00119     // -----------------------------------------------------
00120     MultiObjectiveAlgorithm algorithm(ocp);
00121 
00122     algorithm.set( PARETO_FRONT_DISCRETIZATION, 31 );
00123     algorithm.set( PARETO_FRONT_GENERATION, PFG_NORMAL_BOUNDARY_INTERSECTION );
00124     //algorithm.set( DISCRETIZATION_TYPE        , SINGLE_SHOOTING                  );
00125 
00126     // Minimize individual objective function
00127     algorithm.solveSingleObjective(0);
00128 
00129     // Minimize individual objective function
00130     algorithm.solveSingleObjective(1);
00131 
00132     // Generate Pareto set
00133     //algorithm.set( PARETO_FRONT_HOTSTART      , BT_FALSE                         );
00134     algorithm.solve();
00135 
00136     algorithm.getWeights("crane_nbi_weights.txt");
00137     algorithm.getAllDifferentialStates("crane_nbi_states.txt");
00138     algorithm.getAllControls("crane_nbi_controls.txt");
00139     algorithm.getAllParameters("crane_nbi_parameters.txt");
00140 
00141 
00142     // GET THE RESULT FOR THE PARETO FRONT AND PLOT IT:
00143     // ------------------------------------------------
00144     VariablesGrid paretoFront;
00145     algorithm.getParetoFront( paretoFront );
00146 
00147     GnuplotWindow window1;
00148     window1.addSubplot( paretoFront, "Pareto Front (robustness versus time)", "TIME","ROBUSTNESS", PM_POINTS );
00149     window1.plot( );
00150 
00151 
00152     // PRINT INFORMATION ABOUT THE ALGORITHM:
00153     // --------------------------------------
00154     algorithm.printInfo();
00155 
00156 
00157     // SAVE INFORMATION:
00158     // -----------------
00159     paretoFront.print( "crane_nbi_pareto.txt" );
00160 
00161     return 0;
00162 }
00163 /* <<< end tutorial code <<< */
00164 


acado
Author(s): Milan Vukov, Rien Quirynen
autogenerated on Thu Aug 27 2015 11:58:04