Skip to content

Commit

Permalink
MAJOR: FEATURE: Adding the arms and legs models. Updagrading myo envs…
Browse files Browse the repository at this point in the history
… to the latest of myosuite. Updating envs to be compatible with gymnasium
  • Loading branch information
vikashplus committed Dec 31, 2023
1 parent 9f32f15 commit 3397e80
Show file tree
Hide file tree
Showing 15 changed files with 186 additions and 59 deletions.
74 changes: 74 additions & 0 deletions robohive/envs/myo/assets/arm/myoarm_relocate.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
<mujoco model="MyoArm_v0.01">
<!-- =================================================
Copyright 2020 Vikash Kumar, Vittorio Caggiano, Guillaume Durandau
Model :: Myo Hand (MuJoCoV2.0)
Author :: Vikash Kumar ([email protected]), Vittorio Caggiano, Huawei Wang
source :: https://github.com/vikashplus
License :: Under Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http:https://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
====================================================== -->

<include file="../../../../simhive/myo_sim/arm/assets/myoarm_assets.xml"/>
<include file="../../../../simhive/myo_sim/scene/myosuite_scene.xml"/>
<compiler meshdir='../../../../simhive/myo_sim/' texturedir='../../../../simhive/myo_sim/'/>

<asset>
<texture name="tabletop" type="2d" file="../furniture_sim/common/textures/stone1.png"/>
<material name="tabletop" texture="tabletop" rgba=".95 .95 .95 1"/>
<texture name="texwood" type="cube" file="../myo_sim/scene/floor0.png"/>
<material name="matwood" reflectance="0.01" texture="texwood" texuniform="false"/>
</asset>

<worldbody>

<!-- ======= MyoArm ======= -->
<geom name="body" type="mesh" mesh="body_norighthand" euler="0 0 3.14" contype="0" conaffinity="0"/>
<body name="full_body" pos="-.025 0.1 1.40">
<include file="../../../../simhive/myo_sim/arm/assets/myoarm_body.xml"/>
</body>

<!-- ======= Table ======= -->
<body name="table" pos="0 -.5 .85">
<geom name="table_top" type="box" size=".8 .5 .05" contype="1" conaffinity="1" material="tabletop"/>
<geom name="table_base" type="box" size=".35 .6 .45" pos="0 0 -.45" euler="0 0 1.57" contype="1" conaffinity="1" material="matwood"/>
</body>

<!-- ======= Object ======= -->
<body name="Object" pos="0 -.25 .95">
<joint name="OBJTx" pos="0 0 0" axis="1 0 0" limited="true" type="slide" range="-1.20 1.55" damping="0.001" />
<joint name="OBJTy" pos="0 0 0" axis="0 1 0" limited="true" type="slide" range="-1.10 1.20" damping="0.001" />
<joint name="OBJTz" pos="0 0 0" axis="0 0 1" limited="true" type="slide" range="-1.10 1.35" damping="0.001" />
<joint name="OBJRx" pos="0 0 0 " axis="1 0 0" limited="false" damping="0.001" />
<joint name="OBJRy" pos="0 0 0" axis="0 1 0" limited="false" damping="0.001" />
<joint name="OBJRz" pos="0 0 0" axis="0 0 1" limited="false" damping="0.001" />
<geom type="box" size="0.0284 0.0284 0.0284" euler="0.001 0.001 0.001" condim="4" rgba=".5 .2 .7 1" contype="1" conaffinity="1"/>
<geom type="box" size="0.00284 0.00284 0.00284" euler="0.001 0.001 0.001" condim="4" rgba=".5 .2 .7 1" contype="1" conaffinity="1"/> <!-- dummy geom for creating different objects-->
<geom type="box" size="0.00284 0.00284 0.00284" euler="0.001 0.001 0.001" condim="4" rgba=".5 .2 .7 1" contype="1" conaffinity="1"/> <!-- dummy geom for creating different objects-->
<site name="object_o" type="sphere" size="0.005" rgba="0.8 0.8 0.8 0.8" group="4" pos="0 0 0" />
<site name="object_x" type="sphere" size="0.005" rgba="0.8 0.2 0.2 0.8" group="4" pos="0.028 0 0" />
<site name="object_y" type="sphere" size="0.005" rgba="0.2 0.8 0.2 0.8" group="4" pos="0 .028 0" />
<site name="object_z" type="sphere" size="0.005" rgba="0.2 0.2 0.8 0.8" group="4" pos="0 0 .028" />
</body>

