gazebosim / gazebo-classic

Gazebo classic. For the latest version, see https://github.com/gazebosim/gz-sim
http://classic.gazebosim.org/
Other
1.21k stars 484 forks source link

Deleting model and spawning a new one with the same name takes pose of deleted one #3238

Open JL1709 opened 2 years ago

JL1709 commented 2 years ago

Hi, when deleting a model, let's say "box_1" with pose x = 2.0, y = 2.0 and than spawn a new box, again with name "box_1" but this time with pose x = 0.0 and y = 0.0, the new box will be spawned at the pose of the deleted box (here x = 2.0, y = 2.0) and not at the newly defined pose (but with the newly defined geometry). Way to reproduce the behavior: test.world:

<sdf version="1.5">
    <world name="default">
        <gravity>0 0 -9.8</gravity>
        <physics name ='real_time_sim' type='ode' default='true'>
            <max_step_size>0.001</max_step_size>
            <real_time_factor>1</real_time_factor>
            <real_time_update_rate>1000</real_time_update_rate>
        </physics>
        <physics name ='fast_sim' type='ode'>
            <max_step_size>0.001</max_step_size>
            <real_time_factor>1</real_time_factor>
            <real_time_update_rate>2000</real_time_update_rate>
        </physics>
        <scene>
            <ambient>0.4 0.4 0.4 1</ambient>
            <background>0.7 0.7 0.7 1</background>
            <shadows>0</shadows>
        </scene>
        <!-- A global light source -->
        <include>
            <uri>model://sun</uri>
        </include>
        <!-- A ground plane -->
        <include>
            <uri>model://ground_plane</uri>
        </include>
            <model name='box_1'>
                <pose>2.0 2.0 0.1 0 -0 0</pose>
                <link name='link'>
                    <collision name='collision'>
                        <geometry>
                            <box>
                            <size>1.0 1.0 0.2</size>
                            </box>
                        </geometry>
                        <max_contacts>10</max_contacts>
                        <surface>
                            <friction>
                             <ode><mu>0.0</mu><mu2>0.0</mu2></ode>
                            </friction>
                        </surface>
                    </collision>
                    <visual name='visual'>
                        <geometry>
                            <box>
                            <size>1.0 1.0 0.2</size>
                            </box>
                        </geometry>
                        <material>
                            <script>
                            <name>Gazebo/Grey</name>
                            <uri>file://media/materials/scripts/gazebo.material</uri>
                            </script>
                        </material>
                    </visual>
                    <self_collide>0</self_collide>
                    <enable_wind>0</enable_wind>
                    <kinematic>0</kinematic>
                </link>
            </model>
    </world>
</sdf>

box_1.sdf:

<sdf version="1.5">
    <model name='box_1'>
        <pose>0.0 0.0 0.1 0 -0 0</pose>
        <link name='link'>
            <collision name='collision'>
                <geometry>
                    <box>
                        <size>0.5 0.5 0.2</size>
                    </box>
                </geometry>
                <max_contacts>10</max_contacts>
                <surface>
                    <friction>
                        <ode><mu>0.0</mu><mu2>0.0</mu2></ode>
                    </friction>
                </surface>
            </collision>
            <visual name='visual'>
                <geometry>
                    <box>
                        <size>0.5 0.5 0.2</size>
                    </box>
                </geometry>
                <material>
                    <script>
                        <name>Gazebo/Grey</name>
                        <uri>file://media/materials/scripts/gazebo.material</uri>
                    </script>
                </material>
            </visual>
            <self_collide>0</self_collide>
            <enable_wind>0</enable_wind>
            <kinematic>0</kinematic>
        </link>
    </model>
</sdf>

roscore rosrun gazebo_ros gazebo 'path_to_world_file'/test.world rosservice call gazebo/delete_model '{model_name: box_1}' rosrun gazebo_ros spawn_model -file 'path_to_sdf_file'/box_1.sdf -sdf -model box_1

Also when explicitly giving x and y at the spawn_model call ('rosrun gazebo_ros spawn_model ... -model box_1 -x 0.0 -y 0.0) the box will be spawned at the wrong pose. This behavior does not occur when the newly spawned box gets a different name (but for my use case it is important, that they can have the same name). Version: 11.10.2

Thanks for having a look at this issue.

remod commented 1 year ago

I can confirm this issue.

I've checked whether /gazebo/get_model_state still returns a wrong cached state after deleting a model, but it correctly returns a failure. So there must be some hidden internal state which is not reset.