feedforward_law.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 
00043 #include <acado/control_law/feedforward_law.hpp>
00044 
00045 
00046 BEGIN_NAMESPACE_ACADO
00047 
00048 
00049 
00050 //
00051 // PUBLIC MEMBER FUNCTIONS:
00052 //
00053 
00054 FeedforwardLaw::FeedforwardLaw( ) : ControlLaw( )
00055 {
00056         setStatus( BS_NOT_INITIALIZED );
00057 }
00058 
00059 
00060 FeedforwardLaw::FeedforwardLaw( const uint _nx,
00061                                                                 const Curve& _u,
00062                                                                 double _samplingTime
00063                                                                 ) : ControlLaw( _samplingTime )
00064 {
00065         nx=_nx;
00066         uRef=_u;
00067         setStatus( BS_NOT_INITIALIZED );
00068 }
00069 
00070 
00071 FeedforwardLaw::FeedforwardLaw( const FeedforwardLaw& rhs ) : ControlLaw( rhs )
00072 {
00073         nx=rhs.nx;
00074         uRef=rhs.uRef;
00075 }
00076 
00077 
00078 FeedforwardLaw::~FeedforwardLaw( )
00079 {
00080 }
00081 
00082 
00083 FeedforwardLaw& FeedforwardLaw::operator=( const FeedforwardLaw& rhs )
00084 {
00085         if ( this != &rhs )
00086         {
00087                 ControlLaw::operator=( rhs );
00088 
00089         }
00090 
00091     return *this;
00092 }
00093 
00094 
00095 ControlLaw* FeedforwardLaw::clone( ) const
00096 {
00097         return new FeedforwardLaw( *this );
00098 }
00099 
00100 
00101 returnValue FeedforwardLaw::init(       double startTime,
00102                                                                         const DVector &x0_,
00103                                                                         const DVector &p_,
00104                                                                         const VariablesGrid& _yRef
00105                                                                         )
00106 {
00107         u.init(getNU());
00108         u.setZero();
00109         
00110         p.init( 0 );
00111         p.setZero( );
00112 
00113         setStatus( BS_READY );
00114 
00115         return SUCCESSFUL_RETURN;
00116 }
00117 
00118 
00119 returnValue FeedforwardLaw::step(       double currentTime,
00120                                                                         const DVector& _x,
00121                                                                         const DVector& _p,
00122                                                                         const VariablesGrid& _yRef
00123                                                                         )
00124 {
00125         if ( getStatus( ) != BS_READY )
00126                 return ACADOERROR( RET_BLOCK_NOT_READY );
00127         
00128         if ( _x.getDim( ) != getNX( ) )
00129                 return ACADOERROR( RET_VECTOR_DIMENSION_MISMATCH );
00130 
00131 
00132         // use reference control as control
00133         DVector uEv;
00134         uRef.evaluate(currentTime,uEv);
00135         //printf("FeedforwardLaw controllor outputs %d #.\n",uRef.getDim());
00136         //printf(" -- yref: %d samples of size (%d,%d) -- \n",_yRef.getNumPoints(),_yRef.getNumRows(),_yRef.getNumCols());
00137 
00138         u = uEv;
00139         p = _p;
00140 
00141         //printf(" -- u: [%.3e,%.3e,%.3e] -- \n",u(0),u(1),u(2));
00142 
00143         return SUCCESSFUL_RETURN;       
00144 }
00145 
00146 
00147 
00148 uint FeedforwardLaw::getNX( ) const
00149 {
00150         return nx;
00151 }
00152 
00153 
00154 uint FeedforwardLaw::getNXA( ) const
00155 {
00156         return 0;
00157 }
00158 
00159 
00160 uint FeedforwardLaw::getNU( ) const
00161 {
00162         return uRef.getDim( );
00163 }
00164 
00165 
00166 uint FeedforwardLaw::getNP( ) const
00167 {
00168         return 0;
00169 }
00170 
00171 
00172 uint FeedforwardLaw::getNW( ) const
00173 {
00174         return 0;
00175 }
00176 
00177 
00178 uint FeedforwardLaw::getNY( ) const
00179 {
00180         return getNX( );
00181 }
00182 
00183 
00184 BooleanType FeedforwardLaw::isDynamic( ) const
00185 {
00186         return BT_FALSE;
00187 }
00188 
00189 
00190 BooleanType FeedforwardLaw::isStatic( ) const
00191 {
00192         if ( isDynamic() == BT_TRUE )
00193                 return BT_FALSE;
00194         else
00195                 return BT_TRUE;
00196 }
00197 
00198 
00199 
00200 //
00201 // PROTECTED MEMBER FUNCTIONS:
00202 //
00203 
00204 
00205 
00206 
00207 CLOSE_NAMESPACE_ACADO
00208 
00209 // end of file.


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