Home | Tutorials | Wiki | Issues
Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Not being sure that this question initial author, SP, will receive the notification from my comment and that he is still active, I have created a very light test to let you all either see what's the issue we are facing or even fix it if you can notice any issue in my code.

Just under those words are 3 files, in order to test the sensor, you just have to have ROS installed on your machine, to put the three files in the same directory and to call a roslaunch on the launch file.

So here is the launch file

<launch>
  <!-- Start Simulator -->
  <arg name="world_file" default="test.world"/>
  <include file="$(find gazebo_ros)/launch/empty_world.launch">
  <!--  <arg name="world_name" value="test.world"/> -->
        <arg name="world_name" value="$(env PWD)/$(arg world_file)"/>
    <arg name="paused" value="false"/>
    <arg name="gui" value="true"/>
  </include>

  <!-- Start Robot -->
  <param name="robot_description" command="
    $(find xacro)/xacro.py '$(env PWD)/robot.xacro'
    mav_name:=robot
    color:=White"/>

  <!-- push robot_description to factory and spawn robot in gazebo -->
  <node name="spawn_my_robot" pkg="gazebo_ros" type="spawn_model"
   args="-param robot_description
         -urdf
         -x 2
         -y 2
         -z 0
         -Y 0
         -model robot"
   respawn="false" output="screen">
  </node>

</launch>

Then we have the test.world:

<?xml version="1.0"?>
<sdf version="1.6">
  <world name="default">
    <include>
      <uri>model://ground_plane</uri>
    </include>

     <include>
      <uri>model://sun</uri>
    </include>

    <model name="box">
      <link name="link">
        <pose>0 0 0.5 0 0 0</pose>

        <collision name="box_collision">
          <geometry>
            <box>
              <size>1 1 1</size>
            </box>
          </geometry>
        </collision>

        <visual name="visual">
          <geometry>
            <box>
              <size>1 1 1</size>
            </box>
          </geometry>
        </visual>

        <sensor name='my_contact' type='contact'>
          <contact>
            <collision>box_collision</collision>
          </contact>
        </sensor>

      </link>
    </model>
  </world>
</sdf>

And finally the robot.xacro

<?xml version="1.0"?>
<robot name="bumper_test" xmlns:xacro="http://ros.org/wiki/xacro">

  <xacro:macro name="box_inertial" params="x y z mass *origin">
    <inertial>
      <mass value="${mass}" />
      <xacro:insert_block name="origin" />
      <inertia ixx="${0.0833333 * mass * (y*y + z*z)}" ixy="0.0" ixz="0.0"
        iyy="${0.0833333 * mass * (x*x + z*z)}" iyz="0.0"
        izz="${0.0833333 * mass * (x*x + y*y)}" />
    </inertial>
  </xacro:macro>

  <link name="chassis">
    <xacro:box_inertial x="2" y="1" z="1" mass="100">
      <origin xyz="0  0 0" rpy="0 0 0" />
    </xacro:box_inertial>
    <visual>
      <geometry>
        <box size="2 1 1" />
      </geometry>
    </visual>
    <collision name="chassis_collision">
      <geometry>
        <box size="2 1 1" />
      </geometry>
    </collision>
  </link>


  <gazebo reference="chassis">
    <sensor name="chassis_collision_sensor" type="contact">
      <always_on>true</always_on>
      <update_rate>30</update_rate>
      <contact>
        <collision>chassis_collision</collision>
      </contact>
    </sensor>
  </gazebo>

</robot>

And the issue is that while :

gz topic -e /gazebo/default/box/link/my_contact

is not empty and show the contact with the ground.

gz topic -e /gazebo/default/robot/chassis/chassis_collision_sensor/contacts

is empty and does not show any collision.

I will have 2/3 questions for you : 1/ Do you notice any error in the code ? 2/ Is this contact sensor defined in the robot working for you ?

And if this code works for at least one person ( which i strongly believe since it is almost a copy/paste from an accepted answerinthis forum ) 3/ What are your current gazebo/Ros versions ?

I'm currently using ROS kinetic and gazebo 7.0.0

