Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[(Small) Feature]: small build util changes, extra humanoid keyframes + attrs #651

Merged
merged 7 commits into from
Oct 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 65 additions & 2 deletions mani_skill/agents/robots/unitree_g1/g1.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,25 @@ class UnitreeG1(BaseAgent):
keyframes = dict(
standing=Keyframe(
pose=sapien.Pose(p=[0, 0, 0.755]),
qpos=np.array([0.0] * 37) * 1,
)
# fmt: off
qpos=np.array(
[0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.2, -0.2, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.9, 0.9, 0.0, 0.0, 0.0, 0.0, 0.0, -0.77, -0.77, 0.0, 0.77, 0.77, 0.1, -0.92, -0.92, -0.1, 0.92, 0.92, 0.92, -0.92]
),
),
right_knee_up=Keyframe(
pose=sapien.Pose(p=[0, 0, 0.755]),
# fmt: off
qpos=np.array(
[0.0, -1.5, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.2, -0.2, 0.0, 1.5, 0.0, 0.0, 0.0, 0.0, 0.9, 0.9, 0.0, 0.0, 0.0, 0.0, 0.0, -0.77, -0.77, 0.0, 0.77, 0.77, 0.1, -0.92, -0.92, -0.1, 0.92, 0.92, 0.92, -0.92]
),
),
left_knee_up=Keyframe(
pose=sapien.Pose(p=[0, 0, 0.755]),
# fmt: off
qpos=np.array(
[-1.5, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.2, -0.2, 1.5, 0.0, 0.0, 0.0, 0.0, 0.0, 0.9, 0.9, 0.0, 0.0, 0.0, 0.0, 0.0, -0.77, -0.77, 0.0, 0.77, 0.77, 0.1, -0.92, -0.92, -0.1, 0.92, 0.92, 0.92, -0.92]
),
),
)

