当前位置: 首页>>代码示例>>Python>>正文


Python mujoco_py.MjViewer方法代码示例

本文整理汇总了Python中mujoco_py.MjViewer方法的典型用法代码示例。如果您正苦于以下问题:Python mujoco_py.MjViewer方法的具体用法?Python mujoco_py.MjViewer怎么用?Python mujoco_py.MjViewer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在mujoco_py的用法示例。


在下文中一共展示了mujoco_py.MjViewer方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: render

# 需要导入模块: import mujoco_py [as 别名]
# 或者: from mujoco_py import MjViewer [as 别名]
def render(self, mode='human'):
        ''' Render the environment to the screen '''
        if self.viewer is None:
            self.viewer = MjViewer(self.sim)
            # Turn all the geom groups on
            self.viewer.vopt.geomgroup[:] = 1
            # Set camera if specified
            if mode == 'human':
                self.viewer.cam.fixedcamid = -1
                self.viewer.cam.type = const.CAMERA_FREE
            else:
                self.viewer.cam.fixedcamid = self.model.camera_name2id(mode)
                self.viewer.cam.type = const.CAMERA_FIXED
        if self.update_viewer_sim:
            self.viewer.update_sim(self.sim)
            self.update_viewer_sim = False
        self.viewer.render() 
开发者ID:openai,项目名称:safety-gym,代码行数:19,代码来源:world.py

示例2: play_trajectory_demo

# 需要导入模块: import mujoco_py [as 别名]
# 或者: from mujoco_py import MjViewer [as 别名]
def play_trajectory_demo(self, freq=200):
        """
        Plays a demo of the loaded trajectory by forcing the model
        positions to the ones in the reference trajectory at every step

        """
        viewer = mujoco_py.MjViewer(self.sim)
        viewer._render_every_frame = True
        self.reset_trajectory()
        while True:
            if self.subtraj_step_no >= self.traj_length:
                self.get_next_sub_trajectory()

            self.sim.data.qpos[0:15] = np.r_[
                self.x_dist + self.subtraj[0, self.subtraj_step_no],
                self.subtraj[1:15, self.subtraj_step_no]
            ]
            self.sim.data.qvel[0:14] = self.subtraj[15:29, self.subtraj_step_no]
            self.sim.forward()

            self.subtraj_step_no += 1
            time.sleep(1 / freq)
            viewer.render() 
开发者ID:MushroomRL,项目名称:mushroom-rl,代码行数:25,代码来源:trajectory.py

示例3: start_simulation

# 需要导入模块: import mujoco_py [as 别名]
# 或者: from mujoco_py import MjViewer [as 别名]
def start_simulation(self):
        """
            Starts simulation of the test world
        """
        model = self.world.get_model(mode="mujoco_py")

        self.sim = MjSim(model)
        if self.render:
            self.viewer = MjViewer(self.sim)
        self.sim_state = self.sim.get_state()

        # For gravity correction
        gravity_corrected = ["gripper_z_joint"]
        self._gravity_corrected_qvels = [
            self.sim.model.get_joint_qvel_addr(x) for x in gravity_corrected
        ]

        self.gripper_z_id = self.sim.model.actuator_name2id("gripper_z")
        self.gripper_z_is_low = False

        self.gripper_joint_ids = [
            self.sim.model.actuator_name2id("gripper_" + x)
            for x in self.gripper.joints
        ]
        self.gripper_open_action = self.gripper.format_action([1])
        self.gripper_closed_action = self.gripper.format_action(
            [-1]
        )
        self.gripper_is_closed = True

        self.object_id = self.sim.model.body_name2id("object")
        object_default_pos = self.sim.data.body_xpos[self.object_id]
        self.object_default_pos = np.array(object_default_pos,
                                           copy=True)

        self.reset()
        self.simulation_ready = True 
开发者ID:StanfordVL,项目名称:robosuite,代码行数:39,代码来源:gripper_tester.py

示例4: get_img

