From e86d77a141abbd6feb2af12f423e9f4a895fb513 Mon Sep 17 00:00:00 2001 From: Kentaro Tanaka Date: Mon, 30 Dec 2019 14:25:28 +0900 Subject: [PATCH 1/3] imprement Consai2r2ParametersClient library for C++ node --- consai2r2_description/CMakeLists.txt | 8 ++ .../consai2r2_description/parameters.hpp | 73 +++++++++++++++++++ 2 files changed, 81 insertions(+) create mode 100644 consai2r2_description/include/consai2r2_description/parameters.hpp diff --git a/consai2r2_description/CMakeLists.txt b/consai2r2_description/CMakeLists.txt index 0e51968..7924d02 100644 --- a/consai2r2_description/CMakeLists.txt +++ b/consai2r2_description/CMakeLists.txt @@ -46,6 +46,14 @@ install(DIRECTORY DESTINATION share/${PROJECT_NAME}/ ) +install(DIRECTORY + include +) + +ament_export_include_directories(include) +ament_export_dependencies(ament_cmake) +ament_export_dependencies(python_cmake_module) + if(BUILD_TESTING) find_package(ament_lint_auto REQUIRED) # the following line skips the linter which checks for copyrights diff --git a/consai2r2_description/include/consai2r2_description/parameters.hpp b/consai2r2_description/include/consai2r2_description/parameters.hpp new file mode 100644 index 0000000..9d07969 --- /dev/null +++ b/consai2r2_description/include/consai2r2_description/parameters.hpp @@ -0,0 +1,73 @@ +// Copyright (c) 2019 SSL-Roots +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +#ifndef CONSAI2R2_DESCRIPTION__PARAMETERS_HPP_ +#define CONSAI2R2_DESCRIPTION__PARAMETERS_HPP_ + +#include + +#include +#include +#include +#include + +using std::placeholders::_1; + +struct Consai2r2Parameters +{ +public: + int max_id; + std::string our_side; + std::string our_color; + + Consai2r2Parameters() + { + max_id = 15; + our_side = "left"; + our_color = "blue"; + } +}; + +class Consai2r2ParametersClient +{ +public: + explicit Consai2r2ParametersClient(rclcpp::Node * node) + : client(node, "consai2r2_description") + { + } + + void get_parameters(Consai2r2Parameters * consai2r2_parameters) + { + if (!client.wait_for_service(std::chrono::seconds(5))) { + throw std::runtime_error("Wait for service timed out"); + } + auto parameters = client.get_parameters( + {"max_id", "our_side", "our_color"}); + + consai2r2_parameters->max_id = parameters[0].as_int(); + consai2r2_parameters->our_side = parameters[1].as_string(); + consai2r2_parameters->our_color = parameters[2].as_string(); + } + +private: + rclcpp::SyncParametersClient client; +}; + +#endif // CONSAI2R2_DESCRIPTION__PARAMETERS_HPP_ From eec2fcbc39ffa4f0879d8ff7fe36330694b6d776 Mon Sep 17 00:00:00 2001 From: Kentaro Tanaka Date: Tue, 31 Dec 2019 02:00:36 +0900 Subject: [PATCH 2/3] fix destination --- consai2r2_description/CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/consai2r2_description/CMakeLists.txt b/consai2r2_description/CMakeLists.txt index 7924d02..d388479 100644 --- a/consai2r2_description/CMakeLists.txt +++ b/consai2r2_description/CMakeLists.txt @@ -48,6 +48,7 @@ install(DIRECTORY install(DIRECTORY include + DESTINATION . ) ament_export_include_directories(include) From a649f19511ded612ba329b16ac1b1fe6240aa00a Mon Sep 17 00:00:00 2001 From: Kentaro Tanaka Date: Wed, 8 Jan 2020 00:12:31 +0900 Subject: [PATCH 3/3] add namespace and change class name --- .../consai2r2_description/parameters.hpp | 21 ++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/consai2r2_description/include/consai2r2_description/parameters.hpp b/consai2r2_description/include/consai2r2_description/parameters.hpp index 9d07969..a115c6a 100644 --- a/consai2r2_description/include/consai2r2_description/parameters.hpp +++ b/consai2r2_description/include/consai2r2_description/parameters.hpp @@ -30,14 +30,21 @@ using std::placeholders::_1; -struct Consai2r2Parameters + +namespace consai2r2 +{ + +namespace description +{ + +struct Parameters { public: int max_id; std::string our_side; std::string our_color; - Consai2r2Parameters() + Parameters() { max_id = 15; our_side = "left"; @@ -45,15 +52,15 @@ struct Consai2r2Parameters } }; -class Consai2r2ParametersClient +class ParametersClient { public: - explicit Consai2r2ParametersClient(rclcpp::Node * node) + explicit ParametersClient(rclcpp::Node * node) : client(node, "consai2r2_description") { } - void get_parameters(Consai2r2Parameters * consai2r2_parameters) + void get_parameters(consai2r2::description::Parameters * consai2r2_parameters) { if (!client.wait_for_service(std::chrono::seconds(5))) { throw std::runtime_error("Wait for service timed out"); @@ -70,4 +77,8 @@ class Consai2r2ParametersClient rclcpp::SyncParametersClient client; }; +} // namespace description + +} // namespace consai2r2 + #endif // CONSAI2R2_DESCRIPTION__PARAMETERS_HPP_