Question on Collisions

Discussion in 'Modeling' started by Mara, Jul 2, 2020.

  1. I'm trying to create a very crude billiards table. Essentially I just want to have a ball that rolls on the table (with the possibility of adding friction later) and bounces off the walls when it hits them. I'm having a lot of trouble with the wall collisions though. I know I need to modify the solref and solimp to get the proper collision type, but right now the ball seems to just roll through the walls. Any help would be really appreciated!

    Code:
    <?xml version="1.0" encoding="utf-8"?>
    <mujoco>
        <compiler angle="radian" coordinate="local" meshdir="stls" texturedir="textures"></compiler>
        <option timestep="0.002">
            <flag warmstart="enable"></flag>
        </option>
    
        <default>
            <geom margin=".01" conaffinity="1" contype="1"/>
        </default>
    
        <asset>
            <material name="floor_mat" specular="0" shininess="0.5" reflectance="0" rgba="0.2 0.2 0.2 1"></material>
            <material name="table_mat" specular="0" shininess="0.5" reflectance="0" rgba="0.93 0.93 0.93 1"></material>
            <material name="block_mat" specular="0" shininess="0.5" reflectance="0" rgba="0.2 0.2 0.2 1"></material>
        </asset>
      
        <worldbody>
            <geom name="floor0" pos="0 0 0" size="2 2 1" type="plane" condim="3" material="floor_mat"></geom>
    
            <body pos="0 0 0.2" name="table0">
                <geom size="1 1 0.2" type="box" mass="2000" material="table_mat" condim="3" conaffinity="1" contype="1" ></geom>
            </body>
    
            <body pos="1 .8 0.3" name="edge0">
                <geom size=".1 .2 0.3" type="box" priority = "100" solref="-1000 -.01" solimp="0.95 0.95 0.01" mass="2000" material="table_mat" condim="1"></geom>
            </body>
    
            <body pos="1 0 0.3" name="edge1">
                <geom size=".1 .4 0.3" type="box" priority = "100" solref="-1000 -.01" solimp="0.95 0.95 0.01" mass="2000" material="table_mat" condim="1"></geom>
            </body>
    
            <body pos="1 -.8 0.3" name="edge2">
                <geom size=".1 .2 0.3" type="box" priority = "100" solref="-1000 -.01" solimp="0.95 0.95 0.01" mass="2000" material="table_mat" condim="1"></geom>
            </body>
    
            <body pos="-1 .8 0.3" name="edge3">
                <geom size=".1 .2 0.3" type="box" priority = "100" solref="-1000 -.01" solimp="0.95 0.95 0.01"  mass="2000" material="table_mat" condim="1"></geom>
            </body>
    
            <body pos="-1 0 0.3" name="edge4">
                <geom size=".1 .4 0.3" type="box" priority = "100" solref="-1000 -.01" solimp="0.95 0.95 0.01"  mass="2000" material="table_mat" condim="1"></geom>
            </body>
    
            <body pos="-1 -.8 0.3" name="edge5">
                <geom size=".1 .2 0.3" type="box" priority = "100" solref="-1000 -.01" solimp="0.95 0.95 0.01"  mass="2000" material="table_mat" condim="1"></geom>
            </body>
    
            <body pos=".8 1 0.3" name="edge6">
                <geom size=".2 .1 0.3" type="box" priority = "100" solref="-1000 -.01" solimp="0.95 0.95 0.01"  mass="2000" material="table_mat" condim="1"></geom>
            </body>
    
            <body pos="0 1 0.3" name="edge7">
                <geom size=".4 .1 0.3" type="box" priority = "100" solref="-1000 -.01" solimp="0.95 0.95 0.01"  mass="2000" material="table_mat" condim="1"></geom>
            </body>
    
            <body pos="-.8 1 0.3" name="edge8">
                <geom size=".2 .1 0.3" type="box" priority = "100" solref="-1000 -.01" solimp="0.95 0.95 0.01"  mass="2000" material="table_mat" condim="1"></geom>
            </body>
    
            <body pos=".8 -1 0.3" name="edge9">
                <geom size=".2 .1 0.3" type="box" priority = "100" solref="-1000 -.01" solimp="0.95 0.95 0.01"  mass="2000" material="table_mat" condim="1"></geom>
            </body>
    
            <body pos="0 -1 0.3" name="edge10">
                <geom size=".4 .1 0.3" type="box" priority = "100" solref="-1000 -.01" solimp="0.95 0.95 0.01"  mass="2000" material="table_mat" condim="1"></geom>
            </body>
    
            <body pos="-.8 -1 0.3" name="edge11">
                <geom size=".2 .1 0.3" type="box" priority = "100" solref="-1000 -.01" solimp="0.95 0.95 0.01"  mass="2000" material="table_mat" condim="1"></geom>
            </body>
          
            <body name="object0" pos="0.025 0.025 0.4125">
                <joint name="object0:joint" type="free"></joint>
                <geom size="0.025 0.025 0.025" type="sphere" conaffinity="1" contype="1" condim="3" name="object0" material="block_mat" mass="5"></geom>
                <site name="object0" pos="0 0 0" size="0.02 0.02 0.02" rgba="1 0 0 1" type="sphere"></site>
            </body>
    
            <light directional="true" ambient="0.2 0.2 0.2" diffuse="0.8 0.8 0.8" specular="0.3 0.3 0.3" castshadow="false" pos="0 0 4" dir="0 0 -1" name="light0"></light>
        </worldbody>
    
        <actuator>
            <motor name="mx" gear="0 0 0 1 0 0" joint="object0:joint"/>
            <motor name="my" gear="0 0 0 0 1 0" joint="object0:joint"/>     
        </actuator>
    </mujoco>
    
     
    Last edited: Jul 2, 2020