0
$\begingroup$

Gazebo Answers logo

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


Originally posted by gabri89 on Gazebo Answers with karma: 19 on 2016-03-01

Post score: 0

$\endgroup$

1 Answer 1

0
$\begingroup$

Gazebo Answers logo

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!


Originally posted by pcdangio with karma: 207 on 2016-03-01

This answer was ACCEPTED on the original site

Post score: 2


Original comments

Comment by gabri89 on 2016-03-07:
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!

$\endgroup$

Your Answer

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