Home > matlab > acado > packages > +acado > @Controller > getInstructions.m

getInstructions

PURPOSE ^

Used to generate CPP file

SYNOPSIS ^

function getInstructions(obj, cppobj, get)

DESCRIPTION ^

Used to generate CPP file

  Licence:
    This file is part of ACADO Toolkit  - (http://www.acadotoolkit.org/)

    ACADO Toolkit -- A Toolkit for Automatic Control and Dynamic Optimization.
    Copyright (C) 2008-2009 by Boris Houska and Hans Joachim Ferreau, K.U.Leuven.
    Developed within the Optimization in Engineering Center (OPTEC) under
    supervision of Moritz Diehl. All rights reserved.

    ACADO Toolkit is free software; you can redistribute it and/or
    modify it under the terms of the GNU Lesser General Public
    License as published by the Free Software Foundation; either
    version 3 of the License, or (at your option) any later version.

    ACADO Toolkit is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    Lesser General Public License for more details.

    You should have received a copy of the GNU Lesser General Public
    License along with ACADO Toolkit; if not, write to the Free Software
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA

    Author: David Ariens
    Date: 2010

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function getInstructions(obj, cppobj, get)
0002 %Used to generate CPP file
0003 %
0004 %  Licence:
0005 %    This file is part of ACADO Toolkit  - (http://www.acadotoolkit.org/)
0006 %
0007 %    ACADO Toolkit -- A Toolkit for Automatic Control and Dynamic Optimization.
0008 %    Copyright (C) 2008-2009 by Boris Houska and Hans Joachim Ferreau, K.U.Leuven.
0009 %    Developed within the Optimization in Engineering Center (OPTEC) under
0010 %    supervision of Moritz Diehl. All rights reserved.
0011 %
0012 %    ACADO Toolkit is free software; you can redistribute it and/or
0013 %    modify it under the terms of the GNU Lesser General Public
0014 %    License as published by the Free Software Foundation; either
0015 %    version 3 of the License, or (at your option) any later version.
0016 %
0017 %    ACADO Toolkit is distributed in the hope that it will be useful,
0018 %    but WITHOUT ANY WARRANTY; without even the implied warranty of
0019 %    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0020 %    Lesser General Public License for more details.
0021 %
0022 %    You should have received a copy of the GNU Lesser General Public
0023 %    License along with ACADO Toolkit; if not, write to the Free Software
0024 %    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
0025 %
0026 %    Author: David Ariens
0027 %    Date: 2010
0028 %
0029 
0030 
0031 if (get == 'B')
0032     
0033     if (~isempty(obj.reference.name))
0034         fprintf(cppobj.fileMEX,sprintf('    Controller %s( %s,%s );\n', obj.name, obj.controllaw.name, obj.reference.name));
0035     else
0036         fprintf(cppobj.fileMEX,sprintf('    Controller %s( %s );\n', obj.name, obj.controllaw.name));
0037     end
0038     
0039     if (obj.init_is_set == 1) % Set INIT
0040        
0041         if (~isempty(obj.init_y_ref))   %
0042             fprintf(cppobj.fileMEX,sprintf('    %s.init(%s, %s, %s, %s);\n', obj.name, obj.init_startTime.name, obj.init_x0.name, obj.init_p.name, obj.init_y_ref.name));
0043         elseif (~isempty(obj.init_p))
0044             fprintf(cppobj.fileMEX,sprintf('    %s.init(%s, %s, %s);\n', obj.name, obj.init_startTime.name, obj.init_x0.name, obj.init_p.name));
0045         elseif (~isempty(obj.init_x0))
0046             fprintf(cppobj.fileMEX,sprintf('    %s.init(%s, %s);\n', obj.name, obj.init_startTime.name, obj.init_x0.name));
0047         else
0048             fprintf(cppobj.fileMEX,sprintf('    %s.init(%s);\n', obj.name, obj.init_startTime.name));
0049         end
0050 
0051     end
0052         
0053     
0054     
0055     if (obj.do_one_step == 1)  % PERFORM STEP
0056         
0057         if (~isempty(obj.step_y_ref))
0058             fprintf(cppobj.fileMEX,sprintf('    %s.step(%s, %s, %s);\n', obj.name, obj.step_startTime.name, obj.step_x0.name, obj.step_y_ref.name));
0059            
0060         elseif (~isempty(obj.step_x0))
0061             fprintf(cppobj.fileMEX,sprintf('    %s.step(%s, %s);\n', obj.name, obj.step_startTime.name, obj.step_x0.name));
0062         
0063         else
0064             fprintf(cppobj.fileMEX,sprintf('    %s.step(%s);\n', obj.name, obj.step_startTime.name));
0065             
0066         end
0067         
0068         fprintf(cppobj.fileMEX,'\n');
0069         
0070         % GET RESULTS
0071         
0072         fprintf(cppobj.fileMEX,'    const char* outputFieldNames[] = {"U", "P"}; \n');
0073         fprintf(cppobj.fileMEX,'    plhs[0] = mxCreateStructMatrix( 1,1,2,outputFieldNames ); \n');
0074 
0075         fprintf(cppobj.fileMEX,'    mxArray *OutU = NULL;\n');
0076         fprintf(cppobj.fileMEX,'    double  *outU = NULL;\n');
0077         fprintf(cppobj.fileMEX,sprintf('    OutU = mxCreateDoubleMatrix( 1,%s.getNU(),mxREAL ); \n', obj.name));
0078         fprintf(cppobj.fileMEX,'    outU = mxGetPr( OutU );\n');
0079         
0080         fprintf(cppobj.fileMEX,'    Vector vec_outU; \n');
0081         fprintf(cppobj.fileMEX,sprintf('    %s.getU(vec_outU); \n', obj.name));
0082         
0083         fprintf(cppobj.fileMEX,'    for( int i=0; i<vec_outU.getDim(); ++i ){ \n');
0084         fprintf(cppobj.fileMEX,'        outU[i] = vec_outU(i); \n');
0085         fprintf(cppobj.fileMEX,'    } \n\n');
0086             
0087             
0088         fprintf(cppobj.fileMEX,'    mxArray *OutP = NULL;\n');
0089         fprintf(cppobj.fileMEX,'    double  *outP = NULL;\n');
0090         fprintf(cppobj.fileMEX,sprintf('    OutP = mxCreateDoubleMatrix( 1,%s.getNP(),mxREAL ); \n', obj.name));
0091         fprintf(cppobj.fileMEX,'    outP = mxGetPr( OutP );\n');
0092         
0093         fprintf(cppobj.fileMEX,'    Vector vec_outP; \n');
0094         fprintf(cppobj.fileMEX,sprintf('    %s.getP(vec_outP); \n', obj.name));
0095         
0096         fprintf(cppobj.fileMEX,'    for( int i=0; i<vec_outP.getDim(); ++i ){ \n');
0097         fprintf(cppobj.fileMEX,'        outP[i] = vec_outP(i); \n');
0098         fprintf(cppobj.fileMEX,'    } \n\n');        
0099         
0100         fprintf(cppobj.fileMEX,'    mxSetField( plhs[0],0,"U",OutU );\n');        
0101         fprintf(cppobj.fileMEX,'    mxSetField( plhs[0],0,"P",OutP );\n');
0102         
0103     end
0104     
0105     fprintf(cppobj.fileMEX,'\n');
0106 end
0107 
0108 end

www.acadotoolkit.org/matlab
Generated on Tue 01-Jun-2010 20:14:12 by m2html © 2005