def __init__(self, solve_continuous=False): if not path.exists(self.xml_path): raise IOError("File %s does not exist" % xml_path) self.model = mjcore.MjModel(self.xml_path) self.u = None self.dt = self.model.opt.timestep self.start = None self.target = [0.0, 0.0, 0.0, 0.0] bounds = self.model.actuator_ctrlrange.copy() self.solve_continuous = False low = bounds[:, 0] high = bounds[:, 1] self.action_space = spaces.Box(low, high) self.metadata = { 'render.modes': ['human', 'rgb_array'], 'video.frames_per_second': int(np.round(1.0 / self.dt)) } #ILQR parameters self.t = 0 self.tN = 50 #number of time steps self.maxIter = 100 #maximum iterations self.lambFctr = 10 self.lambMx = 1000 self.epsConv = 1e-3 #converge threshold self.U = np.zeros((self.tN, 1))
def simulateFwd(self, x, u): #simulate locally localModel = mjcore.MjModel(self.xml_path) dof = localModel.nv localModel = self.setState(localModel, x) localModel = self.setControl(localModel, u, 1) xnext = self.getStateVector(localModel) return xnext
def simulateFwd(self, x, u): """ Simulate the arm dynamics locally. """ localModel = mjcore.MjModel(self.xml_path) dof = localModel.nv localModel = self.setState(localModel, x) localModel = self.setControl(localModel, u, 1) xnext = self.getStateVector(localModel) return xnext
def test_render(self): self.viewer.start() model = mjcore.MjModel(self.xml_path) self.viewer.set_model(model) (data, width, height) = self.viewer.get_image() # check image size is consistent # note that width and height may not equal self.width and self.height # e.g. on a computer with retina screen, # the width and height are scaled self.assertEqual(len(data), 3 * width * height) # make sure the image is not pitch black self.assertTrue(any(map(lambda x: x > 0, data)))
def __init__(self, solve_continuous=False): if not path.exists(self.xml_path): raise IOError("File %s does not exist" % xml_path) self.model = mjcore.MjModel(self.xml_path) self.u = None self.dt = self.model.opt.timestep self.target = [0, 0, 0, 0] bounds = self.model.actuator_ctrlrange.copy() self.solve_continuous = False low = bounds[:, 0] high = bounds[:, 1] self.action_space = spaces.Box(low, high) self.metadata = { 'render.modes': ['human', 'rgb_array'], 'video.frames_per_second': int(np.round(1.0 / self.dt)) }
def __init__(self, solve_continuous=False): if not path.exists(self.xml_path): raise IOError("File %s does not exist"%xml_path) self.model = mjcore.MjModel(self.xml_path) self.u = None self.dt = self.model.opt.timestep; self.start = None self.target = None numStates = 4 numCtrls = 1 self.Q = np.matrix(np.zeros((numStates,numStates))) self.Q[0,0] = 0; self.Q[1,1] = 100; self.R = np.matrix(np.eye(numCtrls)) bounds = self.model.actuator_ctrlrange.copy() self.solve_continuous = False low = bounds[:, 0] high = bounds[:, 1] self.action_space = spaces.Box(low, high) self.metadata = {'render.modes': ['human', 'rgb_array'], 'video.frames_per_second' : int(np.round(1.0 / self.dt))}
def __init__(self, model_name, config=MUJOCO_ENV): self.config = config self.xml_path = model_folder_path + model_name self.model = mjcore.MjModel(self.xml_path) self.dt = self.model.opt.timestep;
def load_model(self): if not os.path.exists(self._env_path): raise "Provided XML file does not exist." self.set_model(mjcore.MjModel(self._env_path)) logger.info("Loaded Mujoco model from {}".format(self._env_path))