body_joints = [
Expand Down Expand Up @@ -66,6 +83,52 @@ class UnitreeG1(BaseAgent):
body_damping = 1
body_force_limit = 100

lower_body_joints = [
"left_hip_pitch_joint",
"right_hip_pitch_joint",
"left_hip_roll_joint",
"right_hip_roll_joint",
"left_hip_yaw_joint",
"right_hip_yaw_joint",
"left_knee_joint",
"right_knee_joint",
"left_ankle_pitch_joint",
"right_ankle_pitch_joint",
"left_ankle_roll_joint",
"right_ankle_roll_joint",
]
upper_body_joints = [
"torso_joint",
"left_shoulder_pitch_joint",
"right_shoulder_pitch_joint",
"left_shoulder_roll_joint",
"right_shoulder_roll_joint",
"left_shoulder_yaw_joint",
"right_shoulder_yaw_joint",
"left_elbow_pitch_joint",
"right_elbow_pitch_joint",
"left_elbow_roll_joint",
"right_elbow_roll_joint",
]
left_hand_joints = [
"left_zero_joint",
"left_three_joint",
"left_five_joint",
"left_one_joint",
"left_four_joint",
"left_six_joint",
"left_two_joint",
]
right_hand_joints = [
"right_zero_joint",
"right_three_joint",
"right_five_joint",
"right_one_joint",
"right_four_joint",
"right_six_joint",
"right_two_joint",
]

@property
def _controller_configs(self):
body_pd_joint_pos = PDJointPosControllerConfig(
Expand Down
48 changes: 39 additions & 9 deletions mani_skill/utils/building/actors/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,29 @@
Common utilities for adding primitive prebuilt shapes to a scene
"""

from typing import Optional, Union

import numpy as np
import sapien
import sapien.render

from mani_skill.envs.scene import ManiSkillScene
from mani_skill.utils.building.actor_builder import ActorBuilder
from mani_skill.utils.structs.pose import Pose
from mani_skill.utils.structs.types import Array


def _build_by_type(builder: ActorBuilder, name, body_type):
def _build_by_type(
builder: ActorBuilder,
name,
body_type,
scene_idxs: Optional[Array] = None,
initial_pose: Optional[Union[Pose, sapien.Pose]] = None,
):
if scene_idxs is not None:
builder.set_scene_idxs(scene_idxs)
if initial_pose is not None:
builder.set_initial_pose(initial_pose)
if body_type == "dynamic":
actor = builder.build(name=name)
elif body_type == "static":
Expand All @@ -30,6 +44,8 @@ def build_cube(
name: str,
body_type: str = "dynamic",
add_collision: bool = True,
scene_idxs: Optional[Array] = None,
initial_pose: Optional[Union[Pose, sapien.Pose]] = None,
):
builder = scene.create_actor_builder()
if add_collision:
Expand All @@ -42,7 +58,7 @@ def build_cube(
base_color=color,
),
)
return _build_by_type(builder, name, body_type)
return _build_by_type(builder, name, body_type, scene_idxs, initial_pose)


def build_box(
Expand All @@ -52,6 +68,8 @@ def build_box(
name: str,
body_type: str = "dynamic",
add_collision: bool = True,
scene_idxs: Optional[Array] = None,
initial_pose: Optional[Union[Pose, sapien.Pose]] = None,
):
builder = scene.create_actor_builder()
if add_collision:
Expand All @@ -64,7 +82,7 @@ def build_box(
base_color=color,
),
)
return _build_by_type(builder, name, body_type)
return _build_by_type(builder, name, body_type, scene_idxs, initial_pose)


def build_cylinder(
Expand All @@ -75,6 +93,8 @@ def build_cylinder(
name: str,
body_type: str = "dynamic",
add_collision: bool = True,
scene_idxs: Optional[Array] = None,
initial_pose: Optional[Union[Pose, sapien.Pose]] = None,
):
builder = scene.create_actor_builder()
if add_collision:
Expand All @@ -89,7 +109,7 @@ def build_cylinder(
base_color=color,
),
)
return _build_by_type(builder, name, body_type)
return _build_by_type(builder, name, body_type, scene_idxs, initial_pose)


def build_sphere(
Expand All @@ -99,6 +119,8 @@ def build_sphere(
name: str,
body_type: str = "dynamic",
add_collision: bool = True,
scene_idxs: Optional[Array] = None,
initial_pose: Optional[Union[Pose, sapien.Pose]] = None,
):
builder = scene.create_actor_builder()
if add_collision:
Expand All @@ -111,7 +133,7 @@ def build_sphere(
base_color=color,
),
)
return _build_by_type(builder, name, body_type)
return _build_by_type(builder, name, body_type, scene_idxs, initial_pose)


def build_red_white_target(
Expand All @@ -121,6 +143,8 @@ def build_red_white_target(
name: str,
body_type: str = "dynamic",
add_collision: bool = True,
scene_idxs: Optional[Array] = None,
initial_pose: Optional[Union[Pose, sapien.Pose]] = None,
):
TARGET_RED = np.array([194, 19, 22, 255]) / 255
builder = scene.create_actor_builder()
Expand Down Expand Up @@ -170,7 +194,7 @@ def build_red_white_target(
radius=radius * 1 / 5,
half_length=thickness / 2 + 4e-5,
)
return _build_by_type(builder, name, body_type)
return _build_by_type(builder, name, body_type, scene_idxs, initial_pose)


def build_twocolor_peg(
Expand All @@ -182,6 +206,8 @@ def build_twocolor_peg(
name: str,
body_type="dynamic",
add_collision: bool = True,
scene_idxs: Optional[Array] = None,
initial_pose: Optional[Union[Pose, sapien.Pose]] = None,
):
builder = scene.create_actor_builder()
if add_collision:
Expand All @@ -202,7 +228,7 @@ def build_twocolor_peg(
base_color=color_2,
),
)
return _build_by_type(builder, name, body_type)
return _build_by_type(builder, name, body_type, scene_idxs, initial_pose)


RED_COLOR = [220 / 255, 12 / 255, 12 / 255, 1]
Expand All @@ -221,6 +247,8 @@ def build_fourcolor_peg(
color_4=[1, 1, 1, 1],
body_type="dynamic",
add_collision: bool = True,
scene_idxs: Optional[Array] = None,
initial_pose: Optional[Union[Pose, sapien.Pose]] = None,
):
"""
A peg with four sections and four different colors. Useful for visualizing every possible rotation without any symmetries
Expand Down Expand Up @@ -258,7 +286,7 @@ def build_fourcolor_peg(
base_color=color_4,
),
)
return _build_by_type(builder, name, body_type)
return _build_by_type(builder, name, body_type, scene_idxs, initial_pose)


def build_colorful_cube(
Expand All @@ -268,6 +296,8 @@ def build_colorful_cube(
name: str,
body_type: str = "dynamic",
add_collision: bool = True,
scene_idxs: Optional[Array] = None,
initial_pose: Optional[Union[Pose, sapien.Pose]] = None,
):
builder = scene.create_actor_builder()

Expand All @@ -286,4 +316,4 @@ def build_colorful_cube(
base_color=color,
),
)
return _build_by_type(builder, name, body_type)
return _build_by_type(builder, name, body_type, scene_idxs, initial_pose)
9 changes: 6 additions & 3 deletions mani_skill/utils/building/ground.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Useful utilities for creating the ground of a scene
"""

from __future__ import annotations

import os.path as osp
Expand All @@ -24,16 +25,18 @@ def build_ground(
texture_file=osp.join(osp.dirname(__file__), "assets/grid_texture.png"),
texture_square_len=4,
mipmap_levels=4,
add_collision=True,
):
"""Procedurally creates a checkered floor given a floor width in meters.

Note that this function runs slower as floor width becomes larger, but in general this function takes no more than 0.05s to run
and usually is never run more than once as it is for building a scene, not loading.
"""
ground = scene.create_actor_builder()
ground.add_plane_collision(
sapien.Pose(p=[0, 0, altitude], q=[0.7071068, 0, -0.7071068, 0]),
)
if add_collision:
ground.add_plane_collision(
sapien.Pose(p=[0, 0, altitude], q=[0.7071068, 0, -0.7071068, 0]),
)
ground.initial_pose = sapien.Pose(p=[0, 0, 0], q=[1, 0, 0, 0])
if scene.parallel_in_single_scene:
# when building a ground and using a parallel render in the GUI, we want to only build one ground visual+collision plane
Expand Down