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

imprement Consai2r2ParametersClient library for C++ node #59

Merged
merged 3 commits into from
Aug 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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_