thansk a lot for any help

Not being sure that this question initial author, SP, will receive the notification from my comment and that he is still active, I have created a very light test to let you all either see what's the issue we are facing or even fix it if you can notice any issue in my code.

Just under those words are 3 files, in order to test the sensor, you just have to have ROS installed on your machine, to put the three files in the same directory and to call a roslaunch on the launch file.

So here is the launch file

<launch>
  <!-- Start Simulator -->
  <arg name="world_file" default="test.world"/>
  <include file="$(find gazebo_ros)/launch/empty_world.launch">
  <!--  <arg name="world_name" value="test.world"/> -->
        <arg name="world_name" value="$(env PWD)/$(arg world_file)"/>
    <arg name="paused" value="false"/>
    <arg name="gui" value="true"/>
  </include>

  <!-- Start Robot -->
  <param name="robot_description" command="
    $(find xacro)/xacro.py '$(env PWD)/robot.xacro'
    mav_name:=robot
    color:=White"/>

  <!-- push robot_description to factory and spawn robot in gazebo -->
  <node name="spawn_my_robot" pkg="gazebo_ros" type="spawn_model"
   args="-param robot_description
         -urdf
         -x 2
         -y 2
         -z 0
         -Y 0
         -model robot"
   respawn="false" output="screen">
  </node>

</launch>

Then we have the test.world:

<?xml version="1.0"?>
<sdf version="1.6">
  <world name="default">
    <include>
      <uri>model://ground_plane</uri>
    </include>

     <include>
      <uri>model://sun</uri>
    </include>

    <model name="box">
      <link name="link">
        <pose>0 0 0.5 0 0 0</pose>

        <collision name="box_collision">
          <geometry>
            <box>
              <size>1 1 1</size>
            </box>
          </geometry>
        </collision>

        <visual name="visual">
          <geometry>
            <box>
              <size>1 1 1</size>
            </box>
          </geometry>
        </visual>

        <sensor name='my_contact' type='contact'>
          <contact>
            <collision>box_collision</collision>
          </contact>
        </sensor>

      </link>
    </model>
  </world>
</sdf>

And finally the robot.xacro

<?xml version="1.0"?>
<robot name="bumper_test" xmlns:xacro="http://ros.org/wiki/xacro">

  <xacro:macro name="box_inertial" params="x y z mass *origin">
    <inertial>
      <mass value="${mass}" />
      <xacro:insert_block name="origin" />
      <inertia ixx="${0.0833333 * mass * (y*y + z*z)}" ixy="0.0" ixz="0.0"
        iyy="${0.0833333 * mass * (x*x + z*z)}" iyz="0.0"
        izz="${0.0833333 * mass * (x*x + y*y)}" />
    </inertial>
  </xacro:macro>

  <link name="chassis">
    <xacro:box_inertial x="2" y="1" z="1" mass="100">
      <origin xyz="0  0 0" rpy="0 0 0" />
    </xacro:box_inertial>
    <visual>
      <geometry>
        <box size="2 1 1" />
      </geometry>
    </visual>
    <collision name="chassis_collision">
      <geometry>
        <box size="2 1 1" />
      </geometry>
    </collision>
  </link>


  <gazebo reference="chassis">
    <sensor name="chassis_collision_sensor" type="contact">
      <always_on>true</always_on>
      <update_rate>30</update_rate>
      <contact>
        <collision>chassis_collision</collision>
      </contact>
    </sensor>
  </gazebo>

</robot>

And the issue is that while :

gz topic -e /gazebo/default/box/link/my_contact

is not empty and show the contact with the ground.

gz topic -e /gazebo/default/robot/chassis/chassis_collision_sensor/contacts

is empty and does not show any collision.

I will have 2/3 questions for you : 1/ Do you notice any error in the code ? 2/ Is this contact sensor defined in the robot working for you ?

And if this code works for at least one person ( which i strongly believe since it is almost a copy/paste from an accepted answerinthis forum ) 3/ What are your current gazebo/Ros versions ?

I'm currently using ROS kinetic and gazebo 7.0.0

thansk a lot for any help

