介绍
主要包含Modeling APIs和Simulation APIs两部分。Modeling部分定义了环境和任务。 Simulation部分提供了policy。
- 其中Modeling APIs包含三部分: 机器人模型,物体模型和arena(场景)。
RobotModel包含了 机器人模型和对应的抓手模型;Object Mode包含了物体模型;Arena定义了机器人的工作空间和场景。这三个会生成一个MJCF文件,然后使用mujoco引擎生成仿真环境。 - Environment APIs包含了上述的Modeling APIs(Simulation Model),以及机器人控制的输入(获取action),获取环境的观测值作为输出(提供observation)。 作为直接与agent进行交互的API,是OpenAI Gym类型的类。
Environment 一方面可以调用已经写好的标准任务,也可以通过一系列configure来配置环境。
- Environment环境是模块化结构,能够快速改变机器人的结构(机械结构和控制方式),控制器的类型。 每一个environment都有自己的MJCF模型,通过_load_model来生成每个任务的实例。
- Task类 将 placement_initializer 作为输入,决定了 task中不同类的初始化。
- Robot 包含 RobotModel, GripperModel 和 Controller 三个类。
- Robot包含8中机器人,7种抓手和6种控制器。
- 每一个机器人都有一个独一无二的ID,相同种类的机器人可以在仿真器中同时仿真。
1.1 PandaGripper: 7自由度,平行抓手(手指较小)。
1.2 Sawyer: 7自由度,平行抓手(手指较长)。
1.3 IIWA: KUKA工业级机器人,7自由度,传动力最大。 抓手仿人两手指。
1.4 Jaco:KInova 7自由度,3手指抓手。
1.5 Kinova3: 7自由度,平行抓手。
1.6 UR5e:6自由度机器人,平行抓手。
1.7 Baxter: 双手机器人。
基于位置的控制,输入量为相对移动。
Objects 比如 盒子或者罐子,通过 MujocoObject来进行控制,一方面可以通过 MujocoXMLObject生成, 另一方面可以通过 MujocoGeneratedObject来生成。
- sensors 用于生成观测值。 机器人的关节位置和速度并不在sensor类中,而是直接作为robot类的属性 _joint_positions 和 _joint_velocities。
- I/O devices: 定义了用户通过teleoperator来控制机器人。
Environments
tasks
- Block Lifting: cube举起一定高度。
- Block Stacking: 多个cube进行堆叠。
- Pick-and-Place: 将对应的物体放在对应的箱子中。
- Nut Assembly: 装配。
- Door Opening: 开门。
- Table Wiping: 桌子表面擦拭。
- Two-Arm Lifting: 两个手臂提取壶。
- Two Arm Peg-In-Hole。
- Two-Arm HandOver.
documentation
Installation
对应MUJOCO 200.
sudo apt install curl git libgl1-mesa-dev libgl1-mesa-glx libglew-dev \
libosmesa6-dev software-properties-common net-tools unzip vim \
virtualenv wget xpra xserver-xorg-dev libglfw3-dev patchelf
pip install robosuite
QuickStart
import numpy as np
import robosuite as suite
# create environment instance
env = suite.make(
env_name="Lift", # try with other tasks like "Stack" and "Door"
robots="Panda", # try with other robots like "Sawyer" and "Jaco"
has_renderer=True,
has_offscreen_renderer=False,
use_camera_obs=False,
)
# reset the environment
env.reset()
# get action limits
low, high = env.action_spec
for i in range(1000):
action = np.random.randn(env.robots[0].dof) # sample random action
obs, reward, done, info = env.step(action) # take action in the environment
env.render() # render on display
Modules
Mujoco Model
MujocoModel类是其他类的基础类。
Robot Model
RobotModel用于构建机器人。
Manipulator Model
拓展自 RobotModel。
Gripper Model
作为Manipulator的一部分。
Object Model
Arena
Task
包含 Robot Model, Arena, Object Model。
Build tasks by standard components
environment
robosuite.ALL_ENVIRONMENTS
'Lift',
'Stack',
'NutAssembly',
'NutAssemblySingle',
'NutAssemblySquare',
'NutAssemblyRound',
'PickPlace',
'PickPlaceSingle',
'PickPlaceMilk',
'PickPlaceBread',
'PickPlaceCereal',
'PickPlaceCan',
'Door',
'Wipe',
'TwoArmLift',
'TwoArmPegInHole',
'TwoArmHandover'
robot
robosuite.ALL_ROBOTS
'Sawyer',
'Baxter',
'Panda',
'Jaco',
'Kinova3',
'IIWA',
'UR5e'
controller
robosuite.ALL_CONTROLLERS
'JOINT_VELOCITY',
'JOINT_TORQUE',
'JOINT_POSITION',
'OSC_POSITION',
'OSC_POSE',
'IK_POSE'
gripper
robosuite.ALL_GRIPPERS
'RethinkGripper',
'PandaGripper',
'JacoThreeFingerGripper',
'JacoThreeFingerDexterousGripper',
'WipingGripper',
'Robotiq85Gripper',
'Robotiq140Gripper',
'RobotiqThreeFingerGripper',
'RobotiqThreeFingerDexterousGripper',
None
env
import robosuite as suite
from robosuite import load_controller_config
from robosuite.wrappers import GymWrapper # gym
config = load_controller_config(default_controller='JOINT_POSITION')
# first we build the grasp task
env = suite.make(
env_name='PickPlaceCan',
# env_configuration=,
robots='Jaco',
gripper_types='PandaGripper',
controller_configs=config,
has_renderer=True,
has_offscreen_renderer=False,
ignore_done=True,
use_camera_obs=False,
use_object_obs=True,
horizon=10000,
reward_shaping=True, # use dense rewards
control_freq=20)
parameters
robots and objects
env.robots[0]
# 单机械臂环境中只有一个机器人,所以index=0 |
# 也就是说 robosuite中可以实现 双机械臂控制,
# 对应任务 'TwoArmLift', 'TwoArmPegInHole', 'TwoArmHandover'
# _joint 和 _hand 分别对应 机械臂和hand
# gripper表示抓手
!!!! hand 并不是 end-effector
env.robot[0] 没有找到关于gripper的状态。 environment返回的状态可以在下一部分获得。
# --------action space----------------
print("action dim", env.robots[0].action_dim)
>>> action dim 8
print("action limits", env.robots[0].action_limits)
>>> action limits (array([-1., -1., -1., -1., -1., -1., -1., -1.]), array([1., 1., 1., 1., 1., 1., 1., 1.])) # 动作有8个自由度, 7个机械臂 + 1个gripper,并且动作范围都在 [-1,1]之间
# --------observation space------------
# #### ------joint state---------------
print("robot joints", env.robots[0].robot_joints)
>>> robot joints ['robot0_j2s7s300_joint_1', 'robot0_j2s7s300_joint_2', 'robot0_j2s7s300_joint_3', 'robot0_j2s7s300_joint_4', 'robot0_j2s7s300_joint_5', 'robot0_j2s7s300_joint_6', 'robot0_j2s7s300_joint_7']
print("joint pos", env.robots[0]._joint_positions)
>>> joint pos [3.17274829e+00 3.67605222e+00 1.99827716e-03 1.12296742e+00
3.16228320e-02 3.76672808e+00 3.13208957e+00] # joint pos 最大范围是 [-2*pi,2*pi]
print("joint vel", env.robots[0]._joint_velocities)
>>> joint vel [0. 0. 0. 0. 0. 0. 0.]
# ### --------hand state---------------
print("hand pos", env.robots[0]._hand_pos)
>>> hand pos [ 0.37779775 -0.00454982 0.26592814]
print("hand orn", env.robots[0]._hand_orn)
>>> hand orn [[ 0.99918625 -0.0160639 -0.03699711]
[-0.01675014 -0.99969197 -0.01831366]
[-0.03669152 0.01891847 -0.99914755]] # 旋转矩阵法
print("hand pose", env.robots[0]._hand_pose)
>>> hand pose [[ 0.99918625 -0.0160639 -0.03699711 0.37779775]
[-0.01675014 -0.99969197 -0.01831366 -0.00454982]
[-0.03669152 0.01891847 -0.99914755 0.26592814]
[ 0. 0. 0. 1. ]] # 等于 pos + orn
print("hand quat", env.robots[0]._hand_quat)
>>> hand quat [ 0.9997532 -0.00820553 -0.0184267 0.00931033] # 四元数表示
print("hand vel", env.robots[0]._hand_vel)
>>> hand vel [0. 0. 0.] # 线速度
print("hand ang vel", env.robots[0]._hand_ang_vel)
>>> hand ang vel [0. 0. 0.] # 角速度
print("hand total vel", env.robots[0]._hand_total_velocity)
>>> hand total vel [0. 0. 0. 0. 0. 0.] # 线速度 + 角速度
# ### ------------gripper state-------------
print("gripper",env.robots[0].gripper)
>>> gripper <robosuite.models.grippers.panda_gripper.PandaGripper object at 0x7f41a4e5ca90>
print("gripper action", env.robots[0].grip_action)
>>> gripper action <bound method Manipulator.grip_action of <robosuite.robots.single_arm.SingleArm object at 0x7f41d46f3a58>>
print("gripper joints", env.robots[0].gripper_joints)
>>> gripper joints ['gripper0_finger_joint1', 'gripper0_finger_joint2']
observation:
{
"frontview_image": np.array(...), # this has modality "image"
"frontview_depth": np.array(...), # this has modality "image"
"frontview_segmentation_instance": np.array(...), # this has modality "image"
"robot0_joint_pos": np.array(...), # this has modality "robot0_proprio"
"robot0_gripper_pos": np.array(...), # this has modality "robot0_proprio"
"image-state": np.array(...), # this is a concatenation of all image observations
"robot0_proprio-state": np.array(...), # this is a concatenation of all robot0_proprio observations
}
OrderedDict([
('robot0_joint_pos_cos', array([-0.99769503, -0.85681021, 0.99980593, 0.41310899, 0.99930241,-0.8115118 , -0.99999725])),
('robot0_joint_pos_sin', array([-0.06785743, -0.51563191, 0.01970008, 0.91068159, 0.03734571,
-0.58433603, -0.00234431])),
('robot0_joint_vel', array([0., 0., 0., 0., 0., 0., 0.])),
('robot0_eef_pos', array([-0.11723944, -0.12816939, 1.08193961])),
('robot0_eef_quat', array([ 0.9994818 , -0.02599663, -0.01115 , 0.01536171])),
('robot0_gripper_qpos', array([ 0.020833, -0.020833])),
('robot0_gripper_qvel', array([0., 0.])),
('Can_pos', array([ 0.17312353, -0.21908787, 0.86 ])),
('Can_quat', array([0. , 0. , 0.9774751 , 0.21105077])),
('Can_to_robot0_eef_pos', array([0.29942357, 0.0688192 , 0.21781518])),
('Can_to_robot0_eef_quat', array([ 0.18553033, -0.98245513, -0.0173689 , 0.00765675], dtype=float32)),
('robot0_proprio-state', array([-0.99769503, -0.85681021, 0.99980593, 0.41310899, 0.99930241,
-0.8115118 , -0.99999725, -0.06785743, -0.51563191, 0.01970008,
0.91068159, 0.03734571, -0.58433603, -0.00234431, 0. ,
0. , 0. , 0. , 0. , 0. ,
0. , -0.11723944, -0.12816939, 1.08193961, 0.9994818 ,
-0.02599663, -0.01115 , 0.01536171, 0.020833 , -0.020833 ,
0. , 0. ])),
('object-state', array([ 0.17312353, -0.21908787, 0.86 , 0. , 0.,
0.9774751 , 0.21105077, 0.29942357, 0.0688192 , 0.21781518,
0.18553033, -0.98245513, -0.0173689 , 0.00765675]))])
下一篇: Robosuite Stack 环境解析