There are a few differences, but the major ones are:
rosrun can only launch one node at a time, from a single package WHILE
roslaunch can launch two or more nodes at the same time, from multiple packages
roslaunch will automatically start
roscore (if not running already) WHILE
rosrun does not.
roslaunch uses launch files, which can automatically start other programs by including other launch files, set some parameters, etc WHILE
rosrun does not use launch files - it launches the nodes directly.
Thanks for clarifying, I would like to understand something when launching 2 nodes from the same launch file
my executable is
#! /usr/bin/env python
rate = rospy.Rate(2) # We create a Rate object of 2Hz
c = 0
while not rospy.is_shutdown(): # Endless loop until Ctrl + C
print (c, " Help me Obi-Wan Kenobi, you're my only hope")
and my launch file is
<!-- comment on my launch file -->
<node name="ObiWan" pkg="my_package" type="simple.py" output="screen"></node>
<node name="ObiWan2" pkg="my_package" type="simple.py" output="screen"></node>
it runs perfectly, but how come in my executable I specify a different node name but it still runs eg on
rospy.init_node('test') I initiated the node with the name test, but my launch file I launch 2 nodes with names
ObiWan2 does the launch file automatically override the name ?
Yes, the launch file automatically overrides the node name specified in the script.