openai / roboschool

DEPRECATED: Open-source software for robot simulation, integrated with OpenAI Gym.
Other
2.13k stars 488 forks source link

Changing density or friction in my model doesn't affect the simulation #140

Open HeshamMeneisi opened 6 years ago

HeshamMeneisi commented 6 years ago

I have a custom model XML and I'm trying to tune the parameters. I need to change the material density and joint friction values. However, changing these values seem to have no effect whatsoever on the simulation.

This is my code

from roboschool.gym_mujoco_xml_env import RoboschoolMujocoXmlEnv
from roboschool.gym_forward_walker import RoboschoolForwardWalker
import numpy as np

class ForwardServoWalker(RoboschoolForwardWalker):

    def apply_action(self, a):
        assert(np.isfinite(a).all())
        for n,j in enumerate(self.ordered_joints):
            an = float(np.clip(a[n], -1, +1))
            # j.set_motor_torque( self.power*j.power_coef*an )
            cp = j.current_position()[0]

            label = j.name.split('_')[0]
            low, high, pwm = self.servo_settings[label]

            p = (an + 1) / 2.0 * (high - low) + low

            j.set_servo_target(p, 0.1, 0.01, self.power*pwm)

class ForwardServoWalkerMujocoXML(ForwardServoWalker, RoboschoolMujocoXmlEnv):
    def __init__(self, fn, robot_name, action_dim, obs_dim, power):
        RoboschoolMujocoXmlEnv.__init__(self, fn, robot_name, action_dim, obs_dim)
        ForwardServoWalker.__init__(self, power)

class MiKoBot(ForwardServoWalkerMujocoXML):
    foot_list = ['front_left_foot', 'front_right_foot', 'left_back_foot', 'right_back_foot']

    servo_settings = {'hip': (-np.pi/2, np.pi/2, 1), 'ankle': (0, 0.35, 1)}

    def __init__(self):
        ForwardServoWalkerMujocoXML.__init__(self, "miko.xml", "torso", action_dim=8, obs_dim=28, power=14)

    def alive_bonus(self, z, pitch):
        return +1 if z > 0.4 else -1 

And this is my model:

<mujoco model="miko">
  <compiler angle="degree" coordinate="local" inertiafromgeom="true"/>
  <option integrator="RK4" timestep="0.01"/>
  <custom>
    <numeric data="0.0 0.0 0.55 1.0 0.0 0.0 0.0 0.0 1.0 0.0 -1.0 0.0 -1.0 0.0 1.0" name="init_qpos"/>
  </custom>
  <default>
    <joint armature="1" damping="0" condimi="6" density="0.1" limited="true" friction="10 10 10"/>
    <geom damping="0" conaffinity="0" condim="6" density="0.1" friction="10 10 10" margin="0.01" rgba="0.8 0.6 0.4 1"/>
  </default>
  <worldbody>
    <body name="torso" pos="0 0 1.2">
      <geom name="torso_geom" pos="0 0 0" size="1 1 0.4" type="box" rgba="0.7 0.6 0.3 1"/>
      <!--joint armature="0" damping="0" limited="false" margin="0.01" name="root" pos="0 0 0" type="free"/-->
        <body name="front_right_leg" pos="0.4242 0.4242 0">
          <joint axis="0 0 1" name="hip_1" pos="0.0 0.0 0.0" range="-90 90" type="hinge"/>
          <geom fromto="0.0 0.0 0.0 0.318 0.318 0.0" name="front_left_leg_geom" size="0.08" type="capsule" rgba="0 1 0 1"/>
          <body pos="0.318 0.318 0" name="front_left_foot">
            <joint axis="0 0 1" name="ankle_1" pos="0.0 0.0 0.0" range="0 0.35" type="slide"/>
            <geom fromto="0.0 0.0 0.0 0.0 0.0 -1.0" name="front_left_ankle_geom" size="0.08" type="capsule" rgba="0 0 1 1"/>
        </body>
      </body>
        <body name="back_right_leg" pos="-0.4242 0.4242 0">
          <joint axis="0 0 1" name="hip_2" pos="0.0 0.0 0.0" range="-90 90" type="hinge"/>
          <geom fromto="0.0 0.0 0.0 -0.318 0.318 0.0" name="right_leg_geom" size="0.08" type="capsule" rgba="0 1 0 1"/>
          <body pos="-0.318 0.318 0" name="front_right_foot">
            <joint axis="0 0 1" name="ankle_2" pos="0.0 0.0 0.0" range="0 0.35" type="slide"/>
            <geom fromto="0.0 0.0 0.0 0.0 0.0 -1.0" name="right_ankle_geom" size="0.08" type="capsule" rgba="0 0 1 1"/>
          </body>
      </body>
        <body name="back_left_leg" pos="-0.4242 -0.4242 0">
          <joint axis="0 0 1" name="hip_3" pos="0.0 0.0 0.0" range="-90 90" type="hinge"/>
          <geom fromto="0.0 0.0 0.0 -0.318 -0.318 0.0" name="back_leg_geom" size="0.08" type="capsule" rgba="0 1 0 1"/>
          <body pos="-0.318 -0.318 0" name="left_back_foot">
            <joint axis="0 0 1" name="ankle_3" pos="0.0 0.0 0.0" range="0 0.35" type="slide"/>
            <geom fromto="0.0 0.0 0.0 0.0 0.0 -1.0" name="third_ankle_geom" size="0.08" type="capsule" rgba="0 0 1 1"/>
          </body>
      </body>
        <body name="front_left_leg" pos="0.42 -0.4242 0">
          <joint axis="0 0 1" name="hip_4" pos="0.0 0.0 0.0" range="-90 90" type="hinge"/>
          <geom fromto="0.0 0.0 0.0 0.318 -0.318 0.0" name="rightback_leg_geom" size="0.08" type="capsule" rgba="0 1 0 1"/>
          <body pos="0.318 -0.318 0" name="right_back_foot">
            <joint axis="0 0 1" name="ankle_4" pos="0.0 0.0 0.0" range="0 0.35" type="slide"/>
            <geom fromto="0.0 0.0 0.0 0.0 0.0 -1.0" name="fourth_ankle_geom" size="0.08" type="capsule" rgba="0 0 1 1"/>
          </body>
        </body>
    </body>
  </worldbody>
  <actuator>
    <position ctrlctrlrange="-1.0 1.0" joint="hip_1" gear="1"/>
    <position ctrlctrlrange="-1.0 1.0" joint="ankle_1" gear="1"/>
    <position ctrlctrlrange="-1.0 1.0" joint="hip_2" gear="1"/>
    <position ctrlctrlrange="-1.0 1.0" joint="ankle_2" gear="1"/>
    <position ctrlctrlrange="-1.0 1.0" joint="hip_3" gear="1"/>
    <position ctrlctrlrange="-1.0 1.0" joint="ankle_3" gear="1"/>
    <position ctrlctrlrange="-1.0 1.0" joint="hip_4" gear="1"/>
    <position ctrlctrlrange="-1.0 1.0" joint="ankle_4" gear="1"/>
  </actuator>
</mujoco>