make and run a simple Python file?

1,237 views
Skip to first unread message

KM6VV

unread,
Mar 14, 2013, 10:11:39 PM3/14/13
to hbrob...@googlegroups.com
I'm trying to get a simple Python program running under ROS (& Turtlebot).

Ubuntu 10.04 and Diamondback.

Following the ROS tutorials, I created a package:

roscreate-pkg my_py std_msgs rospy roscpp

I added a launch folder with a py.launch file and a nodes folder with a
node.py file.

I ran rosmake

I ran roslaunch my_py py.launch

But I get: "cannot launch node of type [my_py/node.py]: cannot locate
node of type [node.py] in package [my_py]"

node.py may not be correct Python code, but I can't get it to execute.

I've gone over the ROS tutorials,

Creating a ROS Package
Building a ROS Package
Understanding ROS Nodes

But they load a turtlebot sim, rather then building a node to run a
Python or C/C++ file.


Thoughts?

Alan Marconett
node.py
py.launch

Tyson Tucker

unread,
Mar 15, 2013, 1:18:24 AM3/15/13
to hbrob...@googlegroups.com
Not that I know what I'm talking about, but have you made the file
executable, and/or added a shebang line on line 1? E.g.:

#!/usr/bin/env python
> --
> You received this message because you are subscribed to the Google Groups
> "HomeBrew Robotics Club" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to hbrobotics+...@googlegroups.com.
> To post to this group, send email to hbrob...@googlegroups.com.
> Visit this group at http://groups.google.com/group/hbrobotics?hl=en.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>

KM6VV

unread,
Mar 15, 2013, 2:33:53 AM3/15/13
to hbrob...@googlegroups.com
I don't know what that is, but I'll look it up and try it!

Alan KM6VV

anfederman@comcast

unread,
Mar 15, 2013, 10:39:48 AM3/15/13
to hbrob...@googlegroups.com
Sounds like you can't find the node. Most likely because your environment
is not set up correctly. If you can't "roscd my_py" You need to fix your
environment. You need to 'source setup.bash' in both the main
/opt/ros/electric/ (whatever distribution) and ~/workspace_ros (if you
use ros work spaces. If you use the alternate build system (catkin) you
have to something else to get the paths working correctly.

"You got to suffer if you want to sing the blues."

--------------------------------------------------
From: "KM6VV" <KM...@sbcglobal.net>
Sent: Thursday, March 14, 2013 11:33 PM
To: <hbrob...@googlegroups.com>
Subject: Re: [HBRobotics] make and run a simple Python file?

Patrick Goebel

unread,
Mar 15, 2013, 10:52:33 AM3/15/13
to hbrob...@googlegroups.com
Hi Alan KM6VV,

As Tyson said, put the "shebang" line at the top of your node.py file.
Then to make the node executable, run the following command in the
my_py/nodes directory:

$ chmod 755 node.py

--patrick

P.S. Most editors will create a text file with initial permissions 644
or 600 which is read/write but not executable.

KM6VV

unread,
Mar 15, 2013, 1:22:37 PM3/15/13
to hbrob...@googlegroups.com
Hi Alan F,

I can do a roscd, and setup.bash is set.

Alan KM6VV

KM6VV

unread,
Mar 15, 2013, 1:43:05 PM3/15/13
to hbrob...@googlegroups.com
Hi Patrick, Tyson,

I added the #!/usr/bin/env python, and made the file executable, and I'm
now running the Python code!

I haven't figured out where the test.txt file is being written to, but
it's a start...

I just used the GUI properties command to set the file to executable,
does $ chmod 755 node.py do anything more?

Thanks!

Alan KM6VV
P.S. A simple exercise like this to get a Python or C++ program to run
would be a useful addition to the ROS Wiki.

Michael Ferguson

unread,
Mar 15, 2013, 1:46:07 PM3/15/13
to hbrob...@googlegroups.com
Typically, if an output file goes missing on me in ROS, I find it in ~/.ros folder....

-Fergs

KM6VV

unread,
Mar 15, 2013, 2:34:17 PM3/15/13
to hbrob...@googlegroups.com
Wow!

That's where it was! And all the SerialNNNN.txt files from trying to
run razor_iu_9dof.

Thanks Fergs!

Alan KM6VV
Reply all
Reply to author
Forward
0 new messages