Not being sure that this question initial author, SP, will receive the notification from my comment and that he is still active, I have created a very light test to let you all either see what's the issue we are facing or even fix it if you can notice any issue in my code.

Just under those words are 3 files, in order to test the sensor, you just have to have ROS installed on your machine, to put the three files in the same directory a ROS Package and to call a roslaunch on the launch file.

So here is the launch file

<launch>
  <!-- Start Simulator -->
  <arg name="world_file" default="test.world"/>
  <include file="$(find gazebo_ros)/launch/empty_world.launch">
    <arg name="world_name" value="$(env PWD)/$(arg world_file)"/>
    <arg name="paused" value="false"/>
    <arg name="gui" value="true"/>
  </include>

  <!-- Start Robot -->
  <param name="robot_description" command="
    $(find xacro)/xacro.py '$(env PWD)/robot.xacro'
    mav_name:=robot
    color:=White"/>

  <!-- push robot_description to factory and spawn robot in gazebo -->
  <node name="spawn_my_robot" pkg="gazebo_ros" type="spawn_model"
   args="-param robot_description
         -urdf
         -x 2
0
         -y 2
0
         -z 0
         -Y 0
         -model robot"
   respawn="false" output="screen">
  </node>

</launch>

Then we have the test.world:

<?xml version="1.0"?>
<sdf version="1.6">
  <world name="default">
    <include>
      <uri>model://ground_plane</uri>
    </include>

     <include>
      <uri>model://sun</uri>
    </include>

    <model name="box">
      <link name="link">
        <pose>0 0 0.5 2 0 0 0</pose>

        <collision name="box_collision">
          <geometry>
            <box>
              <size>1 1 1</size>
<size>0.5 0.5 0.5</size>
            </box>
          </geometry>
        </collision>

        <visual name="visual">
          <geometry>
            <box>
              <size>1 1 1</size>
<size>0.5 0.5 0.5</size>
            </box>
          </geometry>
        </visual>

        <sensor name='my_contact' type='contact'>
          <contact>
            <collision>box_collision</collision>
          </contact>
        </sensor>

      </link>
    </model>
  </world>
</sdf>

And finally the robot.xacro

<?xml version="1.0"?>
<robot name="bumper_test" xmlns:xacro="http://ros.org/wiki/xacro">

  <xacro:macro name="box_inertial" params="x y z mass *origin">
    <inertial>
      <mass value="${mass}" />
      <xacro:insert_block name="origin" />
      <inertia ixx="${0.0833333 * mass * (y*y + z*z)}" ixy="0.0" ixz="0.0"
        iyy="${0.0833333 * mass * (x*x + z*z)}" iyz="0.0"
        izz="${0.0833333 * mass * (x*x + y*y)}" />
    </inertial>
  </xacro:macro>

  <link name="chassis">
    <xacro:box_inertial x="2" y="1" z="1" mass="100">
      <origin xyz="0  0 0" rpy="0 0 0" />
    </xacro:box_inertial>
    <visual>
      <geometry>
        <box size="2 1 1" />
      </geometry>
    </visual>
    <collision name="chassis_collision">
      <geometry>
        <box size="2 1 1" />
      </geometry>
    </collision>
  </link>


  <gazebo reference="chassis">
    <sensor name="chassis_collision_sensor" type="contact">
      <always_on>true</always_on>
      <update_rate>30</update_rate>
      <contact>
        <collision>chassis_collision</collision>
      </contact>
    </sensor>
  </gazebo>

</robot>

And the issue is that while :

gz topic -e /gazebo/default/box/link/my_contact

is not empty and show the contact with the ground.

gz topic -e /gazebo/default/robot/chassis/chassis_collision_sensor/contacts

is empty and does not show any collision.

I will have 2/3 questions for you : 1/ Do you notice any error in the code ? 2/ Is this contact sensor defined in the robot working for you ?

And if this code works for at least one person ( which i strongly believe since it is almost a copy/paste from an accepted answerinthis forum ) 3/ What are your current gazebo/Ros versions ?

I'm currently using ROS kinetic and gazebo 7.0.0

