Ask Your Question
0

Python nodes and re-usable modules

asked 2015-12-09 20:48:20 -0600

130s gravatar image

In REP-0008 (as of today), there's a statement:

Node Files

In ROS, the name of a node type is the same as its executable name. Typically, for python files, this means including #!/usr/bin/env python at the top of your main code file.

If your node is simple, this file may contain the entire code for it. Otherwise, the node file will likely do an import packagename and invoke code there.
NOTE: we strive to keep ROS-specific code separate from reusable, generic code. The separation of 'node files' and files you place in src/packagename helps encourage this.

Because of the above statement, recommended folder structure becomes:

packagename
 |- nodes/
    |- ROS node executable files
 |- src/
    |- packagename/
      |- __init__.py
      |- yourfiles.py

I understand the meaning and the necessity of this difference of node and reusable module. However, do developers care this subtle difference? I have a feeling that many developers mix the usage without caring much of the stuff in this REP; some people sometimes write resable portion into node, and sometimes write node portion in src.

IMO, if a package is made as a ROS package, it's a ROS package and there's less advantage of separating ROS-specific code and else. So why not put all Python code into src and make them exportable (since other code being not able to refer to the existing code in the package in question is worse)?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2015-12-12 01:13:52 -0600

tfoote gravatar image

This is like the difference between an executable and a library. Typically things like command line parsing are not shareable between nodes. If they are, you can make a module and share it. But otherwise there's no need to expose the non-reusuable code.

As stated our goal is to encourage reuse, and minimizing dependency creep is a very good way to do that. For reusability the code needs to stay clean and separated. In languages like python it's easy to start to write spaghetti code which does not have an understandable structure. It is actually harder to reuse code if the resuable parts are mixed with the non-reusable parts, as an external developer might try to reuse the parts that are not designed to be reused etc. The separation makes a clear distinction as to where to look for reusable bits.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

2 followers

Stats

Asked: 2015-12-09 20:48:20 -0600

Seen: 154 times

Last updated: Dec 12 '15