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

Commit

Permalink
Merge pull request #59 from spiralray/dev/distribute_params_cpp
Browse files Browse the repository at this point in the history
imprement Consai2r2ParametersClient library for C++ node
  • Loading branch information
ShotaAk authored Aug 8, 2020
2 parents 4a2b4e3 + a649f19 commit 83f288e
Show file tree
Hide file tree
Showing 2 changed files with 93 additions and 0 deletions.
9 changes: 9 additions & 0 deletions consai2r2_description/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,15 @@ install(DIRECTORY
DESTINATION share/${PROJECT_NAME}/
)

install(DIRECTORY
include
DESTINATION .
)

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
Expand Down
84 changes: 84 additions & 0 deletions consai2r2_description/include/consai2r2_description/parameters.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
// 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 <rclcpp/rclcpp.hpp>

#include <chrono>
#include <memory>
#include <stdexcept>
#include <string>

using std::placeholders::_1;


namespace consai2r2
{

namespace description
{

struct Parameters
{
public:
int max_id;
std::string our_side;
std::string our_color;

Parameters()
{
max_id = 15;
our_side = "left";
our_color = "blue";
}
};

class ParametersClient
{
public:
explicit ParametersClient(rclcpp::Node * node)
: client(node, "consai2r2_description")
{
}

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");
}
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;
};

} // namespace description

} // namespace consai2r2

#endif // CONSAI2R2_DESCRIPTION__PARAMETERS_HPP_

0 comments on commit 83f288e

Please sign in to comment.