thansk a lot for any help

Not being sure that this I found a work around !!!!!

Investigating what cause the issue, I found that there are issues parsing from urdf to sdf especially in the gazebo flag. Here is a link to a question initial author, SP, will receive the notification in ros answer that does raise this issue : http://answers.gazebosim.org/question/12687/problems-while-parsing-gazebo-urdf-elements-with-gazebo7-and-ros-jade/

You can check on your own with editing an urdf from my comment a xacro (rosrun xacro xacro.py -o robot.urdf robot.xacro) and that he is still active, I have created a very light test to let you all either see what's the issue we are facing or even fix it if you can notice any issue in my code.

Just under those words are 3 files, in order to test the sensor, you just have to have ROS installed on your machine, to put the three files in a ROS Package and to call a roslaunch on the launch file.

So here is the launch file

<launch>
  <!-- Start Simulator -->
  <arg name="world_file" default="test.world"/>
  <include file="$(find gazebo_ros)/launch/empty_world.launch">
    <arg name="world_name" value="$(env PWD)/$(arg world_file)"/>
    <arg name="paused" value="false"/>
    <arg name="gui" value="true"/>
  </include>

  <!-- Start Robot -->
  <param name="robot_description" command="
    $(find xacro)/xacro.py '$(env PWD)/robot.xacro'
    mav_name:=robot
    color:=White"/>

  <!-- push robot_description to factory and spawn robot in gazebo -->
  <node name="spawn_my_robot" pkg="gazebo_ros" type="spawn_model"
   args="-param robot_description
         -urdf
         -x 0
         -y 0
         -z 0
         -Y 0
         -model robot"
   respawn="false" output="screen">
  </node>

</launch>

Then we have the test.world:

<?xml version="1.0"?>
<sdf version="1.6">
  <world name="default">
    <include>
      <uri>model://ground_plane</uri>
    </include>

     <include>
      <uri>model://sun</uri>
    </include>

    <model name="box">
      <link name="link">
        <pose>0 0 2 0 0 0</pose>

        <collision name="box_collision">
          <geometry>
            <box>
              <size>0.5 0.5 0.5</size>
            </box>
          </geometry>
        </collision>

        <visual name="visual">
          <geometry>
            <box>
              <size>0.5 0.5 0.5</size>
            </box>
          </geometry>
        </visual>

        <sensor name='my_contact' type='contact'>
          <contact>
            <collision>box_collision</collision>
          </contact>
        </sensor>

      </link>
    </model>
  </world>
</sdf>

And finally the robot.xacro

<?xml version="1.0"?>
<robot name="bumper_test" xmlns:xacro="http://ros.org/wiki/xacro">

  <xacro:macro name="box_inertial" params="x y z mass *origin">
    <inertial>
      <mass value="${mass}" />
      <xacro:insert_block name="origin" />
      <inertia ixx="${0.0833333 * mass * (y*y + z*z)}" ixy="0.0" ixz="0.0"
        iyy="${0.0833333 * mass * (x*x + z*z)}" iyz="0.0"
        izz="${0.0833333 * mass * (x*x + y*y)}" />
    </inertial>
  </xacro:macro>

  <link name="chassis">
    <xacro:box_inertial x="2" y="1" z="1" mass="100">
      <origin xyz="0  0 0" rpy="0 0 0" />
    </xacro:box_inertial>
    <visual>
      <geometry>
        <box size="2 1 1" />
      </geometry>
    </visual>
    <collision name="chassis_collision">
      <geometry>
        <box size="2 1 1" />
      </geometry>
    </collision>
  </link>


  <gazebo reference="chassis">
    <sensor name="chassis_collision_sensor" type="contact">
      <always_on>true</always_on>
      <update_rate>30</update_rate>
      <contact>
        <collision>chassis_collision</collision>
      </contact>
    </sensor>
  </gazebo>

</robot>

And the issue is that while :

gz topic -e /gazebo/default/box/link/my_contact

is not empty and show the contact with the ground.

gz topic -e /gazebo/default/robot/chassis/chassis_collision_sensor/contacts

