Home | Tutorials | Wiki | Issues
Ask Your Question
0

You must call ros::init() before creating the first NodeHandle

asked 2013-07-12 06:42:40 -0600

Christoph gravatar image

updated 2013-07-12 06:46:50 -0600

Hi all,

I got some strange and annoying problems after installing Gazebo 1.9 from source to be able to compile the gazebo_ros_pkgs.

I followed the installation instructions as shown in Installing_gazebo_ros_Packages and Compiling_From_Source. At this time the link pointing to the compiling_from_source of version 1.6. wasn't crossed out.

After the installation I was able to compile the gazebo_ros_pkgs in my catkin folder. But I got problems starting my models in Gazebo due to some ROS problems, saying something like:

"Not loading plugin since ROS hasn't been properly initialized".

I wasn't able to fix that. But because I achieved to compile the plugin package I went back to Gazebo 1.8.6 and ROS 1.9.45. Therefore I completely uninstalled all the old Gazebo and ROS versions.

What happens now is - when I try to start my models in Gazebo, using some self made plugins, I got the following error message:

file = /tmp/buildd/ros-groovy-roscpp-1.9.44-0precise-20130325-1240/src/libros/node_handle.cpp
line=151

I got two plugins and both of them worked fine before I made the previously mentioned changes.

The strange thing is, this error message appears only with one of the plugins. And they both initialize ros in the same way.

    public: void Load(physics::ModelPtr _parent, sdf::ElementPtr _sdf)
    {
        // Start up ROS
        std::string name = "scitos_gazebo_platform_control";
        int argc = 0;
        ros::init(argc, NULL, name);


        // ROS Nodehandle
        this->my_rosnode = new ros::NodeHandle("~");
                    ...

When I try to comment the rosnode or to get an message to the console by only using std::cout the error message stay the same.

Thank you for your help.

Christoph

edit retag flag offensive close merge delete

Comments

1

The Code you posted here does not seem to be the Problem!

btw. std::cout does not pipe the message directly to the console(it is buffered first). If you want to use an console output for debuging use std::err. this is the same for all C/C++ apllications.

evilBiber gravatar imageevilBiber ( 2013-07-12 09:47:23 -0600 )edit

The Code you posted here does not seem to be the Problem!

btw. std::cout does not pipe the message directly to the console(it is buffered first). If you want to use an console output for debuging use std::err. this is the same for all C/C++ apllications.

evilBiber gravatar imageevilBiber ( 2013-07-12 09:48:05 -0600 )edit

you seem to have two questions here... 1) properly installing and running gazebo and 2) fixing your custom plugin. it would be easier if we had 1 question per topic. for 1) how are you starting gazebo?

davetcoleman gravatar imagedavetcoleman ( 2013-07-12 18:10:04 -0600 )edit

@evilBiber: I used std:err during my problem analysis, but that didn't give me an output either. Thanks for the information about the operation principles of std::cout though. @davetcoleman: before I tried Gazebo 1.9. everything worked fine for me. At some point I installed DRCSim too, to get the laser plugin. I start Gazebo from the console typing "gazebo" and then insert my model from the gui.

Christoph gravatar imageChristoph ( 2013-07-17 04:51:37 -0600 )edit

2 Answers

Sort by ยป oldest newest most voted
0

answered 2013-08-01 10:54:13 -0600

Christoph gravatar image

Finally reinstalling ROS and all Gazebo components from source worked for me. See my newer question 4026.

I changed nothing in my code regarding the ROS initialization.

edit flag offensive delete link more
0

answered 2013-07-12 18:11:24 -0600

davetcoleman gravatar image

For your second question, I don't believe you want to call "init" ever within your own plugin, but you should leave that for the master gazeborosapi_plugin.cpp to do, then in your plugin just make sure that has already been called by doing something like:

  // Exit if no ROS
  if (!ros::isInitialized())
  {
    gzerr << "Not loading plugin since ROS hasn't been "
          << "properly initialized.  Try starting gazebo with ros plugin:\n"
          << "  gazebo -s libgazebo_ros_api_plugin.so\n";
    return;
  }
edit flag offensive delete link more

Comments

I did it that way, because the Gazebo tutorials for ros_enabled_model_plugins are built like that. Besides it worked that way before without problems. Is the gazebo_ros_api_plugin.cpp called automatically when you start the Gazebo "core"? Because I never implemented or called that file manually.

Christoph gravatar imageChristoph ( 2013-07-17 05:07:04 -0600 )edit

the gazebo_ros_api_plugin.cpp is automatically started with rosrun gazebo_ros gzserver and rosrun gazebo_ros gazebo. what/where are the ros_enabledmodelplugins tutorials?

davetcoleman gravatar imagedavetcoleman ( 2013-07-17 12:36:17 -0600 )edit

As one example Gazebo 1.5 tutorial.

Christoph gravatar imageChristoph ( 2013-07-18 07:20:21 -0600 )edit

I don't know the state of the 1.5 tutorials but they are outdated.

davetcoleman gravatar imagedavetcoleman ( 2013-07-18 16:28:17 -0600 )edit

That may be the fact, but they were up to date when I build my plugins. I am not sure if the problems are related with the old ways to build a plugin, but I'll check the new 1.9 tutorials and the hints you gave me. Thanks for your help.

Christoph gravatar imageChristoph ( 2013-07-19 03:21:49 -0600 )edit
Login/Signup to Answer

Question Tools

Stats

Asked: 2013-07-12 06:42:40 -0600

Seen: 2,903 times

Last updated: Aug 01 '13