Gazebo | Ignition | Community
Ask Your Question

How to understand if my plugin is loaded in gazebo?

asked 2016-03-01 05:52:53 -0500

gabri89 gravatar image

Hi again,

I created a ModelPlugin to simulate a motor with spring in a R robot. When I compile the plugin, it works and a file .so is generated. The I add the plugin in my URDF file in this way :

    <plugin name="motor_spring_plugin" filename="">

When I run gazebo with roslaunch there is no error and the robot appears. However I'm not able to understand if my plugin is effectively loaded in my model. How can I test it?

Moreover in this plugin I created a ros_node subscriber in the Load() function:

 public: void Load(physics::ModelPtr _parent, sdf::ElementPtr /*_sdf*/)

    if (!ros::isInitialized()) //check if ros is initialized properly
          ROS_FATAL("ROS has not been initialized!");

  ros::NodeHandle n;
  ros::Subscriber sub=n.subscribe("chatter", 1000, &MotorSpring::Callback, this);


(the Callback function is defined as public function) Is it true?

When gazebo is running, if I start rostopic list from terminal, the topic chatter doesn't appear.

Why? It is caused by the whole plugin or I made some mistakes in the ros piece of code?

Thank you

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2016-03-01 10:47:38 -0500

pcdangio gravatar image

Making a ros-interoperable plugin isn't exactly straightforward. Your chatter topic doesn't show up in rostopic list for a few reasons:

  1. Your nodehandle, n, is going out of scope after the Load method finishes. You need to make the nodehandle a member of the plugin class that load method resides within. This will keep your nodehandle in scope as long as the plugin is alive.

  2. You are creating a subscriber in the example code you posted, which will only read from the "chatter" topic. rostopic list only shows topics that are being advertised, not subscribed to.

A quick way to test if your plugin gets loaded is to use ROS_INFO("insert text here"); in the load method. This will send a message to the terminal that roscore is running in.

Hope this helps!

edit flag offensive delete link more


Yes, I made the nodehandle as a class member and I created a "publisher". So I can see the topic with rostopic list. Thank you!

gabri89 gravatar imagegabri89 ( 2016-03-07 09:49:36 -0500 )edit
Login/Signup to Answer

Question Tools



Asked: 2016-03-01 05:52:53 -0500

Seen: 3,667 times

Last updated: Mar 01 '16