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

rosrun vs roslaunch to run a single node, any difference?

asked 2017-10-18 03:10:42 -0500

Jasmin gravatar image

updated 2017-10-22 06:52:00 -0500

Hi everyone!

Well, in my understanding launch files are meant to launch a node or so many nodes at a time and allow setting parameters dynamically , remapping and making sure that nodes don't stop if respawn is set to True and so many other stuff. I was wondering what is the difference between:

 <?xml version="1.0"?>
    <launch>
      <node name="my_node" pkg="my_package" type="my_node"/>
    </launch>

and

roscore&     
rosrun my_package my_node

There shouldn't be any difference ?!

In my case, when using rosrun, my node was crashing every 30 min and no ros logs where generated but when using roslaunch instead, it didn't crash for hours and the log files where saved successfully.

Is it just a coincidence!? or does the roslaunch command run nodes in a more coherent way?

I would be pleased if you could explain this to me...

Thanks!


Edit 1

In response to john.j.oneill 's comment

Basically I'm running the node from a bash script, start_my_node.sh and I do use the & after the rosrun command, my script is as follows:

#!/bin/bash
#ROS exportations 
#ROS source 
roscore&  
sleep 1
rosrun my_package my_node&

So it is not about having a lot of text in the output?

Is using a similar script a good way to start ros nodes?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
2

answered 2017-10-18 05:53:37 -0500

john.j.oneill gravatar image

I'm not sure how it would affect the stability of your node, but roslaunch does spawn each node into its own process, and then pipe the output of that node to a log file (unless you told it output=screen). Whereas rosrun, to my knowledge, is really just a shortcut to run the executable of your node in the terminal. This should explain why your rosrun generates no log files, but outputs text to the screen.

It's possible the crashing rosrun has to do with the terminal trying to keep up with a lot of text, or something along those lines. To test that you could run something like:

rosrun my_package my_node &

That will spawn it into it's own thread, and if that doesn't crash you will know it's something about the terminal causing it to die, in which case we would need to know more about what terminal emulator you are using to diagnose that problem.

edit flag offensive delete link more

Comments

Thanks for your answer @john.j.oneill ! I updated my question, can you please check it out?

Jasmin gravatar image Jasmin  ( 2017-10-18 11:36:35 -0500 )edit

I don't know enough about job control to tell you whether that is the source of your problem. But there are some ways to keep track of the processes you forked off: https://www.digitalocean.com/communit...

john.j.oneill gravatar image john.j.oneill  ( 2017-10-25 11:24:38 -0500 )edit

Also, as to whether using a script like this is a good idea, I've never seen anyone do it but I don't see why it wouldn't be fine. You may needlessly try to start another roscore if one is running, but it will shutdown cleanly on its own.

john.j.oneill gravatar image john.j.oneill  ( 2017-10-25 11:29:21 -0500 )edit

OK, thanks.

Jasmin gravatar image Jasmin  ( 2017-10-26 02:40:19 -0500 )edit

If you really are just recreating the functionality of roslaunch though, I would recommend using that instead, as it provides good logging functionality and is the 'ROSsy' way of doing things. And you don't need to run roscore to run roslaunch, it will auto-start a new master roscore for you.

john.j.oneill gravatar image john.j.oneill  ( 2017-10-26 04:22:08 -0500 )edit

Basically, I'm using bash scripts because I kind of need to run some nodes on startup or behind some simple user interfaces. Maybe I should keep in mind that I may group the nodes in one launch file and launch them together... I will look around for the best way to do it.

Jasmin gravatar image Jasmin  ( 2017-10-30 06:35:14 -0500 )edit

Okay. Probably better to use job control, or some other process monitor then, that way you can keep an eye on things and recover gracefully if/when nodes eventually die.

john.j.oneill gravatar image john.j.oneill  ( 2017-10-30 09:21:39 -0500 )edit

Question Tools

2 followers

Stats

Asked: 2017-10-18 03:10:42 -0500

Seen: 13,216 times

Last updated: Oct 18 '17