ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
1

Failed to add flash plugin in xacro file

asked 2020-04-08 03:49:28 -0500

myboyhood gravatar image

hello, I have seen tutorial given by johnconn similar problem, but it is SDF format, I try libFlashLightPlugin in sdf, it works! however, I fail to run this plugin in xacro file. here is my code:

<joint name="${robot_namespace}/led_joint" type="fixed">
  <origin xyz="0 0 0" rpy="0 0 0" />
  <parent link="${robot_namespace}/base_link" />
  <child link="led_link" />
</joint>
<link name="led_link">
  <visual name="led">
    <origin xyz="0 0 -0.2" rpy="0 0 0" />
    <geometry>
     ...
    </geometry>
  </visual>
  <light name="led" type="point">
    ...
  </light>
</link>
<gazebo>
  <light> name ='led_link/led' type = 'point'</light>
  <plugin name='light_control' filename='libFlashLightPlugin.so'>
  <enable>true</enable>
  <light>
    <id>led_link/led</id>
    <duration>0.3</duration>
    <interval>0.4</interval>
    <color>0.5 1 0.8</color>
  </light>
  </plugin>
</gazebo>

here is my successful demo in SDF format

<joint name="quad01/led_joint" type="fixed">
  <parent>quad01/base_link</parent>
  <child>led_link</child>
</joint>

<link name="led_link">
<pose>0 0 0.1 0 0 0</pose>
  <visual name="led">
    <geometry>
      <sphere>
        <radius>0.01</radius>
      </sphere>
    </geometry>
  </visual>
  <light name="led" type="point">
    <attenuation>
      <range>0.5</range>
      <linear>0.5</linear>
    </attenuation>
    <diffuse>1 0.2 0.2 1</diffuse>
    <specular>1 1 1 1</specular>
  </light>
</link>

<plugin name='light_control' filename='libFlashLightPlugin.so'>
  <enable>true</enable>
  <light>
    <id>led_link/led</id>
    <duration>0.3</duration>
    <interval>0.4</interval>
    <color>0.5 1 0.8</color>
  </light>
</plugin>
edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
2

answered 2020-04-08 13:25:57 -0500

Weasfas gravatar image

Hi @myboyhood,

I had the same issue, and I ended in the same post you linked. I tried their solution and did not work so I decided to include in the gazebo tag a direct reference to the SDF format to avoid the conversion from URDF, because when I use it as a xacro, when converting form URDF to SDF the parser always warned me saying the light link did not exist, thus omiting the generation of the plugin. I will place here my approach but may not be the best.

<?xml version="1.0"?>

<robot name="mol" xmlns:xacro="http://www.ros.org/wiki/xacro">

    <!-- Base Link -->
    <link name="base_link">
        <collision>
            <origin xyz="0 0 0" rpy="0 0 0"/>
            <geometry>
                <box size="1 1 1"/>
            </geometry>
        </collision>

        <visual>
            <origin xyz="0 0 0" rpy="0 0 0"/>
            <geometry>
                <box size="1 1 1"/>
            </geometry>
        </visual>

        <inertial>
            <origin xyz="0 0 0" rpy="0 0 0"/>
            <mass value="1"/>
            <inertia
                ixx="1.0" ixy="0.0" ixz="0.0"
                iyy="1.0" iyz="0.0"
                izz="1.0"/>
        </inertial>
    </link>

    <gazebo>
      <model name='flashlight'>
        <pose>0 0 0 0 0 0</pose> 
        <link name='light_source'>
          <pose>0 0 0.0 0.01 0 0</pose>
          <inertial>
            <mass>0.0025</mass>
            <inertia>
              <ixx>1.0e-05</ixx>
              <ixy>0</ixy>
              <ixz>0</ixz>
              <iyy>1.0e-05</iyy>
              <iyz>0</iyz>
              <izz>1.0e-05</izz>
            </inertia>
          </inertial>
          <light name='lamp' type='spot'>
            <pose>0 0 0.0 0 0 0</pose>
            <attenuation>
              <range>15</range>
              <linear>0</linear>
              <constant>0.1</constant>
              <quadratic>0.01</quadratic>
            </attenuation>
            <diffuse>0.8 0.8 0.5 1</diffuse>
            <specular>0.8 0.8 0.5 1</specular>
            <spot>
              <inner_angle>1</inner_angle>
              <outer_angle>1.1</outer_angle>
              <falloff>1</falloff>
            </spot>
            <direction>0 0 -1</direction>
          </light>
          <visual name='lamp'>
            <geometry>
              <cylinder>
                <radius>0.019</radius>
                <length>0.005</length>
              </cylinder>
            </geometry>
            <transparency>0.0</transparency>
            <material>
              <ambient>1 1 1 1</ambient>
              <diffuse>1 1 1 1</diffuse>
              <specular>1 1 1 1</specular>
              <emissive>0.8 0.8 0.5 1</emissive>
            </material>
          </visual>
        </link>
        <plugin name='light_control' filename='libFlashLightPlugin.so'>
              <enable>true</enable>
              <light>
                <id>light_source/lamp</id>
                <duration>0.5</duration>
                <interval>0.5</interval>
              </light>
        </plugin>
      </model>
    </gazebo>
    <gazebo>
      <joint name='flashlight_joint' type='fixed'>
        <parent>base_link</parent>
        <child>flashlight::light_source</child>
      </joint>
    </gazebo>