<!-- ======= BIN ======= -->
<body name="target" pos="0 -.25 0.9" euler="0.001 0.001 0.001" mocap="true">
<!-- <geom name="target_dice" type="box" size="0.026 0.026 0.026" contype="0" conaffinity="0" rgba='.1 1 .1 .3' group="2" /> -->
<geom name="base" type="box" size="0.10 0.10 0.10" pos="0.0 0.0 -.09" contype="1" conaffinity="1" group="2" material="matwood"/>
<geom name="wall0" type="box" size="0.10 0.01 0.10" pos="0 0.091 0.1" contype="1" conaffinity="1" group="2" material="matwood"/>
<geom name="wall1" type="box" size="0.01 0.10 0.10" pos="0.091 0 0.1" contype="1" conaffinity="1" group="2" material="matwood"/>
<geom name="wall2" type="box" size="0.10 0.01 0.10" pos="0 -.091 0.1" contype="1" conaffinity="1" group="2" material="matwood"/>
<geom name="wall3" type="box" size="0.01 0.10 0.10" pos="-.091 0 0.1" contype="1" conaffinity="1" group="2" material="matwood"/>

<site name="target_ball" type="sphere" size="0.045" rgba="0.2 1.7 0.2 0.1"/>
<site name="target_o" type="sphere" size="0.005" rgba="0.8 0.8 0.8 0.8" group="4" pos="0 0 0" />
<site name="target_x" type="sphere" size="0.005" rgba="0.8 0.2 0.2 0.8" group="4" pos="0.03 0 0" />
<site name="target_y" type="sphere" size="0.005" rgba="0.2 0.8 0.2 0.8" group="4" pos="0 .03 0" />
<site name="target_z" type="sphere" size="0.005" rgba="0.2 0.2 0.8 0.8" group="4" pos="0 0 .03" />
</body>

</worldbody>

<keyframe>
<key qpos='-0.022856 0.00967764 -0.00968029 0.10125 -0.00458344 0.20262 0.0828 -0.0168106 -0.2149 0.03876 0.168055 0.17281 -0.254074 -0.109975 1.11181 0.92689 0.106468 0 0.332 0.4114 -0.177165 -0.26182 0.18852 0.17017 0.447735 0.26707 0.28278 -0.010472 0.0168535 0.00701979 0.09139 -0.06545 0.243505 0.337765 0.23565 -0.101844 0.000607067 0.03142 -.2 0 -0.02 0 0 0'/>
<key qpos='-0.022856 0.01113 -0.08268 0.10125 -0.0494 0.16578 0.11868 -0.1932 -0.19648 0.03876 0.168055 0.17281 -0.254074 -0.109975 1.47485 1.28822 0.106468 -0.27489 0.332 0.4114 -0.177165 -0.26182 0.18852 0.17017 0.447735 0.26707 0.28278 -0.010472 0.0168535 0.00701979 0.09139 -0.06545 0.243505 0.337765 0.23565 -0.101844 0.000607067 0.03142 -0.2 0 -0.02 0 0 0'/>
</keyframe>
</mujoco>
57 changes: 57 additions & 0 deletions robohive/envs/myo/assets/leg/myolegs_chasetag.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?xml version="1.0" ?>
<mujoco model="MyoSuite's MyoQuad">
<!-- =================================================
Copyright 2023 MyoSuite
Model :: Myo Quad (MuJoCoV2.7)
Author :: Vikash Kumar ([email protected]), Vittorio Caggiano, Pierre Schumahchar, Chun Kwang Tan
source :: https://github.com/MyoHub/MyoSuite
License :: Under Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http:https://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
====================================================== -©vk©-->

