0
$\begingroup$

Gazebo Answers logo

Hi, I am using gazebo to simulate a sonar. Thus I will use hector_sonar_plugin. While after I install the hector plugins from source and call it in my sdf, errors come.

At first, an error appear asking me to add libhector_sonar_plugin.so to gazebo_ros package.

I cannot understand it and thought it cannot find the plugin. Thus,I use

export GAZEBO_PLUGIN_PATH=`pwd`:$GAZEBO_PLUGIN_PATH 

to add hector_plugin folder into path, then more error come:

Error [Plugin.hh:156] Failed to load plugin libRayPlugin.so: libRayPlugin.so: cannot open shared object file: No such file or directory
[FATAL] [1464103865.820981859]: A ROS node for Gazebo has not been initialized, unable to load plugin. Load the Gazebo system plugin 'libgazebo_ros_api_plugin.so' in the gazebo_ros package)

Could someone tell me how to set the GAZEBO_PLUGIN_PATH correctly (or reset it correctly)? And if I want to use plug-Ins such as hector's, what should I do? (just copy .so to the model folder or ...?)

I am using Indigo full desktop, and thus version should be gazebo2

Thank you.


Originally posted by wyxf007 on Gazebo Answers with karma: 5 on 2016-05-25

Post score: 0


Original comments

Comment by Aiven92 on 2016-05-27:
Can you show line of SDF file, where you include plugin ? Frequent problem is a relative path to the plugin.

Comment by Weiwei on 2016-05-28:
Can you check out the current GAZEBO_PLUGIN_PATH? Run $echo $GAZEBO_PLUGIN_PATH to see whether the path is right.

Comment by wyxf007 on 2016-05-28:
I just use

    <plugin name="gazebo_ros_sonar_data" filename="libhector_gazebo_ros_sonar.so">
      <gaussianNoise>0.005</gaussianNoise>
      <topicName>radiofence</topicName>
      <frameId>radiofence1</frameId>
    </plugin>
  </sensor>

to call the plugin in my sensor sdf file.

Comment by wyxf007 on 2016-05-28:
After echo GAZEBO_PLUGIN_PATH in Terminal, I just get the result

GAZEBO_PLUGIN_PATH

Comment by Aiven92 on 2016-05-28:
I have zero string result of echo $GAZEBO_PLUGIN_PATH, but I'm use ABSOLUTE path to the plugin *.so file and all work fine.

Comment by wyxf007 on 2016-05-30:
Could you tell me how to use the ABSOLUTE path? do changes in URDF file ?

$\endgroup$

2 Answers 2

0
$\begingroup$

Gazebo Answers logo

as already mentioned previously you can see your current GAZEBO_PLUGIN_PATH by the command echo $GAZEBO_PLUGIN_PATH. The path should point directly to the folder where the .so file is located (for example the build folder).

the export GAZEBO_PLUGIN_PATH=´pwd´:$GAZEBO_PLUGIN_PATH doesn't overwrite the path it just append the current directory(pwd) to the variable. (you can also use $PWD which is handier) Resulting you have a mess after several tries. In addition, export is just temporary and depends on the current terminal. (don't confuse yourself with too many tabs / terminals)

To clean the variable use unset GAZEBO_PLUGIN_PATH , then check again the variable: echo $GAZEBO_PLUGIN_PATH (no nothing should be returned)

Now you have to navigate in terminal to the folder where the .so file is located (since pwd is the current folder). After using export GAZEBO_PLUGIN_PATH=$PWD your variable should be set correctly. (overwrites existing values)

If you want to append your path to the variable use export GAZEBO_PLUGIN_PATH=$PWD:$GAZEBO_PLUGIN_PATH.

(Hint: you can also set the path directly for example: export  GAZEBO_PLUGIN_PATH=/home/#USERNAME#/Documents/testplugin/build)

To have the GAZEBO_PLUGIN_PATH permanent you can include the "export xx=xx" line into your ~/.bashrc file

Edit/Remark:

The default gazebo plugins are loading since gazebo is sourcing its default environment variables before the start. This is carried out using the file /usr/share/gazebo/setup.sh or /usr/share/gazebo-X.X/setup.sh(the X.X is your respective gazebo version)

To be aware of this behavior and be able to see its default values, you can use source /usr/share/gazebo/setup.sh

Again, to have this permanent in every console instance, add the line to your .bashrc file.


Originally posted by m4k with karma: 61 on 2016-05-31

This answer was ACCEPTED on the original site

Post score: 1


Original comments

Comment by wyxf007 on 2016-06-02:
Thank you! I was quite confused why echo GAZEBO_PLUGIN_PATH just return a same name a same name, even if the gazebo default plugin setting still works. But at least I can use your method now.

$\endgroup$
1
$\begingroup$

I have tried this and found it to be effective. If you want others to run your code conveniently, you might consider using relative paths. I achieved this through ros2 humble .launch.py file.

The main approach is by utilizing AppendEnvironmentVariable and get_package_share_directory

import os

from ament_index_python.packages import get_package_share_directory
from launch.actions.append_environment_variable import AppendEnvironmentVariable

def generate_launch_description():
    # Set Gazebo plugin path
    append_environment = AppendEnvironmentVariable(
        'GAZEBO_PLUGIN_PATH',
        os.path.join(os.path.join(get_package_share_directory('pb_rm_simulation'), 'meshes', 'obstacles', 'obstacle_plugin', 'lib'))
    )

    ld = LaunchDescription()

    # Set environment variables
    ld.add_action(append_environment)

    return ld

then you can use your own gazebo plugin conveniently. Like these:

<model name="turtlebot3_drl_obstacle1">
  <plugin name="obstacle1" filename="libobstacle1.so"/>
  <include>
    <pose>1 -2.5 0.4 0 0 0</pose>
    <uri>model://obstacles/obstacle1</uri>
  </include>
</model>

Hoping that it will be helpful for you :)

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.