ROS Resources: Documentation | Support | Discussion Forum | Service Status | Q&A answers.ros.org

Applying best practices to tutorials (or having a best practices example)?

As a relatively new ROS developer, I find myself rewriting a lot of my work as I learn “better” / “standard” / “common” ways of doing things. The latest examples include

  1. writing a hardware interface for PWM drive motors
  2. structuring python code examples for students

On the 2nd topic I went looking for the “best practice”. I found the PyStyleGuide. Then I went to look for an example and when I look at the tutorials, they do not follow the PyStyleGuide.

I can imagine much effort has gone into the tutorials. There is probably solid reasoning for they way the code has been structured.

It would help noob developers like myself if there was at least one preference in the PyStyleGuide to a real example. Is there one that people feel is a good example? Might it be referenced from PyStyleGuide?

1 Like

The best starting point I’m aware of is: https://github.com/ethz-asl/ros_best_practices/wiki

I finally read through all of the links from the github wiki page. Good information. That said, it did not answer the particular question of “structuring python code”.

From ros.org, there is the suggestion of the following directory structure:

packagename
 |- src/
    |- packagename/
      |- __init__.py
      |- yourfiles.py

Thus, you end up with something like this:

~/catkin_ws/src/package/src/package/file.py

The extra package/ folder seems overly redundant. This extra level does not exist in the C++ guide. I could not find an explanation as to why it is recommended for python.

I suppose that the reason for structuring the python code this way is to follow the setuptools convention that recommends the code to be under a subdirectory of the same name as the python module to install.

1 Like