gazebosim / gz-sim

Open source robotics simulator. The latest version of Gazebo.
https://gazebosim.org
Apache License 2.0
619 stars 251 forks source link

Using a plane as collision geometry causes immense slowdown #2416

Closed anticitizn closed 1 month ago

anticitizn commented 1 month ago

Environment

Description

Steps to reproduce

Spawn 40 or so of either model and see the performance impact:

Box collision

<?xml version="1.0"?>
<sdf version="1.9">
<model name='box_collision'>
    <static>true</static>
    <link name='box_collision_link'>
        <pose>0 0 0.5 0 0 0</pose>
        <visual name='visual'>
            <geometry>
                <box>
                    <size>1 1 1</size>
                </box>
            </geometry>
            <material>
                <ambient>0.5 0.5 1.0 1</ambient>
                <diffuse>0.5 0.5 1.0 1</diffuse>
                <specular>0.0 0.0 1.0 1</specular>
            </material>
        </visual>
        <collision name='collision'>
            <geometry>
                <box>
                    <size>1 1 1</size>
                </box>
            </geometry>
        </collision>
    </link>
</model>
</sdf>

Plane collision

<?xml version="1.0"?>
<sdf version="1.9">
<model name='plane_collision'>
    <static>true</static>
    <link name='plane_collision_link'>
        <pose>0 0 0.5 0 0 0</pose>
        <visual name='visual'>
            <geometry>
                <plane>
                    <normal>1 0 0</normal>
                    <size>1 1</size>
                </plane>
            </geometry>
            <material>
                <ambient>0.5 0.5 1.0 1</ambient>
                <diffuse>0.5 0.5 1.0 1</diffuse>
                <specular>0.0 0.0 1.0 1</specular>
            </material>
        </visual>
        <collision name="collision">
            <geometry>
                <plane>
                    <normal>1 0 0</normal>
                    <size>1 1</size>
                </plane>
            </geometry>
        </collision>
    </link>
</model>
</sdf>

Output

With box collision: image

With plane collision: image

azeey commented 1 month ago

This is to be expected since the plane is a special type of geometry with infinite size and depth. As the spec indicates, the size is only meaningful for visualizing the plane. The depth part probably needs to be mentioned in the spec, but essentially, the space on one side of the plane (on the side of the normal vector) is considered free space and the other side of the plane is considered occupied/solid from the physics perspective. The slow down is happening because the robot is in constant collision with one of the planes.

The plane is not appropriate for modelling walls, especially the ones on the inside of a room. Consider using thin cubes instead.

anticitizn commented 1 month ago

Thanks. I thought that since it has a size attribute it would function essentially like a cube. Should have read the docs more carefully :)