Hi all!
Welcome to this “ROS In 5 Minutes” videos series.
In today’s videos we are going to see what’s a launch file and how to launch it.
If you want to Learn ROS Fast, we recommend you the following courses:
ROS In 5 Days (Python)
ROS In 5 Days (C++)
Whether you like the video or not, please leave a comment on the comments section below, so we can interact and learn from each other.
Step1. Create a project in Robot Ignite Academy(RIA)
We have the best online ROS course available in RIA. It helps you learn ROS in the easiest way without setting up ROS environment locally. The only thing you need is a browser! Create an account here and start to browse the trial course for free now! We’ll use the ROS Basic course as an example today.
Step2. Create package
Let’s create a package called tutorial first with the following command
cd ~/catkin_ws/src catkin_create_pkg tutorial rospy
Under the tutorial/src folder, create 2 files called publisher.py and subscriber.py.
#! /usr/bin/env python import rospy from std_msgs.msg import String rospy.init_node('tutorial') publisher = rospy.Publisher('/say_hello', String, queue_size=1) rate = rospy.Rate(3) # 3 Hz while not rospy.is_shutdown(): publisher.publish('Hey!') rate.sleep()
#! /usr/bin/env python import rospy from std_msgs.msg import String rospy.init_node('subscriber') def callback(data): print 'Subscriber received a msg: ', data.data sub = rospy.Subscriber('/say_hello', String, callback) rospy.spin()
Remember to give execute permission to the file with chmod +x command. Then you can run the file with rosrun command. However, it’s not quite convenient, right? What if you want to run several files at the same time?
That’s why we need launch files. Let’s create one called pub_sub.launch under the tutorial/launch folder with the following content.
<launch> <node name="publisher" pkg="tutorial" type="publisher.py" /> <node name="subscriber" pkg="tutorial" type="subscriber.py" output="screen" /> </launch>
Then we can run it with roslaunch tutorial pub_sub.launch . You can see a launch file is a powerful tool for us to launch multiple files in one single file.
If you want to learn more about this topic, please check our ROS In 5 Days (Python) course. You’ll learn much more about what launch files can do in this course.
Edit by: Tony Huang
0 Comments