def makeMhe(dae,N,dt): from rawe.ocp import Ocp mhe = Ocp(dae, N=N, ts=dt) ocpOpts = rawe.OcpExportOptions() ocpOpts['HESSIAN_APPROXIMATION'] = 'GAUSS_NEWTON' ocpOpts['DISCRETIZATION_TYPE'] = 'MULTIPLE_SHOOTING' ocpOpts['QP_SOLVER'] = 'QP_QPOASES' ocpOpts['HOTSTART_QP'] = False ocpOpts['SPARSE_QP_SOLUTION'] = 'CONDENSING' # ocpOpts['SPARSE_QP_SOLUTION'] = 'FULL_CONDENSING_U2' # ocpOpts['AX_NUM_QP_ITERATIONS'] = '30' ocpOpts['FIX_INITIAL_STATE'] = False # mhe.minimizeLsq(C.veccat([mhe['x'],mhe['u']])) # mhe.minimizeLsqEndTerm(C.veccat([mhe['x']])) mhe.minimizeLsq(mhe['measurements']) mhe.minimizeLsqEndTerm(mhe['measurementsN']) cgOpts = {'CXX':'g++', 'CC':'gcc'} print "makeMhe calling rawe.OcpRT" return rawe.OcpRT(mhe, ocpOptions=ocpOpts, integratorOptions=intOpts, codegenOptions=cgOpts)
import casadi as C if __name__=='__main__': dae = rawe.dae.Dae() [pos,vel] = dae.addX( ["pos","vel"] ) dae.addZ('dummyZ') force = dae.addU( "force" ) endTime = dae.addP( 'someRandomParameter' ) # specify the dae residual dae.setResidual([dae.ddt('pos') - vel, dae.ddt('vel') - (force - 3.0*pos - 0.2*vel), dae['dummyZ']]) from rawe.ocp import Ocp mpc = Ocp(dae, N=10, ts=0.2) mpc.constrain(mpc['pos'], '==', 3, when='AT_START') mpc.constrain(mpc['vel'], '==', 0, when='AT_START') mpc.constrain(mpc['pos'], '==', 0, when='AT_END') mpc.constrain(mpc['vel'], '==', 0, when='AT_END') mpc.constrain(mpc['force']**2, '<=', 4) mpc.constrain(mpc['someRandomParameter']/4.0, '<=', 2) mpc.minimizeLsq(C.veccat([mpc['pos'],mpc['vel'],mpc['someRandomParameter']])) mpc.minimizeLsqEndTerm(C.veccat([mpc['pos']])) mpc.exportCode(CXX='clang++')