</robot>

Also I found this reference from a DARPA challenge but they are using directly some ROS custom plugins instead of Gazebo ones. Furthermore, they were manage to implement a Xacro for Flashlights and Leds, you may want to take a look at that, maybe you find some inspiration to make up a good solution.

edit flag offensive delete link more
2

answered 2020-04-08 20:53:00 -0500

myboyhood gravatar image

updated 2020-04-08 20:56:31 -0500

hello, @Weasfas yes,I tried your method and got the same error like below:

Warning [parser.cc:950] XML Element[plugin], child of element[link] not defined in SDF. Ignoring[plugin]. You may have an incorrect SDF file, or an sdformat version that doesn't support this element.

But I find the solution first you can refer to link:original author solution second,the reason to your warning is that this block below

    <material>
      <ambient>0 0 0 1</ambient>
      <diffuse>0 0 0 1</diffuse>
      <specular>0 0 0 1</specular>
      <emissive>0 1 0 1</emissive>
    </material>

can not be include in link tag ,because they are SDF format,which will not be recognize by xacro. the solution is

<gazebo reference="led_link_0"> <visual> <material> <ambient>0 0 0 1</ambient> <diffuse>0 0 0 1</diffuse> <specular>0 0 0 1</specular> <emissive>0 1 0 1</emissive> </material> </visual> </gazebo>

only give "material" in gazebo tag with reference name(your link)


Third,I can not add flashlight by adding libFlashLightPlugin.so,However, below is my code for constant white light and colored emissive link

<joint name="${robot_namespace}/led_joint_0" type="fixed"> <origin xyz="0 0 0" rpy="0 0 0"/> <parent link="${robot_namespace}/base_link"/> <child link="led_link_0"/> </joint>

<link name="led_link_0">
  <visual>
    <origin xyz="0.17 0 -0.1" rpy="0 0 0" />
    <geometry>
      <cylinder radius="0.01" length="0.05"/>
    </geometry>
  </visual>
</link><!--it is useless to define light tag here, it helps to define light tag in gazebo tag below-->

<gazebo reference="${robot_namespace}/led_link_0">
  <visual>
    <material>
      <ambient>0 0 0 1</ambient>
      <diffuse>0 0 0 1</diffuse>
      <specular>0 0 0 1</specular>
      <emissive>0 1 0 1</emissive>
    </material>
  </visual>
  <light name ='${robot_namespace}/led_link_0/led' type = 'point'>
    <pose>-0.025 0 0.5 0 0 0</pose><!--you can place light position here ,and it is useless to give position in link-->
  </light>
  <plugin name='light_control' filename='libFlashLightPlugin.so'>
  <enable>true</enable>
  <light>
    <id>${robot_namespace}/led_link_0/led</id>
    <duration>0.3</duration>
    <interval>0.4</interval>
    <color>0.1 1 0.1</color>
    <enable>true</enable>
  </light>
  </plugin>
</gazebo>

Forth, if you want a emissive link and constant white light, above is a solution.another approach to make your link lighted is adding below tag outside of link tag

<gazebo reference="led_link_0">
  <material>Gazebo/GreenGlow</material>
</gazebo>
edit flag offensive delete link more

Comments

Hi @myboyhood,

Great! You are correct. Great work!.

Weasfas gravatar image Weasfas  ( 2020-04-09 04:49:17 -0500 )edit

Question Tools

3 followers

Stats

Asked: 2020-04-08 03:23:34 -0500

Seen: 849 times

Last updated: Apr 08 '20