[ROS Beginner Mistakes] – 1. Missing execute permission on the Python file

Written by Bayode Aderinola

07/10/2019

In this short post, we will show how to avoid a very common mistake most ROS beginners make: missing execute permission on the Python file.

Step 1: Create a Project (ROSject) on ROSDS

Head to http://rosds.online and create a project with a similar configuration as the one shown below. You can change the details as you like, but please make sure you select “Ubuntu 16.04 + ROS Kinetic + Gazebo 7” under “Configuration”.

Once done with that, open your ROSject. This might take a few moments, please be patient.

Step 2: Create a ROS package with a Python program

Pick a Shell from the Tools menu and create a Python package.

user:~$ cd catkin_ws/
user:~/catkin_ws$ cd src
user:~/catkin_ws/src$ catkin_create_pkg missing_permission
Created file missing_permission/package.xml
Created file missing_permission/CMakeLists.txt
Successfully created files in /home/user/catkin_ws/src/missing_permission. Please adjust the values in package.xml.
user:~/catkin_ws/src$ cd missing_permission/
user:~/catkin_ws/src/missing_permission$ mkdir -p src/
user:~/catkin_ws/src/missing_permission$ cd src
user:~/catkin_ws/src/missing_permission/src$ touch missing_perm.py
user:~/catkin_ws/src/missing_permission/src$

Fire up the IDE from the Tools menu, find the missing_perm.py file in the missing_permission package, open the file and paste the following code into it.

#! /usr/bin/env python
import rospy

rospy.init_node("Obiwan")
rate = rospy.Rate(2)
while not rospy.is_shutdown():
    print "Help me Obi-Wan Kenobi, you're my only hope"
    rate.sleep()

Save().

Step 3: Compile and source the workspace.

cd ~/catkin_ws
catkin_make
source devel/setup.bash

Step 4: Run the package with rosrun and roslaunch.

First, we check that the package has been recognized, with rospack list. Then we run it with rosrun.

user:~/catkin_ws$ rospack list | grep missing
missing_permission /home/user/catkin_ws/src/missing_permission
user:~/catkin_ws$ rosrun missing_permission missing_perm.py
[rosrun] Couldn't find executable named missing_perm.py below /home/user/catkin_ws/src/missing_permission
[rosrun] Found the following, but they're either not files,
[rosrun] or not executable:
[rosrun]   /home/user/catkin_ws/src/missing_permission/src/missing_perm.py
user:~/catkin_ws$

The program did not run! What’s that error? Surely that not what we expected. Maybe rosrun does not like us – let’s try roslaunch!

Create a launch file and use it to launch the python program:

user:~/catkin_ws$ cd src/missing_permission/
user:~/catkin_ws/src/missing_permission$ mkdir -p launch
user:~/catkin_ws/src/missing_permission$ cd launch
user:~/catkin_ws/src/missing_permission/launch$ touch missing_perm.launch
user:~/catkin_ws/src/missing_permission$

Open the launch file in the IDE and paste in the following code:

<launch>
    <node name="missing_permission_ex" pkg="missing_permission" type="missing_perm.py" output="screen" />
</launch>

Launch!

user:~/catkin_ws/src/missing_permission$ cd ~/catkin_ws
user:~/catkin_ws$ source devel/setup.bash
user:~/catkin_ws$ roslaunch missing_permission missing_perm.launch
... logging to /home/user/.ros/log/e3188a2e-e921-11e9-8ac1-025ee6e69cec/roslaunch-rosdscomputer-11105.log
...

NODES
  /
    missing_permission_ex (missing_permission/missing_perm.py)

auto-starting new master
process[master]: started with pid [11147]
ROS_MASTER_URI=http://master:11311

setting /run_id to e3188a2e-e921-11e9-8ac1-025ee6e69cec
process[rosout-1]: started with pid [11170]
started core service [/rosout]
ERROR: cannot launch node of type [missing_permission/missing_perm.py]: can't locate node [missing_perm.py] in package [missing_permission]

Oops! It didn’t run again. Now we have another error screaming:

ERROR: cannot launch node of type [missing_permission/missing_perm.py]: can't locate node [missing_perm.py] in package [missing_permission]

What do we do now?

Step 5: Fix the missing execute permission on the Python file and be happy!

user:~/catkin_ws$ cd src/missing_permission/src/
user:~/catkin_ws/src/missing_permission/src$ chmod +x missing_perm.py
user:~/catkin_ws/src/missing_permission/src$

Now let’s try again with both roslaunch and rosrun:

user:~/catkin_ws/src/missing_permission/src$ roslaunch missing_permission missing_perm.launch
...

NODES
  /
    missing_permission_ex (missing_permission/missing_perm.py)

auto-starting new master
process[master]: started with pid [13206]
ROS_MASTER_URI=http://master:11311

setting /run_id to eec6e306-e922-11e9-b72a-025ee6e69cec
process[rosout-1]: started with pid [13229]
started core service [/rosout]
process[missing_permission_ex-2]: started with pid [13242]
Help me Obi-Wan Kenobi, you're my only hope
Help me Obi-Wan Kenobi, you're my only hope
Help me Obi-Wan Kenobi, you're my only hope
...

Running fine with roslaunch. Press Ctrl + C on the roslaunch program and try rosrun:

user:~/catkin_ws/src/missing_permission/src$ rosrun missing_permission missing_perm.py
Unable to register with master node [http://master:11311]: master may not be running yet. Will keep trying.

If you get the error above, please spin another Shell from the Tools menu, and run the following to start the ROS master:

user:~$ roscore

After this, the roscore command should resume and you’ll get:

user:~/catkin_ws/src/missing_permission/src$ rosrun missing_permission missing_perm.py
Unable to register with master node [http://master:11311]: master may not be running yet. Will keep trying.
Help me Obi-Wan Kenobi, you're my only hope
Help me Obi-Wan Kenobi, you're my only hope
Help me Obi-Wan Kenobi, you're my only hope
...

And that was it. As it turned out, roscore had no ill-feeling towards us!

Related Resources

Feedback

Did you like this post? Do you have questions about what was explained? Whatever the case, please leave a comment on the comments section below, so we can interact and learn from each other.

If you want to learn about other ROS or ROS2 topics, please let us know in the comments area and we will do a video or post about it 🙂

 

Discover How to Equip Your Teams with ROS Skills Fast

The Construct For Enterprise

Check Out These Related Posts

5 Mistakes Robotics & ROS Teachers Make

5 Mistakes Robotics & ROS Teachers Make

Last week, a colleague of mine asked me for advice on how to teach ROS at university because she is going to start delivering a ROS class next month. Then I decided to record this video with 5 mistakes I have made in the past while teaching ROS at the university. I hope that this video is useful for you and helps you avoid the mistakes that I made so you can start delivering ROS classes smoothly.

read more

0 Comments

Share This