export_common_header.cpp
Go to the documentation of this file.
1 /*
2  * This file is part of ACADO Toolkit.
3  *
4  * ACADO Toolkit -- A Toolkit for Automatic Control and Dynamic Optimization.
5  * Copyright (C) 2008-2014 by Boris Houska, Hans Joachim Ferreau,
6  * Milan Vukov, Rien Quirynen, KU Leuven.
7  * Developed within the Optimization in Engineering Center (OPTEC)
8  * under supervision of Moritz Diehl. All rights reserved.
9  *
10  * ACADO Toolkit is free software; you can redistribute it and/or
11  * modify it under the terms of the GNU Lesser General Public
12  * License as published by the Free Software Foundation; either
13  * version 3 of the License, or (at your option) any later version.
14  *
15  * ACADO Toolkit is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18  * Lesser General Public License for more details.
19  *
20  * You should have received a copy of the GNU Lesser General Public
21  * License along with ACADO Toolkit; if not, write to the Free Software
22  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23  *
24  */
25 
33 #include <acado/code_generation/templates/templates.hpp>
34 
35 #include <algorithm>
36 
37 using namespace std;
38 
40 
41 ExportCommonHeader::ExportCommonHeader( const std::string& _fileName,
42  const std::string& _commonHeaderName,
43  const std::string& _realString,
44  const std::string& _intString,
45  int _precision,
46  const std::string& _commentString
47  ) : ExportTemplatedFile(COMMON_HEADER_TEMPLATE, _fileName, _commonHeaderName, _realString, _intString, _precision, _commentString)
48 {}
49 
50 returnValue ExportCommonHeader::configure( const std::string& _moduleName,
51  const std::string& _modulePrefix,
52  bool _useSinglePrecision,
53  bool _useComplexArithmetic,
54  QPSolverName _qpSolver,
55  const std::map<std::string, std::pair<std::string, std::string> >& _options,
56  const std::string& _variables,
57  const std::string& _workspace,
58  const std::string& _functions
59  )
60 {
61  // Configure the template
62  dictionary[ "@MODULE_NAME@" ] = _moduleName;
63  dictionary[ "@MODULE_PREFIX@" ] = _modulePrefix;
64 
65  stringstream ss;
66  if( _useComplexArithmetic ) ss << "\n#include <complex.h>\n" << endl;
67 
68  ss << "/** qpOASES QP solver indicator. */" << endl
69  << "#define " << _modulePrefix << "_QPOASES 0" << endl
70  << "#define " << _modulePrefix << "_QPOASES3 1" << endl
71  << "/** FORCES QP solver indicator.*/" << endl
72  << "#define " << _modulePrefix << "_FORCES 2" << endl
73  << "/** qpDUNES QP solver indicator.*/" << endl
74  << "#define " << _modulePrefix << "_QPDUNES 3" << endl
75  << "/** HPMPC QP solver indicator. */" << endl
76  << "#define " << _modulePrefix << "_HPMPC 4" << endl
77  << "#define " << _modulePrefix << "_GENERIC 5" << endl << endl
78  << "/** Indicator for determining the QP solver used by the ACADO solver code. */" << endl;
79 
80  switch ( _qpSolver )
81  {
82  case QP_QPOASES:
83  ss << "#define " << _modulePrefix << "_QP_SOLVER " << _modulePrefix << "_QPOASES\n" << endl;
84  ss << "#include \"" << _moduleName << "_qpoases_interface.hpp\"\n";
85 
86  break;
87 
88  case QP_QPOASES3:
89  ss << "#define " << _modulePrefix << "_QP_SOLVER " << _modulePrefix << "_QPOASES3\n" << endl;
90  ss << "#include \"" << _moduleName << "_qpoases3_interface.h\"\n";
91 
92  break;
93 
94  case QP_FORCES:
95  case QP_HPMPC:
96  case QP_QPDUNES:
97  if (_qpSolver == QP_FORCES)
98  ss << "#define " << _modulePrefix << "_QP_SOLVER " << _modulePrefix << "_FORCES\n" << endl;
99  else if (_qpSolver == QP_HPMPC)
100  ss << "#define " << _modulePrefix << "_QP_SOLVER " << _modulePrefix << "_HPMPC\n" << endl;
101  else
102  ss << "#define " << _modulePrefix << "_QP_SOLVER " << _modulePrefix << "_QPDUNES\n" << endl;
103 
104  ss << "\n#include <string.h>\n\n" << endl;
105 
106  ss << "/** Definition of the floating point data type. */\n";
107  if (_useSinglePrecision == true)
108  ss << "typedef float real_t;\n";
109  else
110  ss << "typedef double real_t;\n";
111 
112  break;
113 
114  case QP_GENERIC:
115  ss << "#define " << _modulePrefix << "_QP_SOLVER " << _modulePrefix << "_GENERIC\n" << endl;
116  case QP_NONE:
117  ss << "/** Definition of the floating point data type. */\n";
118  if (_useSinglePrecision == true)
119  ss << "typedef float real_t;\n";
120  else
121  ss << "typedef double real_t;\n";
122 
123  break;
124 
125  default:
126  return ACADOERROR( RET_INVALID_OPTION );
127 
128  }
129  dictionary[ "@QP_SOLVER_INTERFACE@" ] = ss.str();
130 
131  ss.str( string() );
132  // Key: define name
133  // Value.first: value
134  // Value.second: comment
135  std::map<std::string, std::pair<std::string, std::string> >::const_iterator it;
136  for (it = _options.begin(); it != _options.end(); ++it)
137  {
138  ss << "/** " << it->second.second << " */" << endl;
139  ss << "#define " << it->first << " " << it->second.first << endl;
140  }
141 
142  dictionary[ "@COMMON_DEFINITIONS@" ] = ss.str();
143 
144  dictionary[ "@VARIABLES_DECLARATION@" ] = _variables;
145 
146  dictionary[ "@WORKSPACE_DECLARATION@" ] = _workspace;
147 
148  dictionary[ "@FUNCTION_DECLARATIONS@" ] = _functions;
149 
150  // And then fill a template file
151  fillTemplate();
152 
153  return SUCCESSFUL_RETURN;
154 }
155 
std::map< std::string, std::string > dictionary
Allows to pass back messages to the calling function.
#define CLOSE_NAMESPACE_ACADO
Allows export of template files.
ExportCommonHeader(const std::string &_fileName, const std::string &_commonHeaderName="", const std::string &_realString="real_t", const std::string &_intString="int", int _precision=16, const std::string &_commentString=std::string())
#define BEGIN_NAMESPACE_ACADO
QPSolverName
virtual returnValue configure()
#define ACADOERROR(retval)


acado
Author(s): Milan Vukov, Rien Quirynen
autogenerated on Mon Jun 10 2019 12:34:33