def run(self,x0,x1,autoInit=True,threshold=1e-3,**kwargs): if autoInit: _,_,T = self.buildInitGuess(x0,x1) if 'horizon' not in self.options: if 'additionalOptions' not in kwargs: kwargs['additionalOptions'] = '' kwargs['additionalOptions'] += ' --horizon=%.4f' % T[-1] AcadoRunner.run(self,states=self.stateDict(x0,x1), **kwargs) # # Run may raise an error but always return True. return self.checkResult(True,x0,x1,threshold=threshold)
def __init__(self,path="/home/nmansard/src/pinocchio/pycado/build/unittest/connect_pendulum", model=None,data=None,datadir='/tmp/'): AcadoRunner.__init__(self,path) self.options['istate'] = datadir+'guess.stx' self.options['icontrol'] = datadir+'guess.ctl' self.options['ocontrol'] = datadir+'mpc.ctl' self.options['ostate'] = datadir+'mpc.stx' self.options['oparam'] = datadir+'mpc.prm' self.withRunningCost = False # The problem is Mayer cost. self.guess = InitGuessBuilder(model,data)
def run_async(self,x0,x1,autoInit=True,jobid=None, **kwargs): # We have to pre-book to know where the init-guess should be stored. if jobid is None: jobid = self.book_async() if autoInit: _,_,T = self.buildInitGuess(x0,x1,jobid=jobid) if 'horizon' not in self.options: if 'additionalOptions' not in kwargs: kwargs['additionalOptions'] = '' kwargs['additionalOptions'] += ' --horizon=%.4f' % T[-1] return AcadoRunner.run_async(self, states = self.stateDict(x0,x1), jobid = jobid, **kwargs)
def join(self,jobid,x1=None,x2=None,threshold=1e-3,**kwargs): '''Join the solver process and check if the result satisfies the constraints''' ret = AcadoRunner.join(self,jobid,**kwargs) return self.checkResult(ret,x1,x2,jobid,threshold)
def rerun(self): return AcadoRunner.run(self) # DEPREC??? # --- ASYNC -------------------------------------------------------------------------- # --- ASYNC -------------------------------------------------------------------------- # --- ASYNC -------------------------------------------------------------------------- def run_async(self,x0,x1,autoInit=True,jobid=None, **kwargs):
def initrun(self,x0,x1,iterations=100,autoInit = True,**kwargs): if autoInit: self.buildInitGuess(x0,x1) AcadoRunner.initrun(self, states=self.stateDict(x0,x1), iterations=iterations) return self.checkResult(True,x0,x1)
x, reward = env.step(u) env.render() time.sleep(1e-1) rsum += reward if verbose: print 'Lasted ', i, ' timestep -- total reward:', rsum signal.signal(signal.SIGTSTP, lambda x, y: rendertrial()) # Roll-out when CTRL-Z is pressed env.NDT = 1 env.modulo = False from acado_runner import AcadoRunner acado = AcadoRunner() acado.options['horizon'] = NSTEPS * env.DT acado.options['steps'] = NSTEPS acado.options['shift'] = 0 acado.options['iter'] = 20 acado.options['friction'] = env.Kf acado.options['decay'] = DECAY_RATE acado.options['icontrol'] = '/tmp/guess.ctl' del acado.options['istate'] def policyOptim(x0): ''' Rollout the net to get a warmstart, then run Acado to optimize the warmstart Return the policy and the value at input state. '''
mod = round(env.x[0, 0] / 2 / np.pi) dx = -mod * 2 * np.pi X[:, 0] += dx return X, U x0 = np.matrix([2., .2]).T #X,U=rollout(x0) env.NDT = 10 x0 = np.matrix([0.30459664, -7.20891078]).T NNODES = 16 FNODES = NSTEPS / NNODES from acado_runner import AcadoRunner acado = AcadoRunner( "/home/nmansard/src/pinocchio/pycado/build/unittest/pendulum2o") acado.options['horizon'] = NSTEPS * env.DT acado.options['steps'] = NNODES acado.options['shift'] = 0 acado.options['iter'] = 10 # 100 acado.options['friction'] = env.Kf #acado.options['decay'] = 0 # DECAY_RATE #del acado.options['istate'] def policyOptim(x0=None): X, U = rollout(x0) guess = np.hstack([ np.matrix(np.arange(0, (NSTEPS + 1) * env.DT, env.DT)).T, X, U, zero(NSTEPS + 1),