<include file="../../../../simhive/myo_sim/torso/assets/myotorsorigid_assets.xml"/>
<include file="../../../../simhive/myo_sim/leg/assets/myolegs_assets.xml"/>
<include file="../../../../simhive/myo_sim/scene/myosuite_quad.xml"/>
<compiler meshdir='../../../../simhive/myo_sim/' texturedir='../../../../simhive/myo_sim/'/>

<asset>
<hfield name="terrain" size="6 6 1 0.001" nrow="100" ncol="100"/>
<texture name="texmyo" type="cube" file="scene/myosuite_icon.png"/>
<material name="matmyo" texture="texmyo" rgba="1 1 1 1"/>
</asset>

<worldbody>
<geom name="terrain" type="hfield" hfield="terrain" pos="0 0 -0.005" material="matfloor" conaffinity="1" contype="1" rgba=".9 .9 .9 1"/>

<!-- <camera name="side_view" pos="-3 0 2.25" xyaxes="0 -1 0 1 0 2" mode="trackcom"/> -->


<!-- ======= Opponent ======= -->
<body name='opponent' pos="0 0 0" zaxis="0 0 1" mocap="true">
<light directional="false" diffuse=".25 .25 .25" specular="0.25 0.25 0.25" pos="0 -3 3" dir="0 1 -1" mode="trackcom"/>
<camera name="opponent_view" pos="4 0 2.75" xyaxes="0 1 0 -1 0 2" mode="trackcom"/>
<geom name="base" type="capsule" pos="0 0 0.15" euler="0 0 0" size="0.25 0.15" rgba=".11 .1 .1 1" group="2" contype="0" conaffinity="0"/>
<geom name="base_bar" type="cylinder" pos="0 0 0.8" euler="0 0 0" size="0.078 0.28" rgba=".7 .7 .7 1" group="2" contype="0" conaffinity="0"/>
<geom name="logo" type="sphere" pos="0 0 1.20" euler="1.57 0 0" size="0.25 0.02010" material="matmyo" group="2" contype="0" conaffinity="0"/>
<site name="opponent_indicator" size="0.3" pos="0 0 1.2" rgba="0 0 0 0"/>
</body>

<!-- ======= MyoAgent ======= -->
<site name="pelvis_target" size="0.02" pos="0 0 .92" group="4"/>
<body name="root" pos="0 0 1" euler="0 0 -1.57">
<light directional="false" diffuse=".25 .25 .25" specular="0.25 0.25 0.25" pos="3 0 2" dir="-1 0 -1" mode="trackcom"/>
<camera name="agent_view" pos="4 0 1.85" xyaxes="0 1 0 -1 0 2" mode="trackcom"/>
<site name="head" size="0.02" pos="0 0 1.80" group="4"/>
<include file="../../../../simhive/myo_sim/torso/assets/myotorsorigid_chain.xml"/>
<include file="../../../../simhive/myo_sim/leg/assets/myolegs_chain.xml"/>
<freejoint name="root"/>
</body>
</worldbody>

