0.前置
- 机器人持续学习基准LIBERO系列1——基本介绍与安装测试
- 机器人持续学习基准LIBERO系列2——路径与基准基本信息
- 后面的代码是在这些基础上完成的
1.导包
from libero.libero.envs import OffScreenRenderEnv
from IPython.display import display
from PIL import Image
import torch
import torchvision
2.创建环境
env_args = {
"bddl_file_name": os.path.join(os.path.join(get_libero_path("bddl_files"), task.problem_folder, task.bddl_file)),
"camera_heights": 128,
"camera_widths": 128
}
env = OffScreenRenderEnv(**env_args)
#设置种子
env.seed(0)
#环境重置
env.reset()
#初始化
env.set_init_state(init_states[0])
3.运动机械臂更新环境,获取相机视角
- 这里的控制模式是OSC_POSE,参考robosuite相关资料,这篇博文里有控制模式相关解释,大致就是控制机械臂末端的平移和旋转
#运动机械臂更新环境
obs, _, _, _ = env.step([0.] * 7)
#获取手外相机视角图片
image = (obs["agentview_image"])
image_ = (obs["robot0_eye_in_hand_image"])
display(Image.fromarray(image))
display(Image.fromarray(image_))
obs, _, _, _ = env.step([500.,0.,0.,0.,0.,0.,0.] )
#获取手外相机视角图片
image = (obs["agentview_image"])
display(Image.fromarray(image))
obs, _, _, _ = env.step([500.,0.,0.,0.,0.,0.,0.] )
#获取手外相机视角图片
image = (obs["agentview_image"])
display(Image.fromarray(image))
obs, _, _, _ = env.step([500.,0.,0.,0.,0.,0.,0.] )
#获取手外相机视角图片
image = (obs["agentview_image"])
display(Image.fromarray(image))
运行结果
4.查看obs
- obs是观测字典,里面存储了观测信息,根据环境不同可能会有不同的物体位置相关的键
print(obs,keys())
- 结果如下:
odict_keys(['robot0_joint_pos', 'robot0_joint_pos_cos', 'robot0_joint_pos_sin', 'robot0_joint_vel', 'robot0_eef_pos', 'robot0_eef_quat', 'robot0_gripper_qpos', 'robot0_gripper_qvel', 'agentview_image', 'agentview_depth', 'robot0_eye_in_hand_image', 'robot0_eye_in_hand_depth', 'alphabet_soup_1_pos', 'alphabet_soup_1_quat', 'alphabet_soup_1_to_robot0_eef_pos', 'alphabet_soup_1_to_robot0_eef_quat', 'cream_cheese_1_pos', 'cream_cheese_1_quat', 'cream_cheese_1_to_robot0_eef_pos', 'cream_cheese_1_to_robot0_eef_quat', 'tomato_sauce_1_pos', 'tomato_sauce_1_quat', 'tomato_sauce_1_to_robot0_eef_pos', 'tomato_sauce_1_to_robot0_eef_quat', 'ketchup_1_pos', 'ketchup_1_quat', 'ketchup_1_to_robot0_eef_pos', 'ketchup_1_to_robot0_eef_quat', 'orange_juice_1_pos', 'orange_juice_1_quat', 'orange_juice_1_to_robot0_eef_pos', 'orange_juice_1_to_robot0_eef_quat', 'milk_1_pos', 'milk_1_quat', 'milk_1_to_robot0_eef_pos', 'milk_1_to_robot0_eef_quat', 'butter_1_pos', 'butter_1_quat', 'butter_1_to_robot0_eef_pos', 'butter_1_to_robot0_eef_quat', 'basket_1_pos', 'basket_1_quat', 'basket_1_to_robot0_eef_pos', 'basket_1_to_robot0_eef_quat', 'robot0_proprio-state', 'object-state'])
5.关闭环境
env.close()