Robotics StackExchange | Archived questions

[ROS2 Foxy][Gazebo] Can't make the libgazebo_ros_bumper plugin work

Hello, I am using ros2 foxy and gazebo I am trying to integrate bumpers into my mobile robot but i can't find a way to make the libgazeborosbumper plugin work in my urdf file

I first followed the logic of this link (https://github.com/ros-simulation/gazebo_ros_pkgs/pull/943) but the topic bumperdemo wasn't even published. here is a part of my urdf file (the baselink link is defined earlier

<!-- front_bumper -->
  <link name="front_bumper">
    <collision>
      <geometry>
        <box size="0.03 0.400 0.03"/>
      </geometry>
    </collision>

    <visual>
      <geometry>
        <box size="0.03 0.400 0.03"/>
      </geometry>
      <material name="Cyan">
        <color rgba="0 1.0 1.0 1.0"/>
      </material>
    </visual>

    <xacro:box_inertia m="1" w="1.282" d="0.03" h="0.03"/>
  </link>

  <gazebo reference="front_bumper">
    <plugin name="bumper_plugin" filename="libgazebo_ros_bumper.so">
      <ros>
        <namespace>demo</namespace>
        <argument>bumper_states:=bumper_demo</argument>
      </ros>
      <frame_name>front_bumper</frame_name>
    </plugin>
  </gazebo>

  <joint name="front_bumper_joint" type="fixed">
    <parent link="base_link"/>
    <child link="front_bumper"/>
    <origin xyz="0.4812 0 -0.1514" rpy="0 0 0"/>
  </joint>
</robot>

Then I tried with what can be found on the gazebo official documentation : https://classic.gazebosim.org/tutorials?tut=ros_gzplugins

  <gazebo>
    <plugin name="bumper_plugin" filename="libgazebo_ros_bumper.so">
      <alwaysOn>true</alwaysOn>
      <updateRate>20</updateRate>
      <bumperTopicName>front_bumper</bumperTopicName>
      <frameName>front_bumper</frameName>
    </plugin>
  </gazebo>

And the topic front_bumper still isn't published ... then I tried with the follwing code

  <gazebo reference="front_bumper">
    <plugin name="bumper_plugin" filename="libgazebo_ros_bumper.so">
      <alwaysOn>true</alwaysOn>
      <updateRate>20</updateRate>
      <bumperTopicName>front_bumper</bumperTopicName>
      <frameName>base_link</frameName>
    </plugin>
  </gazebo>

This code also doens't show anything new ...

I'm pretty lost right now so any advice would be greaty appreciated ! Thank you for taking the time to read this question.

Asked by Bastian2909 on 2022-07-19 10:04:43 UTC

Comments

Answers

The bumper plugin needs to be inside a <sensor> element in your urdf:

<gazebo reference="front_bumper">
    <sensor name=front_bumper_sensor" type="contact">
        <update_rate>10.0</update_rate>
        <contact>
            <!-- These collision names need to match the names used in the generated -->
            <!-- SDF, not the urdf names or this still won't work! -->
            <collision>front_bumper_collision</collision>
        </contact>
        <plugin name="bumper_plugin" filename="libgazebo_ros_bumper.so">
            <ros>
                <namespace>demo</namespace>
                <remapping>bumper_states:=bumper_demo</remapping>
            </ros>
        </plugin>
    </sensor>
</gazebo>

To find the actual collision name you should use in the collision element look at https://answers.ros.org/question/277175/gazebo_ros_bumper_controller-not-updating-bumper-states/?answer=286184#post-id-286184

In summary, run gz sdf -p <your_filename>.urdf and check to see the collision name it generates for the front bumper collision, then put that name into the <collision> element.

You'll also need to give an actual name to the collision:

    <collision name="front_bumper_collision">
        <geometry>
            <box size="0.03 0.400 0.03"/>
        </geometry>
    </collision>

Asked by ChuiV on 2022-08-09 21:56:22 UTC

Comments