From 7c73a4e9a56265be7e2bb0daac6158311cf82ec3 Mon Sep 17 00:00:00 2001 From: winterhalderp Date: Tue, 20 Apr 2021 12:07:34 +0200 Subject: [PATCH] Update 'non-ros-files/Programming_Rules.md' --- non-ros-files/Programming_Rules.md | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/non-ros-files/Programming_Rules.md b/non-ros-files/Programming_Rules.md index 98c2ea7..50db9ea 100644 --- a/non-ros-files/Programming_Rules.md +++ b/non-ros-files/Programming_Rules.md @@ -25,11 +25,11 @@ colcon_workspace/ ``` The `src` directory is also the place where you create your new packages using `ros2 pkg create ...` and not in the root of the workspace. -The next chapters will describe the content of the files inside a package directory. However, the occuring files depend on the type of package (`ament_cmake` for C++ scripts or `ament_python` for Python scripts). This is described in detail [here](https://docs.ros.org/en/foxy/Tutorials/Creating-Your-First-ROS2-Package.html). The following chapters only describe Python packages. +The next chapters will describe the content of the files inside a package directory. However, the occuring files depend on the type of package (`ament_cmake` for C++ scripts or `ament_python` for Python scripts). This is described in detail [here](https://docs.ros.org/en/foxy/Tutorials/Creating-Your-First-ROS2-Package.html). The following chapters only describe Python packages (eg. `/pubsub`). ## setup.py -The file setup.py is used to create entry points, meaning you link your python scripts to names which you can be called through `ros2 run ...`. In order for this to work your python scripts must be written using the following mechanism +The file _setup.py_ is used to create entry points, meaning you link your python scripts to names which you can be called through `ros2 run ...`. In order for this to work your python scripts must be written using the following mechanism ```python def main(): # main code @@ -51,3 +51,13 @@ entry_points={ The _setup.py_-excerp above links the the function `main()` from the scripts _talker.py_ and _listener.py_ from inside `/pubsub` to the names _talker_ and _listener_. This way they can be called using `ros2 run pubsub talker` or `ros2 run pubsub listener`. From this you can see that you need to follow the Python programming style of creating a _main()_ procedure, in order for the entry points to work. + +## package.xml +The file _package.xml_ is used to link dependencies to this package. For example, if this package requires a _*.msg_ file which is located inside a different package this is defined in _package.xml_, eg. +``` + colcon_workspace + | + --------------------------------------------------- + | | +pubsub <---- depends on *.msg files ----< pubsub_msg +```