<keyframe>
<key qpos='0 0 .92 0.707388 0 0 -0.706825 0.161153 -0.0279385 -0.041886 0.00247908 0.00101098 0.461137 0.0275069 0.136817 0.334 -0.00117055 -0.000125295 -0.0302192 0.0395202 -0.194029 0.161153 -0.0279385 -0.041886 0.00247908 0.00101098 0.461137 0.0275069 0.136817 0.334 -0.00117055 -0.000125295 -0.0302192 0.0395202 -0.194029'/>
<key qpos='0 0 .9 0.707388 0 0 -0.706825 0.405648 -0.020957 -0.118677 0.0039054 0.00122326 0.7329 0.0102961 0.215496 0.40143 -0.006982 -0.02618 -0.03738 0.0080579 -0.87272 0.405648 -0.020957 -0.118677 0.0039054 0.00122326 0.7329 0.0102961 0.215496 0.40143 -0.006982 -0.02618 -0.03738 0.0080579 -0.87272'/>
<key qpos='0 0 1.0 0.707388 0 0 -0.706825 -0.2326 -0.0279385 -0.041886 0.00247908 0.00101098 1.227 0.0275069 0.136817 0.1672 -0.00117055 -0.000125295 -0.0302192 0.0395202 -0.194029 -0.1652 -0.0279385 -0.041886 0.00247908 0.0010198 0.0888 0.0275069 0.136817 -0.019 -0.00117055 -0.000125295 -0.0302192 0.0395202 -0.194029' qvel='0 -1.5 0 0 0 0 4.9066 0 0 0 0 -3.597 0 0 0.633 0 0 0 0 0 0.175 0 0 0 0 0.175 0 0 0.988 0 0 0 0 0'/>
<key qpos='0 0 1.0 0.707388 0 0 -0.706825 -0.1652 -0.0279385 -0.041886 0.00247908 0.00101098 0.0888 0.0275069 0.136817 -0.019 -0.00117055 -0.000125295 -0.0302192 0.0395202 -0.194029 -0.2326 -0.0279385 -0.041886 0.00247908 0.0010198 1.227 0.0275069 0.136817 0.1672 -0.00117055 -0.000125295 -0.0302192 0.0395202 -0.194029' qvel='0 -1.5 0 0 0 0 -0.576 0 0 0 0 0.175 0 0 0.988 0 0 0 0 0 4.9066 0 0 0 0 -3.597 0 0 0.633 0 0 0 0 0'/>
</keyframe>

</mujoco>
6 changes: 1 addition & 5 deletions robohive/envs/myo/myobase/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,11 +288,7 @@ def register_env_with_variants(id, entry_point, max_episode_steps, kwargs):
# Gait Torso Reaching ==============================
from robohive.physics.sim_scene import SimBackend
sim_backend = SimBackend.get_sim_backend()
if sim_backend == SimBackend.MUJOCO_PY:
leg_model='/../../../simhive/myo_sim/leg/myolegs_v0.54(mj210).mjb'
elif sim_backend == SimBackend.MUJOCO:
leg_model='/../../../simhive/myo_sim/leg/myolegs_v0.56(mj237).mjb'
# leg_model='/../../../simhive/myo_sim/leg/myolegs_suspended_v0.56(mj236).mjb'
leg_model='/../../../simhive/myo_sim/leg/myolegs.xml'


