


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

0001 function generateCPP(obj) 0002 %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 %% Basic settings 0031 % Get global 0032 global ACADO_; 0033 if ~exist(ACADO_.pwd) 0034 error( 'ERROR: Run make script first. Go to <ACADOtoolkit-inst-dir>/interfaces/matlab/ and run <a href="matlab: help make">help make</a>' ); 0035 end 0036 0037 if (isempty(ACADO_.problemname)) 0038 error('ERROR in solve. Problemname is empty. See <a href="matlab: help acadoSet">help acadoSet</a>'); 0039 end 0040 0041 obj.problemname = ACADO_.problemname; 0042 0043 fprintf('Writing c++ files... \n'); 0044 0045 if (~isempty(obj.instructionList)) 0046 % File names 0047 fileIN = sprintf('%s.cpp', obj.problemname); % MEX cpp file name 0048 fileOUT = sprintf('%s_RUN', obj.problemname); % MEX compiles file name 0049 0050 0051 % Write empty .m file. This file is needed to run the MEX file 0052 fileM = fopen(sprintf('%s_RUN.m', obj.problemname),'w'); % Open MEX .m file 0053 fclose(fileM); % Close 0054 0055 0056 %% Load instructions 0057 addtimemanual = false; 0058 if (isempty(obj.t)) 0059 addtimemanual = true; 0060 acado.TIME('autotime', 1); 0061 end 0062 0063 obj.fileMEX = fopen(fileIN, 'w'); % Open MEX cpp file 0064 0065 obj.getCPPheader(); % Get default CPP file header 0066 for i=1:length(obj.instructionList) 0067 obj.instructionList{i}.getInstructions(obj, 'H'); 0068 end 0069 0070 obj.getCPPbody(); % Get default CPP file body 0071 0072 if (addtimemanual) 0073 fprintf(obj.fileMEX,sprintf(' TIME autotime;\n')); 0074 end 0075 0076 for i=1:length(obj.instructionList) 0077 obj.instructionList{i}.getInstructions(obj, 'FB'); % first body elements 0078 end 0079 0080 for i=1:length(obj.instructionList) 0081 obj.instructionList{i}.getInstructions(obj, 'B'); 0082 end 0083 0084 for i=1:length(obj.instructionList) 0085 obj.instructionList{i}.getInstructions(obj, 'F'); 0086 end 0087 obj.getCPPfooter(); % Get default CPP file footer (call after all the rest !) 0088 0089 0090 fclose(obj.fileMEX); % Close MEX FILE 0091 0092 0093 fprintf('Compiling c++ files... \n'); 0094 0095 %% MEX EVAL 0096 eval(sprintf(regexprep(ACADO_.mexcall, '\\', '\\\\'), fileIN, fileOUT)); 0097 0098 else 0099 0100 disp('Nothing to compile.'); 0101 0102 end 0103 0104 end