openai / mujoco-py

MuJoCo is a physics engine for detailed, efficient rigid body simulations with contacts. mujoco-py allows using MuJoCo from Python 3.
Other
2.83k stars 810 forks source link

modifying the reward/observation structure of mujoco environment #675

Open wj210 opened 2 years ago

wj210 commented 2 years ago

I have a project where i have to modify a mujoco environment - Doubleinvertedpendulum into a closed loop kinematic chain, thus i have change the xml file to include a second cart with the end poles joined with the poles of the initial cart, as well as fixing the positions of the carts and only allowing rotational movement.

However i am still using the environment file from the original Doubleinvertedpendulum environment with a single cart.

My question is: if i were to change the xml file, does mujoco somehow modifies the environment dynamics (etc how reward is given) according to how the xml file is modified? Or do i have to modifiy the environment file myself, if so, which are the functions i should be modifying?

xml file:

<mujoco model="cartpole">
  <compiler coordinate="local" inertiafromgeom="true"/>
  <custom>
    <numeric data="2" name="frame_skip"/>
  </custom>
  <default>
    <joint damping="0.05"/>
    <geom contype="0" friction="1 0.1 0.1" rgba="0.7 0.7 0 1"/> # friction: 1st is sliding friction,x plane 2nd is torsional friction about the xy plane. 3rd is rolling, xz plane
  </default>
  <option gravity="1e-5 0 -9.81" integrator="RK4" timestep="0.01"/>
  <size nstack="3000"/>
  <worldbody>
    <geom name="floor" pos="0 0 -3.0" rgba="0.8 0.9 0.8 1" size="40 40 40" type="plane"/>
    <geom name="rail" pos="0 0 0" quat="0.707 0 0.707 0" rgba="0.3 0.3 0.7 1" size="0.02 1.5" type="capsule"/>
    <body name="cart" pos="-.5 0 0">
      <joint axis="1 0 0" limited="true" margin="0.01" name="slider" pos="0 0 0" range="-1 1" type="hinge"/>
      <geom name="cart" pos="0 0 0" quat="0.707 0 0.707 0" size="0.1 0.1" type="capsule"/>
      <body name="pole1" pos="0 0 0">
        <joint axis="0 1 0" name="hinge" pos="0 0 0" type="hinge"/>
        <geom fromto="0 0 0 0.0 0 0.6" name="cpole1" rgba="0 0.7 0.7 1" size="0.045 0.3" type="capsule"/> # fromto is starting x,y,z to ending x,y,z specifing the length
        <body name="pole2" pos="0 0 0.6"> # the x defines the angle from the front view and the y defines the offset from the top view.
          <joint axis="0 1 0" name="hinge2" pos="0 0 0" type="hinge"/>
          <geom fromto="0 0 0 0.5 0 0.5" name="cpole2" rgba="0 0.7 0.7 1" size="0.045 0.3" type="capsule"/>
          <site name="tip" pos="0 0 .5" size="0.01 0.01"/>
        </body>
      </body>
    </body>
    <body name="cart2" pos=".5 0 0">
      <joint axis="1 0 0" limited="true" margin="0.01" name="slider1" pos="0 0 0" range="-1 1" type="hinge"/>
      <geom name="cart2" pos="0 0 0" quat="0.707 0 0.707 0" size="0.1 0.1" type="capsule"/>
      <body name="pole3" pos="0 0 0">
        <joint axis="0 1 0" name="hinge3" pos="0 0 0" type="hinge"/>
        <geom fromto="0 0 0 0 0 0.6" name="cpole3" rgba="0 0.7 0.7 1" size="0.045 0.3" type="capsule"/>
        <body name="pole4" pos="0 0 0.6">
          <joint axis="0 1 0" name="hinge4" pos="0 0 0" type="hinge"/>
          <geom fromto="0 0 0 -0.5 0 0.5" name="cpole4" rgba="0 0.7 0.7 1" size="0.045 0.3" type="capsule"/>
          <site name="tip1" pos="0 0 .5" size="0.01 0.01"/>
        </body>
      </body>
    </body>
  </worldbody>
  <equality>
    <connect active= "true" body1 = "pole2" body2 = "pole4" anchor = "0.5 0.5 0.5"/>
  </equality>
  <actuator>
    <motor ctrllimited="true" ctrlrange="-1 1" gear="500" joint="slider" name="hinge"/>
  </actuator>
</mujoco>