register_env_with_variants(id='myoLegStandRandom-v0',
Expand Down
9 changes: 5 additions & 4 deletions robohive/envs/myo/myobase/key_turn_v0.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import collections
import numpy as np
from robohive.utils.import_utils import gym
from robohive.utils import gym

from robohive.envs.myo.base_v0 import BaseV0

Expand Down Expand Up @@ -110,11 +110,12 @@ def get_reward_dict(self, obs_dict):
rwd_dict['dense'] = np.sum([wt*rwd_dict[key] for key, wt in self.rwd_keys_wt.items()], axis=0)
return rwd_dict

def reset(self, reset_qpos=None, reset_qvel=None):
def reset(self, reset_qpos=None, reset_qvel=None, **kwargs):
qpos = self.init_qpos.copy() if reset_qpos is None else reset_qpos
qvel = self.init_qvel.copy() if reset_qvel is None else reset_qvel
qpos[-1] = self.np_random.uniform(low=self.key_init_range[0], high=self.key_init_range[1])
if self.key_init_range[0]!=self.key_init_range[1]: # randomEnv
self.sim.model.body_pos[-1] = self.key_init_pos+self.np_random.uniform(low=np.array([-0.01, -0.01, -.01]), high=np.array([0.01, 0.01, 0.01]))
self.robot.reset(qpos, qvel)
return self.get_obs()

obs = super().reset(reset_qpos=qpos, reset_qvel=qvel, **kwargs)
return obs
6 changes: 3 additions & 3 deletions robohive/envs/myo/myobase/obj_hold_v0.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import collections
import numpy as np
from robohive.utils.import_utils import gym
from robohive.utils import gym

from robohive.envs.myo.base_v0 import BaseV0

Expand Down Expand Up @@ -101,13 +101,13 @@ def get_reward_dict(self, obs_dict):

class ObjHoldRandomEnvV0(ObjHoldFixedEnvV0):

def reset(self):
def reset(self, **kwargs):
# randomize target pos
self.sim.model.site_pos[self.goal_sid] = self.object_init_pos + self.np_random.uniform(high=np.array([0.030, 0.030, 0.030]), low=np.array([-.030, -.030, -.030]))
# randomize object
size = self.np_random.uniform(high=np.array([0.030, 0.030, 0.030]), low=np.array([.020, .020, .020]))
self.sim.model.geom_size[-1] = size
self.sim.model.site_size[self.goal_sid] = size
self.robot.sync_sims(self.sim, self.sim_obsd)
obs = super().reset()
obs = super().reset(**kwargs)
return obs
6 changes: 3 additions & 3 deletions robohive/envs/myo/myobase/pen_v0.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import collections
import numpy as np
from robohive.utils.import_utils import gym
from robohive.utils import gym

from robohive.envs.myo.base_v0 import BaseV0
from robohive.utils.quat_math import euler2quat
Expand Down Expand Up @@ -123,12 +123,12 @@ def get_reward_dict(self, obs_dict):

class PenTwirlRandomEnvV0(PenTwirlFixedEnvV0):

def reset(self):
def reset(self, **kwargs):
# randomize target
desired_orien = np.zeros(3)
desired_orien[0] = self.np_random.uniform(low=-1, high=1)
desired_orien[1] = self.np_random.uniform(low=-1, high=1)
self.sim.model.body_quat[self.target_obj_bid] = euler2quat(desired_orien)
self.robot.sync_sims(self.sim, self.sim_obsd)
obs = super().reset()
obs = super().reset(**kwargs)
return obs
8 changes: 4 additions & 4 deletions robohive/envs/myo/myobase/pose_v0.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
================================================= """

import collections
from robohive.utils.import_utils import gym
from robohive.utils import gym
import numpy as np

from robohive.envs.myo.base_v0 import BaseV0
Expand Down Expand Up @@ -142,7 +142,7 @@ def update_target(self, restore_sim=False):

# reset_type = none; init; random
# target_type = generate; switch
def reset(self):
def reset(self, **kwargs):

# udpate wegith
if self.weight_bodyname is not None:
Expand Down Expand Up @@ -182,11 +182,11 @@ def reset(self):
obs = self.get_obs()
elif self.reset_type == "init":
# reset to init state
obs = super().reset()
obs = super().reset(**kwargs)
elif self.reset_type == "random":
# reset to random state
jnt_init = self.np_random.uniform(high=self.sim.model.jnt_range[:,1], low=self.sim.model.jnt_range[:,0])
obs = super().reset(reset_qpos=jnt_init)
obs = super().reset(reset_qpos=jnt_init, **kwargs)
else:
print("Reset Type not found")

Expand Down
6 changes: 3 additions & 3 deletions robohive/envs/myo/myobase/reach_v0.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
================================================= """

import collections
from robohive.utils.import_utils import gym
from robohive.utils import gym
import numpy as np

from robohive.envs.myo.base_v0 import BaseV0
Expand Down Expand Up @@ -116,8 +116,8 @@ def generate_target_pose(self):
self.sim.forward()


def reset(self):
def reset(self, **kwargs):
self.generate_target_pose()
self.robot.sync_sims(self.sim, self.sim_obsd)
obs = super().reset()
obs = super().reset(**kwargs)
return obs
Loading

0 comments on commit 3397e80

Please sign in to comment.