Ask Your Question
0

running different nodes from a shell script

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

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)
    package_name1
    |— src
        |— node1_node.cpp
    |— CMakeLists.txt
    |— package.xml

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

    package_name3
    |— 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
./node1_node
cd path_to_package_name2/devel/lib/package_name2
./node2_node
cd path_to_package_name3/devel/lib/package_name3
./node3_node

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
0

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

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

Comments

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 imagegvdhoorn ( 2017-10-26 07:07:22 -0600 )edit

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

gvdhoorn gravatar imagegvdhoorn ( 2017-10-26 07:07:37 -0600 )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 imagerosusernli ( 2017-10-27 02:58:29 -0600 )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 imagegvdhoorn ( 2017-10-27 03:03:03 -0600 )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 imagegvdhoorn ( 2017-10-27 03:04:44 -0600 )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 imagerosusernli ( 2017-10-27 04:59:17 -0600 )edit

You're welcome. No need to apologise.

gvdhoorn gravatar imagegvdhoorn ( 2017-10-27 05:07:07 -0600 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

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

Seen: 408 times

Last updated: Oct 26 '17