third commit
This commit is contained in:
parent
c6f4adfc9f
commit
872e547190
@ -1 +1,2 @@
|
|||||||
hallo
|
# Custom Interface Package
|
||||||
|
ROS2 Package for creating custom interfaces
|
||||||
|
66
src/custom_interfaces/CMakeLists.txt
Normal file
66
src/custom_interfaces/CMakeLists.txt
Normal file
@ -0,0 +1,66 @@
|
|||||||
|
cmake_minimum_required(VERSION 3.5)
|
||||||
|
project(custom_interfaces)
|
||||||
|
|
||||||
|
# Default to C99
|
||||||
|
if(NOT CMAKE_C_STANDARD)
|
||||||
|
set(CMAKE_C_STANDARD 99)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
# Default to C++14
|
||||||
|
if(NOT CMAKE_CXX_STANDARD)
|
||||||
|
set(CMAKE_CXX_STANDARD 14)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
|
||||||
|
add_compile_options(-Wall -Wextra -Wpedantic)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
# find dependencies
|
||||||
|
find_package(ament_cmake REQUIRED)
|
||||||
|
find_package(std_msgs REQUIRED)
|
||||||
|
find_package(builtin_interfaces REQUIRED)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# -->
|
||||||
|
# ADD THESE LINES: START HERE
|
||||||
|
|
||||||
|
find_package(rosidl_default_generators REQUIRED)
|
||||||
|
find_package(rclcpp REQUIRED)
|
||||||
|
|
||||||
|
# CUSTOM LINES: CHANGE FOR YOUR FILENAMES
|
||||||
|
rosidl_generate_interfaces(${PROJECT_NAME}
|
||||||
|
"msg/CustomMsg1.msg"
|
||||||
|
"msg/CustomMsg2.msg"
|
||||||
|
"srv/CustomSrv1.srv"
|
||||||
|
"srv/StateMachineSrv.srv"
|
||||||
|
"srv/CheckState.srv"
|
||||||
|
"srv/ChangeState.srv"
|
||||||
|
DEPENDENCIES builtin_interfaces
|
||||||
|
)
|
||||||
|
|
||||||
|
# END HERE
|
||||||
|
# <--
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
if(BUILD_TESTING)
|
||||||
|
find_package(ament_lint_auto REQUIRED)
|
||||||
|
# the following line skips the linter which checks for copyrights
|
||||||
|
# uncomment the line when a copyright and license is not present in all source files
|
||||||
|
#set(ament_cmake_copyright_FOUND TRUE)
|
||||||
|
# the following line skips cpplint (only works in a git repo)
|
||||||
|
# uncomment the line when this package is not in a git repo
|
||||||
|
#set(ament_cmake_cpplint_FOUND TRUE)
|
||||||
|
ament_lint_auto_find_test_dependencies()
|
||||||
|
endif()
|
||||||
|
|
||||||
|
ament_package()
|
53
src/custom_interfaces/Readme.md
Normal file
53
src/custom_interfaces/Readme.md
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
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 example](https://egit.irs.uni-stuttgart.de/RoverLehre/ROS2_pubsub/src/branch/master/non-ros-files/bashrc_overlay.bash)).
|
||||||
|
|
||||||
|
## 4. Define ROS Package Dependencies
|
||||||
|
Configure *package.xml* of the other ROS packages in which you want to use these custom interfaces. This also works for Python scripts from inside the linked package (eg. library module from inside pubsub package).
|
||||||
|
```xml
|
||||||
|
<depend>std_msgs</depend>
|
||||||
|
|
||||||
|
<!-- START Custom Dependencies -->
|
||||||
|
<!-- This is custom for the package you depend on -->
|
||||||
|
<exec_depend>pubsub_msg</exec_depend>
|
||||||
|
<!-- END Custom Dependencies -->
|
||||||
|
```
|
||||||
|
|
||||||
|
## 5. 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.
|
||||||
|
|
||||||
|
This also works for Python modules stored in the linked ROS packages.
|
8
src/custom_interfaces/msg/CustomMsg1.msg
Normal file
8
src/custom_interfaces/msg/CustomMsg1.msg
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
# Header data, eg timestamp
|
||||||
|
# Problem: "header__struct.hpp: No such file or directory"
|
||||||
|
#Header header
|
||||||
|
|
||||||
|
# Sensor Data coming back from an array of atmospheric sensors
|
||||||
|
float32[] temperature
|
||||||
|
float32[] pressure
|
||||||
|
float32[] humidity
|
7
src/custom_interfaces/msg/CustomMsg2.msg
Normal file
7
src/custom_interfaces/msg/CustomMsg2.msg
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
# Header data, eg timestamp
|
||||||
|
# Problem: "header__struct.hpp: No such file or directory"
|
||||||
|
#Header header
|
||||||
|
|
||||||
|
# User inputs, eg. for controlling a camera mast , eg. set angles [rad]
|
||||||
|
float32 pitch_ctrl
|
||||||
|
float32 yaw_ctrl
|
42
src/custom_interfaces/package.xml
Normal file
42
src/custom_interfaces/package.xml
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
<?xml version="1.0"?>
|
||||||
|
<?xml-model href="http://download.ros.org/schema/package_format3.xsd" schematypens="http://www.w3.org/2001/XMLSchema"?>
|
||||||
|
<package format="3">
|
||||||
|
<name>custom_interfaces</name>
|
||||||
|
<version>0.0.0</version>
|
||||||
|
<description>TODO: Package description</description>
|
||||||
|
<maintainer email="rosmobile@todo.todo">rosmobile</maintainer>
|
||||||
|
<license>TODO: License declaration</license>
|
||||||
|
|
||||||
|
<buildtool_depend>ament_cmake</buildtool_depend>
|
||||||
|
<test_depend>ament_lint_auto</test_depend>
|
||||||
|
<test_depend>ament_lint_common</test_depend>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<!-- ADD THESE LINES: START HERE -->
|
||||||
|
|
||||||
|
<build_depend>builtin_interfaces</build_depend>
|
||||||
|
<build_depend>rosidl_default_generators</build_depend>
|
||||||
|
|
||||||
|
<exec_depend>builtin_interfaces</exec_depend>
|
||||||
|
<exec_depend>rosidl_default_runtime</exec_depend>
|
||||||
|
|
||||||
|
<member_of_group>rosidl_interface_packages</member_of_group>
|
||||||
|
<!-- END HERE -->
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<depend>std_msgs</depend>
|
||||||
|
<!-- DO NOT ENTER THIS DEPENDENCY WHEN CREATING NEW PACKAGE -->
|
||||||
|
<!-- <depend>builtin_interfaces</depend> -->
|
||||||
|
|
||||||
|
<test_depend>ament_lint_auto</test_depend>
|
||||||
|
<test_depend>ament_lint_common</test_depend>
|
||||||
|
|
||||||
|
<export>
|
||||||
|
<build_type>ament_cmake</build_type>
|
||||||
|
</export>
|
||||||
|
</package>
|
5
src/custom_interfaces/srv/ChangeState.srv
Normal file
5
src/custom_interfaces/srv/ChangeState.srv
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
string model_name
|
||||||
|
string state
|
||||||
|
---
|
||||||
|
bool success
|
||||||
|
string return_state
|
4
src/custom_interfaces/srv/CheckState.srv
Normal file
4
src/custom_interfaces/srv/CheckState.srv
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
string model_name
|
||||||
|
---
|
||||||
|
bool success
|
||||||
|
string state_return
|
3
src/custom_interfaces/srv/CustomSrv1.srv
Normal file
3
src/custom_interfaces/srv/CustomSrv1.srv
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
string command
|
||||||
|
---
|
||||||
|
bool success
|
4
src/custom_interfaces/srv/StateMachineSrv.srv
Normal file
4
src/custom_interfaces/srv/StateMachineSrv.srv
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
string command
|
||||||
|
float32 value
|
||||||
|
---
|
||||||
|
bool success
|
Loading…
Reference in New Issue
Block a user