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
00026
00027
00034 #include <acado/code_generation/export_acado_function.hpp>
00035 #include <acado/function/function_.hpp>
00036
00037 using namespace std;
00038 BEGIN_NAMESPACE_ACADO
00039
00040
00041
00042
00043
00044
00045 ExportAcadoFunction::ExportAcadoFunction( ) : ExportFunction( )
00046 {
00047 numX = 0;
00048 numXA = 0;
00049 numU = 0;
00050 numP = 0;
00051 numDX = 0;
00052 numOD = 0;
00053
00054 f = std::tr1::shared_ptr< Function >(new Function( ));
00055
00056 external = false;
00057 }
00058
00059
00060 ExportAcadoFunction::ExportAcadoFunction( const Function& _f,
00061 const std::string& _name
00062 ) : ExportFunction( _name )
00063 {
00064 init(_f, _name);
00065 }
00066
00067 ExportAcadoFunction::ExportAcadoFunction( const std::string& _name
00068 ) : ExportFunction( _name )
00069 {
00070 init(Function(), _name);
00071 external = true;
00072 }
00073
00074 ExportAcadoFunction::~ExportAcadoFunction( )
00075 {}
00076
00077
00078 ExportStatement* ExportAcadoFunction::clone( ) const
00079 {
00080 return new ExportAcadoFunction(*this);
00081 }
00082
00083 returnValue ExportAcadoFunction::init( const Function& _f,
00084 const std::string& _name,
00085 const uint _numX,
00086 const uint _numXA,
00087 const uint _numU,
00088 const uint _numP,
00089 const uint _numDX,
00090 const uint _numOD
00091 )
00092 {
00093 numX = _numX;
00094 numXA = _numXA;
00095 numU = _numU;
00096 numP = _numP;
00097 numDX = _numDX;
00098 numOD = _numOD;
00099
00100 f = std::tr1::shared_ptr< Function >(new Function( _f ));
00101
00102 globalVar.setup("acado_aux", f->getGlobalExportVariableSize(), 1, REAL, ACADO_WORKSPACE);
00103 f->setGlobalExportVariableName( globalVar.getFullName() );
00104
00105 external = false;
00106
00107
00108 return ExportFunction::init(_name, ExportArgument("input", 1, 1), ExportArgument("output", 1, 1));
00109 }
00110
00111 returnValue ExportAcadoFunction::exportDataDeclaration( std::ostream& stream,
00112 const std::string& _realString,
00113 const std::string& _intString,
00114 int _precision
00115 ) const
00116 {
00117 ASSERT( external == false );
00118
00119 stream << _realString << " " << f->getGlobalExportVariableName()
00120 << "[ " << f->getGlobalExportVariableSize( ) << " ];" << std::endl;
00121
00122 return SUCCESSFUL_RETURN;
00123 }
00124
00125
00126 returnValue ExportAcadoFunction::exportForwardDeclaration( std::ostream& stream,
00127 const std::string& _realString,
00128 const std::string& _intString,
00129 int _precision
00130 ) const
00131 {
00132 if (flagPrivate == true)
00133 return SUCCESSFUL_RETURN;
00134
00135 if (external == true)
00136 {
00137 stream << endl;
00138 stream << "/** An external function for evaluation of symbolic expressions. */" << endl;
00139 stream << "void " << name << "(const " << _realString << "* in, " << _realString << "* out);" << endl;
00140
00141 return SUCCESSFUL_RETURN;
00142 }
00143
00144 return f->exportForwardDeclarations(stream, name.c_str(), _realString.c_str());
00145 }
00146
00147
00148 returnValue ExportAcadoFunction::exportCode( std::ostream& stream,
00149 const std::string& _realString,
00150 const std::string& _intString,
00151 int _precision
00152 ) const
00153 {
00154 if (external == true)
00155 return SUCCESSFUL_RETURN;
00156
00157 return f->exportCode(
00158 stream, name.c_str(), _realString.c_str(), numX, numXA, numU, numP, numDX, numOD,
00159
00160 false, false);
00161 }
00162
00163
00164 bool ExportAcadoFunction::isDefined( ) const
00165 {
00166 if (f->getDim() > 0 || external == true)
00167 return true;
00168
00169 return false;
00170 }
00171
00172
00173 unsigned ExportAcadoFunction::getFunctionDim( void )
00174 {
00175 ASSERT( external == false );
00176
00177 return f->getDim();
00178 }
00179
00180 ExportVariable ExportAcadoFunction::getGlobalExportVariable( ) const
00181 {
00182 return deepcopy( globalVar );
00183 }
00184
00185 returnValue ExportAcadoFunction::setGlobalExportVariable(const ExportVariable& var)
00186 {
00187 ASSERT( external == false );
00188
00189 if (getFunctionDim() == 0)
00190 return SUCCESSFUL_RETURN;
00191
00192
00193
00194
00195
00196
00197 globalVar = var;
00198 f->setGlobalExportVariableName( globalVar.getFullName() );
00199
00200 return SUCCESSFUL_RETURN;
00201 }
00202
00203 bool ExportAcadoFunction::isExternal() const
00204 {
00205 return external;
00206 }
00207
00208 CLOSE_NAMESPACE_ACADO