Skip to content
This repository was archived by the owner on Jan 28, 2023. It is now read-only.

Commit 83f288e

Browse files
authored
Merge pull request #59 from spiralray/dev/distribute_params_cpp
imprement Consai2r2ParametersClient library for C++ node
2 parents 4a2b4e3 + a649f19 commit 83f288e

2 files changed

Lines changed: 93 additions & 0 deletions

File tree

consai2r2_description/CMakeLists.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,15 @@ install(DIRECTORY
4646
DESTINATION share/${PROJECT_NAME}/
4747
)
4848

49+
install(DIRECTORY
50+
include
51+
DESTINATION .
52+
)
53+
54+
ament_export_include_directories(include)
55+
ament_export_dependencies(ament_cmake)
56+
ament_export_dependencies(python_cmake_module)
57+
4958
if(BUILD_TESTING)
5059
find_package(ament_lint_auto REQUIRED)
5160
# the following line skips the linter which checks for copyrights
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
// Copyright (c) 2019 SSL-Roots
2+
//
3+
// Permission is hereby granted, free of charge, to any person obtaining a copy
4+
// of this software and associated documentation files (the "Software"), to deal
5+
// in the Software without restriction, including without limitation the rights
6+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7+
// copies of the Software, and to permit persons to whom the Software is
8+
// furnished to do so, subject to the following conditions:
9+
//
10+
// The above copyright notice and this permission notice shall be included in
11+
// all copies or substantial portions of the Software.
12+
//
13+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
16+
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19+
// THE SOFTWARE.
20+
21+
#ifndef CONSAI2R2_DESCRIPTION__PARAMETERS_HPP_
22+
#define CONSAI2R2_DESCRIPTION__PARAMETERS_HPP_
23+
24+
#include <rclcpp/rclcpp.hpp>
25+
26+
#include <chrono>
27+
#include <memory>
28+
#include <stdexcept>
29+
#include <string>
30+
31+
using std::placeholders::_1;
32+
33+
34+
namespace consai2r2
35+
{
36+
37+
namespace description
38+
{
39+
40+
struct Parameters
41+
{
42+
public:
43+
int max_id;
44+
std::string our_side;
45+
std::string our_color;
46+
47+
Parameters()
48+
{
49+
max_id = 15;
50+
our_side = "left";
51+
our_color = "blue";
52+
}
53+
};
54+
55+
class ParametersClient
56+
{
57+
public:
58+
explicit ParametersClient(rclcpp::Node * node)
59+
: client(node, "consai2r2_description")
60+
{
61+
}
62+
63+
void get_parameters(consai2r2::description::Parameters * consai2r2_parameters)
64+
{
65+
if (!client.wait_for_service(std::chrono::seconds(5))) {
66+
throw std::runtime_error("Wait for service timed out");
67+
}
68+
auto parameters = client.get_parameters(
69+
{"max_id", "our_side", "our_color"});
70+
71+
consai2r2_parameters->max_id = parameters[0].as_int();
72+
consai2r2_parameters->our_side = parameters[1].as_string();
73+
consai2r2_parameters->our_color = parameters[2].as_string();
74+
}
75+
76+
private:
77+
rclcpp::SyncParametersClient client;
78+
};
79+
80+
} // namespace description
81+
82+
} // namespace consai2r2
83+
84+
#endif // CONSAI2R2_DESCRIPTION__PARAMETERS_HPP_

0 commit comments

Comments
 (0)