├── .gitignore ├── .gitmodules ├── Dockerfile ├── LICENSE ├── README.md └── src ├── action_tutorials_cpp ├── CHANGELOG.rst ├── CMakeLists.txt ├── README.md ├── include │ └── action_tutorials_cpp │ │ └── visibility_control.h ├── package.xml └── src │ ├── fibonacci_action_client.cpp │ └── fibonacci_action_server.cpp ├── examples_rclpy ├── examples_rclpy_actions │ ├── examples_rclpy_actions │ │ ├── __init__.py │ │ ├── client.py │ │ └── server.py │ ├── package.xml │ ├── resource │ │ └── examples_rclpy_actions │ ├── setup.cfg │ └── setup.py ├── examples_rclpy_services │ ├── CHANGELOG.rst │ ├── README.md │ ├── examples_rclpy_services │ │ ├── __init__.py │ │ ├── client.py │ │ └── service.py │ ├── package.xml │ ├── resource │ │ └── examples_rclpy_services │ ├── setup.cfg │ └── setup.py └── examples_rclpy_topics │ ├── examples_rclpy_topics │ ├── __init__.py │ ├── composed.py │ ├── publisher.py │ └── subscriber.py │ ├── package.xml │ ├── resource │ └── examples_rclpy_topics │ ├── setup.cfg │ └── setup.py ├── hello_world ├── CMakeLists.txt ├── include │ └── hello_world │ │ └── visibility_control.h ├── launch │ ├── params.yaml │ ├── talker_listener.launch.py │ ├── talker_listener.launch.xml │ ├── talker_listener_with_param.launch.py │ └── talker_listener_with_param_file.launch.py ├── package.xml └── src │ ├── client_async.cpp │ ├── client_sync.cpp │ ├── listener.cpp │ ├── listener_component.cpp │ ├── listener_no_main.cpp │ ├── set_and_get_parameters.cpp │ ├── talker.cpp │ ├── talker_component.cpp │ ├── talker_listener_composition.cpp │ ├── talker_no_main.cpp │ ├── talker_with_service.cpp │ └── talker_with_service_param.cpp ├── hello_world_msgs ├── CMakeLists.txt ├── action │ └── Fibonacci.action ├── package.xml └── srv │ └── SetMessage.srv ├── policies ├── add_two_ints.policy.xml ├── common │ ├── lifecycle_node.xml │ ├── node.xml │ └── node │ │ ├── logging.xml │ │ ├── parameters.xml │ │ ├── time.xml │ │ └── types.xml ├── invalid_policy_missing_topics_tag.xml ├── minimal_action.policy.xml ├── permissions │ ├── add_two_ints │ │ └── permissions.xml │ ├── minimal_action │ │ └── permissions.xml │ ├── sample │ │ └── permissions.xml │ ├── single_context │ │ └── permissions.xml │ └── talker_listener │ │ └── permissions.xml ├── policy_to_permissions.py ├── sample.policy.xml ├── single_context.policy.xml └── talker_listener.policy.xml └── ros2_practice ├── CMakeLists.txt ├── config └── haarcascade_frontalface_alt.xml ├── package.xml └── src ├── face_detection.cpp └── voxel_grid_filter.cpp /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | .idea 3 | 4 | # Prerequisites 5 | *.d 6 | 7 | # Compiled Object files 8 | *.slo 9 | *.lo 10 | *.o 11 | *.obj 12 | 13 | # Precompiled Headers 14 | *.gch 15 | *.pch 16 | 17 | # Compiled Dynamic libraries 18 | *.so 19 | *.dylib 20 | *.dll 21 | 22 | # Fortran module files 23 | *.mod 24 | *.smod 25 | 26 | # Compiled Static libraries 27 | *.lai 28 | *.la 29 | *.a 30 | *.lib 31 | 32 | # Executables 33 | *.exe 34 | *.out 35 | *.app 36 | 37 | _site 38 | .jekyll-cache 39 | 40 | build 41 | install 42 | log 43 | 44 | src/dynamixel_hardware_examples 45 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/youtalk/get-started-ros2/31bcb2e5f48c55027d49d5d7956d1586df7ccee1/.gitmodules -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | # hadolint global ignore=DL3006,DL3008,DL3013 2 | FROM ros:jazzy 3 | SHELL ["/bin/bash", "-o", "pipefail", "-c"] 4 | 5 | RUN apt-get update \ 6 | && DEBIAN_FRONTEND=noninteractive apt-get -y install --no-install-recommends \ 7 | ros-dev-tools \ 8 | && rm -rf /var/lib/apt/lists/* 9 | 10 | COPY src /get-started-ros2/src 11 | WORKDIR /get-started-ros2 12 | 13 | RUN apt-get update \ 14 | && rosdep update \ 15 | && rosdep install --ignore-src --from-paths -y src \ 16 | && rm -rf /var/lib/apt/lists/* 17 | 18 | RUN source /opt/ros/jazzy/setup.bash \ 19 | && colcon build \ 20 | --mixin release compile-commands 21 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # 改訂新版「ROS 2ではじめよう 次世代ロボットプログラミング」 2 | 3 | ## サンプルコード 4 | 5 | 本書のサンプルコードは以下のGitHubレポジトリで管理されています。Apache License 2.0の下、ご自由にお使いください。 6 | 7 | [https://github.com/youtalk/get-started-ros2](https://github.com/youtalk/get-started-ros2) 8 | 9 | サンプルコードの動作確認は、以下のROSディストリビューションで行なっております。 10 | 11 | - [ROS 2 Jazzy Jalisco](https://github.com/youtalk/get-started-ros2/tree/main) 12 | 13 | サンプルコードは紙面の文字数制限の都合上、1行あたり72文字以内で記述しています。ROS2公式の `ament_uncrustify` の整形ルールとは合致しない点、ご留意ください。 14 | 15 | ## セットアップ 16 | 17 | ### 2章 開発環境セットアップ 18 | 19 | 誌面より 20 | 21 | > 次章からステップバイステップで実装していくROS 2デモパッケージ `hello_world` および5章、8章で使用するパッケージのソースコードは、次のオンラインリソースにビルド可能な形ですべて保存されています。 22 | > 23 | > [https://github.com/youtalk/get-started-ros2/tree/main/src](https://github.com/youtalk/get-started-ros2/tree/main/src) 24 | > 25 | > 本書では紙面の都合上、ライセンスやインクルード文などを省略し、ソースコードも一部のみを抜粋して記載しています。ソースコード全体をご覧になりたい場合には、こちらを参照してください。 26 | > ライセンス条項に関しては、まとめて付録に記載しています。 27 | > 28 | > サンプルコードのセットアップ方法は以下の通りです。適宜、本文と照らし合わせながら読み進めていってください。 29 | > 30 | > ```shell 31 | > $ cd ~/ && git clone https://github.com/youtalk/get-started-ros2.git 32 | > $ cd get-started-ros2 33 | > $ rosdep install --from-paths src --ignore-src -r -y 34 | > $ colcon build 35 | > $ source install/setup.bash 36 | > ``` 37 | -------------------------------------------------------------------------------- /src/action_tutorials_cpp/CHANGELOG.rst: -------------------------------------------------------------------------------- 1 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 2 | Changelog for package action_tutorials_cpp 3 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 4 | 5 | 0.33.3 (2024-05-13) 6 | ------------------- 7 | 8 | 0.33.2 (2024-03-28) 9 | ------------------- 10 | * Update maintainer list in package.xml files (`#665 `_) 11 | * Contributors: Michael Jeronimo 12 | 13 | 0.33.1 (2024-02-07) 14 | ------------------- 15 | 16 | 0.33.0 (2024-01-24) 17 | ------------------- 18 | * Fix format-security warning with clang. (`#663 `_) 19 | * Migrate std::bind calls to lambda expressions (`#659 `_) 20 | * Contributors: Chris Lalancette, Felipe Gomes de Melo 21 | 22 | 0.32.1 (2023-12-26) 23 | ------------------- 24 | 25 | 0.32.0 (2023-11-06) 26 | ------------------- 27 | 28 | 0.31.1 (2023-09-07) 29 | ------------------- 30 | 31 | 0.31.0 (2023-08-21) 32 | ------------------- 33 | 34 | 0.30.1 (2023-07-11) 35 | ------------------- 36 | 37 | 0.30.0 (2023-06-12) 38 | ------------------- 39 | 40 | 0.29.0 (2023-06-07) 41 | ------------------- 42 | 43 | 0.28.1 (2023-05-11) 44 | ------------------- 45 | 46 | 0.28.0 (2023-04-27) 47 | ------------------- 48 | 49 | 0.27.0 (2023-04-13) 50 | ------------------- 51 | * Change all ROS2 -> ROS 2. (`#610 `_) 52 | * Contributors: Chris Lalancette 53 | 54 | 0.26.0 (2023-04-11) 55 | ------------------- 56 | 57 | 0.25.0 (2023-03-01) 58 | ------------------- 59 | 60 | 0.24.1 (2023-02-24) 61 | ------------------- 62 | 63 | 0.24.0 (2023-02-14) 64 | ------------------- 65 | * Update the demos to C++17. (`#594 `_) 66 | * Add README's for action_tutorials. (`#576 `_) 67 | * [rolling] Update maintainers - 2022-11-07 (`#589 `_) 68 | * Contributors: Audrow Nash, Chris Lalancette, kagibson 69 | 70 | 0.23.0 (2022-11-02) 71 | ------------------- 72 | 73 | 0.22.0 (2022-09-13) 74 | ------------------- 75 | * Fix two small bugs in the fibonacci C++ tutorial. (`#564 `_) 76 | * Contributors: Chris Lalancette 77 | 78 | 0.21.0 (2022-04-29) 79 | ------------------- 80 | 81 | 0.20.1 (2022-04-08) 82 | ------------------- 83 | 84 | 0.20.0 (2022-03-01) 85 | ------------------- 86 | 87 | 0.19.0 (2022-01-14) 88 | ------------------- 89 | 90 | 0.18.0 (2021-12-17) 91 | ------------------- 92 | * Update maintainers to Audrow Nash and Michael Jeronimo (`#543 `_) 93 | * Contributors: Audrow Nash 94 | 95 | 0.17.0 (2021-10-18) 96 | ------------------- 97 | 98 | 0.16.0 (2021-08-11) 99 | ------------------- 100 | 101 | 0.15.0 (2021-05-14) 102 | ------------------- 103 | 104 | 0.14.2 (2021-04-26) 105 | ------------------- 106 | 107 | 0.14.1 (2021-04-19) 108 | ------------------- 109 | 110 | 0.14.0 (2021-04-06) 111 | ------------------- 112 | 113 | 0.13.0 (2021-03-25) 114 | ------------------- 115 | 116 | 0.12.1 (2021-03-18) 117 | ------------------- 118 | 119 | 0.12.0 (2021-01-25) 120 | ------------------- 121 | * Update logging macros (`#476 `_) 122 | * Contributors: Audrow Nash 123 | 124 | 0.11.0 (2020-12-10) 125 | ------------------- 126 | * Update the package.xml files with the latest Open Robotics maintainers (`#466 `_) 127 | * Contributors: Michael Jeronimo 128 | 129 | 0.10.1 (2020-09-21) 130 | ------------------- 131 | * Update goal response callback signature (`#463 `_) 132 | * Contributors: Jacob Perron 133 | 134 | 0.10.0 (2020-06-17) 135 | ------------------- 136 | 137 | 0.9.3 (2020-06-01) 138 | ------------------ 139 | 140 | 0.9.2 (2020-05-26) 141 | ------------------ 142 | 143 | 0.9.1 (2020-05-12) 144 | ------------------ 145 | 146 | 0.9.0 (2020-04-30) 147 | ------------------ 148 | 149 | 0.8.4 (2019-11-19) 150 | ------------------ 151 | * Return without sending goal if exiting (`#415 `_) 152 | * Contributors: Shane Loretz 153 | 154 | 0.8.3 (2019-11-11) 155 | ------------------ 156 | 157 | 0.8.2 (2019-11-08) 158 | ------------------ 159 | 160 | 0.8.1 (2019-10-23) 161 | ------------------ 162 | 163 | 0.8.0 (2019-09-26) 164 | ------------------ 165 | * Add action tutorials in C++ (`#378 `_) 166 | * Contributors: Siddharth Kucheria 167 | 168 | 0.7.6 (2019-05-30) 169 | ------------------ 170 | 171 | 0.7.5 (2019-05-29) 172 | ------------------ 173 | 174 | 0.7.4 (2019-05-20) 175 | ------------------ 176 | 177 | 0.7.3 (2019-05-10) 178 | ------------------ 179 | 180 | 0.7.2 (2019-05-08) 181 | ------------------ 182 | 183 | 0.7.1 (2019-04-26) 184 | ------------------ 185 | 186 | 0.7.0 (2019-04-14) 187 | ------------------ 188 | 189 | 0.6.2 (2019-01-15) 190 | ------------------ 191 | 192 | 0.6.1 (2018-12-12) 193 | ------------------ 194 | 195 | 0.6.0 (2018-12-07) 196 | ------------------ 197 | 198 | 0.5.1 (2018-06-28) 199 | ------------------ 200 | 201 | 0.5.0 (2018-06-27) 202 | ------------------ 203 | 204 | 0.4.0 (2017-12-08) 205 | ------------------ 206 | -------------------------------------------------------------------------------- /src/action_tutorials_cpp/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.5) 2 | project(action_tutorials_cpp) 3 | 4 | # Default to C99 5 | if(NOT CMAKE_C_STANDARD) 6 | set(CMAKE_C_STANDARD 99) 7 | endif() 8 | 9 | # Default to C++17 10 | if(NOT CMAKE_CXX_STANDARD) 11 | set(CMAKE_CXX_STANDARD 17) 12 | set(CMAKE_CXX_STANDARD_REQUIRED ON) 13 | endif() 14 | 15 | if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang") 16 | add_compile_options(-Wall -Wextra -Wpedantic) 17 | endif() 18 | 19 | # find dependencies 20 | find_package(ament_cmake REQUIRED) 21 | find_package(action_tutorials_interfaces REQUIRED) 22 | find_package(rclcpp REQUIRED) 23 | find_package(rclcpp_action REQUIRED) 24 | find_package(rclcpp_components REQUIRED) 25 | 26 | include_directories(include) 27 | 28 | add_library(action_tutorials SHARED 29 | src/fibonacci_action_client.cpp 30 | src/fibonacci_action_server.cpp) 31 | rclcpp_components_register_node(action_tutorials PLUGIN "action_tutorials_cpp::FibonacciActionClient" EXECUTABLE fibonacci_action_client) 32 | rclcpp_components_register_node(action_tutorials PLUGIN "action_tutorials_cpp::FibonacciActionServer" EXECUTABLE fibonacci_action_server) 33 | target_compile_definitions(action_tutorials 34 | PRIVATE "ACTION_TUTORIALS_CPP_BUILDING_DLL") 35 | ament_target_dependencies(action_tutorials 36 | "action_tutorials_interfaces" 37 | "rclcpp" 38 | "rclcpp_action" 39 | "rclcpp_components") 40 | 41 | install(TARGETS 42 | action_tutorials 43 | ARCHIVE DESTINATION lib 44 | LIBRARY DESTINATION lib 45 | RUNTIME DESTINATION bin) 46 | 47 | if(BUILD_TESTING) 48 | find_package(ament_lint_auto REQUIRED) 49 | ament_lint_auto_find_test_dependencies() 50 | endif() 51 | 52 | ament_package() 53 | -------------------------------------------------------------------------------- /src/action_tutorials_cpp/README.md: -------------------------------------------------------------------------------- 1 | # Action Server 2 | 3 | In the constructor for `FibonacciActionServer`, an action server is created with callbacks that are called when a goal is received, when the goal is cancelled, and when the goal is accepted: 4 | 5 | ```cpp 6 | this->action_server_ = rclcpp_action::create_server( 7 | this, 8 | "fibonacci", 9 | handle_goal, 10 | handle_cancel, 11 | handle_accepted); 12 | ``` 13 | 14 | The `handle_goal` callback is called whenever a goal is sent to the action server by an action client. 15 | In the example code, the goal is accepted as long as the order is less than or equal to 46, otherwise it is rejected. 16 | This is to prevent potential [integer overflow](https://en.wikipedia.org/wiki/Integer_overflow): 17 | 18 | ```cpp 19 | if (goal->order > 46) { 20 | return rclcpp_action::GoalResponse::REJECT; 21 | } 22 | return rclcpp_action::GoalResponse::ACCEPT_AND_EXECUTE; 23 | ``` 24 | 25 | The `handle_cancelled` callback is called whenever an action client requests to cancel the goal being executed. 26 | In this case, the goal cancel request is always accepted. 27 | 28 | The `handle_accepted` callback is called following the action server's acceptance of a goal. In this example, a thread is started to execute the goal: 29 | 30 | ```cpp 31 | auto execute_in_thread = [this, goal_handle](){return this->execute(goal_handle);}; 32 | std::thread{execute_in_thread}.detach(); 33 | ``` 34 | 35 | The execution thread calculates the Fibonacci sequence up to *order* and publishes partial sequences as feedback as each item is added to the sequence. 36 | 37 | A `rclcpp::Rate` object is used to sleep between the calculation of each item in order to represent a long-running task. 38 | 39 | When execution is complete, the full sequence is returned to the action client. 40 | If the goal is cancelled during execution, no result is returned, however the caller may have received partial sequences as feedback up until cancelling. 41 | 42 | # Action Client 43 | 44 | In the constructor for `FibonacciActionClient`, and action client for the `fibonacci` action is created: 45 | 46 | ```cpp 47 | this->client_ptr_ = rclcpp_action::create_client( 48 | ... 49 | "fibonacci"); 50 | ``` 51 | 52 | A goal of type `Fibonacci` is created with order 10. 53 | The goal is sent asynchronously with callbacks registered for the goal response, the feedback, and the goal result: 54 | 55 | ```cpp 56 | auto send_goal_options = rclcpp_action::Client::SendGoalOptions(); 57 | send_goal_options.goal_response_callback = [this]( 58 | const GoalHandleFibonacci::SharedPtr & goal_handle) 59 | {...}; 60 | send_goal_options.feedback_callback = [this]( 61 | GoalHandleFibonacci::SharedPtr, 62 | const std::shared_ptr feedback) 63 | {...}; 64 | send_goal_options.result_callback = [this]( 65 | const GoalHandleFibonacci::WrappedResult & result) 66 | {...}; 67 | this->client_ptr_->async_send_goal(goal_msg, send_goal_options); 68 | ``` 69 | 70 | There are three types of callback functions: 71 | 72 | - The `goal_response_callback` is called when the action server accepts or rejects the goal. 73 | - The `feedback_callback` is called whenever the action server sends goal execution feedback. 74 | - The `goal_result_callback` is called when the action server is finished executing the goal and returns the result of the goal which is the full or partial Fibonacci sequence. 75 | -------------------------------------------------------------------------------- /src/action_tutorials_cpp/include/action_tutorials_cpp/visibility_control.h: -------------------------------------------------------------------------------- 1 | // Copyright 2019 Open Source Robotics Foundation, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef ACTION_TUTORIALS_CPP__VISIBILITY_CONTROL_H_ 16 | #define ACTION_TUTORIALS_CPP__VISIBILITY_CONTROL_H_ 17 | 18 | #ifdef __cplusplus 19 | extern "C" 20 | { 21 | #endif 22 | 23 | // This logic was borrowed (then namespaced) from the examples on the gcc wiki: 24 | // https://gcc.gnu.org/wiki/Visibility 25 | 26 | #if defined _WIN32 || defined __CYGWIN__ 27 | #ifdef __GNUC__ 28 | #define ACTION_TUTORIALS_CPP_EXPORT __attribute__ ((dllexport)) 29 | #define ACTION_TUTORIALS_CPP_IMPORT __attribute__ ((dllimport)) 30 | #else 31 | #define ACTION_TUTORIALS_CPP_EXPORT __declspec(dllexport) 32 | #define ACTION_TUTORIALS_CPP_IMPORT __declspec(dllimport) 33 | #endif 34 | #ifdef ACTION_TUTORIALS_CPP_BUILDING_DLL 35 | #define ACTION_TUTORIALS_CPP_PUBLIC ACTION_TUTORIALS_CPP_EXPORT 36 | #else 37 | #define ACTION_TUTORIALS_CPP_PUBLIC ACTION_TUTORIALS_CPP_IMPORT 38 | #endif 39 | #define ACTION_TUTORIALS_CPP_PUBLIC_TYPE ACTION_TUTORIALS_CPP_PUBLIC 40 | #define ACTION_TUTORIALS_CPP_LOCAL 41 | #else 42 | #define ACTION_TUTORIALS_CPP_EXPORT __attribute__ ((visibility("default"))) 43 | #define ACTION_TUTORIALS_CPP_IMPORT 44 | #if __GNUC__ >= 4 45 | #define ACTION_TUTORIALS_CPP_PUBLIC __attribute__ ((visibility("default"))) 46 | #define ACTION_TUTORIALS_CPP_LOCAL __attribute__ ((visibility("hidden"))) 47 | #else 48 | #define ACTION_TUTORIALS_CPP_PUBLIC 49 | #define ACTION_TUTORIALS_CPP_LOCAL 50 | #endif 51 | #define ACTION_TUTORIALS_CPP_PUBLIC_TYPE 52 | #endif 53 | 54 | #ifdef __cplusplus 55 | } 56 | #endif 57 | 58 | #endif // ACTION_TUTORIALS_CPP__VISIBILITY_CONTROL_H_ 59 | -------------------------------------------------------------------------------- /src/action_tutorials_cpp/package.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | action_tutorials_cpp 5 | 0.33.3 6 | C++ action tutorial cpp code 7 | 8 | Aditya Pande 9 | Audrow Nash 10 | 11 | Apache License 2.0 12 | 13 | Jacob Perron 14 | Mabel Zhang 15 | 16 | ament_cmake 17 | 18 | action_tutorials_interfaces 19 | rclcpp 20 | rclcpp_action 21 | rclcpp_components 22 | 23 | ament_lint_auto 24 | ament_lint_common 25 | 26 | 27 | ament_cmake 28 | 29 | 30 | -------------------------------------------------------------------------------- /src/action_tutorials_cpp/src/fibonacci_action_client.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2019 Open Source Robotics Foundation, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include 16 | #include 17 | #include 18 | 19 | #include "action_tutorials_interfaces/action/fibonacci.hpp" 20 | #include "rclcpp/rclcpp.hpp" 21 | // TODO(jacobperron): Remove this once it is included as part of 'rclcpp.hpp' 22 | #include "rclcpp_action/rclcpp_action.hpp" 23 | #include "rclcpp_components/register_node_macro.hpp" 24 | 25 | #include "action_tutorials_cpp/visibility_control.h" 26 | 27 | namespace action_tutorials_cpp 28 | { 29 | class FibonacciActionClient : public rclcpp::Node 30 | { 31 | public: 32 | using Fibonacci = action_tutorials_interfaces::action::Fibonacci; 33 | using GoalHandleFibonacci = rclcpp_action::ClientGoalHandle; 34 | 35 | ACTION_TUTORIALS_CPP_PUBLIC 36 | explicit FibonacciActionClient(const rclcpp::NodeOptions & node_options = rclcpp::NodeOptions()) 37 | : Node("fibonacci_action_client", node_options) 38 | { 39 | this->client_ptr_ = rclcpp_action::create_client( 40 | this->get_node_base_interface(), 41 | this->get_node_graph_interface(), 42 | this->get_node_logging_interface(), 43 | this->get_node_waitables_interface(), 44 | "fibonacci"); 45 | 46 | this->timer_ = this->create_wall_timer( 47 | std::chrono::milliseconds(500), 48 | [this]() {return this->send_goal();}); 49 | } 50 | 51 | ACTION_TUTORIALS_CPP_PUBLIC 52 | void send_goal() 53 | { 54 | using namespace std::placeholders; 55 | 56 | this->timer_->cancel(); 57 | 58 | if (!this->client_ptr_->wait_for_action_server(std::chrono::seconds(10))) { 59 | RCLCPP_ERROR(this->get_logger(), "Action server not available after waiting"); 60 | rclcpp::shutdown(); 61 | return; 62 | } 63 | 64 | auto goal_msg = Fibonacci::Goal(); 65 | goal_msg.order = 10; 66 | 67 | RCLCPP_INFO(this->get_logger(), "Sending goal"); 68 | 69 | auto send_goal_options = rclcpp_action::Client::SendGoalOptions(); 70 | send_goal_options.goal_response_callback = [this]( 71 | const GoalHandleFibonacci::SharedPtr & goal_handle) 72 | { 73 | if (!goal_handle) { 74 | RCLCPP_ERROR(this->get_logger(), "Goal was rejected by server"); 75 | } else { 76 | RCLCPP_INFO(this->get_logger(), "Goal accepted by server, waiting for result"); 77 | } 78 | }; 79 | 80 | send_goal_options.feedback_callback = [this]( 81 | GoalHandleFibonacci::SharedPtr, 82 | const std::shared_ptr feedback) 83 | { 84 | std::stringstream ss; 85 | ss << "Next number in sequence received: "; 86 | for (auto number : feedback->partial_sequence) { 87 | ss << number << " "; 88 | } 89 | RCLCPP_INFO(this->get_logger(), "%s", ss.str().c_str()); 90 | }; 91 | 92 | send_goal_options.result_callback = [this]( 93 | const GoalHandleFibonacci::WrappedResult & result) 94 | { 95 | switch (result.code) { 96 | case rclcpp_action::ResultCode::SUCCEEDED: 97 | break; 98 | case rclcpp_action::ResultCode::ABORTED: 99 | RCLCPP_ERROR(this->get_logger(), "Goal was aborted"); 100 | return; 101 | case rclcpp_action::ResultCode::CANCELED: 102 | RCLCPP_ERROR(this->get_logger(), "Goal was canceled"); 103 | return; 104 | default: 105 | RCLCPP_ERROR(this->get_logger(), "Unknown result code"); 106 | return; 107 | } 108 | std::stringstream ss; 109 | ss << "Result received: "; 110 | for (auto number : result.result->sequence) { 111 | ss << number << " "; 112 | } 113 | RCLCPP_INFO(this->get_logger(), "%s", ss.str().c_str()); 114 | rclcpp::shutdown(); 115 | }; 116 | 117 | this->client_ptr_->async_send_goal(goal_msg, send_goal_options); 118 | } 119 | 120 | private: 121 | rclcpp_action::Client::SharedPtr client_ptr_; 122 | rclcpp::TimerBase::SharedPtr timer_; 123 | }; // class FibonacciActionClient 124 | 125 | } // namespace action_tutorials_cpp 126 | 127 | RCLCPP_COMPONENTS_REGISTER_NODE(action_tutorials_cpp::FibonacciActionClient) 128 | -------------------------------------------------------------------------------- /src/action_tutorials_cpp/src/fibonacci_action_server.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2019 Open Source Robotics Foundation, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include 16 | 17 | #include "action_tutorials_interfaces/action/fibonacci.hpp" 18 | #include "rclcpp/rclcpp.hpp" 19 | // TODO(jacobperron): Remove this once it is included as part of 'rclcpp.hpp' 20 | #include "rclcpp_action/rclcpp_action.hpp" 21 | #include "rclcpp_components/register_node_macro.hpp" 22 | 23 | #include "action_tutorials_cpp/visibility_control.h" 24 | 25 | namespace action_tutorials_cpp 26 | { 27 | class FibonacciActionServer : public rclcpp::Node 28 | { 29 | public: 30 | using Fibonacci = action_tutorials_interfaces::action::Fibonacci; 31 | using GoalHandleFibonacci = rclcpp_action::ServerGoalHandle; 32 | 33 | ACTION_TUTORIALS_CPP_PUBLIC 34 | explicit FibonacciActionServer(const rclcpp::NodeOptions & options = rclcpp::NodeOptions()) 35 | : Node("fibonacci_action_server", options) 36 | { 37 | using namespace std::placeholders; 38 | 39 | auto handle_goal = [this]( 40 | const rclcpp_action::GoalUUID & uuid, 41 | std::shared_ptr goal) 42 | { 43 | (void)uuid; 44 | RCLCPP_INFO(this->get_logger(), "Received goal request with order %d", goal->order); 45 | // Fibonacciアクションはint32型で定義されているので、46より大きい値はオーバーフロー 46 | if (goal->order > 46) { 47 | return rclcpp_action::GoalResponse::REJECT; 48 | } 49 | return rclcpp_action::GoalResponse::ACCEPT_AND_EXECUTE; 50 | }; 51 | 52 | auto handle_cancel = [this]( 53 | const std::shared_ptr goal_handle) 54 | { 55 | RCLCPP_INFO(this->get_logger(), "Received request to cancel goal"); 56 | (void)goal_handle; 57 | return rclcpp_action::CancelResponse::ACCEPT; 58 | }; 59 | 60 | auto handle_accepted = [this]( 61 | const std::shared_ptr goal_handle) 62 | { 63 | // 実行スレッドをexecuteメソッドの完了待ちまでブロックしないようにスレッド実行 64 | auto execute_in_thread = [this, goal_handle]() {return this->execute(goal_handle);}; 65 | std::thread{execute_in_thread}.detach(); 66 | }; 67 | 68 | this->action_server_ = rclcpp_action::create_server( 69 | this, 70 | "fibonacci", 71 | handle_goal, 72 | handle_cancel, 73 | handle_accepted); 74 | } 75 | 76 | private: 77 | rclcpp_action::Server::SharedPtr action_server_; 78 | 79 | ACTION_TUTORIALS_CPP_LOCAL 80 | void execute(const std::shared_ptr goal_handle) 81 | { 82 | RCLCPP_INFO(this->get_logger(), "Executing goal"); 83 | rclcpp::Rate loop_rate(1); 84 | const auto goal = goal_handle->get_goal(); 85 | auto feedback = std::make_shared(); 86 | auto & sequence = feedback->partial_sequence; 87 | sequence.push_back(0); 88 | sequence.push_back(1); 89 | auto result = std::make_shared(); 90 | 91 | for (int i = 1; (i < goal->order) && rclcpp::ok(); ++i) { 92 | // キャンセルリクエストの確認 93 | if (goal_handle->is_canceling()) { 94 | result->sequence = sequence; 95 | goal_handle->canceled(result); 96 | RCLCPP_INFO(this->get_logger(), "Goal canceled"); 97 | return; 98 | } 99 | // フィボナッチ数列の更新 100 | sequence.push_back(sequence[i] + sequence[i - 1]); 101 | // フィードバック(フィボナッチ数列の途中経過)の送信 102 | goal_handle->publish_feedback(feedback); 103 | RCLCPP_INFO(this->get_logger(), "Publish feedback"); 104 | 105 | loop_rate.sleep(); 106 | } 107 | 108 | // 返り値(フィボナッチ数列)の送信 109 | if (rclcpp::ok()) { 110 | result->sequence = sequence; 111 | goal_handle->succeed(result); 112 | RCLCPP_INFO(this->get_logger(), "Goal succeeded"); 113 | } 114 | } 115 | }; // class FibonacciActionServer 116 | 117 | } // namespace action_tutorials_cpp 118 | 119 | RCLCPP_COMPONENTS_REGISTER_NODE(action_tutorials_cpp::FibonacciActionServer) 120 | -------------------------------------------------------------------------------- /src/examples_rclpy/examples_rclpy_actions/examples_rclpy_actions/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/youtalk/get-started-ros2/31bcb2e5f48c55027d49d5d7956d1586df7ccee1/src/examples_rclpy/examples_rclpy_actions/examples_rclpy_actions/__init__.py -------------------------------------------------------------------------------- /src/examples_rclpy/examples_rclpy_actions/examples_rclpy_actions/client.py: -------------------------------------------------------------------------------- 1 | # Copyright 2018 Open Source Robotics Foundation, Inc. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | from action_msgs.msg import GoalStatus 16 | from example_interfaces.action import Fibonacci 17 | 18 | import rclpy 19 | from rclpy.action import ActionClient 20 | from rclpy.node import Node 21 | 22 | 23 | class MinimalActionClient(Node): 24 | def __init__(self): 25 | super().__init__('minimal_action_client') 26 | # fibonacciアクションクライアントを作成 27 | self._action_client = ActionClient(self, Fibonacci, 'fibonacci') 28 | 29 | def goal_response_callback(self, future): 30 | # 目標値の設定成功の判別 31 | goal_handle = future.result() 32 | if not goal_handle.accepted: 33 | self.get_logger().info('goal rejected') 34 | return 35 | 36 | # アクションの実行結果の受信 37 | self._get_result_future = goal_handle.get_result_async() 38 | self._get_result_future.add_done_callback( 39 | self.get_result_callback) 40 | 41 | def feedback_callback(self, feedback): 42 | self.get_logger().info('feedback: {0}'.format( 43 | feedback.feedback.sequence)) 44 | 45 | def get_result_callback(self, future): 46 | result = future.result().result 47 | # アクションの実行状態の取得 48 | status = future.result().status 49 | if status == GoalStatus.STATUS_SUCCEEDED: 50 | # 実行成功ならフィボナッチ数列を標準出力にログ 51 | self.get_logger().info('result: {0}'.format( 52 | result.sequence)) 53 | 54 | # プログラムの終了 55 | rclpy.shutdown() 56 | 57 | def send_goal(self): 58 | self.get_logger().info('waiting...') 59 | self._action_client.wait_for_server() 60 | # 10要素のフィボナッチ数列を標値に設定 61 | goal_msg = Fibonacci.Goal() 62 | goal_msg.order = 10 63 | # アクションの非同期実行 64 | # (フィードバックと実行結果の受信コールバック関数も設定) 65 | self._send_goal_future = self._action_client.send_goal_async( 66 | goal_msg, feedback_callback=self.feedback_callback) 67 | self._send_goal_future.add_done_callback( 68 | self.goal_response_callback) 69 | 70 | 71 | def main(args=None): 72 | rclpy.init(args=args) 73 | action_client = MinimalActionClient() 74 | action_client.send_goal() 75 | rclpy.spin(action_client) 76 | action_client.destroy_node() 77 | 78 | 79 | if __name__ == '__main__': 80 | main() 81 | -------------------------------------------------------------------------------- /src/examples_rclpy/examples_rclpy_actions/examples_rclpy_actions/server.py: -------------------------------------------------------------------------------- 1 | # Copyright 2019 Open Source Robotics Foundation, Inc. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | import time 16 | 17 | from example_interfaces.action import Fibonacci 18 | 19 | import rclpy 20 | from rclpy.action import ActionServer 21 | from rclpy.callback_groups import ReentrantCallbackGroup 22 | from rclpy.executors import MultiThreadedExecutor 23 | from rclpy.node import Node 24 | 25 | 26 | class MinimalActionServer(Node): 27 | def __init__(self): 28 | super().__init__('minimal_action_server') 29 | # fibonacciアクションサーバーの作成 30 | # (execute_callback実行は複数同時処理を許可) 31 | self._action_server = ActionServer( 32 | self, Fibonacci, 'fibonacci', 33 | execute_callback=self.execute_callback, 34 | callback_group=ReentrantCallbackGroup()) 35 | 36 | def destroy(self): 37 | # アクションサーバーの終了 38 | self._action_server.destroy() 39 | super().destroy_node() 40 | 41 | async def execute_callback(self, goal_handle): 42 | # アクションの実行 43 | self.get_logger().info('executing...') 44 | # フィボナッチ数列の初期値0, 1を設定 45 | msg = Fibonacci.Feedback() 46 | msg.sequence = [0, 1] 47 | 48 | # フィボナッチ数列を一つずつ追加 49 | for i in range(1, goal_handle.request.order): 50 | if goal_handle.is_cancel_requested: 51 | # アクションのキャンセル 52 | goal_handle.canceled() 53 | self.get_logger().info('goal canceled') 54 | return Fibonacci.Result() 55 | 56 | # フィボナッチ数列の更新 57 | msg.sequence.append(msg.sequence[i] + msg.sequence[i-1]) 58 | self.get_logger().info('feedback: {0}'.format(msg.sequence)) 59 | # アクションのフィードバックの送信 60 | goal_handle.publish_feedback(msg) 61 | # 1秒待機(重たい処理の代わり) 62 | time.sleep(1) 63 | 64 | # アクションの実行結果の送信 65 | goal_handle.succeed() 66 | result = Fibonacci.Result() 67 | result.sequence = msg.sequence 68 | self.get_logger().info('result: {0}'.format(result.sequence)) 69 | return result 70 | 71 | 72 | def main(args=None): 73 | rclpy.init(args=args) 74 | minimal_action_server = MinimalActionServer() 75 | # マルチスレッドでminimal_action_serverノードを実行し、 76 | # 複数のアクションクライアントを同時処理 77 | executor = MultiThreadedExecutor() 78 | rclpy.spin(minimal_action_server, executor=executor) 79 | minimal_action_server.destroy() 80 | rclpy.shutdown() 81 | 82 | 83 | if __name__ == '__main__': 84 | main() 85 | -------------------------------------------------------------------------------- /src/examples_rclpy/examples_rclpy_actions/package.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | examples_rclpy_actions 5 | 0.6.3 6 | Examples of action servers/clients using rclpy. 7 | 8 | Yutaka Kondo 9 | Apache License 2.0 10 | 11 | Jacob Perron 12 | 13 | example_interfaces 14 | rclpy 15 | 16 | ament_copyright 17 | ament_flake8 18 | ament_pep257 19 | python3-pytest 20 | 21 | 22 | ament_python 23 | 24 | 25 | -------------------------------------------------------------------------------- /src/examples_rclpy/examples_rclpy_actions/resource/examples_rclpy_actions: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/youtalk/get-started-ros2/31bcb2e5f48c55027d49d5d7956d1586df7ccee1/src/examples_rclpy/examples_rclpy_actions/resource/examples_rclpy_actions -------------------------------------------------------------------------------- /src/examples_rclpy/examples_rclpy_actions/setup.cfg: -------------------------------------------------------------------------------- 1 | [develop] 2 | script-dir=$base/lib/examples_rclpy_actions 3 | [install] 4 | install-scripts=$base/lib/examples_rclpy_actions 5 | -------------------------------------------------------------------------------- /src/examples_rclpy/examples_rclpy_actions/setup.py: -------------------------------------------------------------------------------- 1 | from setuptools import setup 2 | 3 | package_name = 'examples_rclpy_actions' 4 | 5 | setup( 6 | name=package_name, 7 | version='0.6.3', 8 | packages=[package_name], 9 | data_files=[ 10 | ('share/ament_index/resource_index/packages', ['resource/' + package_name]), 11 | ('share/' + package_name, ['package.xml']), 12 | ], 13 | install_requires=['setuptools'], 14 | zip_safe=True, 15 | author='Jacob Perron', 16 | author_email='jacob@openrobotics.org', 17 | maintainer='Yutaka Kondo', 18 | maintainer_email='yutaka.kondo@youtalk.jp', 19 | keywords=['ROS'], 20 | classifiers=[ 21 | 'Intended Audience :: Developers', 22 | 'License :: OSI Approved :: Apache Software License', 23 | 'Programming Language :: Python', 24 | 'Topic :: Software Development', 25 | ], 26 | description='Examples of action servers/clients using rclpy.', 27 | license='Apache License, Version 2.0', 28 | tests_require=['pytest'], 29 | entry_points={ 30 | 'console_scripts': [ 31 | 'server = ' + package_name + '.server:main', 32 | 'client = ' + package_name + '.client:main', 33 | ], 34 | }, 35 | ) 36 | -------------------------------------------------------------------------------- /src/examples_rclpy/examples_rclpy_services/CHANGELOG.rst: -------------------------------------------------------------------------------- 1 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 2 | Changelog for package examples_rclpy_minimal_service 3 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 4 | 5 | 0.6.3 (2019-03-09) 6 | ------------------ 7 | 8 | 0.6.2 (2019-02-08) 9 | ------------------ 10 | * Modified examples to install entry point scripts into a package. (`#226 `_) 11 | * Contributors: Shane Loretz 12 | 13 | 0.6.0 (2018-11-20) 14 | ------------------ 15 | * Updated maintainer info. (`#218 `_) 16 | * Contributors: Shane Loretz 17 | 18 | 0.5.1 (2018-06-27) 19 | ------------------ 20 | 21 | 0.5.0 (2018-06-26) 22 | ------------------ 23 | * add pytest markers to linter tests 24 | * set zip_safe to avoid warning during installation (`#205 `_) 25 | * Contributors: Dirk Thomas, Mikael Arguedas 26 | 27 | 0.4.0 (2017-12-08) 28 | ------------------ 29 | * Use logging (`#190 `_) 30 | * Fix import statement and usage for rclpy.node.Node (`#189 `_) 31 | * remove test_suite, add pytest as test_requires 32 | * 0.0.3 33 | * Examples for Executors and callback groups (`#182 `_) 34 | * update style to satisfy new flake8 plugins (`#181 `_) 35 | * remove dependency on ament_python and perform customizations in setup.py (`#178 `_) 36 | * 0.0.2 37 | * rename executables with shorter names (`#177 `_) 38 | * install data_files `#176 `_ from ros2/data_files 39 | * install executables in package specific path `#173 `_ 40 | * use same node_names and service names in cpp and python (`#172 `_) 41 | * use explicit kwargs `#169 `_ from ros2/use_explicit_kwargs 42 | * fix function name (`#168 `_) 43 | * comply with flake8 import order (`#167 `_) 44 | * Rclpy minimal services (`#140 `_) 45 | * Contributors: Dirk Thomas, Mikael Arguedas, Shane Loretz 46 | -------------------------------------------------------------------------------- /src/examples_rclpy/examples_rclpy_services/README.md: -------------------------------------------------------------------------------- 1 | # Minimal service server cookbook recipes 2 | 3 | This package contains a few strategies to create service servers. 4 | The `service` recipe shows how to define a service server in an analog way to ROS 1 and rospy 5 | The `service_member_function` recipe creates a MinimalService class that processes the incoming requests 6 | -------------------------------------------------------------------------------- /src/examples_rclpy/examples_rclpy_services/examples_rclpy_services/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/youtalk/get-started-ros2/31bcb2e5f48c55027d49d5d7956d1586df7ccee1/src/examples_rclpy/examples_rclpy_services/examples_rclpy_services/__init__.py -------------------------------------------------------------------------------- /src/examples_rclpy/examples_rclpy_services/examples_rclpy_services/client.py: -------------------------------------------------------------------------------- 1 | # Copyright 2016 Open Source Robotics Foundation, Inc. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | from example_interfaces.srv import AddTwoInts 16 | 17 | import rclpy 18 | from rclpy.node import Node 19 | 20 | 21 | class MinimalClient(Node): 22 | def __init__(self): 23 | super().__init__('minimal_client') 24 | # add_two_intsサービスのクライアント作成 25 | self.cli = self.create_client(AddTwoInts, 'add_two_ints') 26 | # add_two_intsサービスの起動待機 27 | while not self.cli.wait_for_service(timeout_sec=1.0): 28 | self.get_logger().info('waiting...') 29 | # add_two_intsサービスの引数 30 | self.request = AddTwoInts.Request() 31 | 32 | def call_async(self): 33 | # add_two_intsサービスの引数にa = 1, b = 2を設定 34 | self.request.a = 1 35 | self.request.b = 2 36 | # add_two_intsサービスの非同期実行 37 | return self.cli.call_async(self.request) 38 | 39 | 40 | def main(args=None): 41 | rclpy.init(args=args) 42 | minimal_client = MinimalClient() 43 | future = minimal_client.call_async() 44 | # add_two_intsサービスの非同期実行が完了するまで待機 45 | rclpy.spin_until_future_complete(minimal_client, future) 46 | 47 | # 返り値を正常に得られたか判別 48 | if future.done() and future.result() is not None: 49 | # 返り値の取得 50 | response = future.result() 51 | # 計算結果を標準出力にログ 52 | minimal_client.get_logger().info( 53 | '%d + %d = %d' % 54 | (minimal_client.request.a, minimal_client.request.b, 55 | response.sum)) 56 | 57 | minimal_client.destroy_node() 58 | rclpy.shutdown() 59 | 60 | 61 | if __name__ == '__main__': 62 | main() 63 | -------------------------------------------------------------------------------- /src/examples_rclpy/examples_rclpy_services/examples_rclpy_services/service.py: -------------------------------------------------------------------------------- 1 | # Copyright 2016 Open Source Robotics Foundation, Inc. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | from example_interfaces.srv import AddTwoInts 16 | 17 | import rclpy 18 | from rclpy.node import Node 19 | 20 | 21 | class MinimalService(Node): 22 | def __init__(self): 23 | super().__init__('minimal_service') 24 | # add_two_intsサービスの作成 25 | # (サービスの中身はadd_two_ints_callbackで実装) 26 | self.srv = self.create_service(AddTwoInts, 'add_two_ints', 27 | self.add_two_ints_callback) 28 | 29 | def add_two_ints_callback(self, request, response): 30 | # a + bを答えを返り値responseに設定 31 | response.sum = request.a + request.b 32 | # 計算結果を標準出力にログ 33 | self.get_logger().info('%d + %d = %d' % 34 | (request.a, request.b, response.sum)) 35 | return response 36 | 37 | 38 | def main(args=None): 39 | rclpy.init(args=args) 40 | minimal_service = MinimalService() 41 | rclpy.spin(minimal_service) 42 | minimal_service.destroy_node() 43 | rclpy.shutdown() 44 | 45 | 46 | if __name__ == '__main__': 47 | main() 48 | -------------------------------------------------------------------------------- /src/examples_rclpy/examples_rclpy_services/package.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | examples_rclpy_services 5 | 0.6.3 6 | Examples of service servers/clients using rclpy. 7 | 8 | Yutaka Kondo 9 | Apache License 2.0 10 | 11 | example_interfaces 12 | rclpy 13 | std_msgs 14 | 15 | ament_copyright 16 | ament_flake8 17 | ament_pep257 18 | python3-pytest 19 | 20 | 21 | ament_python 22 | 23 | 24 | -------------------------------------------------------------------------------- /src/examples_rclpy/examples_rclpy_services/resource/examples_rclpy_services: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/youtalk/get-started-ros2/31bcb2e5f48c55027d49d5d7956d1586df7ccee1/src/examples_rclpy/examples_rclpy_services/resource/examples_rclpy_services -------------------------------------------------------------------------------- /src/examples_rclpy/examples_rclpy_services/setup.cfg: -------------------------------------------------------------------------------- 1 | [develop] 2 | script-dir=$base/lib/examples_rclpy_services 3 | [install] 4 | install-scripts=$base/lib/examples_rclpy_services 5 | -------------------------------------------------------------------------------- /src/examples_rclpy/examples_rclpy_services/setup.py: -------------------------------------------------------------------------------- 1 | from setuptools import setup 2 | 3 | package_name = 'examples_rclpy_services' 4 | 5 | setup( 6 | name=package_name, 7 | version='0.6.3', 8 | packages=[package_name], 9 | data_files=[ 10 | ('share/ament_index/resource_index/packages', ['resource/' + package_name]), 11 | ('share/' + package_name, ['package.xml']), 12 | ], 13 | install_requires=['setuptools'], 14 | zip_safe=True, 15 | author='Mikael Arguedas', 16 | author_email='mikael@osrfoundation.org', 17 | maintainer='Yutaka Kondo', 18 | maintainer_email='yutaka.kondo@youtalk.jp', 19 | keywords=['ROS'], 20 | classifiers=[ 21 | 'Intended Audience :: Developers', 22 | 'License :: OSI Approved :: Apache Software License', 23 | 'Programming Language :: Python', 24 | 'Topic :: Software Development', 25 | ], 26 | description='Examples of service servers/clients using rclpy.', 27 | license='Apache License, Version 2.0', 28 | tests_require=['pytest'], 29 | entry_points={ 30 | 'console_scripts': [ 31 | 'service = ' + package_name + '.service:main', 32 | 'client = ' + package_name + '.client:main', 33 | ], 34 | }, 35 | ) 36 | -------------------------------------------------------------------------------- /src/examples_rclpy/examples_rclpy_topics/examples_rclpy_topics/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/youtalk/get-started-ros2/31bcb2e5f48c55027d49d5d7956d1586df7ccee1/src/examples_rclpy/examples_rclpy_topics/examples_rclpy_topics/__init__.py -------------------------------------------------------------------------------- /src/examples_rclpy/examples_rclpy_topics/examples_rclpy_topics/composed.py: -------------------------------------------------------------------------------- 1 | # Copyright 2017 Open Source Robotics Foundation, Inc. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | import sys 16 | 17 | import rclpy 18 | from rclpy.executors import ExternalShutdownException 19 | from rclpy.executors import SingleThreadedExecutor 20 | 21 | from examples_rclpy_topics.publisher import MinimalPublisher 22 | from examples_rclpy_topics.subscriber import MinimalSubscriber 23 | 24 | 25 | def main(args=None): 26 | rclpy.init(args=args) 27 | try: 28 | publisher = MinimalPublisher() 29 | subscriber = MinimalSubscriber() 30 | # すべてのコールバックをメインスレッドで処理 31 | executor = SingleThreadedExecutor() 32 | # executorにすべてのノードを登録 33 | executor.add_node(publisher) 34 | executor.add_node(subscriber) 35 | 36 | try: 37 | # 登録されたすべてのノードを実行 38 | executor.spin() 39 | finally: 40 | executor.shutdown() 41 | subscriber.destroy_node() 42 | publisher.destroy_node() 43 | except KeyboardInterrupt: 44 | pass 45 | except ExternalShutdownException: 46 | sys.exit(1) 47 | finally: 48 | rclpy.try_shutdown() 49 | 50 | 51 | if __name__ == '__main__': 52 | main() 53 | -------------------------------------------------------------------------------- /src/examples_rclpy/examples_rclpy_topics/examples_rclpy_topics/publisher.py: -------------------------------------------------------------------------------- 1 | # Copyright 2016 Open Source Robotics Foundation, Inc. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | import rclpy 16 | from rclpy.node import Node 17 | 18 | from std_msgs.msg import String 19 | 20 | 21 | class MinimalPublisher(Node): 22 | def __init__(self): 23 | super().__init__('minimal_publisher') 24 | # String型のchatterトピックを送信するpublisherの定義 25 | self.publisher = self.create_publisher(String, 'chatter', 10) 26 | # 送信周期毎にtimer_callbackを呼び出し(送信周期は0.5秒) 27 | self.timer = self.create_timer(0.5, self.timer_callback) 28 | self.i = 0 29 | 30 | def timer_callback(self): 31 | msg = String() 32 | msg.data = 'Hello World: %d' % self.i 33 | # chatterトピックにmsgを送信 34 | self.publisher.publish(msg) 35 | # msgの中身を標準出力にログ 36 | self.get_logger().info(msg.data) 37 | self.i += 1 38 | 39 | 40 | def main(args=None): 41 | # Pythonクライアントライブラリの初期化 42 | rclpy.init(args=args) 43 | # minimal_publisherノードの作成 44 | minimal_publisher = MinimalPublisher() 45 | # minimal_publisherノードの実行開始 46 | rclpy.spin(minimal_publisher) 47 | # minimal_publisherノードの削除 48 | minimal_publisher.destroy_node() 49 | # Pythonクライアントライブラリの終了 50 | rclpy.shutdown() 51 | 52 | 53 | if __name__ == '__main__': 54 | main() 55 | -------------------------------------------------------------------------------- /src/examples_rclpy/examples_rclpy_topics/examples_rclpy_topics/subscriber.py: -------------------------------------------------------------------------------- 1 | # Copyright 2016 Open Source Robotics Foundation, Inc. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | import rclpy 16 | from rclpy.node import Node 17 | 18 | from std_msgs.msg import String 19 | 20 | 21 | class MinimalSubscriber(Node): 22 | def __init__(self): 23 | super().__init__('minimal_subscriber') 24 | # String型のchatterトピックを受信するsubscriptionの定義 25 | # (listener_callbackは受信毎に呼び出されるコールバック関数) 26 | self.subscription = self.create_subscription( 27 | String, 'chatter', self.listener_callback, 10) 28 | 29 | def listener_callback(self, msg): 30 | # msgの中身を標準出力にログ 31 | self.get_logger().info(msg.data) 32 | 33 | 34 | def main(args=None): 35 | rclpy.init(args=args) 36 | minimal_subscriber = MinimalSubscriber() 37 | rclpy.spin(minimal_subscriber) 38 | minimal_subscriber.destroy_node() 39 | rclpy.shutdown() 40 | 41 | 42 | if __name__ == '__main__': 43 | main() 44 | -------------------------------------------------------------------------------- /src/examples_rclpy/examples_rclpy_topics/package.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | examples_rclpy_topics 5 | 0.6.3 6 | Examples of publishers/subscribers using rclpy. 7 | 8 | Yutaka Kondo 9 | Apache License 2.0 10 | 11 | rclpy 12 | std_msgs 13 | 14 | ament_copyright 15 | ament_flake8 16 | ament_pep257 17 | python3-pytest 18 | 19 | 20 | ament_python 21 | 22 | 23 | -------------------------------------------------------------------------------- /src/examples_rclpy/examples_rclpy_topics/resource/examples_rclpy_topics: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/youtalk/get-started-ros2/31bcb2e5f48c55027d49d5d7956d1586df7ccee1/src/examples_rclpy/examples_rclpy_topics/resource/examples_rclpy_topics -------------------------------------------------------------------------------- /src/examples_rclpy/examples_rclpy_topics/setup.cfg: -------------------------------------------------------------------------------- 1 | [develop] 2 | script-dir=$base/lib/examples_rclpy_topics 3 | [install] 4 | install-scripts=$base/lib/examples_rclpy_topics 5 | -------------------------------------------------------------------------------- /src/examples_rclpy/examples_rclpy_topics/setup.py: -------------------------------------------------------------------------------- 1 | from setuptools import setup 2 | 3 | package_name = 'examples_rclpy_topics' 4 | 5 | setup( 6 | name=package_name, # パッケージ名 7 | version='0.6.3', # バージョン番号 8 | packages=[package_name], # ソースコードのディレクトリ 9 | data_files=[ # ソースコード以外のファイル 10 | ('share/ament_index/resource_index/packages', ['resource/' + package_name]), 11 | ('share/' + package_name, ['package.xml']), 12 | ], 13 | install_requires=['setuptools'], # 依存Python3モジュール 14 | zip_safe=True, 15 | author='Mikael Arguedas', 16 | author_email='mikael@osrfoundation.org', 17 | maintainer='Yutaka Kondo', 18 | maintainer_email='yutaka.kondo@youtalk.jp', 19 | keywords=['ROS'], 20 | classifiers=[ # PyPIの分類情報 21 | 'Intended Audience :: Developers', 22 | 'License :: OSI Approved :: Apache Software License', 23 | 'Programming Language :: Python', 24 | 'Topic :: Software Development', 25 | ], 26 | description='Examples of publishers/subscribers using rclpy.', 27 | license='Apache License, Version 2.0', 28 | tests_require=['pytest'], # テストフレームワーク名 29 | entry_points={ # 実行コマンド名とその呼び出し先 30 | 'console_scripts': [ 31 | 'publisher = ' + package_name + '.publisher:main', 32 | 'subscriber = ' + package_name + '.subscriber:main', 33 | 'composed = ' + package_name + '.composed:main', 34 | ], 35 | }, 36 | ) 37 | -------------------------------------------------------------------------------- /src/hello_world/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.12) 2 | project(hello_world) 3 | 4 | set(CMAKE_CXX_STANDARD 17) 5 | 6 | find_package(ament_cmake REQUIRED) 7 | find_package(rclcpp REQUIRED) 8 | find_package(rclcpp_components REQUIRED) 9 | find_package(hello_world_msgs REQUIRED) 10 | 11 | # ビルド設定の便利関数 12 | function(custom_executable target) 13 | add_executable(${target} src/${target}.cpp) 14 | ament_target_dependencies(${target} 15 | "rclcpp" 16 | "hello_world_msgs") 17 | install(TARGETS ${target} 18 | DESTINATION lib/${PROJECT_NAME}) 19 | endfunction() 20 | 21 | # talkerノードのビルド設定 22 | custom_executable(talker) 23 | custom_executable(talker_with_service) 24 | custom_executable(talker_with_service_param) 25 | # listenerノードのビルド設定 26 | custom_executable(listener) 27 | # client_syncノードのビルド設定 28 | custom_executable(client_sync) 29 | # client_asyncノードのビルド設定 30 | custom_executable(client_async) 31 | # talker/listenerノードのプロセス間通信のビルド設定 32 | custom_executable(talker_listener_composition) 33 | # パラメータ取得・設定ノードのビルド設定 34 | custom_executable(set_and_get_parameters) 35 | 36 | include_directories(include) 37 | 38 | # コンポーネント設定の便利関数 39 | function(custom_component target class_name) 40 | # クラスローダーへの共有ライブラリの登録 41 | rclcpp_components_register_node(${target} 42 | PLUGIN ${class_name} 43 | EXECUTABLE ${target}) 44 | ament_target_dependencies(${target} 45 | "rclcpp" 46 | "rclcpp_components" 47 | "hello_world_msgs") 48 | endfunction() 49 | 50 | # 共有ライブラリの生成 51 | custom_component(talker_component "hello_world::TalkerComponent") 52 | custom_component(listener_component "hello_world::ListenerComponent") 53 | 54 | install(DIRECTORY 55 | launch 56 | DESTINATION share/${PROJECT_NAME}/ 57 | ) 58 | 59 | ament_package() 60 | -------------------------------------------------------------------------------- /src/hello_world/include/hello_world/visibility_control.h: -------------------------------------------------------------------------------- 1 | // Copyright 2016 Open Source Robotics Foundation, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef HELLO_WORLD__VISIBILITY_CONTROL_H_ 16 | #define HELLO_WORLD__VISIBILITY_CONTROL_H_ 17 | 18 | #ifdef __cplusplus 19 | extern "C" 20 | { 21 | #endif 22 | 23 | // This logic was borrowed (then namespaced) from the examples on the gcc wiki: 24 | // https://gcc.gnu.org/wiki/Visibility 25 | 26 | #if defined _WIN32 || defined __CYGWIN__ 27 | #ifdef __GNUC__ 28 | #define HELLO_WORLD_EXPORT __attribute__ ((dllexport)) 29 | #define HELLO_WORLD_IMPORT __attribute__ ((dllimport)) 30 | #else 31 | #define HELLO_WORLD_EXPORT __declspec(dllexport) 32 | #define HELLO_WORLD_IMPORT __declspec(dllimport) 33 | #endif 34 | #ifdef HELLO_WORLD_BUILDING_DLL 35 | #define HELLO_WORLD_PUBLIC HELLO_WORLD_EXPORT 36 | #else 37 | #define HELLO_WORLD_PUBLIC HELLO_WORLD_IMPORT 38 | #endif 39 | #define HELLO_WORLD_PUBLIC_TYPE HELLO_WORLD_PUBLIC 40 | #define HELLO_WORLD_LOCAL 41 | #else 42 | #define HELLO_WORLD_EXPORT __attribute__ ((visibility("default"))) 43 | #define HELLO_WORLD_IMPORT 44 | #if __GNUC__ >= 4 45 | #define HELLO_WORLD_PUBLIC __attribute__ ((visibility("default"))) 46 | #define HELLO_WORLD_LOCAL __attribute__ ((visibility("hidden"))) 47 | #else 48 | #define HELLO_WORLD_PUBLIC 49 | #define HELLO_WORLD_LOCAL 50 | #endif 51 | #define HELLO_WORLD_PUBLIC_TYPE 52 | #endif 53 | 54 | #ifdef __cplusplus 55 | } 56 | #endif 57 | 58 | #endif // HELLO_WORLD__VISIBILITY_CONTROL_H_ 59 | -------------------------------------------------------------------------------- /src/hello_world/launch/params.yaml: -------------------------------------------------------------------------------- 1 | talker: 2 | ros__parameters: 3 | decoration: "a" 4 | -------------------------------------------------------------------------------- /src/hello_world/launch/talker_listener.launch.py: -------------------------------------------------------------------------------- 1 | # Copyright 2018 Open Source Robotics Foundation, Inc. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | from launch import LaunchDescription 16 | import launch_ros.actions 17 | 18 | 19 | def generate_launch_description(): 20 | return LaunchDescription([ 21 | launch_ros.actions.Node( 22 | package='hello_world', namespace='hello_world', 23 | executable='talker', name='talker', 24 | output='screen'), 25 | launch_ros.actions.Node( 26 | package='hello_world', namespace='hello_world', 27 | executable='listener', name='listener', 28 | output='screen'), 29 | ]) 30 | -------------------------------------------------------------------------------- /src/hello_world/launch/talker_listener.launch.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | 11 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /src/hello_world/launch/talker_listener_with_param.launch.py: -------------------------------------------------------------------------------- 1 | # Copyright 2018 Open Source Robotics Foundation, Inc. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | from launch import LaunchDescription 16 | import launch.actions 17 | import launch.substitutions 18 | import launch_ros.actions 19 | 20 | 21 | def generate_launch_description(): 22 | decoration = launch.substitutions.LaunchConfiguration( 23 | 'decoration') 24 | 25 | return LaunchDescription([ 26 | launch.actions.DeclareLaunchArgument( 27 | 'decoration', default_value='', 28 | description='Message decoration string'), 29 | launch_ros.actions.Node( 30 | package='hello_world', 31 | executable='talker_with_service_param', 32 | name='talker', output='screen', 33 | parameters=[{'decoration': decoration}]), 34 | launch_ros.actions.Node( 35 | package='hello_world', 36 | executable='listener', output='screen'), 37 | ]) 38 | -------------------------------------------------------------------------------- /src/hello_world/launch/talker_listener_with_param_file.launch.py: -------------------------------------------------------------------------------- 1 | # Copyright 2018 Open Source Robotics Foundation, Inc. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | from launch import LaunchDescription 16 | import launch.substitutions 17 | import launch_ros.actions 18 | import os 19 | 20 | 21 | def generate_launch_description(): 22 | params = os.path.join(os.path.dirname(__file__), 'params.yaml') 23 | 24 | return LaunchDescription([ 25 | launch_ros.actions.Node( 26 | package='hello_world', namespace='hello_world', 27 | executable='talker_with_service_param', 28 | name='talker', output='screen', 29 | parameters=[params]), 30 | launch_ros.actions.Node( 31 | package='hello_world', namespace='hello_world', 32 | executable='listener', name='listener', 33 | output='screen'), 34 | ]) 35 | -------------------------------------------------------------------------------- /src/hello_world/package.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | hello_world 5 | 0.1.0 6 | 7 | C++ hello_world demo nodes. 8 | 9 | Yutaka Kondo 10 | Apache License 2.0 11 | 12 | ament_cmake 13 | 14 | rclcpp 15 | rclcpp_components 16 | hello_world_msgs 17 | 18 | rclcpp 19 | rclcpp_components 20 | hello_world_msgs 21 | launch_ros 22 | 23 | 24 | ament_cmake 25 | 26 | 27 | -------------------------------------------------------------------------------- /src/hello_world/src/client_async.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2014 Open Source Robotics Foundation, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | 22 | #include "hello_world_msgs/srv/set_message.hpp" 23 | 24 | using namespace std::chrono_literals; 25 | using hello_world_msgs::srv::SetMessage; 26 | 27 | class ClientNode : public rclcpp::Node 28 | { 29 | public: 30 | explicit ClientNode(const std::string & service_name) 31 | : Node("client_async") 32 | { 33 | client_ = create_client(service_name); 34 | // サービスサーバーの起動待ち 35 | while (!client_->wait_for_service(1s)) { 36 | if (!rclcpp::ok()) { 37 | return; 38 | } 39 | RCLCPP_INFO(this->get_logger(), "Service not available."); 40 | } 41 | // リクエストの設定 42 | auto request = std::make_shared(); 43 | request->message = "Hello service!"; 44 | 45 | // 非同期処理 46 | { 47 | using ServiceResponseFuture = 48 | rclcpp::Client::SharedFuture; 49 | auto response_received_callback = [this]( 50 | ServiceResponseFuture future) { 51 | auto response = future.get(); 52 | RCLCPP_INFO(this->get_logger(), "%s", 53 | response->result ? "true" : "false"); 54 | rclcpp::shutdown(); 55 | }; 56 | auto future_result = client_->async_send_request( 57 | request, response_received_callback); 58 | } 59 | 60 | // 同期処理 61 | // { 62 | // auto future_result = client_->async_send_request(request); 63 | // if (rclcpp::spin_until_future_complete( 64 | // this->shared_from_this(), future_result) == 65 | // rclcpp::FutureReturnCode::SUCCESS) { 66 | // RCLCPP_INFO(this->get_logger(), "%s", 67 | // future_result.get()->result ? "true" : "false"); 68 | // rclcpp::shutdown(); 69 | // } 70 | // } 71 | } 72 | 73 | private: 74 | rclcpp::Client::SharedPtr client_; 75 | }; 76 | 77 | int main(int argc, char ** argv) 78 | { 79 | setvbuf(stdout, NULL, _IONBF, BUFSIZ); 80 | rclcpp::init(argc, argv); 81 | 82 | auto node = std::make_shared("set_message"); 83 | rclcpp::spin(node); 84 | rclcpp::shutdown(); 85 | 86 | return 0; 87 | } 88 | -------------------------------------------------------------------------------- /src/hello_world/src/client_sync.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2014 Open Source Robotics Foundation, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | 22 | #include "hello_world_msgs/srv/set_message.hpp" 23 | 24 | using namespace std::chrono_literals; 25 | using hello_world_msgs::srv::SetMessage; 26 | 27 | class ClientNode : public rclcpp::Node 28 | { 29 | public: 30 | explicit ClientNode(const std::string & service_name) 31 | : Node("client_async") 32 | { 33 | client_ = create_client(service_name); 34 | // サービスサーバーの起動待ち 35 | while (!client_->wait_for_service(1s)) { 36 | if (!rclcpp::ok()) { 37 | return; 38 | } 39 | RCLCPP_INFO(this->get_logger(), "Service not available."); 40 | } 41 | // リクエストの設定 42 | auto request = std::make_shared(); 43 | request->message = "Hello service!"; 44 | 45 | // 同期処理 46 | { 47 | auto future_result = client_->async_send_request(request); 48 | if (rclcpp::spin_until_future_complete( 49 | this->shared_from_this(), future_result) == 50 | rclcpp::FutureReturnCode::SUCCESS) 51 | { 52 | RCLCPP_INFO(this->get_logger(), "%s", 53 | future_result.get()->result ? "true" : "false"); 54 | rclcpp::shutdown(); 55 | } 56 | } 57 | } 58 | 59 | private: 60 | rclcpp::Client::SharedPtr client_; 61 | }; 62 | 63 | int main(int argc, char ** argv) 64 | { 65 | setvbuf(stdout, NULL, _IONBF, BUFSIZ); 66 | rclcpp::init(argc, argv); 67 | 68 | auto node = std::make_shared("set_message"); 69 | rclcpp::spin(node); 70 | rclcpp::shutdown(); 71 | 72 | return 0; 73 | } 74 | -------------------------------------------------------------------------------- /src/hello_world/src/listener.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2014 Open Source Robotics Foundation, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | 21 | class Listener : public rclcpp::Node 22 | { 23 | public: 24 | explicit Listener(const std::string & topic_name) 25 | : Node("listener") 26 | { 27 | // chatterトピックのコールバック関数 28 | auto callback = 29 | [this](const std_msgs::msg::String::UniquePtr msg) -> void 30 | { 31 | RCLCPP_INFO(this->get_logger(), "%s", msg->data.c_str()); 32 | }; 33 | 34 | // chatterトピックの受信設定 35 | rclcpp::QoS qos(rclcpp::KeepLast(10)); 36 | sub_ = create_subscription( 37 | topic_name, qos, callback); 38 | } 39 | 40 | private: 41 | rclcpp::Subscription::SharedPtr sub_; 42 | }; 43 | 44 | int main(int argc, char * argv[]) 45 | { 46 | setvbuf(stdout, NULL, _IONBF, BUFSIZ); 47 | rclcpp::init(argc, argv); 48 | 49 | auto node = std::make_shared("chatter"); 50 | rclcpp::spin(node); 51 | rclcpp::shutdown(); 52 | return 0; 53 | } 54 | -------------------------------------------------------------------------------- /src/hello_world/src/listener_component.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2014 Open Source Robotics Foundation, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | 21 | #include "hello_world/visibility_control.h" 22 | 23 | using namespace std::chrono_literals; 24 | 25 | // ネームスペースの設定 26 | namespace hello_world 27 | { 28 | 29 | class ListenerComponent : public rclcpp::Node 30 | { 31 | public: 32 | // マルチOSに対応した共有ライブラリの最適化 33 | HELLO_WORLD_PUBLIC 34 | // コンストラクター引数をNodeOptionsに変更 35 | explicit ListenerComponent(const rclcpp::NodeOptions & options) 36 | : Node("listener_component", options) 37 | { 38 | // chatterトピックのコールバック関数 39 | auto callback = 40 | [this](const std_msgs::msg::String::UniquePtr msg) -> void 41 | { 42 | RCLCPP_INFO(this->get_logger(), "%s", msg->data.c_str()); 43 | }; 44 | 45 | // chatterトピックの受信設定 46 | rclcpp::QoS qos(rclcpp::KeepLast(10)); 47 | sub_ = create_subscription( 48 | "chatter", qos, callback); 49 | } 50 | 51 | private: 52 | rclcpp::Subscription::SharedPtr sub_; 53 | }; // class ListenerComponent 54 | 55 | } // namespace hello_world 56 | 57 | #include "rclcpp_components/register_node_macro.hpp" 58 | 59 | // クラスローダーにコンポーネントを登録 60 | RCLCPP_COMPONENTS_REGISTER_NODE(hello_world::ListenerComponent) 61 | -------------------------------------------------------------------------------- /src/hello_world/src/listener_no_main.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2014 Open Source Robotics Foundation, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | 21 | class Listener : public rclcpp::Node 22 | { 23 | public: 24 | explicit Listener(const std::string & topic_name) 25 | : Node("listener") 26 | { 27 | // chatterトピックのコールバック関数 28 | auto callback = 29 | [this](const std_msgs::msg::String::UniquePtr msg) -> void 30 | { 31 | RCLCPP_INFO(this->get_logger(), "%s", msg->data.c_str()); 32 | }; 33 | 34 | // chatterトピックの受信設定 35 | rclcpp::QoS qos(rclcpp::KeepLast(10)); 36 | sub_ = create_subscription( 37 | topic_name, qos, callback); 38 | } 39 | 40 | private: 41 | rclcpp::Subscription::SharedPtr sub_; 42 | }; 43 | -------------------------------------------------------------------------------- /src/hello_world/src/set_and_get_parameters.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2015 Open Source Robotics Foundation, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | 21 | using namespace std::chrono_literals; 22 | 23 | int main(int argc, char ** argv) 24 | { 25 | setvbuf(stdout, NULL, _IONBF, BUFSIZ); 26 | rclcpp::init(argc, argv); 27 | auto node = rclcpp::Node::make_shared("set_and_get_parameters"); 28 | 29 | // パラメータの宣言 30 | node->declare_parameter("foo", rclcpp::PARAMETER_INTEGER); 31 | node->declare_parameter("bar", rclcpp::PARAMETER_STRING); 32 | node->declare_parameter("baz", rclcpp::PARAMETER_DOUBLE); 33 | 34 | // パラメータ設定・取得サービスのクライアント 35 | auto parameters_client = std::make_shared< 36 | rclcpp::SyncParametersClient>(node); 37 | // パラメータ設定・取得サービスの起動待ち 38 | while (!parameters_client->wait_for_service(1s)) { 39 | if (!rclcpp::ok()) { 40 | RCLCPP_ERROR(node->get_logger(), "Interrupted"); 41 | return 0; 42 | } 43 | RCLCPP_INFO(node->get_logger(), "Waiting"); 44 | } 45 | 46 | // パラメータの設定 47 | auto set_parameters_results = parameters_client->set_parameters({ 48 | rclcpp::Parameter("foo", 2), 49 | rclcpp::Parameter("bar", "hello"), 50 | rclcpp::Parameter("baz", 1.45), 51 | }); 52 | // パラメータの設定成功の確認 53 | for (auto & result : set_parameters_results) { 54 | if (!result.successful) { 55 | RCLCPP_ERROR(node->get_logger(), "Failed: %s", 56 | result.reason.c_str()); 57 | } 58 | } 59 | 60 | std::stringstream ss; 61 | // パラメータの取得 62 | for (auto & parameter : parameters_client->get_parameters( 63 | {"foo", "bar", "baz"})) 64 | { 65 | // パラメータ名とパラメータの型名のロギング 66 | ss << "\nParameter name: " << parameter.get_name(); 67 | ss << "\nParameter value (" << parameter.get_type_name() 68 | << "): " << parameter.value_to_string(); 69 | } 70 | RCLCPP_INFO(node->get_logger(), ss.str().c_str()); 71 | 72 | rclcpp::shutdown(); 73 | return 0; 74 | } 75 | -------------------------------------------------------------------------------- /src/hello_world/src/talker.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2014 Open Source Robotics Foundation, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | 22 | using namespace std::chrono_literals; 23 | 24 | class Talker : public rclcpp::Node 25 | { 26 | public: 27 | explicit Talker(const std::string & topic_name) 28 | : Node("talker") 29 | { 30 | // タイマー実行されるイベントハンドラー関数 31 | auto publish_message = 32 | [this]() -> void // ラムダ式による関数オブジェクトの定義 33 | { 34 | // 送信するメッセージ 35 | auto msg = std::make_unique(); 36 | msg->data = "Hello world!"; 37 | 38 | RCLCPP_INFO(this->get_logger(), "%s", msg->data.c_str()); 39 | pub_->publish(std::move(msg)); 40 | }; 41 | 42 | // chatterトピックの送信設定 43 | rclcpp::QoS qos(rclcpp::KeepLast(10)); 44 | pub_ = create_publisher(topic_name, qos); 45 | // publish_messageの100ミリ秒周期でのタイマー実行 46 | timer_ = create_wall_timer(100ms, publish_message); 47 | } 48 | 49 | private: 50 | rclcpp::Publisher::SharedPtr pub_; 51 | rclcpp::TimerBase::SharedPtr timer_; 52 | }; 53 | 54 | int main(int argc, char * argv[]) 55 | { 56 | // クライアントライブラリの初期化 57 | setvbuf(stdout, NULL, _IONBF, BUFSIZ); 58 | rclcpp::init(argc, argv); 59 | 60 | // talkerノードの生成とスピン開始 61 | auto node = std::make_shared("chatter"); 62 | rclcpp::spin(node); 63 | rclcpp::shutdown(); 64 | 65 | return 0; 66 | } 67 | -------------------------------------------------------------------------------- /src/hello_world/src/talker_component.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2014 Open Source Robotics Foundation, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | 22 | #include "hello_world/visibility_control.h" 23 | 24 | using namespace std::chrono_literals; 25 | 26 | // ネームスペースの設定 27 | namespace hello_world 28 | { 29 | 30 | class TalkerComponent : public rclcpp::Node 31 | { 32 | public: 33 | // マルチOSに対応した共有ライブラリの最適化 34 | HELLO_WORLD_PUBLIC 35 | // コンストラクター引数をNodeOptionsに変更 36 | explicit TalkerComponent(const rclcpp::NodeOptions & options) 37 | : Node("talker_component", options) 38 | { 39 | // タイマー実行されるイベントハンドラー関数 40 | auto publish_message = 41 | [this]() -> void // ラムダ式による関数オブジェクトの定義 42 | { 43 | // 送信するメッセージ 44 | auto msg = std::make_unique(); 45 | msg->data = "Hello World!"; 46 | 47 | RCLCPP_INFO(this->get_logger(), "%s", msg->data.c_str()); 48 | pub_->publish(std::move(msg)); 49 | }; 50 | 51 | // chatterトピックの送信設定 52 | rclcpp::QoS qos(rclcpp::KeepLast(10)); 53 | pub_ = create_publisher("chatter", qos); 54 | // publish_messageの100ミリ秒周期でのタイマー実行 55 | timer_ = create_wall_timer(100ms, publish_message); 56 | } 57 | 58 | private: 59 | rclcpp::Publisher::SharedPtr pub_; 60 | rclcpp::TimerBase::SharedPtr timer_; 61 | }; // class TalkerComponent 62 | 63 | } // namespace hello_world 64 | 65 | #include "rclcpp_components/register_node_macro.hpp" 66 | 67 | // クラスローダーにコンポーネントを登録 68 | RCLCPP_COMPONENTS_REGISTER_NODE(hello_world::TalkerComponent) 69 | -------------------------------------------------------------------------------- /src/hello_world/src/talker_listener_composition.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2014 Open Source Robotics Foundation, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include 16 | #include 17 | 18 | #include "talker_no_main.cpp" 19 | #include "listener_no_main.cpp" 20 | 21 | int main(int argc, char * argv[]) 22 | { 23 | setvbuf(stdout, NULL, _IONBF, BUFSIZ); 24 | rclcpp::init(argc, argv); 25 | 26 | rclcpp::executors::SingleThreadedExecutor exec; 27 | auto talker = std::make_shared("chatter"); 28 | auto listener = std::make_shared("chatter"); 29 | exec.add_node(talker); 30 | exec.add_node(listener); 31 | exec.spin(); 32 | rclcpp::shutdown(); 33 | 34 | return 0; 35 | } 36 | -------------------------------------------------------------------------------- /src/hello_world/src/talker_no_main.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2014 Open Source Robotics Foundation, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | 22 | using namespace std::chrono_literals; 23 | 24 | class Talker : public rclcpp::Node 25 | { 26 | public: 27 | explicit Talker(const std::string & topic_name) 28 | : Node("talker") 29 | { 30 | // タイマー実行されるイベントハンドラー関数 31 | auto publish_message = 32 | [this]() -> void // ラムダ式による関数オブジェクトの定義 33 | { 34 | // 送信するメッセージ 35 | auto msg = std::make_unique(); 36 | msg->data = "Hello world!"; 37 | 38 | RCLCPP_INFO(this->get_logger(), "%s", msg->data.c_str()); 39 | pub_->publish(std::move(msg)); 40 | }; 41 | 42 | // chatterトピックの送信設定 43 | rclcpp::QoS qos(rclcpp::KeepLast(10)); 44 | pub_ = create_publisher(topic_name, qos); 45 | // publish_messageの100ミリ秒周期でのタイマー実行 46 | timer_ = create_wall_timer(100ms, publish_message); 47 | } 48 | 49 | private: 50 | rclcpp::Publisher::SharedPtr pub_; 51 | rclcpp::TimerBase::SharedPtr timer_; 52 | }; 53 | -------------------------------------------------------------------------------- /src/hello_world/src/talker_with_service.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2014 Open Source Robotics Foundation, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | 23 | #include "hello_world_msgs/srv/set_message.hpp" 24 | 25 | using namespace std::chrono_literals; 26 | using hello_world_msgs::srv::SetMessage; 27 | 28 | class Talker : public rclcpp::Node 29 | { 30 | public: 31 | explicit Talker(const std::string & topic_name) 32 | : Node("talker"), 33 | data_("Hello world!") 34 | { 35 | auto publish_message = 36 | [this]() -> void 37 | { 38 | auto msg = std::make_unique(); 39 | msg->data = data_; 40 | 41 | RCLCPP_INFO(this->get_logger(), "%s", msg->data.c_str()); 42 | pub_->publish(std::move(msg)); 43 | }; 44 | 45 | rclcpp::QoS qos(rclcpp::KeepLast(10)); 46 | pub_ = create_publisher(topic_name, qos); 47 | timer_ = create_wall_timer(100ms, publish_message); 48 | 49 | // set_messageサービスのコールバック関数 50 | auto handle_set_message = 51 | [this](const std::shared_ptr request_header, 52 | const std::shared_ptr request, 53 | std::shared_ptr response) -> void 54 | { 55 | (void)request_header; // Lintツール対策 56 | RCLCPP_INFO(this->get_logger(), "message %s -> %s", 57 | this->data_.c_str(), request->message.c_str()); 58 | // 1秒スリープ(重い処理の代わり) 59 | std::this_thread::sleep_for(1s); 60 | this->data_ = request->message; 61 | response->result = true; 62 | }; 63 | 64 | // set_messageサービスのサーバー設定 65 | srv_ = create_service( 66 | "set_message", handle_set_message); 67 | } 68 | 69 | private: 70 | rclcpp::Publisher::SharedPtr pub_; 71 | rclcpp::TimerBase::SharedPtr timer_; 72 | rclcpp::Service::SharedPtr srv_; 73 | std::string data_; 74 | }; 75 | 76 | int main(int argc, char * argv[]) 77 | { 78 | setvbuf(stdout, NULL, _IONBF, BUFSIZ); 79 | rclcpp::init(argc, argv); 80 | 81 | auto node = std::make_shared("chatter"); 82 | rclcpp::spin(node); 83 | rclcpp::shutdown(); 84 | 85 | return 0; 86 | } 87 | -------------------------------------------------------------------------------- /src/hello_world/src/talker_with_service_param.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2014 Open Source Robotics Foundation, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | 23 | #include "hello_world_msgs/srv/set_message.hpp" 24 | 25 | using namespace std::chrono_literals; 26 | using hello_world_msgs::srv::SetMessage; 27 | 28 | class Talker : public rclcpp::Node 29 | { 30 | public: 31 | explicit Talker(const std::string & topic_name) 32 | : Node("talker"), 33 | data_("Hello world!") 34 | { 35 | auto publish_message = 36 | [this]() -> void 37 | { 38 | auto msg = std::make_unique(); 39 | msg->data = data_; 40 | 41 | // decorationによる文字列の装飾 42 | std::string decorated_data = 43 | decoration_ + msg->data + decoration_; 44 | RCLCPP_INFO(this->get_logger(), "%s", decorated_data.c_str()); 45 | pub_->publish(std::move(msg)); 46 | }; 47 | 48 | rclcpp::QoS qos(rclcpp::KeepLast(10)); 49 | pub_ = create_publisher(topic_name, qos); 50 | timer_ = create_wall_timer(100ms, publish_message); 51 | 52 | auto handle_set_message = 53 | [this](const std::shared_ptr request_header, 54 | const std::shared_ptr request, 55 | std::shared_ptr response) -> void 56 | { 57 | (void)request_header; 58 | RCLCPP_INFO(this->get_logger(), "message %s -> %s", 59 | this->data_.c_str(), request->message.c_str()); 60 | this->data_ = request->message; 61 | response->result = true; 62 | }; 63 | 64 | srv_ = create_service( 65 | "set_message", handle_set_message); 66 | 67 | // decorationパラメータの宣言 68 | decoration_ = declare_parameter("decoration", ""); 69 | // decorationパラメータの監視 70 | param_subscriber_ = std::make_shared< 71 | rclcpp::ParameterEventHandler>(this); 72 | cb_handle_ = param_subscriber_->add_parameter_callback( 73 | "decoration", [this](const rclcpp::Parameter & p) { 74 | decoration_ = p.as_string(); 75 | }); 76 | } 77 | 78 | private: 79 | rclcpp::Publisher::SharedPtr pub_; 80 | rclcpp::TimerBase::SharedPtr timer_; 81 | rclcpp::Service::SharedPtr srv_; 82 | std::shared_ptr param_subscriber_; 83 | std::shared_ptr cb_handle_; 84 | std::string data_; 85 | std::string decoration_; 86 | }; 87 | 88 | int main(int argc, char * argv[]) 89 | { 90 | setvbuf(stdout, NULL, _IONBF, BUFSIZ); 91 | rclcpp::init(argc, argv); 92 | 93 | auto node = std::make_shared("chatter"); 94 | rclcpp::spin(node); 95 | rclcpp::shutdown(); 96 | 97 | return 0; 98 | } 99 | -------------------------------------------------------------------------------- /src/hello_world_msgs/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.5) 2 | project(hello_world_msgs) 3 | 4 | set(CMAKE_CXX_STANDARD 14) 5 | 6 | if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang") 7 | add_compile_options(-Wall -Wextra -Wpedantic) 8 | endif() 9 | 10 | # find dependencies 11 | find_package(ament_cmake REQUIRED) 12 | find_package(std_msgs REQUIRED) 13 | find_package(action_msgs REQUIRED) 14 | find_package(rosidl_default_generators REQUIRED) 15 | 16 | rosidl_generate_interfaces(${PROJECT_NAME} 17 | "srv/SetMessage.srv" 18 | "action/Fibonacci.action" 19 | DEPENDENCIES std_msgs action_msgs 20 | ) 21 | 22 | ament_export_dependencies(rosidl_default_runtime) 23 | ament_package() 24 | -------------------------------------------------------------------------------- /src/hello_world_msgs/action/Fibonacci.action: -------------------------------------------------------------------------------- 1 | # Goal 2 | int32 order 3 | --- 4 | # Result 5 | int32[] sequence 6 | --- 7 | # Feedback 8 | int32[] partial_sequence 9 | -------------------------------------------------------------------------------- /src/hello_world_msgs/package.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | hello_world_msgs 5 | 0.1.0 6 | 7 | C++ hello_world msg package. 8 | 9 | Yutaka Kondo 10 | Apache License 2.0 11 | 12 | ament_cmake 13 | rosidl_default_generators 14 | 15 | std_msgs 16 | action_msgs 17 | 18 | std_msgs 19 | action_msgs 20 | rosidl_default_runtime 21 | 22 | rosidl_interface_packages 23 | 24 | 25 | ament_cmake 26 | 27 | 28 | -------------------------------------------------------------------------------- /src/hello_world_msgs/srv/SetMessage.srv: -------------------------------------------------------------------------------- 1 | string message 2 | --- 3 | bool result 4 | -------------------------------------------------------------------------------- /src/policies/add_two_ints.policy.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 10 | 11 | add_two_ints 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 21 | 22 | add_two_ints 23 | 24 | 25 | 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /src/policies/common/lifecycle_node.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 6 | 7 | ~/change_state 8 | ~/get_available_states 9 | ~/get_available_transitions 10 | ~/get_state 11 | ~/get_transition_graph 12 | 13 | 14 | ~/transition_event 15 | 16 | 17 | -------------------------------------------------------------------------------- /src/policies/common/node.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 7 | 9 | 11 | 12 | -------------------------------------------------------------------------------- /src/policies/common/node/logging.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | rosout 5 | 6 | 7 | -------------------------------------------------------------------------------- /src/policies/common/node/parameters.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | /parameter_events 5 | 6 | 7 | 8 | ~/describe_parameters 9 | ~/get_parameter_types 10 | ~/get_parameters 11 | ~/list_parameters 12 | ~/set_parameters 13 | ~/set_parameters_atomically 14 | 15 | 16 | -------------------------------------------------------------------------------- /src/policies/common/node/time.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | /clock 5 | 6 | 7 | -------------------------------------------------------------------------------- /src/policies/common/node/types.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | ~/get_type_description 5 | 6 | 7 | -------------------------------------------------------------------------------- /src/policies/invalid_policy_missing_topics_tag.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 10 | 11 | chatter 12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /src/policies/minimal_action.policy.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 10 | 11 | fibonacci 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 21 | 22 | fibonacci 23 | 24 | 25 | 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /src/policies/permissions/add_two_ints/permissions.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | CN=/add_two_ints/add_two_ints_server 5 | 6 | 2020-05-01T00:00:00 7 | 2030-05-01T00:00:00 8 | 9 | 10 | 11 | 0 12 | 13 | 14 | 15 | rq/add_two_ints_server/describe_parametersRequest 16 | rq/add_two_ints_server/get_parameter_typesRequest 17 | rq/add_two_ints_server/get_parametersRequest 18 | rq/add_two_ints_server/list_parametersRequest 19 | rq/add_two_ints_server/set_parametersRequest 20 | rq/add_two_ints_server/set_parameters_atomicallyRequest 21 | rq/add_two_ints_server/get_type_descriptionRequest 22 | rr/add_two_intsReply 23 | rr/add_two_ints_server/describe_parametersReply 24 | rr/add_two_ints_server/get_parameter_typesReply 25 | rr/add_two_ints_server/get_parametersReply 26 | rr/add_two_ints_server/list_parametersReply 27 | rr/add_two_ints_server/set_parametersReply 28 | rr/add_two_ints_server/set_parameters_atomicallyReply 29 | rr/add_two_ints_server/get_type_descriptionReply 30 | rt/parameter_events 31 | rt/rosout 32 | 33 | 34 | 35 | 36 | rq/add_two_intsRequest 37 | rq/add_two_ints_server/describe_parametersRequest 38 | rq/add_two_ints_server/get_parameter_typesRequest 39 | rq/add_two_ints_server/get_parametersRequest 40 | rq/add_two_ints_server/list_parametersRequest 41 | rq/add_two_ints_server/set_parametersRequest 42 | rq/add_two_ints_server/set_parameters_atomicallyRequest 43 | rr/add_two_ints_server/describe_parametersReply 44 | rr/add_two_ints_server/get_parameter_typesReply 45 | rr/add_two_ints_server/get_parametersReply 46 | rr/add_two_ints_server/list_parametersReply 47 | rr/add_two_ints_server/set_parametersReply 48 | rr/add_two_ints_server/set_parameters_atomicallyReply 49 | rt/clock 50 | rt/parameter_events 51 | 52 | 53 | 54 | DENY 55 | 56 | 57 | CN=/add_two_ints/add_two_ints_client 58 | 59 | 2020-05-01T00:00:00 60 | 2030-05-01T00:00:00 61 | 62 | 63 | 64 | 0 65 | 66 | 67 | 68 | rq/add_two_intsRequest 69 | rq/add_two_ints_client/describe_parametersRequest 70 | rq/add_two_ints_client/get_parameter_typesRequest 71 | rq/add_two_ints_client/get_parametersRequest 72 | rq/add_two_ints_client/list_parametersRequest 73 | rq/add_two_ints_client/set_parametersRequest 74 | rq/add_two_ints_client/set_parameters_atomicallyRequest 75 | rq/add_two_ints_client/get_type_descriptionRequest 76 | rr/add_two_ints_client/describe_parametersReply 77 | rr/add_two_ints_client/get_parameter_typesReply 78 | rr/add_two_ints_client/get_parametersReply 79 | rr/add_two_ints_client/list_parametersReply 80 | rr/add_two_ints_client/set_parametersReply 81 | rr/add_two_ints_client/set_parameters_atomicallyReply 82 | rr/add_two_ints_client/get_type_descriptionReply 83 | rt/parameter_events 84 | rt/rosout 85 | 86 | 87 | 88 | 89 | rq/add_two_ints_client/describe_parametersRequest 90 | rq/add_two_ints_client/get_parameter_typesRequest 91 | rq/add_two_ints_client/get_parametersRequest 92 | rq/add_two_ints_client/list_parametersRequest 93 | rq/add_two_ints_client/set_parametersRequest 94 | rq/add_two_ints_client/set_parameters_atomicallyRequest 95 | rq/add_two_ints_client/get_type_descriptionRequest 96 | rr/add_two_intsReply 97 | rr/add_two_ints_client/describe_parametersReply 98 | rr/add_two_ints_client/get_parameter_typesReply 99 | rr/add_two_ints_client/get_parametersReply 100 | rr/add_two_ints_client/list_parametersReply 101 | rr/add_two_ints_client/set_parametersReply 102 | rr/add_two_ints_client/set_parameters_atomicallyReply 103 | rr/add_two_ints_client/get_type_descriptionReply 104 | rt/clock 105 | rt/parameter_events 106 | 107 | 108 | 109 | DENY 110 | 111 | 112 | 113 | -------------------------------------------------------------------------------- /src/policies/permissions/minimal_action/permissions.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | CN=/minimal_action/minimal_action_server 5 | 6 | 2020-05-01T00:00:00 7 | 2030-05-01T00:00:00 8 | 9 | 10 | 11 | 0 12 | 13 | 14 | 15 | rq/minimal_action_server/describe_parametersRequest 16 | rq/minimal_action_server/get_parameter_typesRequest 17 | rq/minimal_action_server/get_parametersRequest 18 | rq/minimal_action_server/list_parametersRequest 19 | rq/minimal_action_server/set_parametersRequest 20 | rq/minimal_action_server/set_parameters_atomicallyRequest 21 | rq/minimal_action_server/get_type_descriptionRequest 22 | rr/fibonacci/_action/cancel_goalReply 23 | rr/fibonacci/_action/get_resultReply 24 | rr/fibonacci/_action/send_goalReply 25 | rt/fibonacci/_action/feedback 26 | rt/fibonacci/_action/status 27 | rr/minimal_action_server/describe_parametersReply 28 | rr/minimal_action_server/get_parameter_typesReply 29 | rr/minimal_action_server/get_parametersReply 30 | rr/minimal_action_server/list_parametersReply 31 | rr/minimal_action_server/set_parametersReply 32 | rr/minimal_action_server/set_parameters_atomicallyReply 33 | rr/minimal_action_server/get_type_descriptionReply 34 | rt/parameter_events 35 | rt/rosout 36 | 37 | 38 | 39 | 40 | rq/fibonacci/_action/cancel_goalRequest 41 | rq/fibonacci/_action/get_resultRequest 42 | rq/fibonacci/_action/send_goalRequest 43 | rq/minimal_action_server/describe_parametersRequest 44 | rq/minimal_action_server/get_parameter_typesRequest 45 | rq/minimal_action_server/get_parametersRequest 46 | rq/minimal_action_server/list_parametersRequest 47 | rq/minimal_action_server/set_parametersRequest 48 | rq/minimal_action_server/set_parameters_atomicallyRequest 49 | rq/minimal_action_server/get_type_descriptionRequest 50 | rr/minimal_action_server/describe_parametersReply 51 | rr/minimal_action_server/get_parameter_typesReply 52 | rr/minimal_action_server/get_parametersReply 53 | rr/minimal_action_server/list_parametersReply 54 | rr/minimal_action_server/set_parametersReply 55 | rr/minimal_action_server/set_parameters_atomicallyReply 56 | rr/minimal_action_server/get_type_descriptionReply 57 | rt/clock 58 | rt/parameter_events 59 | 60 | 61 | 62 | DENY 63 | 64 | 65 | CN=/minimal_action/minimal_action_client 66 | 67 | 2020-05-01T00:00:00 68 | 2030-05-01T00:00:00 69 | 70 | 71 | 72 | 0 73 | 74 | 75 | 76 | rq/fibonacci/_action/cancel_goalRequest 77 | rq/fibonacci/_action/get_resultRequest 78 | rq/fibonacci/_action/send_goalRequest 79 | rq/minimal_action_client/describe_parametersRequest 80 | rq/minimal_action_client/get_parameter_typesRequest 81 | rq/minimal_action_client/get_parametersRequest 82 | rq/minimal_action_client/list_parametersRequest 83 | rq/minimal_action_client/set_parametersRequest 84 | rq/minimal_action_client/set_parameters_atomicallyRequest 85 | rq/minimal_action_client/get_type_descriptionRequest 86 | rr/minimal_action_client/describe_parametersReply 87 | rr/minimal_action_client/get_parameter_typesReply 88 | rr/minimal_action_client/get_parametersReply 89 | rr/minimal_action_client/list_parametersReply 90 | rr/minimal_action_client/set_parametersReply 91 | rr/minimal_action_client/set_parameters_atomicallyReply 92 | rr/minimal_action_client/get_type_descriptionReply 93 | rt/parameter_events 94 | rt/rosout 95 | 96 | 97 | 98 | 99 | rq/minimal_action_client/describe_parametersRequest 100 | rq/minimal_action_client/get_parameter_typesRequest 101 | rq/minimal_action_client/get_parametersRequest 102 | rq/minimal_action_client/list_parametersRequest 103 | rq/minimal_action_client/set_parametersRequest 104 | rq/minimal_action_client/set_parameters_atomicallyRequest 105 | rq/minimal_action_client/get_type_descriptionRequest 106 | rr/fibonacci/_action/cancel_goalReply 107 | rr/fibonacci/_action/get_resultReply 108 | rr/fibonacci/_action/send_goalReply 109 | rt/fibonacci/_action/feedback 110 | rt/fibonacci/_action/status 111 | rr/minimal_action_client/describe_parametersReply 112 | rr/minimal_action_client/get_parameter_typesReply 113 | rr/minimal_action_client/get_parametersReply 114 | rr/minimal_action_client/list_parametersReply 115 | rr/minimal_action_client/set_parametersReply 116 | rr/minimal_action_client/set_parameters_atomicallyReply 117 | rr/minimal_action_client/get_type_descriptionReply 118 | rt/clock 119 | rt/parameter_events 120 | 121 | 122 | 123 | DENY 124 | 125 | 126 | 127 | -------------------------------------------------------------------------------- /src/policies/permissions/sample/permissions.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | CN=/talker_listener/talker 5 | 6 | 2020-05-01T00:00:00 7 | 2030-05-01T00:00:00 8 | 9 | 10 | 11 | 0 12 | 13 | 14 | 15 | rq/talker/describe_parametersRequest 16 | rq/talker/get_parameter_typesRequest 17 | rq/talker/get_parametersRequest 18 | rq/talker/list_parametersRequest 19 | rq/talker/set_parametersRequest 20 | rq/talker/set_parameters_atomicallyRequest 21 | rq/talker/get_type_descriptionRequest 22 | rr/talker/describe_parametersReply 23 | rr/talker/get_parameter_typesReply 24 | rr/talker/get_parametersReply 25 | rr/talker/list_parametersReply 26 | rr/talker/set_parametersReply 27 | rr/talker/set_parameters_atomicallyReply 28 | rr/talker/get_type_descriptionReply 29 | rt/chatter 30 | rt/parameter_events 31 | rt/rosout 32 | 33 | 34 | 35 | 36 | rq/talker/describe_parametersRequest 37 | rq/talker/get_parameter_typesRequest 38 | rq/talker/get_parametersRequest 39 | rq/talker/list_parametersRequest 40 | rq/talker/set_parametersRequest 41 | rq/talker/set_parameters_atomicallyRequest 42 | rq/talker/get_type_descriptionRequest 43 | rr/talker/describe_parametersReply 44 | rr/talker/get_parameter_typesReply 45 | rr/talker/get_parametersReply 46 | rr/talker/list_parametersReply 47 | rr/talker/set_parametersReply 48 | rr/talker/set_parameters_atomicallyReply 49 | rr/talker/get_type_descriptionReply 50 | rt/clock 51 | rt/parameter_events 52 | 53 | 54 | 55 | DENY 56 | 57 | 58 | CN=/talker_listener/listener 59 | 60 | 2020-05-01T00:00:00 61 | 2030-05-01T00:00:00 62 | 63 | 64 | 65 | 0 66 | 67 | 68 | 69 | rq/listener/describe_parametersRequest 70 | rq/listener/get_parameter_typesRequest 71 | rq/listener/get_parametersRequest 72 | rq/listener/list_parametersRequest 73 | rq/listener/set_parametersRequest 74 | rq/listener/set_parameters_atomicallyRequest 75 | rq/listener/get_type_descriptionRequest 76 | rr/listener/describe_parametersReply 77 | rr/listener/get_parameter_typesReply 78 | rr/listener/get_parametersReply 79 | rr/listener/list_parametersReply 80 | rr/listener/set_parametersReply 81 | rr/listener/set_parameters_atomicallyReply 82 | rr/listener/get_type_descriptionReply 83 | rt/parameter_events 84 | rt/rosout 85 | 86 | 87 | 88 | 89 | rq/listener/describe_parametersRequest 90 | rq/listener/get_parameter_typesRequest 91 | rq/listener/get_parametersRequest 92 | rq/listener/list_parametersRequest 93 | rq/listener/set_parametersRequest 94 | rq/listener/set_parameters_atomicallyRequest 95 | rq/listener/get_type_descriptionRequest 96 | rr/listener/describe_parametersReply 97 | rr/listener/get_parameter_typesReply 98 | rr/listener/get_parametersReply 99 | rr/listener/list_parametersReply 100 | rr/listener/set_parametersReply 101 | rr/listener/set_parameters_atomicallyReply 102 | rr/listener/get_type_descriptionReply 103 | rt/chatter 104 | rt/clock 105 | rt/parameter_events 106 | 107 | 108 | 109 | DENY 110 | 111 | 112 | CN=/add_two_ints/add_two_ints_server 113 | 114 | 2020-05-01T00:00:00 115 | 2030-05-01T00:00:00 116 | 117 | 118 | 119 | 0 120 | 121 | 122 | 123 | rq/add_two_ints_server/describe_parametersRequest 124 | rq/add_two_ints_server/get_parameter_typesRequest 125 | rq/add_two_ints_server/get_parametersRequest 126 | rq/add_two_ints_server/list_parametersRequest 127 | rq/add_two_ints_server/set_parametersRequest 128 | rq/add_two_ints_server/set_parameters_atomicallyRequest 129 | rq/add_two_ints_server/get_type_descriptionRequest 130 | rr/add_two_intsReply 131 | rr/add_two_ints_server/describe_parametersReply 132 | rr/add_two_ints_server/get_parameter_typesReply 133 | rr/add_two_ints_server/get_parametersReply 134 | rr/add_two_ints_server/list_parametersReply 135 | rr/add_two_ints_server/set_parametersReply 136 | rr/add_two_ints_server/set_parameters_atomicallyReply 137 | rr/add_two_ints_server/get_type_descriptionReply 138 | rt/parameter_events 139 | rt/rosout 140 | 141 | 142 | 143 | 144 | rq/add_two_intsRequest 145 | rq/add_two_ints_server/describe_parametersRequest 146 | rq/add_two_ints_server/get_parameter_typesRequest 147 | rq/add_two_ints_server/get_parametersRequest 148 | rq/add_two_ints_server/list_parametersRequest 149 | rq/add_two_ints_server/set_parametersRequest 150 | rq/add_two_ints_server/set_parameters_atomicallyRequest 151 | rq/add_two_ints_server/get_type_descriptionRequest 152 | rr/add_two_ints_server/describe_parametersReply 153 | rr/add_two_ints_server/get_parameter_typesReply 154 | rr/add_two_ints_server/get_parametersReply 155 | rr/add_two_ints_server/list_parametersReply 156 | rr/add_two_ints_server/set_parametersReply 157 | rr/add_two_ints_server/set_parameters_atomicallyReply 158 | rr/add_two_ints_server/get_type_descriptionReply 159 | rt/clock 160 | rt/parameter_events 161 | 162 | 163 | 164 | DENY 165 | 166 | 167 | CN=/add_two_ints/add_two_ints_client 168 | 169 | 2020-05-01T00:00:00 170 | 2030-05-01T00:00:00 171 | 172 | 173 | 174 | 0 175 | 176 | 177 | 178 | rq/add_two_intsRequest 179 | rq/add_two_ints_client/describe_parametersRequest 180 | rq/add_two_ints_client/get_parameter_typesRequest 181 | rq/add_two_ints_client/get_parametersRequest 182 | rq/add_two_ints_client/list_parametersRequest 183 | rq/add_two_ints_client/set_parametersRequest 184 | rq/add_two_ints_client/set_parameters_atomicallyRequest 185 | rq/add_two_ints_client/get_type_descriptionRequest 186 | rr/add_two_ints_client/describe_parametersReply 187 | rr/add_two_ints_client/get_parameter_typesReply 188 | rr/add_two_ints_client/get_parametersReply 189 | rr/add_two_ints_client/list_parametersReply 190 | rr/add_two_ints_client/set_parametersReply 191 | rr/add_two_ints_client/set_parameters_atomicallyReply 192 | rr/add_two_ints_client/get_type_descriptionReply 193 | rt/parameter_events 194 | rt/rosout 195 | 196 | 197 | 198 | 199 | rq/add_two_ints_client/describe_parametersRequest 200 | rq/add_two_ints_client/get_parameter_typesRequest 201 | rq/add_two_ints_client/get_parametersRequest 202 | rq/add_two_ints_client/list_parametersRequest 203 | rq/add_two_ints_client/set_parametersRequest 204 | rq/add_two_ints_client/set_parameters_atomicallyRequest 205 | rq/add_two_ints_client/get_type_descriptionRequest 206 | rr/add_two_intsReply 207 | rr/add_two_ints_client/describe_parametersReply 208 | rr/add_two_ints_client/get_parameter_typesReply 209 | rr/add_two_ints_client/get_parametersReply 210 | rr/add_two_ints_client/list_parametersReply 211 | rr/add_two_ints_client/set_parametersReply 212 | rr/add_two_ints_client/set_parameters_atomicallyReply 213 | rr/add_two_ints_client/get_type_descriptionReply 214 | rt/clock 215 | rt/parameter_events 216 | 217 | 218 | 219 | DENY 220 | 221 | 222 | CN=/minimal_action/minimal_action_server 223 | 224 | 2020-05-01T00:00:00 225 | 2030-05-01T00:00:00 226 | 227 | 228 | 229 | 0 230 | 231 | 232 | 233 | rq/minimal_action_server/describe_parametersRequest 234 | rq/minimal_action_server/get_parameter_typesRequest 235 | rq/minimal_action_server/get_parametersRequest 236 | rq/minimal_action_server/list_parametersRequest 237 | rq/minimal_action_server/set_parametersRequest 238 | rq/minimal_action_server/set_parameters_atomicallyRequest 239 | rq/minimal_action_server/get_type_descriptionRequest 240 | rr/fibonacci/_action/cancel_goalReply 241 | rr/fibonacci/_action/get_resultReply 242 | rr/fibonacci/_action/send_goalReply 243 | rt/fibonacci/_action/feedback 244 | rt/fibonacci/_action/status 245 | rr/minimal_action_server/describe_parametersReply 246 | rr/minimal_action_server/get_parameter_typesReply 247 | rr/minimal_action_server/get_parametersReply 248 | rr/minimal_action_server/list_parametersReply 249 | rr/minimal_action_server/set_parametersReply 250 | rr/minimal_action_server/set_parameters_atomicallyReply 251 | rr/minimal_action_server/get_type_descriptionReply 252 | rt/parameter_events 253 | rt/rosout 254 | 255 | 256 | 257 | 258 | rq/fibonacci/_action/cancel_goalRequest 259 | rq/fibonacci/_action/get_resultRequest 260 | rq/fibonacci/_action/send_goalRequest 261 | rq/minimal_action_server/describe_parametersRequest 262 | rq/minimal_action_server/get_parameter_typesRequest 263 | rq/minimal_action_server/get_parametersRequest 264 | rq/minimal_action_server/list_parametersRequest 265 | rq/minimal_action_server/set_parametersRequest 266 | rq/minimal_action_server/set_parameters_atomicallyRequest 267 | rq/minimal_action_server/get_type_descriptionRequest 268 | rr/minimal_action_server/describe_parametersReply 269 | rr/minimal_action_server/get_parameter_typesReply 270 | rr/minimal_action_server/get_parametersReply 271 | rr/minimal_action_server/list_parametersReply 272 | rr/minimal_action_server/set_parametersReply 273 | rr/minimal_action_server/set_parameters_atomicallyReply 274 | rr/minimal_action_server/get_type_descriptionReply 275 | rt/clock 276 | rt/parameter_events 277 | 278 | 279 | 280 | DENY 281 | 282 | 283 | CN=/minimal_action/minimal_action_client 284 | 285 | 2020-05-01T00:00:00 286 | 2030-05-01T00:00:00 287 | 288 | 289 | 290 | 0 291 | 292 | 293 | 294 | rq/fibonacci/_action/cancel_goalRequest 295 | rq/fibonacci/_action/get_resultRequest 296 | rq/fibonacci/_action/send_goalRequest 297 | rq/minimal_action_client/describe_parametersRequest 298 | rq/minimal_action_client/get_parameter_typesRequest 299 | rq/minimal_action_client/get_parametersRequest 300 | rq/minimal_action_client/list_parametersRequest 301 | rq/minimal_action_client/set_parametersRequest 302 | rq/minimal_action_client/set_parameters_atomicallyRequest 303 | rq/minimal_action_client/get_type_descriptionRequest 304 | rr/minimal_action_client/describe_parametersReply 305 | rr/minimal_action_client/get_parameter_typesReply 306 | rr/minimal_action_client/get_parametersReply 307 | rr/minimal_action_client/list_parametersReply 308 | rr/minimal_action_client/set_parametersReply 309 | rr/minimal_action_client/set_parameters_atomicallyReply 310 | rr/minimal_action_client/get_type_descriptionReply 311 | rt/parameter_events 312 | rt/rosout 313 | 314 | 315 | 316 | 317 | rq/minimal_action_client/describe_parametersRequest 318 | rq/minimal_action_client/get_parameter_typesRequest 319 | rq/minimal_action_client/get_parametersRequest 320 | rq/minimal_action_client/list_parametersRequest 321 | rq/minimal_action_client/set_parametersRequest 322 | rq/minimal_action_client/set_parameters_atomicallyRequest 323 | rq/minimal_action_client/get_type_descriptionRequest 324 | rr/fibonacci/_action/cancel_goalReply 325 | rr/fibonacci/_action/get_resultReply 326 | rr/fibonacci/_action/send_goalReply 327 | rt/fibonacci/_action/feedback 328 | rt/fibonacci/_action/status 329 | rr/minimal_action_client/describe_parametersReply 330 | rr/minimal_action_client/get_parameter_typesReply 331 | rr/minimal_action_client/get_parametersReply 332 | rr/minimal_action_client/list_parametersReply 333 | rr/minimal_action_client/set_parametersReply 334 | rr/minimal_action_client/set_parameters_atomicallyReply 335 | rr/minimal_action_client/get_type_descriptionReply 336 | rt/clock 337 | rt/parameter_events 338 | 339 | 340 | 341 | DENY 342 | 343 | 344 | CN=/sample_policy/admin 345 | 346 | 2020-05-01T00:00:00 347 | 2030-05-01T00:00:00 348 | 349 | 350 | 351 | 0 352 | 353 | 354 | 355 | rq/add_two_intsRequest 356 | rq/admin/describe_parametersRequest 357 | rq/admin/get_parameter_typesRequest 358 | rq/admin/get_parametersRequest 359 | rq/admin/list_parametersRequest 360 | rq/admin/set_parametersRequest 361 | rq/admin/set_parameters_atomicallyRequest 362 | rq/admin/get_type_descriptionRequest 363 | rq/fibonacci/_action/cancel_goalRequest 364 | rq/fibonacci/_action/get_resultRequest 365 | rq/fibonacci/_action/send_goalRequest 366 | rr/add_two_intsReply 367 | rr/admin/describe_parametersReply 368 | rr/admin/get_parameter_typesReply 369 | rr/admin/get_parametersReply 370 | rr/admin/list_parametersReply 371 | rr/admin/set_parametersReply 372 | rr/admin/set_parameters_atomicallyReply 373 | rr/admin/get_type_descriptionReply 374 | rr/fibonacci/_action/cancel_goalReply 375 | rr/fibonacci/_action/get_resultReply 376 | rr/fibonacci/_action/send_goalReply 377 | rt/fibonacci/_action/feedback 378 | rt/fibonacci/_action/status 379 | rt/chatter 380 | rt/parameter_events 381 | rt/rosout 382 | 383 | 384 | 385 | 386 | rq/add_two_intsRequest 387 | rq/admin/describe_parametersRequest 388 | rq/admin/get_parameter_typesRequest 389 | rq/admin/get_parametersRequest 390 | rq/admin/list_parametersRequest 391 | rq/admin/set_parametersRequest 392 | rq/admin/set_parameters_atomicallyRequest 393 | rq/admin/get_type_descriptionRequest 394 | rq/fibonacci/_action/cancel_goalRequest 395 | rq/fibonacci/_action/get_resultRequest 396 | rq/fibonacci/_action/send_goalRequest 397 | rr/add_two_intsReply 398 | rr/admin/describe_parametersReply 399 | rr/admin/get_parameter_typesReply 400 | rr/admin/get_parametersReply 401 | rr/admin/list_parametersReply 402 | rr/admin/set_parametersReply 403 | rr/admin/set_parameters_atomicallyReply 404 | rr/admin/get_type_descriptionReply 405 | rr/fibonacci/_action/cancel_goalReply 406 | rr/fibonacci/_action/get_resultReply 407 | rr/fibonacci/_action/send_goalReply 408 | rt/fibonacci/_action/feedback 409 | rt/fibonacci/_action/status 410 | rt/chatter 411 | rt/clock 412 | rt/parameter_events 413 | 414 | 415 | 416 | DENY 417 | 418 | 419 | 420 | -------------------------------------------------------------------------------- /src/policies/permissions/single_context/permissions.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | CN=/single_enclave 5 | 6 | 2020-05-01T00:00:00 7 | 2030-05-01T00:00:00 8 | 9 | 10 | 11 | 0 12 | 13 | 14 | 15 | rq/add_two_intsRequest 16 | rq/add_two_ints_client/describe_parametersRequest 17 | rq/add_two_ints_client/get_parameter_typesRequest 18 | rq/add_two_ints_client/get_parametersRequest 19 | rq/add_two_ints_client/list_parametersRequest 20 | rq/add_two_ints_client/set_parametersRequest 21 | rq/add_two_ints_client/set_parameters_atomicallyRequest 22 | rq/add_two_ints_client/get_type_descriptionRequest 23 | rq/add_two_ints_server/describe_parametersRequest 24 | rq/add_two_ints_server/get_parameter_typesRequest 25 | rq/add_two_ints_server/get_parametersRequest 26 | rq/add_two_ints_server/list_parametersRequest 27 | rq/add_two_ints_server/set_parametersRequest 28 | rq/add_two_ints_server/set_parameters_atomicallyRequest 29 | rq/add_two_ints_server/get_type_descriptionRequest 30 | rq/fibonacci/_action/cancel_goalRequest 31 | rq/fibonacci/_action/get_resultRequest 32 | rq/fibonacci/_action/send_goalRequest 33 | rq/listener/describe_parametersRequest 34 | rq/listener/get_parameter_typesRequest 35 | rq/listener/get_parametersRequest 36 | rq/listener/list_parametersRequest 37 | rq/listener/set_parametersRequest 38 | rq/listener/set_parameters_atomicallyRequest 39 | rq/listener/get_type_descriptionRequest 40 | rq/minimal_action_client/describe_parametersRequest 41 | rq/minimal_action_client/get_parameter_typesRequest 42 | rq/minimal_action_client/get_parametersRequest 43 | rq/minimal_action_client/list_parametersRequest 44 | rq/minimal_action_client/set_parametersRequest 45 | rq/minimal_action_client/set_parameters_atomicallyRequest 46 | rq/minimal_action_client/get_type_descriptionRequest 47 | rq/minimal_action_server/describe_parametersRequest 48 | rq/minimal_action_server/get_parameter_typesRequest 49 | rq/minimal_action_server/get_parametersRequest 50 | rq/minimal_action_server/list_parametersRequest 51 | rq/minimal_action_server/set_parametersRequest 52 | rq/minimal_action_server/set_parameters_atomicallyRequest 53 | rq/minimal_action_server/get_type_descriptionRequest 54 | rq/talker/describe_parametersRequest 55 | rq/talker/get_parameter_typesRequest 56 | rq/talker/get_parametersRequest 57 | rq/talker/list_parametersRequest 58 | rq/talker/set_parametersRequest 59 | rq/talker/set_parameters_atomicallyRequest 60 | rq/talker/get_type_descriptionRequest 61 | rr/add_two_intsReply 62 | rr/add_two_ints_client/describe_parametersReply 63 | rr/add_two_ints_client/get_parameter_typesReply 64 | rr/add_two_ints_client/get_parametersReply 65 | rr/add_two_ints_client/list_parametersReply 66 | rr/add_two_ints_client/set_parametersReply 67 | rr/add_two_ints_client/set_parameters_atomicallyReply 68 | rr/add_two_ints_client/get_type_descriptionReply 69 | rr/add_two_ints_server/describe_parametersReply 70 | rr/add_two_ints_server/get_parameter_typesReply 71 | rr/add_two_ints_server/get_parametersReply 72 | rr/add_two_ints_server/list_parametersReply 73 | rr/add_two_ints_server/set_parametersReply 74 | rr/add_two_ints_server/set_parameters_atomicallyReply 75 | rr/add_two_ints_server/get_type_descriptionReply 76 | rr/fibonacci/_action/cancel_goalReply 77 | rr/fibonacci/_action/get_resultReply 78 | rr/fibonacci/_action/send_goalReply 79 | rt/fibonacci/_action/feedback 80 | rt/fibonacci/_action/status 81 | rr/listener/describe_parametersReply 82 | rr/listener/get_parameter_typesReply 83 | rr/listener/get_parametersReply 84 | rr/listener/list_parametersReply 85 | rr/listener/set_parametersReply 86 | rr/listener/set_parameters_atomicallyReply 87 | rr/listener/get_type_descriptionReply 88 | rr/minimal_action_client/describe_parametersReply 89 | rr/minimal_action_client/get_parameter_typesReply 90 | rr/minimal_action_client/get_parametersReply 91 | rr/minimal_action_client/list_parametersReply 92 | rr/minimal_action_client/set_parametersReply 93 | rr/minimal_action_client/set_parameters_atomicallyReply 94 | rr/minimal_action_client/get_type_descriptionReply 95 | rr/minimal_action_server/describe_parametersReply 96 | rr/minimal_action_server/get_parameter_typesReply 97 | rr/minimal_action_server/get_parametersReply 98 | rr/minimal_action_server/list_parametersReply 99 | rr/minimal_action_server/set_parametersReply 100 | rr/minimal_action_server/set_parameters_atomicallyReply 101 | rr/minimal_action_server/get_type_descriptionReply 102 | rr/talker/describe_parametersReply 103 | rr/talker/get_parameter_typesReply 104 | rr/talker/get_parametersReply 105 | rr/talker/list_parametersReply 106 | rr/talker/set_parametersReply 107 | rr/talker/set_parameters_atomicallyReply 108 | rr/talker/get_type_descriptionReply 109 | rt/chatter 110 | rt/parameter_events 111 | rt/rosout 112 | 113 | 114 | 115 | 116 | rq/add_two_intsRequest 117 | rq/add_two_ints_client/describe_parametersRequest 118 | rq/add_two_ints_client/get_parameter_typesRequest 119 | rq/add_two_ints_client/get_parametersRequest 120 | rq/add_two_ints_client/list_parametersRequest 121 | rq/add_two_ints_client/set_parametersRequest 122 | rq/add_two_ints_client/set_parameters_atomicallyRequest 123 | rq/add_two_ints_client/get_type_descriptionRequest 124 | rq/add_two_ints_server/describe_parametersRequest 125 | rq/add_two_ints_server/get_parameter_typesRequest 126 | rq/add_two_ints_server/get_parametersRequest 127 | rq/add_two_ints_server/list_parametersRequest 128 | rq/add_two_ints_server/set_parametersRequest 129 | rq/add_two_ints_server/set_parameters_atomicallyRequest 130 | rq/add_two_ints_server/get_type_descriptionRequest 131 | rq/fibonacci/_action/cancel_goalRequest 132 | rq/fibonacci/_action/get_resultRequest 133 | rq/fibonacci/_action/send_goalRequest 134 | rq/listener/describe_parametersRequest 135 | rq/listener/get_parameter_typesRequest 136 | rq/listener/get_parametersRequest 137 | rq/listener/list_parametersRequest 138 | rq/listener/set_parametersRequest 139 | rq/listener/set_parameters_atomicallyRequest 140 | rq/listener/get_type_descriptionRequest 141 | rq/minimal_action_client/describe_parametersRequest 142 | rq/minimal_action_client/get_parameter_typesRequest 143 | rq/minimal_action_client/get_parametersRequest 144 | rq/minimal_action_client/list_parametersRequest 145 | rq/minimal_action_client/set_parametersRequest 146 | rq/minimal_action_client/set_parameters_atomicallyRequest 147 | rq/minimal_action_client/get_type_descriptionRequest 148 | rq/minimal_action_server/describe_parametersRequest 149 | rq/minimal_action_server/get_parameter_typesRequest 150 | rq/minimal_action_server/get_parametersRequest 151 | rq/minimal_action_server/list_parametersRequest 152 | rq/minimal_action_server/set_parametersRequest 153 | rq/minimal_action_server/set_parameters_atomicallyRequest 154 | rq/minimal_action_server/get_type_descriptionRequest 155 | rq/talker/describe_parametersRequest 156 | rq/talker/get_parameter_typesRequest 157 | rq/talker/get_parametersRequest 158 | rq/talker/list_parametersRequest 159 | rq/talker/set_parametersRequest 160 | rq/talker/set_parameters_atomicallyRequest 161 | rq/talker/get_type_descriptionRequest 162 | rr/add_two_intsReply 163 | rr/add_two_ints_client/describe_parametersReply 164 | rr/add_two_ints_client/get_parameter_typesReply 165 | rr/add_two_ints_client/get_parametersReply 166 | rr/add_two_ints_client/list_parametersReply 167 | rr/add_two_ints_client/set_parametersReply 168 | rr/add_two_ints_client/set_parameters_atomicallyReply 169 | rr/add_two_ints_client/get_type_descriptionReply 170 | rr/add_two_ints_server/describe_parametersReply 171 | rr/add_two_ints_server/get_parameter_typesReply 172 | rr/add_two_ints_server/get_parametersReply 173 | rr/add_two_ints_server/list_parametersReply 174 | rr/add_two_ints_server/set_parametersReply 175 | rr/add_two_ints_server/set_parameters_atomicallyReply 176 | rr/add_two_ints_server/get_type_descriptionReply 177 | rr/fibonacci/_action/cancel_goalReply 178 | rr/fibonacci/_action/get_resultReply 179 | rr/fibonacci/_action/send_goalReply 180 | rt/fibonacci/_action/feedback 181 | rt/fibonacci/_action/status 182 | rr/listener/describe_parametersReply 183 | rr/listener/get_parameter_typesReply 184 | rr/listener/get_parametersReply 185 | rr/listener/list_parametersReply 186 | rr/listener/set_parametersReply 187 | rr/listener/set_parameters_atomicallyReply 188 | rr/listener/get_type_descriptionReply 189 | rr/minimal_action_client/describe_parametersReply 190 | rr/minimal_action_client/get_parameter_typesReply 191 | rr/minimal_action_client/get_parametersReply 192 | rr/minimal_action_client/list_parametersReply 193 | rr/minimal_action_client/set_parametersReply 194 | rr/minimal_action_client/set_parameters_atomicallyReply 195 | rr/minimal_action_client/get_type_descriptionReply 196 | rr/minimal_action_server/describe_parametersReply 197 | rr/minimal_action_server/get_parameter_typesReply 198 | rr/minimal_action_server/get_parametersReply 199 | rr/minimal_action_server/list_parametersReply 200 | rr/minimal_action_server/set_parametersReply 201 | rr/minimal_action_server/set_parameters_atomicallyReply 202 | rr/minimal_action_server/get_type_descriptionReply 203 | rr/talker/describe_parametersReply 204 | rr/talker/get_parameter_typesReply 205 | rr/talker/get_parametersReply 206 | rr/talker/list_parametersReply 207 | rr/talker/set_parametersReply 208 | rr/talker/set_parameters_atomicallyReply 209 | rr/talker/get_type_descriptionReply 210 | rt/chatter 211 | rt/clock 212 | rt/parameter_events 213 | 214 | 215 | 216 | DENY 217 | 218 | 219 | 220 | -------------------------------------------------------------------------------- /src/policies/permissions/talker_listener/permissions.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | CN=/talker_listener/talker 5 | 6 | 2020-05-01T00:00:00 7 | 2030-05-01T00:00:00 8 | 9 | 10 | 11 | 0 12 | 13 | 14 | 15 | rq/talker/describe_parametersRequest 16 | rq/talker/get_parameter_typesRequest 17 | rq/talker/get_parametersRequest 18 | rq/talker/list_parametersRequest 19 | rq/talker/set_parametersRequest 20 | rq/talker/set_parameters_atomicallyRequest 21 | rq/talker/get_type_descriptionRequest 22 | rr/talker/describe_parametersReply 23 | rr/talker/get_parameter_typesReply 24 | rr/talker/get_parametersReply 25 | rr/talker/list_parametersReply 26 | rr/talker/set_parametersReply 27 | rr/talker/set_parameters_atomicallyReply 28 | rr/talker/get_type_descriptionReply 29 | rt/chatter 30 | rt/parameter_events 31 | rt/rosout 32 | 33 | 34 | 35 | 36 | rq/talker/describe_parametersRequest 37 | rq/talker/get_parameter_typesRequest 38 | rq/talker/get_parametersRequest 39 | rq/talker/list_parametersRequest 40 | rq/talker/set_parametersRequest 41 | rq/talker/set_parameters_atomicallyRequest 42 | rq/talker/get_type_descriptionRequest 43 | rr/talker/describe_parametersReply 44 | rr/talker/get_parameter_typesReply 45 | rr/talker/get_parametersReply 46 | rr/talker/list_parametersReply 47 | rr/talker/set_parametersReply 48 | rr/talker/set_parameters_atomicallyReply 49 | rr/talker/get_type_descriptionReply 50 | rt/clock 51 | rt/parameter_events 52 | 53 | 54 | 55 | DENY 56 | 57 | 58 | CN=/talker_listener/listener 59 | 60 | 2020-05-01T00:00:00 61 | 2030-05-01T00:00:00 62 | 63 | 64 | 65 | 0 66 | 67 | 68 | 69 | rq/listener/describe_parametersRequest 70 | rq/listener/get_parameter_typesRequest 71 | rq/listener/get_parametersRequest 72 | rq/listener/list_parametersRequest 73 | rq/listener/set_parametersRequest 74 | rq/listener/set_parameters_atomicallyRequest 75 | rq/listener/get_type_descriptionRequest 76 | rr/listener/describe_parametersReply 77 | rr/listener/get_parameter_typesReply 78 | rr/listener/get_parametersReply 79 | rr/listener/list_parametersReply 80 | rr/listener/set_parametersReply 81 | rr/listener/set_parameters_atomicallyReply 82 | rr/listener/get_type_descriptionReply 83 | rt/parameter_events 84 | rt/rosout 85 | 86 | 87 | 88 | 89 | rq/listener/describe_parametersRequest 90 | rq/listener/get_parameter_typesRequest 91 | rq/listener/get_parametersRequest 92 | rq/listener/list_parametersRequest 93 | rq/listener/set_parametersRequest 94 | rq/listener/set_parameters_atomicallyRequest 95 | rq/listener/get_type_descriptionRequest 96 | rr/listener/describe_parametersReply 97 | rr/listener/get_parameter_typesReply 98 | rr/listener/get_parametersReply 99 | rr/listener/list_parametersReply 100 | rr/listener/set_parametersReply 101 | rr/listener/set_parameters_atomicallyReply 102 | rr/listener/get_type_descriptionReply 103 | rt/chatter 104 | rt/clock 105 | rt/parameter_events 106 | 107 | 108 | 109 | DENY 110 | 111 | 112 | 113 | -------------------------------------------------------------------------------- /src/policies/policy_to_permissions.py: -------------------------------------------------------------------------------- 1 | # Copyright 2018 Open Source Robotics Foundation, Inc. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | import glob 16 | from pathlib import Path 17 | 18 | from lxml import etree 19 | 20 | from sros2.policy import ( 21 | get_policy_schema, 22 | get_transport_schema, 23 | get_transport_template, 24 | ) 25 | 26 | # Get paths 27 | policy_xsd_path = get_policy_schema('policy.xsd') 28 | permissions_xsl_path = get_transport_template('dds', 'permissions.xsl') 29 | permissions_xsd_path = get_transport_schema('dds', 'permissions.xsd') 30 | 31 | # Parse files 32 | policy_xsd = etree.XMLSchema(etree.parse(policy_xsd_path)) 33 | permissions_xsl = etree.XSLT(etree.parse(permissions_xsl_path)) 34 | permissions_xsd = etree.XMLSchema(etree.parse(permissions_xsd_path)) 35 | 36 | for policy_xml_path in glob.glob('*.policy.xml'): 37 | 38 | # Get policy 39 | policy_xml = etree.parse(policy_xml_path) 40 | policy_xml.xinclude() 41 | 42 | # Validate policy schema 43 | policy_xsd.assertValid(policy_xml) 44 | 45 | # Transform policy 46 | permissions_xml = permissions_xsl(policy_xml) 47 | 48 | # Validate permissions schema 49 | permissions_xsd.assertValid(permissions_xml) 50 | 51 | # Get permissions directory 52 | policy_name = Path(policy_xml_path).name 53 | index_of_dot = policy_name.index('.') 54 | policy_name = policy_name[:index_of_dot] 55 | permissions_dir = Path('permissions') / policy_name 56 | permissions_dir.mkdir(parents=True, exist_ok=True) 57 | 58 | # Output permissions 59 | permissions_xml_path = permissions_dir / 'permissions.xml' 60 | with open(permissions_xml_path, 'w') as f: 61 | f.write(etree.tostring(permissions_xml, pretty_print=True).decode()) 62 | -------------------------------------------------------------------------------- /src/policies/sample.policy.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 7 | 9 | 11 | 12 | 13 | 14 | 16 | 17 | fibonacci 18 | 19 | 20 | add_two_ints 21 | 22 | 23 | chatter 24 | 25 | 26 | 27 | 28 | 29 | 30 | -------------------------------------------------------------------------------- /src/policies/single_context.policy.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 9 | 11 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /src/policies/talker_listener.policy.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 10 | 11 | chatter 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 21 | 22 | chatter 23 | 24 | 25 | 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /src/ros2_practice/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.12) 2 | project(ros2_practice) 3 | 4 | # C++17の設定 5 | if(NOT CMAKE_CXX_STANDARD) 6 | set(CMAKE_CXX_STANDARD 17) 7 | set(CMAKE_CXX_STANDARD_REQUIRED ON) 8 | endif() 9 | 10 | # 依存パッケージ 11 | find_package(ament_cmake REQUIRED) 12 | find_package(rclcpp REQUIRED) 13 | find_package(sensor_msgs REQUIRED) 14 | find_package(cv_bridge REQUIRED) 15 | find_package(image_transport REQUIRED) 16 | find_package(OpenCV REQUIRED COMPONENTS highgui imgproc objdetect) 17 | find_package(PCL REQUIRED COMPONENTS common io filters) 18 | find_package(pcl_conversions REQUIRED) 19 | 20 | include_directories(${PCL_INCLUDE_DIRS}) 21 | link_directories(${PCL_LIBRARY_DIRS}) 22 | add_definitions(${PCL_DEFINITIONS}) 23 | 24 | # face_detectionノードのビルド設定 25 | add_executable(face_detection src/face_detection.cpp) 26 | ament_target_dependencies(face_detection 27 | "cv_bridge" 28 | "image_transport" 29 | "rclcpp" 30 | "sensor_msgs" 31 | ) 32 | target_link_libraries(face_detection 33 | opencv_highgui 34 | opencv_imgproc 35 | opencv_objdetect 36 | ) 37 | 38 | # voxel_grid_filterノードのビルド設定 39 | add_executable(voxel_grid_filter src/voxel_grid_filter.cpp) 40 | ament_target_dependencies(voxel_grid_filter 41 | "pcl_conversions" 42 | "rclcpp" 43 | "sensor_msgs" 44 | ) 45 | target_link_libraries(voxel_grid_filter 46 | pcl_common 47 | pcl_io 48 | pcl_filters 49 | ) 50 | 51 | install(TARGETS 52 | face_detection 53 | voxel_grid_filter 54 | DESTINATION lib/${PROJECT_NAME} 55 | ) 56 | 57 | install(DIRECTORY 58 | config 59 | DESTINATION share/${PROJECT_NAME} 60 | ) 61 | 62 | if(BUILD_TESTING) 63 | find_package(ament_lint_auto REQUIRED) 64 | set(ament_cmake_copyright_FOUND TRUE) 65 | set(ament_cmake_cpplint_FOUND TRUE) 66 | ament_lint_auto_find_test_dependencies() 67 | endif() 68 | 69 | ament_package() 70 | -------------------------------------------------------------------------------- /src/ros2_practice/package.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | ros2_practice 5 | 0.1.0 6 | 7 | Real robot and sensor programming examples 8 | 9 | Yutaka Kondo 10 | Apache License 2.0 11 | 12 | ament_cmake 13 | 14 | rclcpp 15 | sensor_msgs 16 | libopencv-dev 17 | cv_bridge 18 | image_transport 19 | libpcl-all-dev 20 | pcl_conversions 21 | 22 | ament_lint_auto 23 | ament_lint_common 24 | 25 | 26 | ament_cmake 27 | 28 | 29 | -------------------------------------------------------------------------------- /src/ros2_practice/src/face_detection.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2024 Yutaka Kondo 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include 16 | #include 17 | 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | 26 | const char * kWindowName = "Result"; 27 | const char * kClassifierPath = "haarcascade_frontalface_alt.xml"; 28 | 29 | class FaceDetection : public rclcpp::Node { 30 | public: 31 | FaceDetection() 32 | : Node("face_detection") 33 | { 34 | cv::namedWindow(kWindowName); 35 | // haarcascadeのXMLファイルへのパス 36 | std::string classifier_path = declare_parameter("classifier_path", 37 | kClassifierPath); 38 | 39 | // haarcascadeのXMLファイルの読み込みに失敗すると実行中断 40 | if (!classifier_.load(classifier_path)) { 41 | RCLCPP_ERROR(this->get_logger(), "%s not found", 42 | classifier_path.c_str()); 43 | std::abort(); 44 | } 45 | 46 | rmw_qos_profile_t qos = rmw_qos_profile_sensor_data; 47 | // 顔検出結果のトピック送信 48 | pub_ = image_transport::create_publisher(this, 49 | "face_detection_result", qos); 50 | // RealSenseカメラのカラー画像のトピック受信 51 | sub_ = image_transport::create_subscription(this, 52 | "/camera/camera/color/image_raw", 53 | std::bind(&FaceDetection::ImageCallback, this, 54 | std::placeholders::_1), "raw", qos); 55 | } 56 | 57 | ~FaceDetection() 58 | { 59 | cv::destroyWindow(kWindowName); 60 | } 61 | 62 | private: 63 | void ImageCallback( 64 | const sensor_msgs::msg::Image::ConstSharedPtr & msg) 65 | { 66 | cv_bridge::CvImagePtr cv_image; 67 | try { 68 | // sensor_msgs/Image型からcv::Mat型への変換 69 | cv_image = cv_bridge::toCvCopy(msg, msg->encoding); 70 | } catch (cv_bridge::Exception & e) { 71 | RCLCPP_ERROR(this->get_logger(), "%s", e.what()); 72 | return; 73 | } 74 | 75 | // 顔検出処理 76 | cv::Mat gray; 77 | cv::cvtColor(cv_image->image, gray, cv::COLOR_BGR2GRAY); 78 | cv::equalizeHist(gray, gray); 79 | std::vector faces; 80 | classifier_.detectMultiScale(gray, faces, 1.1, 2, 81 | 0 | cv::CASCADE_SCALE_IMAGE, cv::Size(30, 30)); 82 | for (auto face: faces) { 83 | // 顔検出領域を四角い枠で描画 84 | cv::rectangle(cv_image->image, face, cv::Scalar(255, 0, 0), 2); 85 | } 86 | 87 | // 顔検出結果のウィンドウ表示 88 | cv::imshow(kWindowName, cv_image->image); 89 | cv::waitKey(1); 90 | // cv::Mat型からsensor_msgs/Image型への変換と顔検出結果画像の送信 91 | pub_.publish(cv_image->toImageMsg()); 92 | } 93 | 94 | cv::CascadeClassifier classifier_; 95 | image_transport::Publisher pub_; 96 | image_transport::Subscriber sub_; 97 | }; 98 | 99 | int main(int argc, char * argv[]) 100 | { 101 | setvbuf(stdout, NULL, _IONBF, BUFSIZ); 102 | rclcpp::init(argc, argv); 103 | auto node = std::make_shared(); 104 | rclcpp::spin(node); 105 | rclcpp::shutdown(); 106 | 107 | return 0; 108 | } 109 | -------------------------------------------------------------------------------- /src/ros2_practice/src/voxel_grid_filter.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2024 Yutaka Kondo 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | 24 | class VoxelGridFilter : public rclcpp::Node { 25 | public: 26 | VoxelGridFilter() 27 | : Node("voxel_grid_filter") 28 | { 29 | // ボクセルグリッドフィルタリングのパラメータ読み込み 30 | leaf_size_ = declare_parameter("leaf_size", 0.05); 31 | RCLCPP_INFO(this->get_logger(), "leaf_size: %f", leaf_size_); 32 | 33 | rclcpp::QoS qos(rclcpp::KeepLast(1)); 34 | // 点群ダウンサンプリング結果のトピック送信 35 | pub_ = 36 | create_publisher( 37 | "filter_result", qos); 38 | // RealSenseカメラの点群のトピック受信 39 | sub_ = 40 | create_subscription( 41 | "/camera/camera/depth/color/points", qos, 42 | std::bind(&VoxelGridFilter::PointCloud2Callback, this, 43 | std::placeholders::_1)); 44 | } 45 | 46 | private: 47 | void PointCloud2Callback( 48 | const sensor_msgs::msg::PointCloud2::SharedPtr msg) 49 | { 50 | pcl::PointCloud::Ptr cloud( 51 | new pcl::PointCloud); 52 | pcl::fromROSMsg(*msg, *cloud); 53 | 54 | // ボクセルグリッドによる点群サンプリング処理 55 | pcl::VoxelGrid filter; 56 | filter.setInputCloud(cloud); 57 | filter.setLeafSize(leaf_size_, leaf_size_, leaf_size_); 58 | pcl::PointCloud::Ptr cloud_filtered( 59 | new pcl::PointCloud); 60 | filter.filter(*cloud_filtered); 61 | 62 | sensor_msgs::msg::PointCloud2::SharedPtr msg_filtered( 63 | new sensor_msgs::msg::PointCloud2); 64 | // pcl::PointCloud型からsensor_msgs/PointCloud2型への変換 65 | pcl::toROSMsg(*cloud_filtered, *msg_filtered); 66 | msg_filtered->header = msg->header; 67 | pub_->publish(*msg_filtered); 68 | } 69 | 70 | double leaf_size_; 71 | rclcpp::Publisher::SharedPtr pub_; 72 | rclcpp::Subscription::SharedPtr sub_; 73 | }; 74 | 75 | int main(int argc, char * argv[]) 76 | { 77 | setvbuf(stdout, NULL, _IONBF, BUFSIZ); 78 | rclcpp::init(argc, argv); 79 | auto node = std::make_shared(); 80 | rclcpp::spin(node); 81 | rclcpp::shutdown(); 82 | 83 | return 0; 84 | } 85 | --------------------------------------------------------------------------------