[python]mujoco_py安装后测试代码
mujoco_py测试:
import mujoco_py
import os
#mj_path, _ = mujoco_py.utils.discover_mujoco()
mj_path = mujoco_py.utils.discover_mujoco() #注意不同版本可能返回参数不一样
xml_path = os.path.join(mj_path, 'model', 'humanoid.xml')
model = mujoco_py.load_model_from_path(xml_path)
sim = mujoco_py.MjSim(model)
print(sim.data.qpos)
# [0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.]
sim.step()
print(sim.data.qpos)
# [-2.09531783e-19 2.72130735e-05 6.14480786e-22 -3.45474715e-06
# 7.42993721e-06 -1.40711141e-04 -3.04253586e-04 -2.07559344e-04
# 8.50646247e-05 -3.45474715e-06 7.42993721e-06 -1.40711141e-04
# -3.04253586e-04 -2.07559344e-04 -8.50646247e-05 1.11317030e-04
# -7.03465386e-05 -2.22862221e-05 -1.11317030e-04 7.03465386e-05
# -2.22862221e-05]
gym测试:
import gym
env = gym.make('Humanoid-v2')
from gym import envs
print(envs.registry.all()) # print the available environments
print(env.action_space)
print(env.observation_space)
print(env.observation_space.high)
print(env.observation_space.low)
for i_episode in range(200):
observation = env.reset()
for t in range(100):
env.render()
print(observation)
action = env.action_space.sample() # take a random action
observation, reward, done, info = env.step(action)
if done:
print("Episode finished after {} timesteps".format(t+1))
break
env.close()
原文地址:https://blog.csdn.net/FL1623863129/article/details/140184262
免责声明:本站文章内容转载自网络资源,如本站内容侵犯了原著者的合法权益,可联系本站删除。更多内容请关注自学内容网(zxcms.com)!