rosrun : Package not found

7.4k views Asked by At

How to run a python script file for ros ?

I have developed python script to make a drone to fly. I have kept the code inside

tumsimulator/src/scripts/DroneFly.py. ## catkin make is done in this directory When I run the code in tumsimulator directory, it throws an error saying that scripts directory is not found.

I gave chmod 777 permission for directory as well as the file.

Can Somebody help me to run the python script in ros ?

1

There are 1 answers

5
cassinaj On BEST ANSWER

Just to be on the same page

  1. you need to create a catkin workspace a catkin package. For example you create a workspace called catkin_ws

    mkdir -p ~/catkin_ws/src
    cd ~/catkin_ws/src
    catkin_init_workspace
    
  2. Create your package called tumsimulator in ~/home/catkin_ws/src

    catkin_create_pkg tumsimulator rospy
    
  3. Put the scripts directory in tumsimulator/ not in tumsimulator/src. Once after running catkin_make, you should be able to run the script via

  4. Run catkin_make

    cd ~/catkin_ws
    catkin_make
    
  5. Finally, run your script

    rosrun tumsimulator DroneFly.py
    

As a side note, scripts should note have the py extension. You can add the python shebang line at the top of your script file #! /usr/bin/env python. If your are writing a python module, you may put these files in tumsimulator/src/tumsimulator/ next to tumsimulator/src/tumsimulator/__init__.py.