diff --git a/README.md b/README.md index 4cf5aa5..e03b186 100644 --- a/README.md +++ b/README.md @@ -1 +1,2 @@ -hallo +# Custom Interface Package +ROS2 Package for creating custom interfaces diff --git a/src/custom_interfaces/CMakeLists.txt b/src/custom_interfaces/CMakeLists.txt new file mode 100644 index 0000000..82b04e1 --- /dev/null +++ b/src/custom_interfaces/CMakeLists.txt @@ -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() diff --git a/src/custom_interfaces/Readme.md b/src/custom_interfaces/Readme.md new file mode 100644 index 0000000..a22d9f6 --- /dev/null +++ b/src/custom_interfaces/Readme.md @@ -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 +std_msgs + + + +pubsub_msg + +``` + +## 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. diff --git a/src/custom_interfaces/msg/CustomMsg1.msg b/src/custom_interfaces/msg/CustomMsg1.msg new file mode 100644 index 0000000..66a846b --- /dev/null +++ b/src/custom_interfaces/msg/CustomMsg1.msg @@ -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 diff --git a/src/custom_interfaces/msg/CustomMsg2.msg b/src/custom_interfaces/msg/CustomMsg2.msg new file mode 100644 index 0000000..2e9603d --- /dev/null +++ b/src/custom_interfaces/msg/CustomMsg2.msg @@ -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 diff --git a/src/custom_interfaces/package.xml b/src/custom_interfaces/package.xml new file mode 100644 index 0000000..8c22c2a --- /dev/null +++ b/src/custom_interfaces/package.xml @@ -0,0 +1,42 @@ + + + + custom_interfaces + 0.0.0 + TODO: Package description + rosmobile + TODO: License declaration + + ament_cmake + ament_lint_auto + ament_lint_common + + + + + + builtin_interfaces + rosidl_default_generators + + builtin_interfaces + rosidl_default_runtime + + rosidl_interface_packages + + + + + + + + std_msgs + + + + ament_lint_auto + ament_lint_common + + + ament_cmake + + diff --git a/src/custom_interfaces/srv/ChangeState.srv b/src/custom_interfaces/srv/ChangeState.srv new file mode 100644 index 0000000..3c6fa74 --- /dev/null +++ b/src/custom_interfaces/srv/ChangeState.srv @@ -0,0 +1,5 @@ +string model_name +string state +--- +bool success +string return_state diff --git a/src/custom_interfaces/srv/CheckState.srv b/src/custom_interfaces/srv/CheckState.srv new file mode 100644 index 0000000..c654445 --- /dev/null +++ b/src/custom_interfaces/srv/CheckState.srv @@ -0,0 +1,4 @@ +string model_name +--- +bool success +string state_return diff --git a/src/custom_interfaces/srv/CustomSrv1.srv b/src/custom_interfaces/srv/CustomSrv1.srv new file mode 100644 index 0000000..2a0fa0e --- /dev/null +++ b/src/custom_interfaces/srv/CustomSrv1.srv @@ -0,0 +1,3 @@ +string command +--- +bool success diff --git a/src/custom_interfaces/srv/StateMachineSrv.srv b/src/custom_interfaces/srv/StateMachineSrv.srv new file mode 100644 index 0000000..608f8b5 --- /dev/null +++ b/src/custom_interfaces/srv/StateMachineSrv.srv @@ -0,0 +1,4 @@ +string command +float32 value +--- +bool success