<mujoco model="humanoid_touch">
  <compiler angle="degree" inertiafromgeom="true"/>

  <option timestep="0.005" iterations="50" tolerance="1e-10"
          solver="Newton" jacobian="dense" cone="elliptic"/>

  <default>
    <joint limited="true" damping="1" armature="0" stiffness="0"/>
    <geom contype="1" conaffinity="1" condim="1"
          friction=".7 .1 .1" rgba="0.78 0.62 0.50 1"/>
    <motor ctrllimited="true" ctrlrange="-0.4 0.4"/>
    <site size="0.012" rgba="0.2 0.8 0.2 0.6" type="sphere"/>
  </default>

  <worldbody>
    <light diffuse="1 1 1" pos="0 0 4" dir="0 0 -1" specular="0.1 0.1 0.1"/>
    <geom name="floor" type="plane" size="20 20 0.125" pos="0 0 0"
          condim="3" friction="1 0.1 0.1" rgba="0.8 0.88 0.8 1"/>

    <!-- Fixed side camera — overview of the whole humanoid -->
    <camera name="side_camera" pos="3.5 0 1.4" xyaxes="0 1 0 0 0 1"/>

    <body name="torso" pos="0 0 1.282">
      <!--
        Ego camera: attached to torso, looking forward (+X in body frame).
        xyaxes: camera-X = body-(-Y) = "0 -1 0", camera-Y = body-Z = "0 0 1"
        => camera looks along body +X  (forward for a standing humanoid).
        Positioned 18 cm up from torso centre to approximate eye level.
      -->
      <camera name="ego_camera" pos="0 0 0.18" xyaxes="0 -1 0 0 0 1"/>

      <joint armature="0" damping="0" limited="false" name="root"
             pos="0 0 0" stiffness="0" type="free"/>

      <geom fromto="0 -.07 0 0 .07 0"  name="torso1"  size="0.07"  type="capsule"/>
      <geom name="head" pos="0 0 .19"   size=".09"     type="sphere"
            density="100" rgba="0.78 0.62 0.50 1"/>
      <geom fromto="-.01 -.06 -.12 -.01 .06 -.12" name="uwaist" size="0.06" type="capsule"/>

      <!-- IMU + contact sites on torso -->
      <site name="touch_torso_front" pos="0.09  0     0"/>
      <site name="touch_torso_back"  pos="-0.09 0     0"/>
      <site name="imu_site"          pos="0     0     0" rgba="1 0 0 0.8"/>

      <!-- ── Lower body ─────────────────────────────────────────── -->
      <body name="lwaist" pos="-.01 0 -0.26">
        <geom fromto="0 -.06 0 0 .06 0" name="lwaist" size="0.06" type="capsule"/>
        <joint armature="0.02" axis="0 0 1" damping="5" name="abdomen_z"
               pos="0 0 0.065" range="-45 45"  stiffness="20" type="hinge"/>
        <joint armature="0.02" axis="0 1 0" damping="5" name="abdomen_y"
               pos="0 0 0.065" range="-75 30"  stiffness="10" type="hinge"/>

        <body name="pelvis" pos="0 0 -0.165">
          <joint armature="0.02" axis="1 0 0" damping="5" name="abdomen_x"
                 pos="0 0 0.1"   range="-35 35" stiffness="10" type="hinge"/>
          <geom fromto="-.02 -.07 0 -.02 .07 0" name="pelvis" size="0.09" type="capsule"/>

          <!-- ── Right leg ──────────────────────────────────── -->
          <body name="right_thigh" pos="0 -0.1 -0.04">
            <joint armature="0.01" axis="1 0 0" damping="5" name="right_hip_x"
                   pos="0 0 0" range="-25 5"   stiffness="10" type="hinge"/>
            <joint armature="0.01" axis="0 0 1" damping="5" name="right_hip_z"
                   pos="0 0 0" range="-60 35"  stiffness="10" type="hinge"/>
            <joint armature="0.01" axis="0 1 0" damping="5" name="right_hip_y"
                   pos="0 0 0" range="-110 20" stiffness="20" type="hinge"/>
            <geom fromto="0 0 0 0 0.01 -.34" name="right_thigh1" size="0.06" type="capsule"/>

            <body name="right_shin" pos="0 0.01 -0.403">
              <joint armature="0.006" axis="0 -1 0" damping="5" name="right_knee"
                     pos="0 0 .02" range="-160 -2" type="hinge"/>
              <geom fromto="0 0 0 0 0 -.3" name="right_shin1" size="0.049" type="capsule"/>

              <body name="right_foot" pos="0 0 -0.45">
                <joint armature="0.0068" axis="1 0 0" damping="3" name="right_ankle_x"
                       pos="0 0 0.08" range="-50 50" stiffness="4" type="hinge"/>
                <joint armature="0.0068" axis="0 1 0" damping="1" name="right_ankle_y"
                       pos="0 0 0.04" range="-50 50" stiffness="8" type="hinge"/>
                <geom fromto="-.08 -.01 0 .14 -.01 0" name="right_foot1" size=".027" type="capsule"/>
                <site name="touch_right_foot" pos="0.03 0 -0.025" rgba="0 0.6 1 0.7"/>
              </body>
            </body>
          </body>

          <!-- ── Left leg ───────────────────────────────────── -->
          <body name="left_thigh" pos="0 0.1 -0.04">
            <joint armature="0.01" axis="-1 0 0" damping="5" name="left_hip_x"
                   pos="0 0 0" range="-25 5"   stiffness="10" type="hinge"/>
            <joint armature="0.01" axis="0 0 1" damping="5" name="left_hip_z"
                   pos="0 0 0" range="-60 35"  stiffness="10" type="hinge"/>
            <joint armature="0.01" axis="0 1 0" damping="5" name="left_hip_y"
                   pos="0 0 0" range="-110 20" stiffness="20" type="hinge"/>
            <geom fromto="0 0 0 0 -0.01 -.34" name="left_thigh1" size="0.06" type="capsule"/>

            <body name="left_shin" pos="0 -0.01 -0.403">
              <joint armature="0.006" axis="0 -1 0" damping="5" name="left_knee"
                     pos="0 0 .02" range="-160 -2" type="hinge"/>
              <geom fromto="0 0 0 0 0 -.3" name="left_shin1" size="0.049" type="capsule"/>

              <body name="left_foot" pos="0 0 -0.45">
                <joint armature="0.0068" axis="1 0 0" damping="3" name="left_ankle_x"
                       pos="0 0 0.08" range="-50 50" stiffness="4" type="hinge"/>
                <joint armature="0.0068" axis="0 1 0" damping="1" name="left_ankle_y"
                       pos="0 0 0.04" range="-50 50" stiffness="8" type="hinge"/>
                <geom fromto="-.08 .01 0 .14 .01 0" name="left_foot1" size=".027" type="capsule"/>
                <site name="touch_left_foot" pos="0.03 0 -0.025" rgba="0 0.6 1 0.7"/>
              </body>
            </body>
          </body>
        </body>
      </body>

      <!-- ── Right arm ──────────────────────────────────────────── -->
      <body name="right_upper_arm" pos="0 -0.17 0.06">
        <joint armature="0.0068" axis="2 1 1" name="right_shoulder1"
               pos="0 0 0" range="-85 60" stiffness="1" type="hinge"/>
        <joint armature="0.0051" axis="0 -1 1" name="right_shoulder2"
               pos="0 0 0" range="-85 60" stiffness="1" type="hinge"/>
        <geom fromto="0 0 0 .16 -.16 -.16" name="right_upper_arm1" size="0.04 0.16" type="capsule"/>

        <body name="right_lower_arm" pos=".18 -.18 -.18">
          <joint armature="0.0028" axis="0 -1 1" name="right_elbow"
                 pos="0 0 0" range="-90 50" stiffness="0" type="hinge"/>
          <geom fromto=".01 .01 .01 .17 .17 .17" name="right_lower_arm1" size="0.031" type="capsule"/>

          <body name="right_hand" pos=".18 .18 .18">
            <!-- Wrist camera: looks along fingertip direction (body +X) -->
            <camera name="right_wrist_camera" pos="0 0 0" xyaxes="0 -1 0 0 0 1"/>
            <geom name="right_hand_geom" pos="0 0 0" size=".04" type="sphere" rgba="0.78 0.62 0.50 1"/>
            <site name="touch_right_hand_palm"  pos=" 0.04  0     0"/>
            <site name="touch_right_hand_back"  pos="-0.04  0     0"/>
            <site name="touch_right_fingertip"  pos=" 0.07  0     0" rgba="1 1 0 0.7"/>
          </body>
        </body>
      </body>

      <!-- ── Left arm ───────────────────────────────────────────── -->
      <body name="left_upper_arm" pos="0 0.17 0.06">
        <joint armature="0.0068" axis="2 -1 1" name="left_shoulder1"
               pos="0 0 0" range="-60 85" stiffness="1" type="hinge"/>
        <joint armature="0.0051" axis="0 1 1" name="left_shoulder2"
               pos="0 0 0" range="-60 85" stiffness="1" type="hinge"/>
        <geom fromto="0 0 0 .16 .16 -.16" name="left_upper_arm1" size="0.04 0.16" type="capsule"/>

        <body name="left_lower_arm" pos=".18 .18 -.18">
          <joint armature="0.0028" axis="0 -1 -1" name="left_elbow"
                 pos="0 0 0" range="-90 50" stiffness="0" type="hinge"/>
          <geom fromto=".01 -.01 .01 .17 -.17 .17" name="left_lower_arm1" size="0.031" type="capsule"/>

          <body name="left_hand" pos=".18 -.18 .18">
            <!-- Wrist camera: looks along fingertip direction (body +X) -->
            <camera name="left_wrist_camera" pos="0 0 0" xyaxes="0 -1 0 0 0 1"/>
            <geom name="left_hand_geom" pos="0 0 0" size=".04" type="sphere" rgba="0.78 0.62 0.50 1"/>
            <site name="touch_left_hand_palm"  pos=" 0.04  0     0"/>
            <site name="touch_left_hand_back"  pos="-0.04  0     0"/>
            <site name="touch_left_fingertip"  pos=" 0.07  0     0" rgba="1 1 0 0.7"/>
          </body>
        </body>
      </body>
    </body>
  </worldbody>

  <!-- Hip-knee coupling tendon (passive biological constraint) -->
  <tendon>
    <fixed name="right_hipflex" limited="true" range="-0.2 0.7">
      <joint coef="-1"  joint="right_knee"/>
      <joint coef="0.5" joint="right_hip_y"/>
    </fixed>
    <fixed name="left_hipflex" limited="true" range="-0.2 0.7">
      <joint coef="-1"  joint="left_knee"/>
      <joint coef="0.5" joint="left_hip_y"/>
    </fixed>
  </tendon>

  <!-- 21 actuators, matching gymnasium Humanoid-v5 DoF -->
  <actuator>
    <motor gear="100" joint="abdomen_y"      name="abdomen_y"/>
    <motor gear="100" joint="abdomen_z"      name="abdomen_z"/>
    <motor gear="100" joint="abdomen_x"      name="abdomen_x"/>
    <motor gear="100" joint="right_hip_x"   name="right_hip_x"/>
    <motor gear="100" joint="right_hip_z"   name="right_hip_z"/>
    <motor gear="300" joint="right_hip_y"   name="right_hip_y"/>
    <motor gear="200" joint="right_knee"    name="right_knee"/>
    <motor gear="100" joint="right_ankle_x" name="right_ankle_x"/>
    <motor gear="100" joint="right_ankle_y" name="right_ankle_y"/>
    <motor gear="100" joint="left_hip_x"    name="left_hip_x"/>
    <motor gear="100" joint="left_hip_z"    name="left_hip_z"/>
    <motor gear="300" joint="left_hip_y"    name="left_hip_y"/>
    <motor gear="200" joint="left_knee"     name="left_knee"/>
    <motor gear="100" joint="left_ankle_x"  name="left_ankle_x"/>
    <motor gear="100" joint="left_ankle_y"  name="left_ankle_y"/>
    <motor gear="25"  joint="right_shoulder1" name="right_shoulder1"/>
    <motor gear="25"  joint="right_shoulder2" name="right_shoulder2"/>
    <motor gear="25"  joint="right_elbow"     name="right_elbow"/>
    <motor gear="25"  joint="left_shoulder1"  name="left_shoulder1"/>
    <motor gear="25"  joint="left_shoulder2"  name="left_shoulder2"/>
    <motor gear="25"  joint="left_elbow"      name="left_elbow"/>
  </actuator>

  <!-- Touch sensors (scalar normal force at site), IMU (accel + gyro) -->
  <sensor>
    <touch name="touch_right_hand_palm" site="touch_right_hand_palm"/>
    <touch name="touch_right_hand_back" site="touch_right_hand_back"/>
    <touch name="touch_right_fingertip" site="touch_right_fingertip"/>
    <touch name="touch_left_hand_palm"  site="touch_left_hand_palm"/>
    <touch name="touch_left_hand_back"  site="touch_left_hand_back"/>
    <touch name="touch_left_fingertip"  site="touch_left_fingertip"/>
    <touch name="touch_right_foot"      site="touch_right_foot"/>
    <touch name="touch_left_foot"       site="touch_left_foot"/>
    <touch name="touch_torso_front"     site="touch_torso_front"/>
    <touch name="touch_torso_back"      site="touch_torso_back"/>
    <accelerometer name="accel_torso"   site="imu_site"/>
    <gyro          name="gyro_torso"    site="imu_site"/>
  </sensor>
</mujoco>
