Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
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
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
00126
00127
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
00144 fillTemplate();
00145
00146 return SUCCESSFUL_RETURN;
00147 }
00148
00149 CLOSE_NAMESPACE_ACADO