ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

Running a Python file from a ROS Launch file : Cant Find it

asked 2017-01-20 09:58:50 -0500

burf2000 gravatar image

updated 2017-01-21 15:55:03 -0500

So I have the following Launch file, when I run the launch file it errors saying it cant find the Python file

<?xml version="1.0"?>
<launch>
  <node name="brickpi.py" pkg="brickpi" type="brickpi.py" output="screen">
  <node pkg="xv_11_laser_driver" type="neato_laser_publisher" name="xv_11_node">
    <!--<param name="port" value="/dev/tty.usbserial-A9UXLBBR"/>-->
    <param name="port" value="/dev/tty.ACM0"/>
    <param name="firmware_version" value="2"/>
    <param name="frame_id" value="laser"/>
  </node>
  <node pkg="tf" type="static_transform_publisher" name="base_frame_2_laser" args="0 0 0 0 0 0 /base_frame /laser 100"/>
  <include file="default_mapping.launch"/>
  <include file="$(find hector_geotiff)/launch/geotiff_mapper.launch"/>
</launch>

The file is in the same directory as the launch file, I have also copied it in to

  • /home/pi/catkin_ws/src/brickpi/brickpi.py
  • /home/pi/catkin_ws/src/brickpi/src/brickpi.py
  • /home/pi/catkin_ws/src/brickpi.py
  • /home/pi/catkin_ws/build/brickpi/brickpi.py

error:

ERROR: cannot launch node of type [brickpi/brickpi.py]: brickpi
ROS path
 [0]=/opt/ros/indigo/share/ros ROS path
 [1]=/home/pi/catkin_ws/src ROS path
 [2]=/opt/ros/indigo/share ROS path
 [3]=/opt/ros/indigo/stacks

Update I have done chmod +x to the file but I must point out I have not made a package.xml, CMakeText or anything, I can run the file on its own via python and all works so maybe my issue is for a Launch file to use it, I must make a Package?

All code can be found here https://github.com/burf2000/ROS_Robot

edit retag flag offensive close merge delete

Comments

Did you make the Python file executable?

Thomas D gravatar image Thomas D  ( 2017-01-20 17:53:20 -0500 )edit

In your CMakeLists.txt do you have you Python program listed in the catkin_install_python section?

I have a working example here: https://gitlab.com/bradanlane/locoro

suforeman gravatar image suforeman  ( 2017-01-20 19:11:51 -0500 )edit

@burf2000: I think you'll only get (well intended) guesses from other board members, unless we can get access to (a minimal working example of) your code. In principle, this should all work, but there is probably a minor thing missing or not setup correctly which causes problems.

gvdhoorn gravatar image gvdhoorn  ( 2017-01-21 03:13:15 -0500 )edit

@suforeman: that is good advice, but installing artefacts is not needed when working with the devel space (as rosrun et al. will typically resolve Python packages to the src space).

gvdhoorn gravatar image gvdhoorn  ( 2017-01-21 04:12:30 -0500 )edit

Thanks @gvdhoorn, I'm still learning. My example still my shed some light. At least it's working for me. I also recall a situation similar to the OP that happened early on in my project. I had forgotten to source devel/setup.bash.

suforeman gravatar image suforeman  ( 2017-01-21 05:26:31 -0500 )edit

Yes, I was thinking something like that may have happened here (as it should just be enough to chmod +x a Python script to rosrun it, as long as it's in a ROS pkg), but the OP claim(s)(ed) that he already did that.

gvdhoorn gravatar image gvdhoorn  ( 2017-01-21 05:36:52 -0500 )edit

I have not chmod +x the file, all I have done is dumped the file in a new directory called brickpi? Do I need to make a cmaketxt?

burf2000 gravatar image burf2000  ( 2017-01-21 15:45:46 -0500 )edit

2 Answers

Sort by ยป oldest newest most voted
1

answered 2017-01-21 17:00:09 -0500

burf2000 gravatar image

updated 2017-01-22 09:38:14 -0500

  • I solved this by creating a package :) called burf_robot
    • Then I copied the script in to a directory called scripts within the package and did chmod +x
    • I then changed the package name in the launch file to the new burf_robot package name
    • I then ran catkin_make
edit flag offensive delete link more

Comments

2

Please don't accept answers when they're not really the answer.

The real solution was to create a package (called brickpi) and put the Python script in that.

Seeing as your launch file had pkg="brickpi" in it, we all assumed you had already done that. A MWE would have immediately ..

gvdhoorn gravatar image gvdhoorn  ( 2017-01-22 03:56:29 -0500 )edit

.. let us know you hadn't.

my issue is for a Launch file to use it, I must make a Package?

so yes, ROS is package based, and anything you want to rosrunmust be part of a package.

gvdhoorn gravatar image gvdhoorn  ( 2017-01-22 03:56:49 -0500 )edit

Sorry about that, yes you are right.

burf2000 gravatar image burf2000  ( 2017-01-22 09:35:21 -0500 )edit
1

answered 2017-01-20 10:40:01 -0500

duck-development gravatar image

you have to put the brickpi.py in the brickpi folder

edit flag offensive delete link more

Comments

I have put it in the brickpi folder? /home/pi/catkin_ws/src/brickpi/brickpi.py and /home/pi/catkin_ws/src/brickpi/src/brickpi.py

burf2000 gravatar image burf2000  ( 2017-01-20 12:32:46 -0500 )edit

After creating the ws and the brickpi packet. Did you run catkin_make in your ws folder

duck-development gravatar image duck-development  ( 2017-01-20 14:12:06 -0500 )edit
1

Could you put the PY file in catkin_ws/SRC/brickpi/scripts/

duck-development gravatar image duck-development  ( 2017-01-20 16:13:11 -0500 )edit

Question Tools

1 follower

Stats

Asked: 2017-01-20 09:58:50 -0500

Seen: 7,442 times

Last updated: Jan 22 '17