is empty and does not show any collision.

I will have 2/3 questions for you : 1/ Do you notice any error in the code ? 2/ Is this contact sensor defined in the robot working for you ?

And if this code works for at least one person ( which i strongly believe since it is almost a copy/paste then a sdf from an accepted answerinthis forum ) 3/ What urdf (gz sdf -p robot.urdf > robot.sdf), you will see that the issues are your current gazebo/Ros versions ?

I'm currently using ROS kinetic with the collision flags, both the one inside the gazebo link and gazebo 7.0.0

thansk a lot for any help

the one inside the link.

So their are 2 issues : - if you directly define a collision inside the <gazebo> flag, the urdf -> sdf parser does not allow it instead puts <collision>__default__</collision> - the 2nd one is that the collision name that you setup in the link part is modified but this modification does not occur in the gazebo collision : If i go back to your exemple, in the link, you will NOT create a "bh_finger_13_collision" collision but you will create a "bh_finger_13_collision_collision" but in the gazebo part you will still call "bh_finger_13_collision" which does not exists.

In order to make it work, this is awful but I believe the only way at the moment, you have to change the names of your collision according to this _collision add on only one side. For exemple you could still call your collision 'bh_finger_13_collision' in the link but then in the gazebo part, you need to call it "bh_finger_13_collision_collision"

TTDM,

I found a work around !!!!!

Investigating what cause the issue, I found that there are issues parsing from urdf to sdf especially in the gazebo flag. Here is a link to a question in ros answer that does raise this issue : http://answers.gazebosim.org/question/12687/problems-while-parsing-gazebo-urdf-elements-with-gazebo7-and-ros-jade/

You can check on your own with editing an urdf from a xacro (rosrun xacro xacro.py -o robot.urdf robot.xacro) and then a sdf from an urdf (gz sdf -p robot.urdf > robot.sdf), you will see that the issues are with the collision flags, both the one inside the gazebo link and the one inside the link.

So their are 2 issues : -

  • if you directly define a collision inside the <gazebo> flag, the urdf -> sdf parser does not allow it instead puts <collision>__default__</collision> - <collision>__default__</collision>
  • the 2nd one is that the collision name that you setup in the link part is modified but this modification does not occur in the gazebo collision : If i go back to your exemple, in the link, you will NOT create a "bh_finger_13_collision" collision but you will create a "bh_finger_13_collision_collision" but in the gazebo part you will still call "bh_finger_13_collision" which does not exists.

In order to make it work, this is awful but I believe the only way at the moment, you have to change the names of your collision according to this _collision add on only one side. For exemple you could still call your collision 'bh_finger_13_collision' in the link but then in the gazebo part, you need to call it "bh_finger_13_collision_collision"

TTDM,

I found a work around !!!!!

Investigating what cause the issue, I found that there are issues parsing from urdf to sdf especially in the gazebo flag. Here is a link to a question in ros answer that does raise this issue : http://answers.gazebosim.org/question/12687/problems-while-parsing-gazebo-urdf-elements-with-gazebo7-and-ros-jade/

You can check on your own with editing an urdf from a xacro (rosrun xacro xacro.py -o robot.urdf robot.xacro) and then a sdf from an urdf (gz sdf -p robot.urdf > robot.sdf), you will see that the issues are with the collision flags, both the one inside the gazebo link and the one inside the link.

So their are 2 issues :

  • if you directly define a collision inside the <gazebo> flag, the urdf -> sdf parser does not allow it instead puts <collision>__default__</collision>
  • the 2nd one is that the collision name that you setup in the link part is modified but this modification does not occur in the gazebo collision : If i go back to your exemple, in the link, you will NOT create a "bh_finger_13_collision" collision but you will create a "bh_finger_13_collision_collision" but in the gazebo part you will still call "bh_finger_13_collision" which does not exists.

In order to make it work, this is awful but I believe the only way at the moment, you have to change the names of your collision according to this _collision add on only one side. For exemple you could still call your collision 'bh_finger_13_collision' in the link but then in the gazebo part, you need to call it "bh_finger_13_collision_collision"

