active_damping.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 
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     // INTRODUCE THE VARIABLES:
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     // DEFINE A DIFFERENTIAL EQUATION:
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     // DEFINE LEAST SQUARE FUNCTION:
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     // DEFINE AN OPTIMAL CONTROL PROBLEM:
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         //ocp.minimizeLagrangeTerm( 0.5*(10.0*xBody*xBody + 10.0*xWheel*xWheel + vBody*vBody + vWheel*vWheel ) );
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     // Additionally, flush a plotting object
00112     GnuplotWindow window1;//( PLOT_AT_EACH_ITERATION );
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     // DEFINE AN OPTIMIZATION ALGORITHM AND SOLVE THE OCP:
00123     // ---------------------------------------------------
00124     OptimizationAlgorithm algorithm(ocp);
00125 
00126     algorithm << window1;
00127 
00128  // algorithm.set( HESSIAN_APPROXIMATION, EXACT_HESSIAN );
00129  //  algorithm.set( HESSIAN_APPROXIMATION, GAUSS_NEWTON );
00130         algorithm.set( HESSIAN_APPROXIMATION, GAUSS_NEWTON_WITH_BLOCK_BFGS );
00131 
00132         //algorithm.set( INTEGRATOR_TOLERANCE, 1e-8 );
00133         algorithm.set( KKT_TOLERANCE, 1e-6 );
00134         //algorithm.set( GLOBALIZATION_STRATEGY, GS_FULLSTEP );
00135         //algorithm.set( MAX_NUM_ITERATIONS, 1 );
00136 
00137         algorithm.solve();
00138 
00139 
00140     return 0;
00141 }
00142 
00143 
00144 


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