# 需要导入模块: import mujoco_py [as 别名]
# 或者: from mujoco_py import MjViewer [as 别名]
def get_img(env_name, seed):
    env = make_env(env_name, int(seed), 0, None)
    env = AnnotatedGymCompete(env, env_name, 'zoo', '1', 'zoo', '1', None,
                              resolution=(640, 480), font='times', font_size=24,
                              draw=False)
    env.reset()

    env_scene = env.unwrapped.env_scene
    env_scene.viewer = mujoco_py.MjViewer(init_width=1000, init_height=750)
    env_scene.viewer.start()
    env_scene.viewer.set_model(env_scene.model)
    env_scene.viewer_setup()

    print("Type save to save the image, step to take one timestep.")

    running = True
    while running:
        img = None
        while sys.stdin not in select.select([sys.stdin], [], [], 0)[0]:
            env.render()
            img = env.render(mode='rgb_array')

        input = sys.stdin.readline().strip()
        if input == 'save':
            running = False
        elif input == 'step':
            action = tuple(np.zeros(space.shape) for space in env.action_space.spaces)
            env.step(action)
        else:
            print(f"Unrecognized command '{input}'")

    return img 
开发者ID:HumanCompatibleAI,项目名称:adversarial-policies,代码行数:34,代码来源:grab_frame.py

示例5: _get_viewer

# 需要导入模块: import mujoco_py [as 别名]
# 或者: from mujoco_py import MjViewer [as 别名]
def _get_viewer(self):
        if self.viewer is None:
            self.viewer = mujoco_py.MjViewer(self.sim)
            self._viewer_setup()
        return self.viewer

    # Extension methods
    # ---------------------------- 
开发者ID:ArztSamuel,项目名称:DRL_DeliveryDuel,代码行数:10,代码来源:robot_env.py

示例6: _get_viewer

# 需要导入模块: import mujoco_py [as 别名]
# 或者: from mujoco_py import MjViewer [as 别名]
def _get_viewer(self):
        if self.viewer is None:
            self.viewer = mujoco_py.MjViewer(self.sim)
            self.viewer_setup()
        return self.viewer 
开发者ID:ArztSamuel,项目名称:DRL_DeliveryDuel,代码行数:7,代码来源:mujoco_env.py

示例7: mj_viewer_setup

# 需要导入模块: import mujoco_py [as 别名]
# 或者: from mujoco_py import MjViewer [as 别名]
def mj_viewer_setup(self):
        self.viewer = MjViewer(self.sim)
        self.viewer.cam.azimuth = 90
        self.sim.forward()
        self.viewer.cam.distance = 1.5 
开发者ID:vikashplus,项目名称:mj_envs,代码行数:7,代码来源:relocate_v0.py

示例8: mj_viewer_setup

# 需要导入模块: import mujoco_py [as 别名]
# 或者: from mujoco_py import MjViewer [as 别名]
def mj_viewer_setup(self):
        self.viewer = MjViewer(self.sim)
        self.viewer.cam.azimuth = -45
        self.sim.forward()
        self.viewer.cam.distance = 1.0 
开发者ID:vikashplus,项目名称:mj_envs,代码行数:7,代码来源:pen_v0.py

示例9: mj_viewer_setup

# 需要导入模块: import mujoco_py [as 别名]
# 或者: from mujoco_py import MjViewer [as 别名]
def mj_viewer_setup(self):
        self.viewer = MjViewer(self.sim)
        self.viewer.cam.azimuth = 45
        self.viewer.cam.distance = 2.0
        self.sim.forward() 
开发者ID:vikashplus,项目名称:mj_envs,代码行数:7,代码来源:hammer_v0.py

示例10: _get_viewer

# 需要导入模块: import mujoco_py [as 别名]
# 或者: from mujoco_py import MjViewer [as 别名]
def _get_viewer(self):
        if self.viewer is None:
            self.viewer = mujoco_py.MjViewer(visible=True, init_width=500, init_height=500, go_fast=False)
            self.viewer.start()
            self.viewer.set_model(self.model)
            self.viewer_setup()
        return self.viewer 
开发者ID:atavakol,项目名称:action-branching-agents,代码行数:9,代码来源:reacher_6dof.py

示例11: run

