當前位置: 首頁>>代碼示例>>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: 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

示例4: 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

示例5: 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

示例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

    # Extension methods
    # ---------------------------- 
開發者ID:ArztSamuel,項目名稱:DRL_DeliveryDuel,代碼行數:10,代碼來源:robot_env.py

示例7: _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

示例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 = 90
        self.sim.forward()
        self.viewer.cam.distance = 1.5 
開發者ID:vikashplus,項目名稱:mj_envs,代碼行數:7,代碼來源:relocate_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.sim.forward()
        self.viewer.cam.distance = 1.0 
開發者ID:vikashplus,項目名稱:mj_envs,代碼行數:7,代碼來源:pen_v0.py

示例10: 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

示例11: _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

示例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;未經允許,請勿轉載。