Skip to content

Commit

Permalink
Improved demo code, moving some robot assets to other repos, bug fixes (
Browse files Browse the repository at this point in the history
#292)

* fix mjcf loader, improved demo robot script

* new keyframe

* default controller choices

* work

* fix bug withbalance passive force only working on combined controllers, add ur10e

* better visualswork

* move old assets to their own githubs
  • Loading branch information
StoneT2000 authored Apr 27, 2024
1 parent d772247 commit 83d279c
Show file tree
Hide file tree
Showing 219 changed files with 487 additions and 17,775 deletions.
Binary file modified docs/source/user_guide/concepts/images/replica_cad_rgbd.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
33 changes: 26 additions & 7 deletions mani_skill/agents/base_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@
from gymnasium import spaces

from mani_skill import format_path
from mani_skill.agents.controllers.pd_joint_pos import (
PDJointPosController,
PDJointPosControllerConfig,
)
from mani_skill.sensors.base_sensor import BaseSensor, BaseSensorConfig
from mani_skill.utils import sapien_utils
from mani_skill.utils.structs import Actor, Array, Articulation, Pose
Expand Down Expand Up @@ -105,7 +109,26 @@ def _sensor_configs(self) -> List[BaseSensorConfig]:
def _controller_configs(
self,
) -> Dict[str, Union[ControllerConfig, DictControllerConfig]]:
raise NotImplementedError()

return dict(
pd_joint_pos=PDJointPosControllerConfig(
[x.name for x in self.robot.active_joints],
lower=None,
upper=None,
stiffness=100,
damping=10,
normalize_action=False,
),
pd_joint_delta_pos=PDJointPosControllerConfig(
[x.name for x in self.robot.active_joints],
lower=-0.1,
upper=0.1,
stiffness=100,
damping=10,
normalize_action=True,
use_delta=True,
),
)

@property
def device(self):
Expand Down Expand Up @@ -170,26 +193,22 @@ def set_control_mode(self, control_mode=None):
# create controller on the fly here
if control_mode not in self.controllers:
config = self._controller_configs[self._control_mode]
balance_passive_force = True
if isinstance(config, dict):
balance_passive_force = True
if "balance_passive_force" in config:
balance_passive_force = config.pop("balance_passive_force")
self.controllers[control_mode] = CombinedController(
config,
self.robot,
self._control_freq,
scene=self.scene,
balance_passive_force=balance_passive_force,
)
else:
self.controllers[control_mode] = config.controller_cls(
config, self.robot, self._control_freq, scene=self.scene
)
self.controllers[control_mode].set_drive_property()
if (
isinstance(self.controllers[control_mode], DictController)
and self.controllers[control_mode].balance_passive_force
):
if balance_passive_force:
# NOTE (stao): Balancing passive force is currently not supported in PhysX, so we work around by disabling gravity
for link in self.robot.links:
link.disable_gravity = True
Expand Down
2 changes: 0 additions & 2 deletions mani_skill/agents/controllers/base_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,14 +190,12 @@ def __init__(
articulation: Articulation,
control_freq: int,
sim_freq: int = None,
balance_passive_force=True,
scene: ManiSkillScene = None,
):
self.scene = scene
self.configs = configs
self.articulation = articulation
self._control_freq = control_freq
self.balance_passive_force = balance_passive_force

self.controllers: Dict[str, BaseController] = dict()
for uid, config in configs.items():
Expand Down
1 change: 1 addition & 0 deletions mani_skill/agents/robots/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@
from .panda import Panda, PandaRealSensed435
from .trifingerpro import TriFingerPro
from .unitree_h1 import UnitreeH1, UnitreeH1Simplified
from .ur_e import UR10e
from .xarm import XArm7Ability
from .xmate3 import Xmate3Robotiq
41 changes: 8 additions & 33 deletions mani_skill/agents/robots/_template/template_robot.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,41 +9,19 @@
class TemplateRobot(BaseAgent):
uid = "todo-give-me-a-name!"
urdf_path = f"path/to/robot.urdf" # You can use f"{PACKAGE_ASSET_DIR}" to reference a urdf file in the mani_skill /assets package folder
urdf_config = dict()

def __init__(self, *args, **kwargs):
# useful to store some references to robot parts (links and joints) like so below, which is copied from the Panda robot implementation
self.arm_joint_names = [
"panda_joint1",
"panda_joint2",
"panda_joint3",
"panda_joint4",
"panda_joint5",
"panda_joint6",
"panda_joint7",
]
self.arm_stiffness = 1e3
self.arm_damping = 1e2
self.arm_force_limit = 100

self.gripper_joint_names = [
"panda_finger_joint1",
"panda_finger_joint2",
]
self.gripper_stiffness = 1e3
self.gripper_damping = 1e2
self.gripper_force_limit = 100

self.ee_link_name = "panda_hand_tcp"

super().__init__(*args, **kwargs)
# you may need to use this modify the friction values of some links in order to make it possible to e.g. grasp objects or avoid sliding on the floor
urdf_config = dict()

@property
def _controller_configs(self):
raise NotImplementedError()
# you will need to implement your controllers to control the robot here. If not implemented, ManiSkill will create two default controllers.
# One does PD joint position control, and the other is PD joint delta position control
# @property
# def _controller_configs(self):
# raise NotImplementedError()

@property
def _sensor_configs(self):
# Add custom cameras mounted to a link on the robot, or remove this if there aren't any you wish to simulate
return [
CameraConfig(
uid="your_custom_camera_on_this_robot",
Expand All @@ -57,6 +35,3 @@ def _sensor_configs(self):
entity_uid="your_mounted_camera",
)
]

def _after_init(self):
pass
29 changes: 27 additions & 2 deletions mani_skill/agents/robots/allegro_hand/allegro.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
from copy import deepcopy
from typing import List

import numpy as np
import sapien
import torch

from mani_skill import PACKAGE_ASSET_DIR
from mani_skill.agents.base_agent import BaseAgent
from mani_skill.agents.base_agent import BaseAgent, Keyframe
from mani_skill.agents.controllers import *
from mani_skill.agents.registration import register_agent
from mani_skill.utils import sapien_utils
Expand Down Expand Up @@ -35,7 +36,31 @@ class AllegroHandRight(BaseAgent):
),
},
)
sensor_configs = {}
keyframes = dict(
palm_up=Keyframe(
qpos=np.array(
[
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
]
),
pose=sapien.Pose([0, 0, 0.5], q=[-0.707, 0, 0.707, 0]),
)
)

