From acf06460ab0b2194c0b2e876357ea134743b70c6 Mon Sep 17 00:00:00 2001 From: mbsaloka Date: Tue, 18 Jun 2024 20:55:03 +0700 Subject: [PATCH 1/2] feat: add brake action grpc service --- CMakeLists.txt | 1 + .../config/grpc/call_data_brake_action.hpp | 45 +++++++++++++++ .../config/grpc/call_data_brake_action.cpp | 57 +++++++++++++++++++ src/akushon/config/grpc/config.cpp | 2 + 4 files changed, 105 insertions(+) create mode 100644 include/akushon/config/grpc/call_data_brake_action.hpp create mode 100644 src/akushon/config/grpc/call_data_brake_action.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 4662221..f90ebba 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -42,6 +42,7 @@ add_library(${PROJECT_NAME} SHARED "src/${PROJECT_NAME}/config/utils/config.cpp" "src/${PROJECT_NAME}/config/grpc/config.cpp" "src/${PROJECT_NAME}/config/grpc/call_data_base.cpp" + "src/${PROJECT_NAME}/config/grpc/call_data_brake_action.cpp" "src/${PROJECT_NAME}/config/grpc/call_data_get_config.cpp" "src/${PROJECT_NAME}/config/grpc/call_data_load_config.cpp" "src/${PROJECT_NAME}/config/grpc/call_data_save_config.cpp" diff --git a/include/akushon/config/grpc/call_data_brake_action.hpp b/include/akushon/config/grpc/call_data_brake_action.hpp new file mode 100644 index 0000000..2633f60 --- /dev/null +++ b/include/akushon/config/grpc/call_data_brake_action.hpp @@ -0,0 +1,45 @@ +// Copyright (c) 2024 Ichiro ITS +// +// 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 AKUSHON__CONFIG__GRPC__BRAKE_ACTION_HPP_ +#define AKUSHON__CONFIG__GRPC__BRAKE_ACTION_HPP_ + +#include "akushon/action/node/action_manager.hpp" +#include "akushon/config/grpc/call_data.hpp" + +namespace akushon +{ +class CallDataBrakeAction +: CallData +{ +public: + CallDataBrakeAction( + akushon_interfaces::proto::Config::AsyncService * service, grpc::ServerCompletionQueue * cq, + const std::string& path, const std::shared_ptr& action_manager); + +protected: + void AddNextToCompletionQueue() override; + void WaitForRequest() override; + void HandleRequest() override; + std::shared_ptr action_manager_; +}; +} // namespace akushon + +#endif // AKUSHON__CONFIG__GRPC__BRAKE_ACTION_HPP_ diff --git a/src/akushon/config/grpc/call_data_brake_action.cpp b/src/akushon/config/grpc/call_data_brake_action.cpp new file mode 100644 index 0000000..4c00d60 --- /dev/null +++ b/src/akushon/config/grpc/call_data_brake_action.cpp @@ -0,0 +1,57 @@ +// Copyright (c) 2024 Ichiro ITS +// +// 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. + +#include "akushon/config/grpc/call_data_brake_action.hpp" +#include "akushon/config/utils/config.hpp" +#include "nlohmann/json.hpp" +#include "rclcpp/rclcpp.hpp" + +namespace akushon +{ + +CallDataBrakeAction::CallDataBrakeAction( + akushon_interfaces::proto::Config::AsyncService * service, grpc::ServerCompletionQueue * cq, + const std::string& path, const std::shared_ptr& action_manager) +: CallData(service, cq, path), action_manager_(action_manager) +{ + Proceed(); +} + +void CallDataBrakeAction::AddNextToCompletionQueue() +{ + new CallDataBrakeAction(service_, cq_, path_, action_manager_); +} + +void CallDataBrakeAction::WaitForRequest() +{ + service_->RequestBrakeAction(&ctx_, &request_, &responder_, cq_, cq_, this); +} + +void CallDataBrakeAction::HandleRequest() +{ + try { + action_manager_->brake(); + RCLCPP_INFO(rclcpp::get_logger("BrakeAction"), "Action has been braked!"); + } catch (nlohmann::json::exception e) { + RCLCPP_ERROR(rclcpp::get_logger("BrakeAction"), e.what()); + } +} + +} // namespace akushon diff --git a/src/akushon/config/grpc/config.cpp b/src/akushon/config/grpc/config.cpp index f2315dc..d20f498 100644 --- a/src/akushon/config/grpc/config.cpp +++ b/src/akushon/config/grpc/config.cpp @@ -27,6 +27,7 @@ #include "akushon/config/utils/config.hpp" #include "rclcpp/rclcpp.hpp" +#include "akushon/config/grpc/call_data_brake_action.hpp" #include "akushon/config/grpc/call_data_get_config.hpp" #include "akushon/config/grpc/call_data_load_config.hpp" #include "akushon/config/grpc/call_data_save_config.hpp" @@ -68,6 +69,7 @@ void ConfigGrpc::Run(uint16_t port, const std::string& path, rclcpp::Node::Share exit(signum); }); async_server = std::thread([path, this, &node, &action_manager]() { + new CallDataBrakeAction(&service_, cq_.get(), path, action_manager); new CallDataGetConfig(&service_, cq_.get(), path); new CallDataSaveConfig(&service_, cq_.get(), path, action_manager); new CallDataPublishSetJoints(&service_, cq_.get(), path, node); From fe25f9678db7152669f535202aaec37109df3cf7 Mon Sep 17 00:00:00 2001 From: mbsaloka Date: Tue, 18 Jun 2024 23:08:03 +0700 Subject: [PATCH 2/2] fix: use angled brackets for external libraries --- src/akushon/config/grpc/call_data_brake_action.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/akushon/config/grpc/call_data_brake_action.cpp b/src/akushon/config/grpc/call_data_brake_action.cpp index 4c00d60..339d0fa 100644 --- a/src/akushon/config/grpc/call_data_brake_action.cpp +++ b/src/akushon/config/grpc/call_data_brake_action.cpp @@ -20,8 +20,9 @@ #include "akushon/config/grpc/call_data_brake_action.hpp" #include "akushon/config/utils/config.hpp" -#include "nlohmann/json.hpp" -#include "rclcpp/rclcpp.hpp" + +#include +#include namespace akushon {