43 #include <acado/code_generation/templates/templates.hpp> 69 const std::string& _realString,
70 const std::string& _intString,
77 string moduleName, modulePrefix;
116 ExportFile integratorFile(dirName +
"/" + moduleName +
"_integrator.c",
132 ExportFile solverFile(dirName +
"/" + moduleName +
"_solver.c",
135 solver->getCode( solverFile );
151 dirName +
string(
"/") + moduleName +
"_auxiliary_functions.h",
152 dirName +
string(
"/") + moduleName +
"_auxiliary_functions.c",
162 int generateMakeFile;
164 int hessianApproximation;
166 int hessianRegularization;
169 if ( (
bool)generateMakeFile == true )
172 makefile.
dictionary[
"@MODULE_NAME@" ] = moduleName;
173 makefile.
dictionary[
"@MODULE_PREFIX@" ] = modulePrefix;
174 str = dirName +
"/Makefile";
181 makefile.
setup( MAKEFILE_EH_QPOASES,str,
"",
"real_t",
"int",16,
"#" );
185 makefile.
setup( MAKEFILE_QPOASES,str,
"",
"real_t",
"int",16,
"#" );
194 makefile.
setup( MAKEFILE_EH_QPOASES3,str,
"",
"real_t",
"int",16,
"#" );
198 makefile.
setup( MAKEFILE_QPOASES3,str,
"",
"real_t",
"int",16,
"#" );
206 makefile.
setup( MAKEFILE_FORCES,str,
"",
"real_t",
"int",16,
"#" );
214 makefile.
setup( MAKEFILE_EH_QPDUNES,str,
"",
"real_t",
"int",16,
"#" );
218 makefile.
setup( MAKEFILE_QPDUNES,str,
"",
"real_t",
"int",16,
"#" );
226 makefile.
setup( MAKEFILE_HPMPC,str,
"",
"real_t",
"int",16,
"#" );
240 int generateTestFile;
242 string testFileName = dirName +
"/test.c";
243 if ((
bool) generateTestFile ==
true)
247 testFile.
dictionary[
"@MODULE_NAME@" ] = moduleName;
248 testFile.
dictionary[
"@MODULE_PREFIX@" ] = modulePrefix;
250 testFile.
setup( DUMMY_TEST_FILE,testFileName );
260 int generateMexInterface;
262 if ( (
bool)generateMexInterface == true )
265 mexInterface.
dictionary[
"@MODULE_NAME@" ] = moduleName;
266 mexInterface.
dictionary[
"@MODULE_PREFIX@" ] = modulePrefix;
267 str = dirName +
"/" + moduleName +
"_solver_mex.c";
271 mexInterface.
setup( EH_SOLVER_MEX,str );
277 mexInterface.
setup( SOLVER_MEX,str );
283 mexInterfaceMake.
dictionary[
"@MODULE_NAME@" ] = moduleName;
284 mexInterfaceMake.
dictionary[
"@MODULE_PREFIX@" ] = modulePrefix;
285 str = dirName +
"/make_" + moduleName +
"_solver.m";
292 mexInterfaceMake.
setup( MAKE_MEX_EH_QPOASES,str,
"",
"real_t",
"int",16,
"%" );
298 mexInterfaceMake.
setup( MAKE_MEX_QPOASES,str,
"",
"real_t",
"int",16,
"%" );
307 mexInterfaceMake.
setup( MAKE_MEX_EH_QPOASES3,str,
"",
"real_t",
"int",16,
"%" );
313 mexInterfaceMake.
setup( MAKE_MEX_QPOASES3,str,
"",
"real_t",
"int",16,
"%" );
321 mexInterfaceMake.
setup( MAKE_MEX_FORCES,str,
"",
"real_t",
"int",16,
"%" );
329 mexInterfaceMake.
setup( MAKE_MEX_EH_QPDUNES,str,
"",
"real_t",
"int",16,
"%" );
338 mexInterfaceMake.
setup( MAKE_MEX_QPDUNES,str,
"",
"real_t",
"int",16,
"%" );
352 mexInterfaceMake.
setup( MAKE_MEX_HPMPC,str,
"",
"real_t",
"int",16,
"%" );
369 int generateSimulinkInterface;
371 if ((
bool) generateSimulinkInterface ==
true)
375 "At the moment, Simulink interface is available only with qpOASES, qpOASES3 and qpDUNES based OCP solvers.");
378 string makefileName = dirName +
"/make_" + moduleName +
"_solver_sfunction.m";
379 string wrapperHeaderName = dirName +
"/" + moduleName +
"_solver_sfunction.h";
380 string wrapperSourceName = dirName +
"/" + moduleName +
"_solver_sfunction.c";
381 string qpSolverString;
384 qpSolverString =
"QPOASES";
386 qpSolverString =
"QPOASES3";
388 qpSolverString =
"QPDUNES";
390 qpSolverString =
"HPMPC";
393 int useSinglePrecision;
397 if( useSinglePrecision ) {
398 esi =
ExportSimulinkInterface(makefileName, wrapperHeaderName, wrapperSourceName, moduleName, modulePrefix,
"",
"single");
401 int hardcodeConstraintValues;
403 if ((
bool)hardcodeConstraintValues ==
false)
417 (bool)fixInitialState,
418 (
unsigned)
solver->weightingMatricesType(),
419 (bool)hardcodeConstraintValues,
434 dirName +
string(
"/") + moduleName +
"_hessian_regularization.c",
444 dirName +
string(
"/") + moduleName +
"_hessian_regularization.c",
449 if( (
bool)fixInitialState == 1 ) {
469 LOG(
LVL_INFO ) <<
"ACADO Code Generation Tool:" << endl
470 <<
"\t* Number of QP variables: " <<
solver->getNumQPvars( ) << endl
471 <<
"\t* Number of path and point constraints: " <<
solver->getNumComplexConstraints() << endl;
522 int hessianApproximation;
534 "For condensed solution only qpOASES and qpOASES3 QP solver are supported");
546 "For condensed solution only qpOASES and qpOASES3 QP solver are supported");
566 "For block condensed solution only qpDUNES QP solver is currently supported");
586 "For condensed solution only qpOASES and qpOASES3 QP solver are supported");
596 "For sparse solution FORCES, qpDUNES and HPMPC QP solvers are supported");
631 statusObjective =
solver->setObjective( objective );
638 double levenbergMarquardt;
641 solver->setLevenbergMarquardt( levenbergMarquardt );
644 statusSetup =
solver->setup( );
661 int hessianApproximation;
686 if ( f.
getNP( ) > 0 )
688 "Free parameters are not supported. For the old functionality use OnlineData class.");
693 int discretizationType;
730 const std::string& _fileName,
731 const std::string& _realString,
732 const std::string& _intString,
736 string moduleName, modulePrefix;
743 int useSinglePrecision;
746 int hardcodeConstraintValues;
758 bool useComplexArithmetic =
false;
763 fileName = _dirName +
"/" + _fileName;
765 map<string, pair<string, string> >
options;
767 options[ modulePrefix +
"_N" ] = make_pair(
toString(
ocp.
getN() ),
"Number of control/estimation intervals.");
768 options[ modulePrefix +
"_NX" ] = make_pair(
toString(
ocp.
getNX() ),
"Number of differential variables.");
769 options[ modulePrefix +
"_NXD" ] = make_pair(
toString(
ocp.
getNDX() ),
"Number of differential derivative variables.");
770 options[ modulePrefix +
"_NXA" ] = make_pair(
toString(
ocp.
getNXA() ),
"Number of algebraic variables.");
771 options[ modulePrefix +
"_NU" ] = make_pair(
toString(
ocp.
getNU() ),
"Number of control variables.");
772 options[ modulePrefix +
"_NOD" ] = make_pair(
toString(
ocp.
getNOD() ),
"Number of online data values.");
773 options[ modulePrefix +
"_NY" ] = make_pair(
toString(
solver->getNY() ),
"Number of references/measurements per node on the first N nodes.");
774 options[ modulePrefix +
"_NYN" ] = make_pair(
toString(
solver->getNYN() ),
"Number of references/measurements on the last (N + 1)st node.");
775 options[ modulePrefix +
"_NPAC" ] = make_pair(
toString(
solver->getNumPathConstraints() ),
"Number of path constraints.");
777 Grid integrationGrid;
783 options[ modulePrefix +
"_RK_NSTAGES" ] = make_pair(
toString( rk_integrator->
getNumStages() ),
"Number of Runge-Kutta stages per integration step.");
785 options[ modulePrefix +
"_INITIAL_STATE_FIXED" ] =
786 make_pair(
toString( fixInitialState ),
"Indicator for fixed initial state.");
787 options[ modulePrefix +
"_WEIGHTING_MATRICES_TYPE" ] =
788 make_pair(
toString( (
unsigned)
solver->weightingMatricesType() ),
"Indicator for type of fixed weighting matrices.");
789 options[ modulePrefix +
"_USE_LINEAR_TERMS" ] =
790 make_pair(
toString( (
unsigned)
solver->usingLinearTerms() ),
"Indicator for usage of non-hard-coded linear terms in the objective.");
791 options[ modulePrefix +
"_HARDCODED_CONSTRAINT_VALUES" ] =
792 make_pair(
toString( hardcodeConstraintValues ),
"Flag indicating whether constraint values are hard-coded or not.");
793 options[ modulePrefix +
"_USE_ARRIVAL_COST" ] =
794 make_pair(
toString( useAC ),
"Providing interface for arrival cost.");
795 options[ modulePrefix +
"_COMPUTE_COVARIANCE_MATRIX" ] =
796 make_pair(
toString( covCalc ),
"Compute covariance matrix of the last state estimate.");
797 options[ modulePrefix +
"_QP_NV" ] =
798 make_pair(
toString(
solver->getNumQPvars() ),
"Total number of QP optimization variables.");
804 options[ modulePrefix +
"_QP_NLB" ] =
806 options[ modulePrefix +
"_QP_NUB" ] =
814 options[ modulePrefix +
"_BLOCK_CONDENSING" ] =
815 make_pair(
toString( 1 ),
"User defined block based condensing.");
816 options[ modulePrefix +
"_QP_NCA" ] =
820 options[ modulePrefix +
"_BLOCK_CONDENSING" ] =
821 make_pair(
toString( 0 ),
"User defined block based condensing.");
829 stringstream variables;
833 variablesBlock.
exportCode(variables, _realString, _intString, _precision);
836 stringstream workspace;
840 workspaceBlock.
exportCode(workspace, _realString, _intString, _precision);
843 stringstream functions;
847 functionsBlock.
exportCode(functions, _realString);
850 ech.
configure( moduleName, modulePrefix, useSinglePrecision, useComplexArithmetic, (
QPSolverName)qpSolver,
851 options, variables.str(), workspace.str(), functions.str());
#define LOG(level)
Just define a handy macro for getting the logger.
uint getNumLagrangeTerms() const
Returned value is a information.
Lowest level, the debug level.
returnValue collectFunctionDeclarations(ExportStatementBlock &declarations) const
virtual unsigned getNumStateBoundsPerBlock() const
virtual returnValue setup(const std::string &_templateName, 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())
std::map< std::string, std::string > dictionary
returnValue getObjective(Objective &objective_) const
std::shared_ptr< IntegratorExport > IntegratorExportPtr
Allows to export a tailored Runge-Kutta integrator for fast model predictive control.
returnValue setStatus(BlockStatus _status)
A class for generating the glue code and makefile for interfacing generated code and Simulink...
returnValue configure(unsigned N, unsigned NX, unsigned NDX, unsigned NXA, unsigned NU, unsigned NP, unsigned NY, unsigned NYN, bool _initialStateFixed, unsigned _wMatrixType, bool _hardcodedConstraints, bool _useArrivalCost, bool _compCovMatrix, std::string _qpSolver)
returnValue setNumberIntegrationSteps(const uint numSteps)
returnValue exportAcadoHeader(const std::string &_dirName, const std::string &_fileName, const std::string &_realString="real_t", const std::string &_intString="int", int _precision=16) const
Allows to pass back messages to the calling function.
returnValue configure(uint DIM, double eps)
HessianRegularizationMode
A class for export of an OCP solver using sparse QP solver FORCES.
BEGIN_NAMESPACE_ACADO typedef unsigned int uint
virtual returnValue exportCode(const std::string &dirName, const std::string &_realString="real_t", const std::string &_intString="int", int _precision=16)
Allows to conveniently handle (one-dimensional) grids consisting of time points.
unsigned getNumLowerBounds() const
string toString(T const &value)
unsigned getNumUpperBounds() const
#define CLOSE_NAMESPACE_ACADO
virtual returnValue exportCode(std::ostream &stream, const std::string &_realString="real_t", const std::string &_intString="int", int _precision=16) const
std::shared_ptr< ExportNLPSolver > ExportNLPSolverPtr
An OCP solver based on the block N^2 condensing algorithm.
Allows to export files containing automatically generated algorithms for fast model predictive contro...
std::string commonHeaderName
Allows export of template files.
returnValue getModel(DifferentialEquation &_f) const
User-interface to automatically generate algorithms for fast model predictive control.
BlockStatus getStatus() const
static std::string fcnPrefix
returnValue acadoCopyTemplateFile(const std::string &source, const std::string &destination, const std::string &commentString, bool printCodegenNotice)
A class for generating code implementing a symmetric EigenValue Decomposition.
uint getNumMayerTerms() const
BooleanType hasEquidistantControlGrid() const
static std::string fcnPrefix
returnValue acadoPrintCopyrightNotice(const std::string &subpackage)
Data class for defining optimal control problems.
returnValue acadoCreateFolder(const std::string &name)
returnValue getIntegrationGrid(Grid &_grid) const
A class for generating some helper functions.
#define ACADOWARNINGTEXT(retval, text)
returnValue checkConsistency() const
uint getNumIntervals() const
std::shared_ptr< ExportNLPSolver > solver
uint getNumberOfBlocks() const
returnValue printDimensionsQP()
#define BEGIN_NAMESPACE_ACADO
BooleanType hasObjective() const
static ExportAlgorithmFactory & instance()
returnValue collectDataDeclarations(ExportStatementBlock &declarations, ExportStruct dataStruct=ACADO_ANY) const
virtual returnValue configure()
ModelData & getModelData()
Allows to export code for a block of statements.
Stores and evaluates the objective function of optimal control problems.
std::shared_ptr< IntegratorExport > integrator
virtual returnValue exportCode() const
static std::string varPrefix
#define ACADOERROR(retval)
#define ACADOERRORTEXT(retval, text)
Allows to setup and evaluate differential equations (ODEs and DAEs) based on SymbolicExpressions.