.msg and .srv creation documented
This commit is contained in:
parent
183e08e853
commit
770bb9a983
@ -52,10 +52,10 @@ In this workshop you will:
|
|||||||
* Add your workspace overlay to the shell startup script for sourcing everytime you open a new console:
|
* Add your workspace overlay to the shell startup script for sourcing everytime you open a new console:
|
||||||
* Add [this](https://egit.irs.uni-stuttgart.de/RoverLehre/ROS2_pubsub/src/branch/master/non-ros-files/bashrc_overlay.bash) to the end of .bashrc (`sudo nano .bashrc`)
|
* Add [this](https://egit.irs.uni-stuttgart.de/RoverLehre/ROS2_pubsub/src/branch/master/non-ros-files/bashrc_overlay.bash) to the end of .bashrc (`sudo nano .bashrc`)
|
||||||
* In [this template](https://egit.irs.uni-stuttgart.de/RoverLehre/ROS2_pubsub/src/branch/master/non-ros-files/bashrc_overlay.bash) find all instances of "`~/ws_overlay_foxy`" and replace it with the path to your own _colcon_ workspace (replace `~/` with `$HOME` for representing the home directory variable in bash scripts)
|
* In [this template](https://egit.irs.uni-stuttgart.de/RoverLehre/ROS2_pubsub/src/branch/master/non-ros-files/bashrc_overlay.bash) find all instances of "`~/ws_overlay_foxy`" and replace it with the path to your own _colcon_ workspace (replace `~/` with `$HOME` for representing the home directory variable in bash scripts)
|
||||||
* Create a custom ROS message (*.msg) in order to define custom topics to exchange information between nodes by following [these instructions](https://egit.irs.uni-stuttgart.de/RoverLehre/ROS2_pubsub/src/branch/master/non-ros-files/instructions_custom_topics.md).
|
* Create custom message (*.msg) or service (*.srv) files in order to create custom interfaces to exchange information between nodes. For this you can use the pre-made `/custom_interface` package and add your own *.msg and/or *.srv files using this [instruction document](None) (__easy__), or you can start from scratch by following [these instructions](https://egit.irs.uni-stuttgart.de/RoverLehre/ROS2_pubsub/src/branch/master/non-ros-files/instructions_custom_topics.md) (__hard__).
|
||||||
|
|
||||||
## Rules and Standard
|
## Rules and Standard
|
||||||
In order for your code to work and to prevent major problems please read through [this document](https://egit.irs.uni-stuttgart.de/RoverLehre/ROS2_pubsub/src/branch/master/non-ros-files/Programming_Rules.md). This will give you a brief oversight over how to develop a ROS2 package using Python.
|
In order for your code to work and to prevent major problems please read through [this document](https://egit.irs.uni-stuttgart.de/RoverLehre/ROS2_pubsub/src/branch/master/non-ros-files/Programming_Rules.md). This will give you a brief oversight over how to develop a ROS2 package using Python.
|
||||||
|
|
||||||
## Presentation
|
## Presentation
|
||||||
The workshop's content is covered in [this presentation](https://egit.irs.uni-stuttgart.de/RoverLehre/ROS2_pubsub/src/branch/master/non-ros-files/ws-05-ros-workshop%20%281%29.pdf).
|
The workshop's content is covered in [this presentation](https://egit.irs.uni-stuttgart.de/RoverLehre/ROS2_pubsub/src/branch/master/non-ros-files/ws-05-ros-workshop%20%281%29.pdf).
|
||||||
|
40
src/custom_interfaces/Readme.md
Normal file
40
src/custom_interfaces/Readme.md
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
Use this ROS2 package to create custom interfaces, eg. topic (*.msg) and/or service (*.srv) files.
|
||||||
|
This package must only be used for interface files and __no__ Python scripts.
|
||||||
|
|
||||||
|
The following steps describe how to create a new custom topic or service.
|
||||||
|
|
||||||
|
## 1. Create new interface file
|
||||||
|
Topic *.msg files got into `msg` directory,
|
||||||
|
Service *.srv files got into `srv` directory.
|
||||||
|
|
||||||
|
Create these files according to the example on this [instructions page](https://docs.ros.org/en/foxy/Tutorials/Writing-A-Simple-Py-Service-And-Client.html).
|
||||||
|
|
||||||
|
## 2. CMakeLists.txt
|
||||||
|
Edit the `CMakeLists.txt` file by adding the newly created *.msg or *.srv files to this part:
|
||||||
|
```cmake
|
||||||
|
rosidl_generate_interfaces(${PROJECT_NAME}
|
||||||
|
"msg/CustomMsg1.msg"
|
||||||
|
"msg/CustomMsg2.msg"
|
||||||
|
"srv/CustomSrv1.srv"
|
||||||
|
DEPENDENCIES builtin_interfaces
|
||||||
|
)
|
||||||
|
```
|
||||||
|
|
||||||
|
## 3. Build colcon workspace
|
||||||
|
Move back to the root of your _colcon_ workspace and rebuild it: `colcon build --symlink-install`
|
||||||
|
It should build without any errors. If you encounter errors fix these before continuing.
|
||||||
|
|
||||||
|
After a successful build you must __close and reopen all terminals__ in order to source the newly built workspace. For this to happen you must have edited _.bashrc_ and added your current workspace (`sudo nano ~/.bashrc` and follow [this instruction](None)).
|
||||||
|
|
||||||
|
## 4. Import interfaces
|
||||||
|
Import the newly created interfaces into the Python scripts. These scripts must be located in _Python packages_ inside the same workspace (or another _sourced_ workspace):
|
||||||
|
* Topics:
|
||||||
|
```python
|
||||||
|
from custom_interfaces.msg import CustomMsg1
|
||||||
|
```
|
||||||
|
|
||||||
|
* Services:
|
||||||
|
```python
|
||||||
|
from custom_interfaces.srv import CustomSrv1
|
||||||
|
```
|
||||||
|
Now you can work with your custom interface in order to exchange custom information between nodes.
|
Loading…
Reference in New Issue
Block a user