Skip to content

Commit

Permalink
added stompyv2
Browse files Browse the repository at this point in the history
  • Loading branch information
nathanjzhao committed Jul 4, 2024
1 parent 822797f commit 85405f7
Show file tree
Hide file tree
Showing 15 changed files with 574 additions and 32 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# .gitignore

# Robot Parts
*.stl
*.dae
*.urdf
# Local files
.env
# Python
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ python sim/humanoid_gym/train.py --task=stompy_ppo --num_envs=4096 --headless
3. Run evaluation with the following command:
```bash
python sim/humanoid_gym/play.py --task legs_ppo --sim_device cpu

```
See [this doc](https://docs.google.com/document/d/1YZzBqIXO7oq7vIKu-BZr5ssNsi3nKtxpRPnfSnTXojA/edit?usp=sharing) for more beginner tips.

Expand Down
2 changes: 1 addition & 1 deletion sim/deploy/run.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

from sim.deploy.config import RobotConfig
from sim.env import stompy_mjcf_path
from sim.stompy.joints import StompyFixed
from sim.stompy2.joints import StompyFixed


class Worlds(Enum):
Expand Down
9 changes: 8 additions & 1 deletion sim/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,16 @@
import os
from pathlib import Path

from dotenv import load_dotenv

load_dotenv()


def model_dir() -> Path:
return Path(os.environ.get("MODEL_DIR", "models"))
# return Path(os.environ.get("MODEL_DIR", "models"))
# return Path(os.environ.get("MODEL_DIR", "stompytherobot"))
# return Path("/home/dpsh/isaacs_sim/sim/sim/stompy2")
return Path("/home/dpsh/isaacs_sim/sim/sim/stompy2")


def run_dir() -> Path:
Expand Down
10 changes: 7 additions & 3 deletions sim/humanoid_gym/envs/getup_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from humanoid.envs.base.legged_robot_config import LeggedRobotCfg, LeggedRobotCfgPPO

from sim.env import stompy_urdf_path
from sim.stompy.joints import Stompy
from sim.stompy2.joints import Stompy

NUM_JOINTS = len(Stompy.all_joints()) # 37

Expand Down Expand Up @@ -39,8 +39,12 @@ class asset(LeggedRobotCfg.asset): # noqa: N801
file = str(stompy_urdf_path())

name = "stompy"
foot_name = "_leg_1_x4_1_outer_1" # "foot"
knee_name = "belt_knee" # "knee"
foot_name = "_foot_1_rmd_x4_24_mock_1_inner_rmd_x4_24_1"
knee_name = "_rmd_x8_90_mock_3_inner_rmd_x8_90_1"

# old
# foot_name = "_leg_1_x4_1_outer_1" # "foot"
# knee_name = "belt_knee"
terminate_after_contacts_on = [] # "link_torso_1_top_torso_1"]
penalize_contacts_on = []
self_collisions = 1 # 1 to disable, 0 to enable...bitwise filter
Expand Down
2 changes: 1 addition & 1 deletion sim/humanoid_gym/envs/getup_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from isaacgym import gymtorch
from isaacgym.torch_utils import *

from sim.stompy.joints import Stompy
from sim.stompy2.joints import Stompy

default_feet_height = 0.0

Expand Down
14 changes: 10 additions & 4 deletions sim/humanoid_gym/envs/legs_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from sim.env import stompy_urdf_path
from sim.humanoid_gym.envs.stompy_config import StompyCfg
from sim.stompy.joints import StompyFixed
from sim.stompy2.joints import StompyFixed

NUM_JOINTS = len(StompyFixed.default_standing()) # 17

Expand Down Expand Up @@ -33,13 +33,19 @@ class asset(LeggedRobotCfg.asset):

name = "stompy"

foot_name = "_leg_1_x4_1_outer_1" # "foot"
knee_name = "belt_knee"
# foot_name = "_foot_1_foot_1"
foot_name = "_foot_1_rmd_x4_24_mock_1_inner_rmd_x4_24_1"
knee_name = "_rmd_x8_90_mock_3_inner_rmd_x8_90_1"

# old
# foot_name = "_leg_1_x4_1_outer_1" # "foot"
# knee_name = "belt_knee"

termination_height = 0.23
default_feet_height = 0.0

terminate_after_contacts_on = ["link_torso_1_top_torso_1"]
terminate_after_contacts_on = ["link_upper_limb_assembly_7_dof_1_torso_1_top_skeleton_2"]
# terminate_after_contacts_on = ["link_torso_1_top_torso_1"]

penalize_contacts_on = []
self_collisions = 1 # 1 to disable, 0 to enable...bitwise filter
Expand Down
11 changes: 6 additions & 5 deletions sim/humanoid_gym/envs/legs_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from isaacgym import gymtorch
from isaacgym.torch_utils import *

from sim.stompy.joints import StompyFixed
from sim.stompy2.joints import StompyFixed


class LegsFreeEnv(LeggedRobot):
Expand Down Expand Up @@ -124,14 +124,14 @@ def compute_ref_state(self):
sin_pos_l[sin_pos_l > 0] = 0

self.ref_dof_pos[:, self.legs_joints["left_hip_pitch"]] = sin_pos_l * scale_1
self.ref_dof_pos[:, self.legs_joints["left_knee"]] = sin_pos_l * scale_2
self.ref_dof_pos[:, self.legs_joints["left_ankle"]] = sin_pos_l * scale_1
self.ref_dof_pos[:, self.legs_joints["left_knee_pitch"]] = sin_pos_l * scale_2
self.ref_dof_pos[:, self.legs_joints["left_ankle_roll"]] = sin_pos_l * scale_1

# right foot stance phase set to default joint pos
sin_pos_r[sin_pos_r < 0] = 0
self.ref_dof_pos[:, self.legs_joints["right_hip_pitch"]] = sin_pos_r * scale_1
self.ref_dof_pos[:, self.legs_joints["right_knee"]] = sin_pos_r * scale_2
self.ref_dof_pos[:, self.legs_joints["right_ankle"]] = sin_pos_r * scale_1
self.ref_dof_pos[:, self.legs_joints["right_knee_pitch"]] = sin_pos_r * scale_2
self.ref_dof_pos[:, self.legs_joints["right_ankle_roll"]] = sin_pos_r * scale_1

# Double support phase
self.ref_dof_pos[torch.abs(sin_pos) < 0.1] = 0
Expand Down Expand Up @@ -302,6 +302,7 @@ def _reward_knee_distance(self):
"""
Calculates the reward based on the distance between the knee of the humanoid.
"""
# breakpoint()
foot_pos = self.rigid_state[:, self.knee_indices, :2]
foot_dist = torch.norm(foot_pos[:, 0, :] - foot_pos[:, 1, :], dim=1)
fd = self.cfg.rewards.min_dist
Expand Down
16 changes: 10 additions & 6 deletions sim/humanoid_gym/envs/stompy_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
from humanoid.envs.base.legged_robot_config import LeggedRobotCfg, LeggedRobotCfgPPO

from sim.env import stompy_urdf_path
from sim.stompy.joints import Stompy
from sim.stompy2.joints import Stompy

NUM_JOINTS = len(Stompy.all_joints()) # 37
NUM_JOINTS = len(Stompy.all_joints()) # 33


class StompyCfg(LeggedRobotCfg):
Expand Down Expand Up @@ -38,13 +38,17 @@ class asset(LeggedRobotCfg.asset):

name = "stompy"

foot_name = "_leg_1_x4_1_outer_1" # "foot"
knee_name = "belt_knee"
foot_name = "_foot_1_rmd_x4_24_mock_1_inner_rmd_x4_24_1"
knee_name = "_rmd_x8_90_mock_3_inner_rmd_x8_90_1"

# old
# foot_name = "_leg_1_x4_1_outer_1" # "foot"
# knee_name = "belt_knee"

termination_height = 0.23
default_feet_height = 0.0

terminate_after_contacts_on = ["link_torso_1_top_torso_1"]
terminate_after_contacts_on = ["link_upper_limb_assembly_7_dof_1_torso_1_top_skeleton_2"]
# terminate_after_contacts_on = ["link_torso_1_top_torso_1"]

penalize_contacts_on = []
self_collisions = 1 # 1 to disable, 0 to enable...bitwise filter
Expand Down
13 changes: 7 additions & 6 deletions sim/humanoid_gym/envs/stompy_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from isaacgym import gymtorch
from isaacgym.torch_utils import *

from sim.stompy.joints import Stompy
from sim.stompy2.joints import Stompy


class StompyFreeEnv(LeggedRobot):
Expand Down Expand Up @@ -56,6 +56,7 @@ def __init__(self, cfg: LeggedRobotCfg, sim_params, physics_engine, sim_device,

self.legs_joints = {}
for name, joint in Stompy.legs.left.joints_motors():
print(name)
joint_handle = self.gym.find_actor_dof_handle(env_handle, actor_handle, joint)
self.legs_joints["left_" + name] = joint_handle

Expand Down Expand Up @@ -125,14 +126,14 @@ def compute_ref_state(self):
sin_pos_l[sin_pos_l > 0] = 0

self.ref_dof_pos[:, self.legs_joints["left_hip_pitch"]] = sin_pos_l * scale_1
self.ref_dof_pos[:, self.legs_joints["left_knee"]] = sin_pos_l * scale_2
self.ref_dof_pos[:, self.legs_joints["left_ankle"]] = sin_pos_l * scale_1
self.ref_dof_pos[:, self.legs_joints["left_knee_pitch"]] = sin_pos_l * scale_2
self.ref_dof_pos[:, self.legs_joints["left_ankle_roll"]] = sin_pos_l * scale_1

# right foot stance phase set to default joint pos
sin_pos_r[sin_pos_r < 0] = 0
self.ref_dof_pos[:, self.legs_joints["right_hip_pitch"]] = sin_pos_r * scale_1
self.ref_dof_pos[:, self.legs_joints["right_knee"]] = sin_pos_r * scale_2
self.ref_dof_pos[:, self.legs_joints["right_ankle"]] = sin_pos_r * scale_1
self.ref_dof_pos[:, self.legs_joints["right_knee_pitch"]] = sin_pos_r * scale_2
self.ref_dof_pos[:, self.legs_joints["right_ankle_roll"]] = sin_pos_r * scale_1

# Double support phase
self.ref_dof_pos[torch.abs(sin_pos) < 0.1] = 0
Expand Down Expand Up @@ -207,7 +208,6 @@ def compute_observations(self):
contact_mask = self.contact_forces[:, self.feet_indices, 2] > 5.0

self.command_input = torch.cat((sin_pos, cos_pos, self.commands[:, :3] * self.commands_scale), dim=1)
breakpoint()
q = (self.dof_pos - self.default_dof_pos) * self.obs_scales.dof_pos
dq = self.dof_vel * self.obs_scales.dof_vel

Expand Down Expand Up @@ -389,6 +389,7 @@ def _reward_base_height(self):
The reward is computed based on the height difference between the robot's base and the average height
of its feet when they are in contact with the ground.
"""
# breakpoint()
stance_mask = self._get_gait_phase()
measured_heights = torch.sum(self.rigid_state[:, self.feet_indices, 2] * stance_mask, dim=1) / torch.sum(
stance_mask, dim=1
Expand Down
2 changes: 1 addition & 1 deletion sim/scripts/create_fixed_torso.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import xml.etree.ElementTree as ET

from sim.stompy.joints import StompyFixed
from sim.stompy2.joints import StompyFixed

STOMPY_URDF = "stompy/robot.urdf"

Expand Down
Empty file modified sim/scripts/print_joints.py
100644 → 100755
Empty file.
Empty file modified sim/scripts/simulate_mjcf.py
100644 → 100755
Empty file.
7 changes: 4 additions & 3 deletions sim/scripts/simulate_urdf.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,9 @@
from typing import Any, Dict, Literal, NewType

from isaacgym import gymapi, gymtorch, gymutil

from sim.env import stompy_urdf_path
from sim.logging import configure_logging
from sim.stompy.joints import Stompy
from sim.stompy2.joints import Stompy

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -150,8 +149,9 @@ def load_gym() -> GymParams:

# Resets the DOF positions to the starting positions.
# dof_vel[:] = 0.0
starting_positions = Stompy.default_positions()
starting_positions = Stompy.default_standing()
dof_ids: Dict[str, int] = gym.get_actor_dof_dict(env, robot)
print(starting_positions)
for joint_name, joint_position in starting_positions.items():
dof_pos[0, dof_ids[joint_name]] = joint_position
env_ids_int32 = torch.zeros(1, dtype=torch.int32)
Expand All @@ -161,6 +161,7 @@ def load_gym() -> GymParams:
gymtorch.unwrap_tensor(env_ids_int32),
1,
)
print(dof_pos)

return GymParams(
gym=gym,
Expand Down
Loading

0 comments on commit 85405f7

Please sign in to comment.