# 需要导入模块: import mujoco_py [as 别名]
# 或者: from mujoco_py import MjViewer [as 别名]
def run(self):
        (_, _, obs_rgb_view2) = self.env.reset()

        if self.render:
            viewer = mujoco_py.MjViewer(self.env.sim)
        else:
            f, ax = plt.subplots()
            im = ax.imshow(obs_rgb_view2)

        while True:
            self.env.reset()

            while True:

                # random action selection
                action = np.random.choice([0, 1, 2, 3, 4], 6)

                # take the random action and observe the reward and next state (2 rgb views and proprioception)
                (obs_joint, obs_rgb_view1, obs_rgb_view2), reward, done = self.env.step(action)

                # print("action : ", action)
                # print("reward : ", reward)

                if done:
                    break

                if self.render:
                    viewer.render()
                else:
                    im.set_data(obs_rgb_view2)
                    plt.draw()
                    plt.pause(0.1) 
开发者ID:Feryal,项目名称:a3c-mujoco,代码行数:34,代码来源:random_agent.py

示例12: get_viewer

# 需要导入模块: import mujoco_py [as 别名]
# 或者: from mujoco_py import MjViewer [as 别名]
def get_viewer(self):
        if self.viewer is None:
            self.viewer = MjViewer(self.sim)
        return self.viewer 
开发者ID:rlworkgroup,项目名称:gym-sawyer,代码行数:6,代码来源:mujoco_env.py

示例13: _get_viewer

# 需要导入模块: import mujoco_py [as 别名]
# 或者: from mujoco_py import MjViewer [as 别名]
def _get_viewer(self, mode):
        self.viewer = self._viewers.get(mode)
        if self.viewer is None:
            if mode == 'human':
                self.viewer = mujoco_py.MjViewer(self.sim)
            elif mode == 'rgb_array' or mode == 'depth_array':
                self.viewer = mujoco_py.MjRenderContextOffscreen(self.sim, -1)
                
            self.viewer_setup()
            self._viewers[mode] = self.viewer
        return self.viewer 
开发者ID:joanby,项目名称:ia-course,代码行数:13,代码来源:mujoco_env.py

示例14: get_current_image_obs

# 需要导入模块: import mujoco_py [as 别名]
# 或者: from mujoco_py import MjViewer [as 别名]
def get_current_image_obs(self):
        # print(self._get_viewer)
        # print(self._get_viewer())
        # self.viewer = mujoco_py.MjRenderContextOffscreen(self.sim, -1)
        # self.viewer = mujoco_py.MjViewer()
        # self.viewer.start()
        # self.viewer.set_model(self.model)
        # self.viewer_setup()
        # self._get_viewer()

        
        # image = self.viewer.get_image()
        # pil_image = Image.frombytes('RGB', (image[1], image[2]), image[0])
        # pil_image = pil_image.resize((125,125), Image.ANTIALIAS)
        # image = np.flipud(np.array(pil_image))

        # image = self.render(mode='rgb_array', width=125, height=125)
        # transpose to make it have correct ordering of dimensions for pytorch
        # image = image.transpose((2,0,1))
        # image = np.array(image).astype(np.float32)
        # image /= 255.0

        image = self.render(mode='rgb_array', width=500, height=500)
        image = Image.fromarray(image)
        image = image.resize((125,125), PIL.Image.LANCZOS)
        image = np.array(image)
        image = image.transpose((2,0,1))
        image = np.array(image).astype(np.float32)
        image /= 255.0

        X = np.concatenate([
            self.sim.data.qpos.flat[:7],
            self.sim.data.qvel.flat[:7],
            self.get_body_com('tips_arm'),
            self.get_body_com('goal'),
        ]).copy()
        X = (X - self.state_mean) / self.state_std

        return image, X 
开发者ID:KamyarGh,项目名称:rl_swiss,代码行数:41,代码来源:mil_pusher_env.py

示例15: mj_viewer_setup

# 需要导入模块: import mujoco_py [as 别名]
# 或者: from mujoco_py import MjViewer [as 别名]
def mj_viewer_setup(self):
        self.viewer = MjViewer(self.sim)
        self.sim.forward() 
开发者ID:aravindr93,项目名称:mjrl,代码行数:5,代码来源:point_mass.py


注:本文中的mujoco_py.MjViewer方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。