def exportOcp(ocp, ocpOptions, integratorOptions, cgOptions, phase1Options): defaultCgOptions = { 'CXX': 'g++', 'CC': 'gcc', 'CXXFLAGS': '-O3 -fPIC -finline-functions', 'CFLAGS': '-O3 -fPIC -finline-functions', 'hideSymbols': False, 'export_without_build_path': None } defaultPhase1Options = {'CXX': 'g++'} validateOptions(defaultCgOptions, cgOptions, "codegen") validateOptions(defaultPhase1Options, phase1Options, "phase 1") cgOptions['hashPrefix'] = ocp.hashPrefix phase1Options['hashPrefix'] = ocp.hashPrefix # write the OCP exporter and run it, returning an exported OCP files = phase1.runPhase1(ocp, phase1Options, integratorOptions, ocpOptions) # add model for rt integrator files['model.c'] = '''\ #include "qpoases/solver.hpp" #include "rhs.h" #include "rhsJacob.h" ''' rtModelGen = rtModelExport.generateCModel(ocp.dae, ocp.ts, None) files['rhs.cpp'] = '#include "rhs.h"\n' + rtModelGen['rhsFile'][0] files['rhsJacob.cpp'] = '#include "rhsJacob.h"\n' + rtModelGen[ 'rhsJacobFile'][0] files['rhs.h'] = rtModelGen['rhsFile'][1] files['rhsJacob.h'] = rtModelGen['rhsJacobFile'][1] # add objective and jacobian externObj = writeObjective(ocp, ocp._minLsq, 'lsqExtern') externObjEnd = writeObjective(ocp, ocp._minLsqEndTerm, 'lsqEndTermExtern') externFile = '''\ #include "acado_external_functions.h" #include <math.h> #include <stdio.h> ''' externFile += externObj[0] + '\n' externFile += externObjEnd[0] files['acado_external_functions.cpp'] = externFile externHeader = externObj[1] + '\n' externHeader += externObjEnd[1] files['acado_external_functions.h'] = externHeader # #include objective/jacobian in acado_solver.c files['acado_solver.c'] = '#include "acado_external_functions.h"\n'+\ files['acado_solver.c'] # add python_interface.c files['python_interface.c'] = ocg_interface.ocg_interface if ocpOptions['QP_SOLVER'] == 'QP_QPOASES': exportPath = qpoases.exportPhase2(cgOptions, files) else: raise Exception('the impossible happened, unsupported qp solver: "' + str(ocpOptions['QP_SOLVER']) + '"') return exportPath
def exportOcp(ocp, ocpOptions, integratorOptions, cgOptions, phase1Options): defaultCgOptions = {'CXX':'g++', 'CC':'gcc', 'CXXFLAGS':'-O3 -fPIC -finline-functions', 'CFLAGS':'-O3 -fPIC -finline-functions', 'hideSymbols':False, 'export_without_build_path':None, 'force_export_path':None} defaultPhase1Options = {'CXX':'g++'} validateOptions(defaultCgOptions, cgOptions, "codegen") validateOptions(defaultPhase1Options, phase1Options, "phase 1") cgOptions['hashPrefix'] = ocp.hashPrefix phase1Options['hashPrefix'] = ocp.hashPrefix # write the OCP exporter and run it, returning an exported OCP files = phase1.runPhase1(ocp, phase1Options, integratorOptions, ocpOptions) # add model for rt integrator files['model.c'] = '''\ #include "qpoases/solver.hpp" #include "rhs.h" #include "rhsJacob.h" ''' rtModelGen = rtModelExport.generateCModel(ocp.dae, ocp.ts, None) files['rhs.cpp'] = '#include "rhs.h"\n'+rtModelGen['rhsFile'][0] files['rhsJacob.cpp'] = '#include "rhsJacob.h"\n'+rtModelGen['rhsJacobFile'][0] files['rhs.h'] = rtModelGen['rhsFile'][1] files['rhsJacob.h'] = rtModelGen['rhsJacobFile'][1] # add objective and jacobian externObj = writeObjective(ocp, ocp._minLsq, 'lsqExtern') externObjEnd = writeObjective(ocp, ocp._minLsqEndTerm, 'lsqEndTermExtern') externFile = '''\ #include "acado_external_functions.h" #include <math.h> #include <stdio.h> ''' externFile += externObj[0] + '\n' externFile += externObjEnd[0] files['acado_external_functions.cpp'] = externFile externHeader = externObj[1] + '\n' externHeader += externObjEnd[1] files['acado_external_functions.h'] = externHeader # #include objective/jacobian in acado_solver.c files['acado_solver.c'] = '#include "acado_external_functions.h"\n'+\ files['acado_solver.c'] # add python_interface.c files['python_interface.c'] = ocg_interface.ocg_interface if ocpOptions['QP_SOLVER'] == 'QP_QPOASES': exportPath = qpoases.exportPhase2(cgOptions, files) else: raise Exception('the impossible happened, unsupported qp solver: "'+str(ocpOptions['QP_SOLVER'])+'"') return exportPath
def exportOcp(ocp, ocpOptions, integratorOptions, cgOptions, phase1Options): defaultCgOptions = {'CXX':'g++', 'CC':'gcc', 'CXXFLAGS':'-O3 -fPIC -finline-functions', 'CFLAGS':'-O3 -fPIC -finline-functions', 'hideSymbols':False, 'export_without_build_path':None, 'force_export_path':None} defaultPhase1Options = {'CXX':'g++'} validateOptions(defaultCgOptions, cgOptions, "codegen") validateOptions(defaultPhase1Options, phase1Options, "phase 1") cgOptions['hashPrefix'] = ocp.hashPrefix phase1Options['hashPrefix'] = ocp.hashPrefix # write the OCP exporter and run it, returning an exported OCP files = phase1.runPhase1(ocp, phase1Options, integratorOptions, ocpOptions) # add model for rt integrator files['model.c'] = '''\ #include "qpoases/solver.hpp" #include "acado_external_functions.h" ''' rtModelGen = rtModelExport.generateCModel(ocp.dae, ocp.ts, None) # add objective and jacobian externObj = writeObjective(ocp, ocp._minLsq, 'lsqExtern') externObjEnd = writeObjective(ocp, ocp._minLsqEndTerm, 'lsqEndTermExtern') externFile = '''\ #include "acado_external_functions.h" #include <math.h> #include <stdio.h> ''' externFile += externObj[0] + '\n' externFile += externObjEnd[0] + '\n' externFile += rtModelGen['rhsFile'][0] + '\n' externFile += rtModelGen['rhsJacobFile'][0] files['acado_external_functions.cpp'] = externFile externHeader = externObj[1] + '\n' externHeader += externObjEnd[1] externHeader += rtModelGen['rhsFile'][1] + '\n' externHeader += rtModelGen['rhsJacobFile'][1] files['acado_external_functions.h'] = externHeader # #include objective/jacobian in acado_solver.c files['acado_solver.c'] = '#include "acado_external_functions.h"\n'+\ files['acado_solver.c'] if ocpOptions['QP_SOLVER'] == 'QP_QPDUNES': # Patch the source if we are using qpDUNES files['acado_solver.c'] = files['acado_solver.c'].replace("#include <qpDUNES.h>", "#include <qpdunes/qpDUNES.h>") # make c++ file with everything included files['everything.cpp'] = '''\ #include "acado_external_functions.cpp" #undef d #include "acado_common.h" #include "acado_integrator.c" #include "acado_solver.c" ACADOworkspace acadoWorkspace; ACADOvariables acadoVariables; ''' # add python_interface.c files['python_interface.c'] = ocg_interface.ocg_interface if ocpOptions['QP_SOLVER'] == 'QP_QPOASES': import qpoases exportPath = qpoases.exportPhase2(cgOptions, files) elif ocpOptions['QP_SOLVER'] == 'QP_HPMPC': import hpmpc exportPath = hpmpc.exportPhase2(cgOptions, files) elif ocpOptions['QP_SOLVER'] == 'QP_QPDUNES': import qpdunes exportPath = qpdunes.exportPhase2(cgOptions, files) elif ocpOptions['QP_SOLVER'] == 'QP_FORCES': import forces exportPath = forces.exportPhase2(cgOptions, files) else: raise Exception('the impossible happened, unsupported qp solver: "'+str(ocpOptions['QP_SOLVER'])+'"') return exportPath