google / brax

Massively parallel rigidbody physics simulation on accelerator hardware.
Apache License 2.0
2.14k stars 234 forks source link

Collision of robot with solid object #462

Closed eleninisioti closed 4 months ago

eleninisioti commented 4 months ago

Hi! This must be a pretty basic mujoco question. I would like to create environments where robots collide with solid objects. For example with the following xml schema I am defining a very simple robot and building a t-maze using capsules. My expectation was that by setting the contype and consaffinity to 1 for both torso and walls and having a high friction for walls should ensure that the robot bounces back when it hits a wall. Instead it just passes through, as I show in the gif.

<mujoco model="fish">
  <compiler angle="degree" coordinate="local" inertiafromgeom="true" />
  <option timestep="0.01" iterations="4" />
  <custom>

    <numeric data="0.0 0.0" name="init_qpos" />
    <numeric data="1000" name="constraint_limit_stiffness" />
    <numeric data="4000" name="constraint_stiffness" />
    <numeric data="10" name="constraint_ang_damping" />
    <numeric data="20" name="constraint_vel_damping" />
    <numeric data="0.5" name="joint_scale_pos" />
    <numeric data="0.2" name="joint_scale_ang" />
    <numeric data="0.0" name="ang_damping" />
    <numeric data="1" name="spring_mass_scale" />
    <numeric data="1" name="spring_inertia_scale" />
    <numeric data="15" name="solver_maxls" />
  </custom>
  <default>
    <joint armature="1" damping="1" limited="true" />
    <geom contype="0" conaffinity="0" condim="3" density="5.0" friction="1 0.5 0.5" />
  </default>
  <asset>
    <texture builtin="gradient" height="100" rgb1="1 1 1" rgb2="0 0 0" type="skybox" width="100" />
    <texture builtin="flat" height="1278" mark="cross" markrgb="1 1 1" name="texgeom" random="0.01" rgb1="0.8 0.6 0.4" rgb2="0.8 0.6 0.4" type="cube" width="127" />
    <texture builtin="checker" height="100" name="texplane" rgb1="0 0 0" rgb2="0.8 0.8 0.8" type="2d" width="100" />
    <material name="MatPlane" reflectance="0.5" shininess="1" specular="1" texrepeat="60 60" texture="texplane" />
    <material name="geom" texture="texgeom" texuniform="true" />
  </asset>
  <worldbody>
    <light cutoff="100" diffuse="1 1 1" dir="-0 0 -1.3" directional="true" exponent="1" pos="0 0 1.3" specular=".1 .1 .1" />
    <geom conaffinity="1" condim="3" material="MatPlane" name="floor" pos="0 0 0" size="40 40 40" type="plane" />
    <body name="torso" pos="0 0 0.5">
      <geom name="torso_geom" size="0.25" type="sphere" contype="1" conaffinity="1" />
      <joint axis="1 0 0" name="move_joint_x" pos="0 0 0" range="-180 180" type="slide" />
      <joint axis="0 1 0" name="move_joint_y" pos="0 0 0" range="-180 180" type="slide" />
    </body>
  <body name="wall_0" pos="-2.0 4 0"><geom contype="1" conaffinity="1" name="wall_0" size="0.5 28" type="capsule" rgba="0 0 1 1" fromto="0 28 0 0 0 0" friction="30.0" /></body><body name="wall_1" pos="2.0 4 0"><geom contype="1" conaffinity="1" name="wall_1" size="0.5 28" type="capsule" rgba="0 0 1 1" fromto="0 28 0 0 0 0" friction="30.0" /></body><body name="wall_2" pos="2.0 28 0"><geom contype="1" conaffinity="1" name="wall_2" size="0.5 3.5" type="capsule" rgba="0 0 1 1" fromto="0 0 0 3.5 0 0" friction="30.0" /></body><body name="wall_3" pos="-2.0 28 0"><geom contype="1" conaffinity="1" name="wall_3" size="0.5 3.5" type="capsule" rgba="0 0 1 1" fromto="-3.5 0 0 0 0 0" friction="30.0" /></body></worldbody>
  <actuator>
    <motor ctrllimited="true" ctrlrange="0.0 1.0" joint="move_joint_x" gear="-500" />
    <motor ctrllimited="true" ctrlrange="0.0 1.0" joint="move_joint_x" gear="500" />
    <motor ctrllimited="true" ctrlrange="0.0 1.0" joint="move_joint_y" gear="500" />
    <motor ctrllimited="true" ctrlrange="0.0 1.0" joint="move_joint_y" gear="-500" />
  </actuator>

</mujoco>

Feb-28-2024 15-25-28

Another example is just putting a capsule in the worldbody of the ant xml file:

<body name="wall" pos="0.01 0.01 0.5">
    <geom contype="1" conaffinity="1" name="wall" size="0.5 28" type="capsule" rgba="0 0 1 1" fromto="0 0.2 0 0 1 0" />
    </body>

This leads to the same dynamic, the ant goes through the capsule.

Increasing the friction above 10 makes the html video crash.

eleninisioti commented 4 months ago

Closing this, as I solved it by reducing the speed of the ball. I realise that collision dynamics do not work well at high speed