def __init__(self, *args, **kwargs):
self.joint_names = [
Expand Down
4 changes: 2 additions & 2 deletions mani_skill/agents/robots/anymal/anymal_c.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@

@register_agent()
class ANYmalC(BaseAgent):
uid = "anymal-c"
urdf_path = f"{PACKAGE_ASSET_DIR}/robots/anymal-c/urdf/anymal_old.urdf"
uid = "anymal_c"
urdf_path = f"{PACKAGE_ASSET_DIR}/robots/anymal_c/urdf/anymal_old.urdf"
urdf_config = dict(
_materials=dict(
foot=dict(static_friction=2.0, dynamic_friction=2.0, restitution=0.0)
Expand Down
29 changes: 28 additions & 1 deletion mani_skill/agents/robots/fetch/fetch.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import torch

from mani_skill import PACKAGE_ASSET_DIR
from mani_skill.agents.base_agent import BaseAgent
from mani_skill.agents.base_agent import BaseAgent, Keyframe
from mani_skill.agents.controllers import *
from mani_skill.agents.registration import register_agent
from mani_skill.sensors.camera import CameraConfig
Expand Down Expand Up @@ -39,6 +39,33 @@ class Fetch(BaseAgent):
),
)

keyframes = dict(
rest=Keyframe(
pose=sapien.Pose(),
qpos=np.array(
np.array(
[
0,
0,
0,
0.1,
0,
-0.370,
0.562,
-0.75,
0.695,
1.0,
0.0,
np.pi / 2,
0,
0.015,
0.015,
]
)
),
)
)

@property
def _sensor_configs(self):
return [
Expand Down
36 changes: 35 additions & 1 deletion mani_skill/agents/robots/humanoid/humanoid.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import numpy as np
import sapien

from mani_skill import PACKAGE_ASSET_DIR
from mani_skill.agents.base_agent import BaseAgent
from mani_skill.agents.base_agent import BaseAgent, Keyframe
from mani_skill.agents.controllers import *
from mani_skill.agents.registration import register_agent
from mani_skill.sensors.camera import CameraConfig
Expand All @@ -12,6 +15,37 @@ class Humanoid(BaseAgent):
urdf_config = dict()
fix_root_link = False # False as there is a freejoint on the root body

keyframes = dict(
squat=Keyframe(
qpos=np.array(
[
0.0,
0.0,
0.0,
0.12,
0.0,
0.0,
0.0,
0.0,
0.0,
-0.25,
-0.25,
-0.25,
-0.25,
-0.5,
-0.5,
-1.3,
-1.3,
-0.8,
-0.8,
0.0,
0.0,
]
),
pose=sapien.Pose(p=[0, 0, -0.375]),
)
)

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)

Expand Down
22 changes: 21 additions & 1 deletion mani_skill/agents/robots/panda/panda.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import torch

from mani_skill import PACKAGE_ASSET_DIR
from mani_skill.agents.base_agent import BaseAgent
from mani_skill.agents.base_agent import BaseAgent, Keyframe
from mani_skill.agents.controllers import *
from mani_skill.agents.registration import register_agent
from mani_skill.utils import common, sapien_utils
Expand All @@ -31,6 +31,26 @@ class Panda(BaseAgent):
),
),
)

