Ejemplo n.º 1
0
def gen_robot_configs(ref_file, robot_num, vars_to_change,
                      param_var_num, root_save_dir):
    pre_gen_params = pre_gen_robot_params(vars_to_change=vars_to_change,
                                          param_var_num=param_var_num)
    for idx in tqdm(range(robot_num)):
        model = load_model_from_path(ref_file)
        sim = MjSim(model)
        robot_param_random_sample(sim, vars_to_change, pre_gen_params)
        sim.reset()
        sub_save_dir = os.path.join(root_save_dir, 'robot_%d' % idx)
        os.makedirs(sub_save_dir, exist_ok=True)
        with open(os.path.join(sub_save_dir, 'robot.xml'), 'w') as f:
            sim.save(f, keep_inertials=True)
Ejemplo n.º 2
0
def test_sim_save():
    model = load_model_from_xml(BASIC_MODEL_XML)
    assert model.nkey == 0
    sim = MjSim(model)

    with StringIO() as f:
        sim.save(f)

        f.seek(0)
        loaded_model = load_model_from_xml(f.read())

        assert loaded_model.nkey == 1

    with BytesIO() as f:
        sim.save(f, format='mjb')

        f.seek(0)
        loaded_model = load_model_from_mjb(f.read())
        assert loaded_model.nkey == 1
Ejemplo n.º 3
0
def test_sim_save():
    model = load_model_from_xml(BASIC_MODEL_XML)
    assert model.nkey == 0
    sim = MjSim(model)

    with StringIO() as f:
        sim.save(f)

        f.seek(0)
        loaded_model = load_model_from_xml(f.read())

        assert loaded_model.nkey == 1

    with BytesIO() as f:
        sim.save(f, format='mjb')

        f.seek(0)
        loaded_model = load_model_from_mjb(f.read())
        assert loaded_model.nkey == 1
Ejemplo n.º 4
0
def gen_robot_configs(ref_file, robot_num, vars_to_change, param_var_num,
                      skip_geom, root_save_dir):
    pre_gen_params = pre_gen_robot_params(vars_to_change=vars_to_change,
                                          param_var_num=param_var_num)
    joint_sites = ['j0', 'j1', 'j2', 'j3', 'j4', 'j5', 'j6']
    for idx in tqdm(range(robot_num)):
        model = load_model_from_path(ref_file)
        sim = MjSim(model)
        valid_joint_sites = [
            el for el in joint_sites if el in sim.model._site_name2id
        ]
        valid_joints_num = len(valid_joint_sites)

        robot_param_random_sample(sim, vars_to_change, pre_gen_params,
                                  valid_joints_num, skip_geom)
        sim.model.vis.map.znear = 0.02
        sim.model.vis.map.zfar = 50.0
        sim.reset()
        robot_id = int(re.findall(r'\d+', ref_file.split('/')[-1])[0])
        save_dir = os.path.join(
            root_save_dir, '%d_dof_%d_%d' % (valid_joints_num, robot_id, idx))
        os.makedirs(save_dir, exist_ok=True)
        with open(os.path.join(save_dir, 'robot.xml'), 'w') as f:
            sim.save(f, keep_inertials=True)