[ROS Q&A] 123 – Roslaunch can’t locate node, but rosrun works fine
In this video, we are going to answer a question found at ROS answers (https://answers.ros.org/question/291235/roslaunch-cant-locate-node-but-rosrun-works-fine/). The person is asking why he can run a Python script with rosrun, but not when using roslaunch.
Let’s try this out and solve this problem in ROS Development Studio. You can register a free account and follow the tutorial below!
Step1: create a package
After creating a new project in RDS, open a new shell from the tools tab and type the following command into the shell to create a ROS package.
catkin_create_pkg video_qa rospy
Step2: create a test file for the code.
It’s easier to do this with an IDE. You can find IDE in the tools tab.
Now right click and select the new file to open a new file test under the folder /video_qa/src
Paste the following code into the test file.
#! /usr/bin/env python
rate = rospy.Rate(1)
while not rospy.is_shutdown():
print "Hello there"
Step3: create a launch file
According to ROS’s file structure, the launch file should be created under the launch directory. Let’s create it with the IDE and add a test.launch file under the /video_qa/launch folder.
Copy and paste the following code for testing.
<node pkg="video_qa" type="test" name="test" output="screen">
Step4: start roscore
To run the code with roslaunch, we need to start roscore. You can either do that by typing roscore into the shell or start a simulation from the Simulations tab.
Step5: rosrun and roslaunch
Firstly, we try to directly execute the test file using rosrun video_qa test, but we got some error message.
[rosrun] Couldn’t find executable named test below /home/user/catkin_ws/src/video_qa
That’s because of the lack of permission for this file. We can give the file permission by typing:
chmod +x video_qa/src/test
then we do rosrun video_qa test again. It works!
Then we try roslaunch video_qa test.launch. Strangely, it also works…WHY?
It turns out if we name the file test.py instead of test, we will have the same problem. To solve it, we rename the file to test.py and also in the launch file we use test.py instead of test.
Always name the file with extension(e.g. test.py). However, the type in the launch file takes the executable during the compiling process. Since there is no need for compiling .py file. If you use python, just put the file name with the extension(e.g. test.py) in the type section.
I hope you enjoy the ROS Q&A video today. If you are interested in learning ROS, please check the links below for the Robot ignite academy.
// RELATED LINKS
▸ ROS answers question: https://answers.ros.org/question/291235/roslaunch-cant-locate-node-but-rosrun-works-fine/
▸ ROS Development Studio: https://goo.gl/273g12
▸ Robot Ignite Academy: https://goo.gl/LsMMqh
▸ ROS Basics in 5 days online course: https://goo.gl/TDVG1j
- Click to share on Twitter (Opens in new window)
- Click to share on Facebook (Opens in new window)
- Click to share on Reddit (Opens in new window)
- Click to email this to a friend (Opens in new window)
- Click to print (Opens in new window)
- Click to share on Google+ (Opens in new window)
- Click to share on Tumblr (Opens in new window)
- Share on Skype (Opens in new window)
- Click to share on Pinterest (Opens in new window)
- Click to share on WhatsApp (Opens in new window)
- Click to share on Telegram (Opens in new window)