import numpy as np import time import mujoco import mujoco.viewer from robot_descriptions.loaders.mujoco import load_robot_description ''' pip install git+https://github.com/robot-descriptions/robot_descriptions.py.git@main ''' def mj_play(data, fr): m = load_robot_description("elf2_mj_description") # load robot description like python module # or load from local xml file # m = mujoco.MjModel.from_xml_path('path/to/elf2_dof25.xml') m.opt.timestep = 1.0/fr d = mujoco.MjData(m) len = data.shape[0] step = 0 with mujoco.viewer.launch_passive(m, d, show_left_ui=False, show_right_ui=False) as viewer: # set camera viewer.cam.lookat = d.body("base_link").xpos # camera following "base_link" body viewer.cam.distance = 5.0 viewer.cam.elevation = -20 #viewer.paused = True while viewer.is_running() and step 0: time.sleep(time_until_next_step) def read_rtj(fpath): #get frame rate from file name fr = fpath[-12:-9] fr = int(fr[1:]) if fr[0]=='_' else int(fr) jpos = np.load(fpath) jpos[:,2] += 0.793 return jpos,fr if __name__ == '__main__': jpos, fr = read_rtj('./bxi_elf2/CMU/01/01_01_poses_120_jpos.npy') mj_play(jpos, fr)