export_common_header.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 
00032 #include <acado/code_generation/export_common_header.hpp>
00033 #include <acado/code_generation/templates/templates.hpp>
00034 
00035 #include <algorithm>
00036 
00037 using namespace std;
00038 
00039 BEGIN_NAMESPACE_ACADO
00040 
00041 ExportCommonHeader::ExportCommonHeader( const std::string& _fileName,
00042                                                                                 const std::string& _commonHeaderName,
00043                                                                                 const std::string& _realString,
00044                                                                                 const std::string& _intString,
00045                                                                                 int _precision,
00046                                                                                 const std::string& _commentString
00047                                                                                 ) : ExportTemplatedFile(COMMON_HEADER_TEMPLATE, _fileName, _commonHeaderName, _realString, _intString, _precision, _commentString)
00048 {}
00049 
00050 returnValue ExportCommonHeader::configure(      const std::string& _moduleName,
00051                                                                                         bool _useSinglePrecision,
00052                                                                                         QPSolverName _qpSolver,
00053                                                                                         const std::map<std::string, std::pair<std::string, std::string> >& _options,
00054                                                                                         const std::string& _variables,
00055                                                                                         const std::string& _workspace,
00056                                                                                         const std::string& _functions
00057                                                                                         )
00058 {
00059         // Configure the template
00060         string foo = _moduleName;
00061         transform(foo.begin(), foo.end(), foo.begin(), ::toupper);
00062         dictionary[ "@MODULE_NAME@" ] = foo;
00063 
00064         stringstream ss;
00065         ss      << "/** qpOASES QP solver indicator. */" << endl
00066                 << "#define ACADO_QPOASES 0" << endl
00067                 << "/** FORCES QP solver indicator.*/" << endl
00068                 << "#define ACADO_FORCES  1" << endl
00069                 << "/** qpDUNES QP solver indicator.*/" << endl
00070                 << "#define ACADO_QPDUNES 2" << endl
00071                 << "/** HPMPC QP solver indicator. */" << endl
00072                 << "#define ACADO_HPMPC 3" << endl
00073                 << "/** Indicator for determining the QP solver used by the ACADO solver code. */" << endl;
00074 
00075         switch ( _qpSolver )
00076         {
00077         case QP_QPOASES:
00078                 ss << "#define ACADO_QP_SOLVER ACADO_QPOASES\n" << endl;
00079                 ss << "#include \"" << _moduleName << "_qpoases_interface.hpp\"\n";
00080 
00081                 break;
00082 
00083         case QP_FORCES:
00084         case QP_HPMPC:
00085         case QP_QPDUNES:
00086                 if (_qpSolver == QP_FORCES)
00087                         ss << "#define ACADO_QP_SOLVER ACADO_FORCES\n" << endl;
00088                 else if (_qpSolver == QP_HPMPC)
00089                         ss << "#define ACADO_QP_SOLVER ACADO_HPMPC\n" << endl;
00090                 else
00091                         ss << "#define ACADO_QP_SOLVER ACADO_QPDUNES\n" << endl;
00092 
00093                 ss << "\n#include <string.h>\n\n" << endl;
00094 
00095                 ss << "/** Definition of the floating point data type. */\n";
00096                 if (_useSinglePrecision == true)
00097                         ss << "typedef float real_t;\n";
00098                 else
00099                         ss << "typedef double real_t;\n";
00100 
00101                 break;
00102 
00103         case QP_QPDUNES2:
00104                 ss << "#define ACADO_QP_SOLVER ACADO_QPDUNES\n" << endl;
00105                 ss << "#include \"qpDUNES.h\"\n";
00106 
00107                 break;
00108         
00109         case QP_NONE:
00110                 ss << "/** Definition of the floating point data type. */\n";
00111                 if (_useSinglePrecision == true)
00112                         ss << "typedef float real_t;\n";
00113                 else
00114                         ss << "typedef double real_t;\n";
00115 
00116                 break;
00117 
00118         default:
00119                 return ACADOERROR( RET_INVALID_OPTION );
00120 
00121         }
00122         dictionary[ "@QP_SOLVER_INTERFACE@" ] = ss.str();
00123 
00124         ss.str( string() );
00125         // Key: define name
00126         // Value.first: value
00127         // Value.second: comment
00128         std::map<std::string, std::pair<std::string, std::string> >::const_iterator it;
00129         for (it = _options.begin(); it != _options.end(); ++it)
00130         {
00131                 ss << "/** " << it->second.second << " */" << endl;
00132                 ss << "#define " << it->first << " " << it->second.first << endl;
00133         }
00134 
00135         dictionary[ "@COMMON_DEFINITIONS@" ] = ss.str();
00136 
00137         dictionary[ "@VARIABLES_DECLARATION@" ] = _variables;
00138 
00139         dictionary[ "@WORKSPACE_DECLARATION@" ] = _workspace;
00140 
00141         dictionary[ "@FUNCTION_DECLARATIONS@" ] = _functions;
00142 
00143         // And then fill a template file
00144         fillTemplate();
00145 
00146         return SUCCESSFUL_RETURN;
00147 }
00148 
00149 CLOSE_NAMESPACE_ACADO


acado
Author(s): Milan Vukov, Rien Quirynen
autogenerated on Sat Jun 8 2019 19:37:01