keyframes = dict(
rest=Keyframe(
qpos=np.array(
[
0.0,
np.pi / 8,
0,
-np.pi * 5 / 8,
0,
np.pi * 3 / 4,
np.pi / 4,
0.04,
0.04,
]
),
pose=sapien.Pose(),
)
)

arm_joint_names = [
"panda_joint1",
"panda_joint2",
Expand Down
6 changes: 3 additions & 3 deletions mani_skill/agents/robots/unitree_h1/h1.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import numpy as np
import sapien

from mani_skill import PACKAGE_ASSET_DIR
from mani_skill import ASSET_DIR
from mani_skill.agents.base_agent import BaseAgent, Keyframe
from mani_skill.agents.controllers import *
from mani_skill.agents.registration import register_agent
Expand All @@ -11,7 +11,7 @@
@register_agent()
class UnitreeH1(BaseAgent):
uid = "unitree_h1"
urdf_path = f"{PACKAGE_ASSET_DIR}/robots/unitree_h1/urdf/h1.urdf"
urdf_path = f"{ASSET_DIR}/robots/unitree_h1/urdf/h1.urdf"
urdf_config = dict()
fix_root_link = False
load_multiple_collisions = True
Expand Down Expand Up @@ -117,4 +117,4 @@ def is_fallen(self):
@register_agent()
class UnitreeH1Simplified(UnitreeH1):
uid = "unitree_h1_simplified"
urdf_path = f"{PACKAGE_ASSET_DIR}/robots/unitree_h1/urdf/h1_simplified.urdf"
urdf_path = f"{ASSET_DIR}/robots/unitree_h1/urdf/h1_simplified.urdf"
1 change: 1 addition & 0 deletions mani_skill/agents/robots/ur_e/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from .ur_10e import UR10e
Loading

0 comments on commit 83d279c

Please sign in to comment.