Update 'non-ros-files/Programming_Rules.md'
This commit is contained in:
parent
47495f23cb
commit
7f112ad4ff
@ -1,4 +1,4 @@
|
||||
# Rules for programming Python in ROS2
|
||||
# Rules for programming with Python in ROS2
|
||||
## File Structure
|
||||
```
|
||||
colcon_workspace
|
||||
@ -8,12 +8,12 @@ colcon_workspace
|
||||
|- src (contains your source code - this is where you work)
|
||||
```
|
||||
|
||||
## Colcon build
|
||||
## Colcon Build
|
||||
Performing a `colcon build` is neccessary after every change to the `src` directory. This must be performed in the `root` of the _colcon_ workspace (eg. `cd ~/colcon_ws`).
|
||||
|
||||
In order to avoid this procedure after every change made to a Python script you must run `colcon build --symlink-install` once. This links the files created in `/build` and `/install` to your source files in `/src`. However, after creating a new Python script this procedure must be repeated in order to also link this new script.
|
||||
|
||||
## Source directory
|
||||
## Source Directory
|
||||
The source directory holds your ROS2 packages as further directories. In this example the `src` directory contains the packages `pubsub` and `pubsub_msg`:
|
||||
```
|
||||
colcon_workspace/
|
||||
@ -22,4 +22,19 @@ colcon_workspace/
|
||||
|
|
||||
|- pubsub/
|
||||
|- pubsub_msg/
|
||||
```
|
||||
```
|
||||
|
||||
## setup.py
|
||||
The file `<colcon_ws>/<package_dir>/setup.py` defines how to call your scripts using the command line. This results in commands such as
|
||||
`ros2 run pubsub talker`
|
||||
`ros2 run pubsub listener`.
|
||||
This is done by linking the names _talker_ and _listener_ to the Python scripts of your choice, eg.
|
||||
```python
|
||||
entry_points={
|
||||
'console_scripts': [
|
||||
'talker = pubsub.talker:main',
|
||||
'listener = pubsub.listener:main'
|
||||
],
|
||||
},
|
||||
```
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user