RoboSuite
RobotSuite github
主要包含Modeling APIs和Simulation APIs两部分。Modeling部分定义了环境和任务。 Simulation部分提供了policy。
Objects 比如 盒子或者罐子,通过 MujocoObject来进行控制,一方面可以通过 MujocoXMLObject生成, 另一方面可以通过 MujocoGeneratedObject来生成。
对应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
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
MujocoModel类是其他类的基础类。
RobotModel用于构建机器人。
拓展自 RobotModel。
作为Manipulator的一部分。
包含 Robot Model, Arena, Object Model。
robosuite.ALL_ENVIRONMENTS
'Lift',
'Stack',
'NutAssembly',
'NutAssemblySingle',
'NutAssemblySquare',
'NutAssemblyRound',
'PickPlace',
'PickPlaceSingle',
'PickPlaceMilk',
'PickPlaceBread',
'PickPlaceCereal',
'PickPlaceCan',
'Door',
'Wipe',
'TwoArmLift',
'TwoArmPegInHole',
'TwoArmHandover'
robosuite.ALL_ROBOTS
'Sawyer',
'Baxter',
'Panda',
'Jaco',
'Kinova3',
'IIWA',
'UR5e'
robosuite.ALL_CONTROLLERS
'JOINT_VELOCITY',
'JOINT_TORQUE',
'JOINT_POSITION',
'OSC_POSITION',
'OSC_POSE',
'IK_POSE'
robosuite.ALL_GRIPPERS
'RethinkGripper',
'PandaGripper',
'JacoThreeFingerGripper',
'JacoThreeFingerDexterousGripper',
'WipingGripper',
'Robotiq85Gripper',
'Robotiq140Gripper',
'RobotiqThreeFingerGripper',
'RobotiqThreeFingerDexterousGripper',
None
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)
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]))])