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

How launch a python script with roslaunch

asked 2016-03-22 04:45:14 -0500

mohsen1989m gravatar image

Hello there,

I am trying to launch a script called mtnode.py from a package called xsens_drive. When I use rosrun it works perfectly, however i have difficulty to launch it with roslaunch. This is the syntax that I use:

  <node pkg="xsens_drive" name="mtnode.py" type="mtnode.py" output="screen">
        <param name="frame_id" value="base_link" />
  </node>

and this is the warning and error form the roslaunch:

WARNING: WARN: illegal <node> name 'mtnode.py'.
http://ros.org/wiki/Names
This will likely cause problems with other ROS tools.
Node xml is <node name="mtnode.py" output="screen" pkg="xsens_drive" type="mtnode.py">
        <param name="frame_id" value="base_link"/>
  </node>

and the error:

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

I tried different combination of name and type without .py with no luck, I am using ros indigo

Thanks in advance

edit retag flag offensive close merge delete

4 Answers

Sort by ยป oldest newest most voted
20

answered 2016-03-22 04:54:20 -0500

gvdhoorn gravatar image
<node pkg="xsens_drive" name="mtnode.py" type="mtnode.py" output="screen">

I think the package is actually called xsens_driver, so the following should work:

<node pkg="xsens_driver" name="mtnode" type="mtnode.py" output="screen"> 
  ..
</node>

The type for a Python script is always just the script itself. The name can be anything, but must follow the ROS naming conventions.

edit flag offensive delete link more

Comments

2

Thanks, yep that was a stupid mistake of mine...

mohsen1989m gravatar image mohsen1989m  ( 2016-04-07 08:08:20 -0500 )edit
2

This was useful, Thankyou !

Haresh Karnan gravatar image Haresh Karnan  ( 2018-02-26 00:09:27 -0500 )edit
1

I did the same mistake, thank you!

meterix gravatar image meterix  ( 2018-06-11 16:53:07 -0500 )edit

In my case (Kinetic), the node name was not sufficient, I had to specify nodename.py.

Avio gravatar image Avio  ( 2018-06-29 11:05:58 -0500 )edit
3

answered 2020-01-09 02:01:11 -0500

Rufus gravatar image

updated 2020-01-09 02:01:25 -0500

Additionally, make sure that the python script is executable (has execute bit set to 1), i.e. can be run with ./my_script.py

edit flag offensive delete link more
4

answered 2020-08-09 02:22:24 -0500

Sanjuna Mariam Mathews gravatar image

Make the python script executable chmod +x python_script_name.py

So give pkg= "name of package where script lies" name ="name of python script without extension" type="name of python scrupt with extension"

Example : <node pkg="v1robot_description" name="fake_encoder_count" type="fake_encoder_count.py" output="screen"/>

Name of python script in my case: fake_encoder_count.py Name of my ROS package : v1robot_description

edit flag offensive delete link more
1

answered 2021-08-07 04:54:42 -0500

Yash Sahu gravatar image

As, @Rufus mentioned above make sure the file is executable. You can to do that with below command: $ chmod +x python_script.py

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2016-03-22 04:45:14 -0500

Seen: 56,207 times

Last updated: Aug 07 '21