Home | Tutorials | Wiki | Issues
Ask Your Question
0

How to understand if my plugin is loaded in gazebo?

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

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 :

  <gazebo>
    <plugin name="motor_spring_plugin" filename="libmotor_spring_plugin.so">
    </plugin>
 </gazebo>

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!");
          return;
        }


  ros::NodeHandle n;
  ros::Subscriber sub=n.subscribe("chatter", 1000, &MotorSpring::Callback, this);
      ...something... 
 this->UpdateConnection=event::Events::ConnectWorldUpdateBegin(boost::bind(&MotorSpring::OnUpdate,this,_1));

}

(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
2

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

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

Comments

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 -0600 )edit
Login/Signup to Answer

Question Tools

1 follower

Stats

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

Seen: 2,563 times

Last updated: Mar 01 '16