TTDM,

Supplementary note : in complex projects, there are usually other adds to the name of the collision ( with my collision box being mav_collision_box, this is the final name, on the sdf of my collision box that i have to call in my gazebo part : shredder/base_link_fixed_joint_lump__mav_collision_box_collision ) so you should really edit your sdf using the two command lines i gave previously then manually search for the name of your collision and put it into the gazebo part

I found a work around !!!!!

Investigating what cause the issue, I found that there are issues parsing from urdf to sdf especially in the gazebo flag. Here is a link to a question in ros answer that does raise this issue : http://answers.gazebosim.org/question/12687/problems-while-parsing-gazebo-urdf-elements-with-gazebo7-and-ros-jade/

You can check on your own with editing an urdf from a xacro (rosrun xacro xacro.py -o robot.urdf robot.xacro) and then a sdf from an urdf (gz sdf -p robot.urdf > robot.sdf), you will see that the issues are with the collision flags, both the one inside the gazebo link and the one inside the link.

So their are 2 issues :

  • if you directly define a collision inside the <gazebo> flag, the urdf -> sdf parser does not allow it instead puts <collision>__default__</collision>
  • the 2nd one is that the collision name that you setup in the link part is modified but this modification does not occur in the gazebo collision : If i go back to your exemple, in the link, you will NOT create a "bh_finger_13_collision" collision but you will create a "bh_finger_13_collision_collision" but in the gazebo part you will still call "bh_finger_13_collision" which does not exists.

In order to make it work, this is awful but I believe the only way at the moment, you have to change the names of your collision according to this _collision add on only one side. For exemple you could still call your collision 'bh_finger_13_collision' in the link but then in the gazebo part, you need to call it "bh_finger_13_collision_collision"

TTDM,

Supplementary note : in complex projects, there are usually other adds to the name of the collision ( in my project, with my collision box being mav_collision_box, this is called "mav_collision_box", the final name, name on the sdf of my collision box that is : shredder/base_link_fixed_joint_lump__mav_collision_box_collision and i have to call in my gazebo part : shredder/base_link_fixed_joint_lump__mav_collision_box_collision ) that exact name on inside the <gazebo> flag) so you should really edit your sdf using the two command lines i gave previously then manually search for the name of your collision and put it into the gazebo part

I found a work around !!!!!

Investigating what cause the issue, I found that there are issues parsing from urdf to sdf especially in the gazebo flag. Here is a link to a question in ros answer that does raise this issue : http://answers.gazebosim.org/question/12687/problems-while-parsing-gazebo-urdf-elements-with-gazebo7-and-ros-jade/

You can check on your own with editing an urdf from a xacro (rosrun xacro xacro.py -o robot.urdf robot.xacro) and then a sdf from an urdf (gz sdf -p robot.urdf > robot.sdf), you will see that the issues are with the collision flags, both the one inside the gazebo link and the one inside the link.

So their are 2 issues :

  • if you directly define a collision inside the <gazebo> flag, the urdf -> sdf parser does not allow it instead puts <collision>__default__</collision>
  • the 2nd one is that the collision name that you setup in the link part is modified but this modification does not occur in the gazebo collision : If i go back to your exemple, in the link, you will NOT create a "bh_finger_13_collision" collision but you will create a "bh_finger_13_collision_collision" but in the gazebo part you will still call "bh_finger_13_collision" which does not exists.

In order to make it work, this is awful but I believe the only way at the moment, you have to change the names of your collision according to this _collision add on only one side. For exemple you could still call your collision 'bh_finger_13_collision' in the link but then in the gazebo part, you need to call it "bh_finger_13_collision_collision"

TTDM,

Supplementary note : in complex projects, there are usually other adds to the name of the collision ( in my project, with my collision box being called "mav_collision_box", the final name on the sdf of my collision box is : shredder/base_link_fixed_joint_lump__mav_collision_box_collision and i have to call that exact name on inside the <gazebo> flag) so you should really edit generate your sdf using the two command lines i gave previously then manually search for the name of your collision and put it into the gazebo part

part (of your xacro file)