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

running different nodes from a shell script

asked 2017-10-26 06:57:56 -0500

rosusernli gravatar image

I have different nodes from different packages and I want to run it from a single shell script. The description is given below:

I have 3 different packages and each package contains 3 different nodes

(sample directory structure)
    |— src
        |— node1_node.cpp
    |— CMakeLists.txt
    |— package.xml

    |— src
        |— node2_node.cpp
    |— CMakeLists.txt
    |— package.xml

    |— src
        |— node3_node.cpp
    |— CMakeLists.txt
    |— package.xml

Each package has 1 executable. Every time I have to go to each executable path and execute. Instead of that I want to write a single script which will run the 3 different executable from 3 packages.

Is there a way to do that?

I tried by running the script:

cd path_to_package_name1/devel/lib/package_name1
cd path_to_package_name2/devel/lib/package_name2
cd path_to_package_name3/devel/lib/package_name3

But it is executing only the first node.How can I execute the 3 nodes together?

edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted

answered 2017-10-26 07:04:09 -0500

gvdhoorn gravatar image

Unless you have a specific reason to use them, I would stay away from using shell scripts.

To start individual nodes, use rosrun: rosrun pkg_name node_name.

To start entire applications, use roslaunch: roslaunch pkg_name some_file.launch.

See #q268337 for an older question about this.

edit flag offensive delete link more


And if you haven't yet, also take a look at the wiki/Using rqt_console and roslaunch - Using roslaunch tutorial. That should have covered this.

Have you done the basic tutorials?

gvdhoorn gravatar image gvdhoorn  ( 2017-10-26 07:07:22 -0500 )edit

And I'm linking to the eu mirror of the wiki as it appears to be down right now.

gvdhoorn gravatar image gvdhoorn  ( 2017-10-26 07:07:37 -0500 )edit

I usually run the executable directly rather than using rosrun. But when I used rosrun the following error occured: 'package not found'

I sourced the setup.bash file of the workspace and appended the src path to ROS_PACKAGE_PATH.But the error remained the same. Any suggestions on this?

rosusernli gravatar image rosusernli  ( 2017-10-27 02:58:29 -0500 )edit

I would really recommend you start using rosrun for this.

appended the src path to ROS_PACKAGE_PATH

don't do that. Ever.

Please edit your question with the complete error message that you get, and with the output of ls -al /path/to/your/catkin_ws/src.

gvdhoorn gravatar image gvdhoorn  ( 2017-10-27 03:03:03 -0500 )edit

Also: I only mentioned rosrun as you were starting binaries directly, which is not really 'the ROS way'.

Your question is/was about starting multiple nodes properly, which is really what roslaunch was created for.

gvdhoorn gravatar image gvdhoorn  ( 2017-10-27 03:04:44 -0500 )edit

Thanks for your answer and suggestion. I found out why it was giving 'package not found' . There was a space in my file path. Really sorry to bother you for this.

I am now able to use roslaunch and run the applications. Thanks for suggesting the ros way of running it.

rosusernli gravatar image rosusernli  ( 2017-10-27 04:59:17 -0500 )edit

You're welcome. No need to apologise.

gvdhoorn gravatar image gvdhoorn  ( 2017-10-27 05:07:07 -0500 )edit

Question Tools

1 follower


Asked: 2017-10-26 06:57:56 -0500

Seen: 1,294 times

Last updated: Oct 26 '17