ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

Node created at runtime will not start

asked 2013-06-07 05:32:14 -0500

kaoao gravatar image

updated 2013-11-14 11:07:57 -0500

tfoote gravatar image

I'm having some trouble getting a node that is created at run time to be "recognized". Here is the node class:

class node {
        ros::NodeHandle *n;

        node() { n = NULL; }
        ros::NodeHandle getHandle() { return *n; }
        init(int argc, char **argv, std::string s) {
            ros::init(argc, argv, s);
        void create() {
            if (n == NULL) { n = new ros::NodeHandle(); }

I use the node class inside of a coorinator

class coordinator {
        node myNode;
        /** Pub, Subs, etc go here */
        void setup(int argc, char **argv, std::string s) {
            myNode.init(argc, argv, s);
            /* setup pubs, subs etc using myNode.getHandle() */
int main(int argc, char **arv) {
    ros::init(argc, argc, "starter");
    coordinator c;
    c.init(argc, argv, "coordinator");

When I call c.setup() from a main method of another node, the newly created node doesn't show up using rosnode list and clients that requests its services wait forever. I can't use rosspawn because I'm using ros fuerte.

EDIT: I even tried to pass the main methods node handle into the node constructor but it still doesn't get recognized.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2013-06-09 02:50:36 -0500

As far as I know, roscpp only creates one node per process. Multiple calls to ros::init() will not actually create multiple nodes. This function actually protects itself against repeated calls using an initialized flag to bypass many operations if called more than once.

If you need to create multiple nodes in a single process, I suggest you look into nodelets. These are fully supported, and are the typical method used to combine nodes for image processing.

See this question for more discussion.

edit flag offensive delete link more

Question Tools


Asked: 2013-06-07 05:32:14 -0500

Seen: 345 times

Last updated: Jun 09 '13