Update 'non-ros-files/Programming_Rules.md'

This commit is contained in:
winterhalderp 2021-04-20 12:07:34 +02:00
parent 59b95f5786
commit 7c73a4e9a5
1 changed files with 12 additions and 2 deletions

View File

@ -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
```