From b2b1d154f6c4224146e77e39fa89221ac85bd37b Mon Sep 17 00:00:00 2001 From: mbsaloka Date: Tue, 2 Apr 2024 00:54:35 +0700 Subject: [PATCH 01/31] feat: Synchronize with the add-configuration-capture-setting branch --- data/capture_settings.json | 8 ++++ src/shisen_cpp/camera/node/camera_node.cpp | 39 +++++++++++++++++++ src/shisen_cpp/config/grpc/call_data_base.cpp | 6 +++ .../grpc/call_data_get_capture_setting.cpp | 32 +++++++++++++++ src/shisen_cpp/node/shisen_cpp_node.cpp | 1 + src/shisen_cpp/utility/capture_setting.cpp | 2 +- 6 files changed, 87 insertions(+), 1 deletion(-) create mode 100644 data/capture_settings.json create mode 100644 src/shisen_cpp/config/grpc/call_data_base.cpp create mode 100644 src/shisen_cpp/config/grpc/call_data_get_capture_setting.cpp diff --git a/data/capture_settings.json b/data/capture_settings.json new file mode 100644 index 0000000..6620552 --- /dev/null +++ b/data/capture_settings.json @@ -0,0 +1,8 @@ +{ + "brightness": 115, + "contrast": 100, + "saturation": 185, + "temperature": 5280, + "exposure": 230, + "gain": 138 +} \ No newline at end of file diff --git a/src/shisen_cpp/camera/node/camera_node.cpp b/src/shisen_cpp/camera/node/camera_node.cpp index b285c6e..0e96e7b 100644 --- a/src/shisen_cpp/camera/node/camera_node.cpp +++ b/src/shisen_cpp/camera/node/camera_node.cpp @@ -20,6 +20,8 @@ #include +#include +#include #include #include #include @@ -230,4 +232,41 @@ void CameraNode::load_configuration(const std::string & path) configure_capture_setting(capture_setting); } +void CameraNode::load_configuration(const std::string & path) +{ + std::string ss = path + "capture_settings.json"; + + std::ifstream input(ss, std::ifstream::in); + if (!input.is_open()) { + throw std::runtime_error("Unable to open `" + ss + "`!"); + } + + nlohmann::json config = nlohmann::json::parse(input); + + CaptureSetting capture_setting; + + // Get all config + for (auto & item : config.items()) { + try { + if (item.key() == "brightness") { + capture_setting.brightness.set(item.value()); + } else if (item.key() == "contrast") { + capture_setting.contrast.set(item.value()); + } else if (item.key() == "saturation") { + capture_setting.saturation.set(item.value()); + } else if (item.key() == "temperature") { + capture_setting.temperature.set(item.value()); + } else if (item.key() == "exposure") { + capture_setting.exposure.set(item.value()); + } else if (item.key() == "gain") { + capture_setting.gain.set(item.value()); + } + } catch (nlohmann::json::parse_error & ex) { + throw std::runtime_error("Parse error at byte `" + std::to_string(ex.byte) + "`!"); + } + } + + configure_capture_setting(capture_setting); +} + } // namespace shisen_cpp::camera diff --git a/src/shisen_cpp/config/grpc/call_data_base.cpp b/src/shisen_cpp/config/grpc/call_data_base.cpp new file mode 100644 index 0000000..2fca89c --- /dev/null +++ b/src/shisen_cpp/config/grpc/call_data_base.cpp @@ -0,0 +1,6 @@ +#include "shisen_cpp/config/grpc/call_data_base.hpp" + +namespace shisen +{ + CallDataBase::CallDataBase() {} +} // namespace shisen diff --git a/src/shisen_cpp/config/grpc/call_data_get_capture_setting.cpp b/src/shisen_cpp/config/grpc/call_data_get_capture_setting.cpp new file mode 100644 index 0000000..38189e5 --- /dev/null +++ b/src/shisen_cpp/config/grpc/call_data_get_capture_setting.cpp @@ -0,0 +1,32 @@ +#include "shisen_cpp/config/grpc/call_data_get_capture_setting.hpp" + +#include "shisen_cpp/config/utils/config.hpp" +#include "aruku_interfaces/aruku.grpc.pb.h" +#include "aruku_interfaces/aruku.pb.h" +#include "rclcpp/rclcpp.hpp" + +namespace aruku +{ +CallDataGetConfig::CallDataGetConfig( + aruku_interfaces::proto::Config::AsyncService * service, grpc::ServerCompletionQueue * cq, + const std::string & path) +: CallData(service, cq, path) +{ + Proceed(); +} + +void CallDataGetConfig::AddNextToCompletionQueue() { new CallDataGetConfig(service_, cq_, path_); } + +void CallDataGetConfig::WaitForRequest() +{ + service_->RequestGetConfig(&ctx_, &request_, &responder_, cq_, cq_, this); +} + +void CallDataGetConfig::HandleRequest() +{ + Config config(path_); + reply_.set_json_kinematic(config.get_config("kinematic")); + reply_.set_json_walking(config.get_config("walking")); + RCLCPP_INFO(rclcpp::get_logger("Get config"), "config has been sent!"); +} +} // namespace aruku diff --git a/src/shisen_cpp/node/shisen_cpp_node.cpp b/src/shisen_cpp/node/shisen_cpp_node.cpp index 6ccdca6..48f6d54 100644 --- a/src/shisen_cpp/node/shisen_cpp_node.cpp +++ b/src/shisen_cpp/node/shisen_cpp_node.cpp @@ -31,6 +31,7 @@ ShisenCppNode::ShisenCppNode(rclcpp::Node::SharedPtr node, const std::string & p { auto image_provider = std::make_shared(options); auto camera_config_provider = std::make_shared(options); + camera_node->load_configuration(path); camera_node->set_provider(image_provider, camera_config_provider); camera_node->load_configuration(path); diff --git a/src/shisen_cpp/utility/capture_setting.cpp b/src/shisen_cpp/utility/capture_setting.cpp index 4bfc4cb..b12c436 100644 --- a/src/shisen_cpp/utility/capture_setting.cpp +++ b/src/shisen_cpp/utility/capture_setting.cpp @@ -119,4 +119,4 @@ void CaptureSetting::update_with(const CaptureSetting & capture_setting) } } -} // namespace shisen_cpp +} // namespace shisen_cpp \ No newline at end of file From ae95bb874e4d35eb55f4a0b9a727bd431ca692ab Mon Sep 17 00:00:00 2001 From: mbsaloka Date: Tue, 2 Apr 2024 23:19:21 +0700 Subject: [PATCH 02/31] feat: add grpc server code --- include/shisen_cpp/config/grpc/call_data.hpp | 87 +++++++++++++++++++ .../shisen_cpp/config/grpc/call_data_base.hpp | 19 ++++ .../grpc/call_data_get_capture_setting.hpp | 23 +++++ .../grpc/call_data_save_capture_setting.hpp | 25 ++++++ .../grpc/call_data_set_capture_setting.hpp | 27 ++++++ include/shisen_cpp/config/grpc/config.hpp | 53 +++++++++++ include/shisen_cpp/node/shisen_cpp_node.hpp | 3 + .../grpc/call_data_get_capture_setting.cpp | 39 ++++----- .../grpc/call_data_save_capture_setting.cpp | 39 +++++++++ .../grpc/call_data_set_capture_setting.cpp | 41 +++++++++ src/shisen_cpp/config/grpc/config.cpp | 67 ++++++++++++++ src/shisen_cpp/node/shisen_cpp_node.cpp | 4 + 12 files changed, 406 insertions(+), 21 deletions(-) create mode 100644 include/shisen_cpp/config/grpc/call_data.hpp create mode 100644 include/shisen_cpp/config/grpc/call_data_base.hpp create mode 100644 include/shisen_cpp/config/grpc/call_data_get_capture_setting.hpp create mode 100644 include/shisen_cpp/config/grpc/call_data_save_capture_setting.hpp create mode 100644 include/shisen_cpp/config/grpc/call_data_set_capture_setting.hpp create mode 100644 include/shisen_cpp/config/grpc/config.hpp create mode 100644 src/shisen_cpp/config/grpc/call_data_save_capture_setting.cpp create mode 100644 src/shisen_cpp/config/grpc/call_data_set_capture_setting.cpp create mode 100644 src/shisen_cpp/config/grpc/config.cpp diff --git a/include/shisen_cpp/config/grpc/call_data.hpp b/include/shisen_cpp/config/grpc/call_data.hpp new file mode 100644 index 0000000..6256511 --- /dev/null +++ b/include/shisen_cpp/config/grpc/call_data.hpp @@ -0,0 +1,87 @@ +// 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 __SHISEN_CPP__CONFIG__GRPC__CALL_DATA_HPP__ +#define __SHISEN_CPP__CONFIG__GRPC__CALL_DATA_HPP__ + +#include "shisen_cpp/config/grpc/call_data_base.hpp" +#include "shisen_interfaces/shisen.grpc.pb.h" +#include "shisen_interfaces/shisen.pb.h" +#include "grpc/support/log.h" +#include "grpcpp/grpcpp.h" + +namespace shisen +{ +template +class CallData : public CallDataBase +{ +public: + CallData( + shisen_interfaces::proto::Config::AsyncService * service, grpc::ServerCompletionQueue * cq, + const std::string path); + + void Proceed(); + +protected: + virtual void AddNextToCompletionQueue() = 0; + + enum CallStatus { CREATE, PROCESS, FINISH }; + + CallStatus status_; // The current serving state. + + shisen_interfaces::proto::Config::AsyncService * service_; + + const std::string path_; + + grpc::ServerCompletionQueue * cq_; + grpc::ServerContext ctx_; + ConfigRequest request_; + ConfigReply reply_; + grpc::ServerAsyncResponseWriter responder_; +}; + +template +CallData::CallData( + shisen_interfaces::proto::Config::AsyncService * service, grpc::ServerCompletionQueue * cq, + const std::string path) +: status_(CREATE), service_(service), cq_(cq), responder_(&ctx_), path_(path) +{ +} + +template +void CallData::Proceed() +{ + if (status_ == CREATE) { + status_ = PROCESS; + WaitForRequest(); + } else if (status_ == PROCESS) { + AddNextToCompletionQueue(); + HandleRequest(); + status_ = FINISH; + responder_.Finish(reply_, grpc::Status::OK, this); + } else { + GPR_ASSERT(status_ == FINISH); + delete this; + } +} + +} // namespace shisen + +#endif // __SHISEN_CPP__CONFIG__GRPC__CALL_DATA_HPP__ diff --git a/include/shisen_cpp/config/grpc/call_data_base.hpp b/include/shisen_cpp/config/grpc/call_data_base.hpp new file mode 100644 index 0000000..1f2298c --- /dev/null +++ b/include/shisen_cpp/config/grpc/call_data_base.hpp @@ -0,0 +1,19 @@ +#ifndef SHISEN_CPP__CONFIG__GRPC__CALL_DATA_BASE_HPP_ +#define SHISEN_CPP__CONFIG__GRPC__CALL_DATA_BASE_HPP_ + +namespace shisen +{ +class CallDataBase +{ +public: + CallDataBase(); + + virtual void Proceed() = 0; + +protected: + virtual void WaitForRequest() = 0; + virtual void HandleRequest() = 0; +}; +} // namespace shisen + +#endif // SHISEN_CPP__CONFIG__GRPC__CALL_DATA_BASE_HPP_ \ No newline at end of file diff --git a/include/shisen_cpp/config/grpc/call_data_get_capture_setting.hpp b/include/shisen_cpp/config/grpc/call_data_get_capture_setting.hpp new file mode 100644 index 0000000..2be6d21 --- /dev/null +++ b/include/shisen_cpp/config/grpc/call_data_get_capture_setting.hpp @@ -0,0 +1,23 @@ +#ifndef SHISEN_CPP__CONFIG__GRPC__CALL_DATA_GET_CAPTURE_SETTING_HPP__ +#define SHISEN_CPP__CONFIG__GRPC__CALL_DATA_GET_CAPTURE_SETTING_HPP__ + +#include "shisen_cpp/config/grpc/call_data.hpp" + +namespace shisen +{ +class CallDataGetCaptureSetting + : CallData + { + public: + CallDataGetCaptureSetting( + shisen_interfaces::proto::Config::AsyncService * service, grpc::ServerCompletionQueue * cq, + const std::string & path); + + protected: + void AddNextToCompletionQueue() override; + void WaitForRequest() ; + void HandleRequest() ; + }; +} // namespace shisen + +#endif // SHISEN_CPP__CONFIG__GRPC__CALL_DATA_GET_CAPTURE_SETTING_HPP__ diff --git a/include/shisen_cpp/config/grpc/call_data_save_capture_setting.hpp b/include/shisen_cpp/config/grpc/call_data_save_capture_setting.hpp new file mode 100644 index 0000000..e21e21a --- /dev/null +++ b/include/shisen_cpp/config/grpc/call_data_save_capture_setting.hpp @@ -0,0 +1,25 @@ +#ifndef SHISEN_CPP__CONFIG__GRPC__CALL_DATA_SAVE_CAPTURE_SETTING_HPP__ +#define SHISEN_CPP__CONFIG__GRPC__CALL_DATA_SAVE_CAPTURE_SETTING_HPP__ + +#include "shisen_cpp/config/grpc/call_data.hpp" +#include "rclcpp/rclcpp.hpp" + +namespace shisen +{ +class CallDataSaveCaptureSetting +: CallData +{ +public: + CallDataSaveCaptureSetting( + shisen_interfaces::proto::Config::AsyncService * service, grpc::ServerCompletionQueue * cq, + const std::string & path); + +protected: + void AddNextToCompletionQueue() override; + void WaitForRequest(); + void HandleRequest(); +}; + +} // namespace shisen + +#endif // SHISEN_CPP__CONFIG__GRPC__CALL_DATA_SAVE_CAPTURE_SETTING_HPP__ \ No newline at end of file diff --git a/include/shisen_cpp/config/grpc/call_data_set_capture_setting.hpp b/include/shisen_cpp/config/grpc/call_data_set_capture_setting.hpp new file mode 100644 index 0000000..40d1d76 --- /dev/null +++ b/include/shisen_cpp/config/grpc/call_data_set_capture_setting.hpp @@ -0,0 +1,27 @@ +#ifndef SHISEN_CPP_CONFIG__GRPC__CALL_DATA_SET_CAPTURE_SETTING_HPP__ +#define SHISEN_CPP_CONFIG__GRPC__CALL_DATA_SET_CAPTURE_SETTING_HPP__ + +#include "shisen_cpp/config/grpc/call_data.hpp" +#include "shisen_interfaces/msg/set_capture.hpp" +#include "rclcpp/rclcpp.hpp" + +namespace shisen +{ +class CallDataSetCaptureSetting +: CallData +{ +public: + CallDataSetCaptureSetting( + shisen_interfaces::proto::Config::AsyncService * service, grpc::ServerCompletionQueue * cq, + const std::string & path, rclcpp::Node::SharedPtr node); + +protected: + rclcpp::Node::SharedPtr node_; + rclcpp::Publisher::SharedPtr set_capture_publisher_; + void AddNextToCompletionQueue() override; + void WaitForRequest(); + void HandleRequest(); +}; +} // namespace shisen + +#endif // SHISEN_CPP__CONFIG__GRPC__CALL_DATA_SET_CAPTURE_SETTING_HPP__ \ No newline at end of file diff --git a/include/shisen_cpp/config/grpc/config.hpp b/include/shisen_cpp/config/grpc/config.hpp new file mode 100644 index 0000000..480b136 --- /dev/null +++ b/include/shisen_cpp/config/grpc/config.hpp @@ -0,0 +1,53 @@ +#ifndef SHISEN_CPP__CONFIG__GRPC__CONFIG_HPP_ +#define SHISEN_CPP__CONFIG__GRPC__CONFIG_HPP_ + +#include +#include +#include +#include +#include +#include +#include +#include + +#include "absl/flags/flag.h" +#include "absl/flags/parse.h" +#include "absl/strings/str_format.h" +#include "shisen_cpp/config/grpc/call_data.hpp" +#include "shisen_cpp/config/grpc/call_data_base.hpp" +// #include "shisen_cpp/walking/process/kinematic.hpp" +#include "shisen_interfaces/shisen.grpc.pb.h" +#include "shisen_interfaces/shisen.pb.h" +#include "shisen_interfaces/msg/set_capture.hpp" +#include "grpc/support/log.h" +#include "grpcpp/grpcpp.h" +#include "nlohmann/json.hpp" +#include "rclcpp/rclcpp.hpp" + +using shisen_interfaces::proto::Config; + +namespace shisen +{ +class ConfigGrpc +{ +public: + explicit ConfigGrpc(); + explicit ConfigGrpc(const std::string & path); + + ~ConfigGrpc(); + + void Run(uint16_t port, const std::string & path, rclcpp::Node::SharedPtr node); + +private: + std::string path; + static void SignIntHandler(int signum); + + static inline std::unique_ptr cq_; + static inline std::unique_ptr server_; + std::thread thread_; + shisen_interfaces::proto::Config::AsyncService service_; +}; + +} // namespace shisen + +#endif // SHISEN_CPP__CONFIG__GRPC__CONFIG_HPP_ diff --git a/include/shisen_cpp/node/shisen_cpp_node.hpp b/include/shisen_cpp/node/shisen_cpp_node.hpp index 7cdbc00..7ffcf17 100644 --- a/include/shisen_cpp/node/shisen_cpp_node.hpp +++ b/include/shisen_cpp/node/shisen_cpp_node.hpp @@ -24,6 +24,7 @@ #include #include +#include "shisen_cpp/config/grpc/config.hpp" #include "shisen_cpp/camera/node/camera_node.hpp" #include "../utility.hpp" @@ -40,6 +41,8 @@ class ShisenCppNode rclcpp::Node::SharedPtr node; rclcpp::TimerBase::SharedPtr node_timer; + ConfigGrpc config_grpc; + std::shared_ptr camera_node; }; diff --git a/src/shisen_cpp/config/grpc/call_data_get_capture_setting.cpp b/src/shisen_cpp/config/grpc/call_data_get_capture_setting.cpp index 38189e5..571e212 100644 --- a/src/shisen_cpp/config/grpc/call_data_get_capture_setting.cpp +++ b/src/shisen_cpp/config/grpc/call_data_get_capture_setting.cpp @@ -1,32 +1,29 @@ #include "shisen_cpp/config/grpc/call_data_get_capture_setting.hpp" #include "shisen_cpp/config/utils/config.hpp" -#include "aruku_interfaces/aruku.grpc.pb.h" -#include "aruku_interfaces/aruku.pb.h" +#include "shisen_interfaces/shisen.grpc.pb.h" +#include "shisen_interfaces/shisen.pb.h" #include "rclcpp/rclcpp.hpp" -namespace aruku -{ -CallDataGetConfig::CallDataGetConfig( - aruku_interfaces::proto::Config::AsyncService * service, grpc::ServerCompletionQueue * cq, - const std::string & path) -: CallData(service, cq, path) -{ - Proceed(); +namespace shisen { +CallDataGetCaptureSetting::CallDataGetCaptureSetting( + shisen_interfaces::proto::Config::AsyncService* service, + grpc::ServerCompletionQueue* cq, const std::string& path) + : CallData(service, cq, path) { + Proceed(); } -void CallDataGetConfig::AddNextToCompletionQueue() { new CallDataGetConfig(service_, cq_, path_); } +void CallDataGetCaptureSetting::AddNextToCompletionQueue() { + new CallDataGetCaptureSetting(service_, cq_, path_); +} -void CallDataGetConfig::WaitForRequest() -{ - service_->RequestGetConfig(&ctx_, &request_, &responder_, cq_, cq_, this); +void CallDataGetCaptureSetting::WaitForRequest() { + service_->RequestGetCaptureSetting(&ctx_, &request_, &responder_, cq_, cq_, this); } -void CallDataGetConfig::HandleRequest() -{ - Config config(path_); - reply_.set_json_kinematic(config.get_config("kinematic")); - reply_.set_json_walking(config.get_config("walking")); - RCLCPP_INFO(rclcpp::get_logger("Get config"), "config has been sent!"); +void CallDataGetCaptureSetting::HandleRequest() { + Config config(path_); + reply_.set_json_capture(config.get_config("capture")); + RCLCPP_INFO(rclcpp::get_logger("Get config"), "config has been sent!"); } -} // namespace aruku +} // namespace shisen diff --git a/src/shisen_cpp/config/grpc/call_data_save_capture_setting.cpp b/src/shisen_cpp/config/grpc/call_data_save_capture_setting.cpp new file mode 100644 index 0000000..4defd14 --- /dev/null +++ b/src/shisen_cpp/config/grpc/call_data_save_capture_setting.cpp @@ -0,0 +1,39 @@ +#include "shisen_cpp/config/grpc/call_data_save_capture_setting.hpp" + +#include "shisen_cpp/config/utils/config.hpp" +#include "shisen_interfaces/shisen.grpc.pb.h" +#include "shisen_interfaces/shisen.pb.h" +#include "rclcpp/rclcpp.hpp" + +namespace shisen +{ +CallDataSaveCaptureSetting::CallDataSaveCaptureSetting( + shisen_interfaces::proto::Config::AsyncService * service, grpc::ServerCompletionQueue * cq, + const std::string & path) +: CallData(service, cq, path) +{ + Proceed(); +} + +void CallDataSaveCaptureSetting::AddNextToCompletionQueue() +{ + new CallDataSaveCaptureSetting(service_, cq_, path_); +} + +void CallDataSaveCaptureSetting::WaitForRequest() +{ + service_->RequestSaveConfig(&ctx_, &request_, &responder_, cq_, cq_, this); +} + +void CallDataSaveCaptureSetting::HandleRequest() +{ + Config config(path_); + try { + nlohmann::json capture_data = nlohmann::json::parse(request_.json_capture()); + config.save_config(capture_data); + RCLCPP_INFO(rclcpp::get_logger("Save config"), " config has been saved! "); + } catch (nlohmann::json::exception e) { + RCLCPP_ERROR(rclcpp::get_logger("Save config"), e.what()); + } +} +} // namespace shisen \ No newline at end of file diff --git a/src/shisen_cpp/config/grpc/call_data_set_capture_setting.cpp b/src/shisen_cpp/config/grpc/call_data_set_capture_setting.cpp new file mode 100644 index 0000000..fd4d34b --- /dev/null +++ b/src/shisen_cpp/config/grpc/call_data_set_capture_setting.cpp @@ -0,0 +1,41 @@ +#include "shisen_cpp/config/grpc/call_data_set_capture_setting.hpp" + +#include "shisen_cpp/config/utils/config.hpp" +#include "shisen_interfaces/shisen.grpc.pb.h" +#include "shisen_interfaces/shisen.pb.h" +#include "rclcpp/rclcpp.hpp" + +namespace shisen +{ +CallDataSetCaptureSetting::CallDataSetCaptureSetting( + shisen_interfaces::proto::Config::AsyncService * service, grpc::ServerCompletionQueue * cq, + const std::string & path, rclcpp::Node::SharedPtr node) +: CallData(service, cq, path), node_(node) +{ + set_capture_publisher_ = + node_->create_publisher("shisen_cpp/config/set_capture", 10); + Proceed(); +} + +void CallDataSetCaptureSetting::AddNextToCompletionQueue() +{ + new CallDataSetCaptureSetting(service_, cq_, path_, node_); +} + +void CallDataSetCaptureSetting::WaitForRequest() +{ + service_->RequestPublishConfig(&ctx_, &request_, &responder_, cq_, cq_, this); +} + +void CallDataSetCaptureSetting::HandleRequest() +{ + try { + shisen_interfaces::msg::SetConfig msg; + msg.json_capture = request_.json_capture(); + set_capture_publisher_->publish(msg); + RCLCPP_INFO(rclcpp::get_logger("Publish config"), "config has been published! "); + } catch (nlohmann::json::exception e) { + RCLCPP_ERROR(rclcpp::get_logger("Publish config"), e.what()); + } +} +} // namespace shisen \ No newline at end of file diff --git a/src/shisen_cpp/config/grpc/config.cpp b/src/shisen_cpp/config/grpc/config.cpp new file mode 100644 index 0000000..513f650 --- /dev/null +++ b/src/shisen_cpp/config/grpc/config.cpp @@ -0,0 +1,67 @@ +// #include "aruku/config/utils/config.hpp" + +#include +#include +#include +#include + +#include "shisen_cpp/config/grpc/call_data_base.hpp" +#include "shisen_cpp/config/grpc/call_data_get_capture_setting.hpp" +#include "shisen_cpp/config/grpc/call_data_save_capture_setting.hpp" +#include "shisen_cpp/config/grpc/call_data_set_capture_setting.hpp" +#include "shisen_cpp/config/grpc/config.hpp" +#include "rclcpp/rclcpp.hpp" + +using grpc::ServerBuilder; +using namespace std::chrono_literals; + +namespace shisen +{ +ConfigGrpc::ConfigGrpc() {} +ConfigGrpc::ConfigGrpc(const std::string & path) : path(path) {} + +ConfigGrpc::~ConfigGrpc() +{ + server_->Shutdown(); + cq_->Shutdown(); +} + +void ConfigGrpc::SignIntHandler(int signum) +{ + server_->Shutdown(); + cq_->Shutdown(); + exit(signum); +} + +void ConfigGrpc::Run(uint16_t port, const std::string & path, rclcpp::Node::SharedPtr node) +{ + Config config(path); + std::string server_address = + absl::StrFormat("0.0.0.0:%d", config.get_grpc_config()["port"].get()); + + ServerBuilder builder; + builder.AddListeningPort(server_address, grpc::InsecureServerCredentials()); + builder.RegisterService(&service_); + + cq_ = builder.AddCompletionQueue(); + server_ = builder.BuildAndStart(); + std::cout << "Server listening on " << server_address << std::endl; + + signal(SIGINT, SignIntHandler); + thread_ = std::thread([&path, &node, this]() { + new CallDataGetCaptureSetting(&service_, cq_.get(), path); + new CallDataSaveCaptureSetting(&service_, cq_.get(), path); + new CallDataSetCaptureSetting(&service_, cq_.get(), path, node); + void * tag; // uniquely identifies a request. + bool ok = true; + while (true) { + this->cq_->Next(&tag, &ok); + if (ok) { + static_cast(tag)->Proceed(); + } + } + }); + std::this_thread::sleep_for(200ms); +} + +} // namespace shisen diff --git a/src/shisen_cpp/node/shisen_cpp_node.cpp b/src/shisen_cpp/node/shisen_cpp_node.cpp index 48f6d54..7a10ce1 100644 --- a/src/shisen_cpp/node/shisen_cpp_node.cpp +++ b/src/shisen_cpp/node/shisen_cpp_node.cpp @@ -19,6 +19,7 @@ // THE SOFTWARE. #include +#include "shisen_cpp/config/grpc/config.hpp" #include @@ -41,6 +42,9 @@ ShisenCppNode::ShisenCppNode(rclcpp::Node::SharedPtr node, const std::string & p camera_node->update(); } ); + + config_grpc.Run(5050, path, node); + RCLCPP_INFO(rclcpp::get_logger("GrpcServers"), "grpc running"); } ShisenCppNode::~ShisenCppNode() From 61fffc398f7375e70eb8a1d78e1e8ab7cdd242f3 Mon Sep 17 00:00:00 2001 From: mbsaloka Date: Tue, 2 Apr 2024 23:28:01 +0700 Subject: [PATCH 03/31] feat: update cmakelists files with grpc dependencies --- CMakeLists.txt | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 906aba4..1b85d80 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -22,6 +22,8 @@ find_package(rclcpp REQUIRED) find_package(shisen_interfaces REQUIRED) find_package(sensor_msgs REQUIRED) find_package(std_msgs REQUIRED) +find_package(Protobuf CONFIG REQUIRED) +message(STATUS "Using protobuf ${Protobuf_VERSION}") install(DIRECTORY "include" DESTINATION ".") @@ -33,21 +35,35 @@ add_library(${PROJECT_NAME} SHARED "src/${PROJECT_NAME}/utility/interface.cpp" "src/${PROJECT_NAME}/node/shisen_cpp_node.cpp" "src/${PROJECT_NAME}/viewer/consumer/image_consumer.cpp" - "src/${PROJECT_NAME}/viewer/node/viewer_node.cpp") + "src/${PROJECT_NAME}/viewer/node/viewer_node.cpp" + "src/${PROJECT_NAME}/config/grpc/config.cpp" + "src/${PROJECT_NAME}/config/grpc/call_data_base.cpp" + "src/${PROJECT_NAME}/config/grpc/call_data_get_capture_setting.cpp" + "src/${PROJECT_NAME}/config/grpc/call_data_set_capture_setting.cpp" + "src/${PROJECT_NAME}/config/grpc/call_data_save_capture_setting.cpp" +) target_include_directories(${PROJECT_NAME} PUBLIC + $ $ $) ament_target_dependencies(${PROJECT_NAME} keisan OpenCV rclcpp shisen_interfaces sensor_msgs cv_bridge std_msgs) +target_link_libraries(${PROJECT_NAME} + gRPC::grpc++_reflection + gRPC::grpc++ +) + install(TARGETS ${PROJECT_NAME} EXPORT export_${PROJECT_NAME} ARCHIVE DESTINATION "lib" LIBRARY DESTINATION "lib" RUNTIME DESTINATION "bin") +target_compile_options(${PROJECT_NAME} PRIVATE -fPIC) + add_executable(camera "src/shisen_cpp_main.cpp") target_include_directories(camera PUBLIC $ From 97c49122111c34e1c522a7b96ba3a28b72ca1ec6 Mon Sep 17 00:00:00 2001 From: mbsaloka Date: Thu, 4 Apr 2024 18:46:19 +0700 Subject: [PATCH 04/31] fix: fixing grpc code and implement adjusted proto --- CMakeLists.txt | 1 + data/grpc.json | 3 ++ include/shisen_cpp/config/grpc/call_data.hpp | 4 +- .../shisen_cpp/config/grpc/call_data_base.hpp | 4 +- .../grpc/call_data_get_capture_setting.hpp | 28 +++++----- .../grpc/call_data_save_capture_setting.hpp | 6 +-- .../grpc/call_data_set_capture_setting.hpp | 10 ++-- include/shisen_cpp/config/grpc/config.hpp | 7 +-- include/shisen_cpp/config/utils/config.hpp | 28 ++++++++++ include/shisen_cpp/node/shisen_cpp_node.hpp | 6 ++- src/shisen_cpp/config/grpc/call_data_base.cpp | 6 +-- .../grpc/call_data_get_capture_setting.cpp | 33 +++++++----- .../grpc/call_data_save_capture_setting.cpp | 11 ++-- .../grpc/call_data_set_capture_setting.cpp | 53 ++++++++++++++++--- src/shisen_cpp/config/grpc/config.cpp | 6 +-- src/shisen_cpp/config/utils/config.cpp | 39 ++++++++++++++ 16 files changed, 181 insertions(+), 64 deletions(-) create mode 100644 data/grpc.json create mode 100644 include/shisen_cpp/config/utils/config.hpp create mode 100644 src/shisen_cpp/config/utils/config.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 1b85d80..0cf32e5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -28,6 +28,7 @@ message(STATUS "Using protobuf ${Protobuf_VERSION}") install(DIRECTORY "include" DESTINATION ".") add_library(${PROJECT_NAME} SHARED + "src/${PROJECT_NAME}/config/utils/config.cpp" "src/${PROJECT_NAME}/camera/node/camera_node.cpp" "src/${PROJECT_NAME}/camera/provider/camera_config_provider.cpp" "src/${PROJECT_NAME}/camera/provider/image_provider.cpp" diff --git a/data/grpc.json b/data/grpc.json new file mode 100644 index 0000000..01fbcef --- /dev/null +++ b/data/grpc.json @@ -0,0 +1,3 @@ +{ + "port": 5757 +} \ No newline at end of file diff --git a/include/shisen_cpp/config/grpc/call_data.hpp b/include/shisen_cpp/config/grpc/call_data.hpp index 6256511..63078d1 100644 --- a/include/shisen_cpp/config/grpc/call_data.hpp +++ b/include/shisen_cpp/config/grpc/call_data.hpp @@ -27,7 +27,7 @@ #include "grpc/support/log.h" #include "grpcpp/grpcpp.h" -namespace shisen +namespace shisen_cpp { template class CallData : public CallDataBase @@ -82,6 +82,6 @@ void CallData::Proceed() } } -} // namespace shisen +} // namespace shisen_cpp #endif // __SHISEN_CPP__CONFIG__GRPC__CALL_DATA_HPP__ diff --git a/include/shisen_cpp/config/grpc/call_data_base.hpp b/include/shisen_cpp/config/grpc/call_data_base.hpp index 1f2298c..1a131fa 100644 --- a/include/shisen_cpp/config/grpc/call_data_base.hpp +++ b/include/shisen_cpp/config/grpc/call_data_base.hpp @@ -1,7 +1,7 @@ #ifndef SHISEN_CPP__CONFIG__GRPC__CALL_DATA_BASE_HPP_ #define SHISEN_CPP__CONFIG__GRPC__CALL_DATA_BASE_HPP_ -namespace shisen +namespace shisen_cpp { class CallDataBase { @@ -14,6 +14,6 @@ class CallDataBase virtual void WaitForRequest() = 0; virtual void HandleRequest() = 0; }; -} // namespace shisen +} // namespace shisen_cpp #endif // SHISEN_CPP__CONFIG__GRPC__CALL_DATA_BASE_HPP_ \ No newline at end of file diff --git a/include/shisen_cpp/config/grpc/call_data_get_capture_setting.hpp b/include/shisen_cpp/config/grpc/call_data_get_capture_setting.hpp index 2be6d21..8296368 100644 --- a/include/shisen_cpp/config/grpc/call_data_get_capture_setting.hpp +++ b/include/shisen_cpp/config/grpc/call_data_get_capture_setting.hpp @@ -3,21 +3,21 @@ #include "shisen_cpp/config/grpc/call_data.hpp" -namespace shisen +namespace shisen_cpp { class CallDataGetCaptureSetting - : CallData - { - public: - CallDataGetCaptureSetting( - shisen_interfaces::proto::Config::AsyncService * service, grpc::ServerCompletionQueue * cq, - const std::string & path); +: CallData +{ +public: + CallDataGetCaptureSetting( + shisen_interfaces::proto::Config::AsyncService * service, grpc::ServerCompletionQueue * cq, + const std::string & path); - protected: - void AddNextToCompletionQueue() override; - void WaitForRequest() ; - void HandleRequest() ; - }; -} // namespace shisen +protected: + void AddNextToCompletionQueue() override; + void WaitForRequest(); + void HandleRequest(); +}; +} // namespace shisen_cpp -#endif // SHISEN_CPP__CONFIG__GRPC__CALL_DATA_GET_CAPTURE_SETTING_HPP__ +#endif // SHISEN_CPP__CONFIG__GRPC__CALL_DATA_GET_CAPTURE_SETTING_HPP__ diff --git a/include/shisen_cpp/config/grpc/call_data_save_capture_setting.hpp b/include/shisen_cpp/config/grpc/call_data_save_capture_setting.hpp index e21e21a..ff6750c 100644 --- a/include/shisen_cpp/config/grpc/call_data_save_capture_setting.hpp +++ b/include/shisen_cpp/config/grpc/call_data_save_capture_setting.hpp @@ -4,10 +4,10 @@ #include "shisen_cpp/config/grpc/call_data.hpp" #include "rclcpp/rclcpp.hpp" -namespace shisen +namespace shisen_cpp { class CallDataSaveCaptureSetting -: CallData +: CallData { public: CallDataSaveCaptureSetting( @@ -20,6 +20,6 @@ class CallDataSaveCaptureSetting void HandleRequest(); }; -} // namespace shisen +} // namespace shisen_cpp #endif // SHISEN_CPP__CONFIG__GRPC__CALL_DATA_SAVE_CAPTURE_SETTING_HPP__ \ No newline at end of file diff --git a/include/shisen_cpp/config/grpc/call_data_set_capture_setting.hpp b/include/shisen_cpp/config/grpc/call_data_set_capture_setting.hpp index 40d1d76..2070b4f 100644 --- a/include/shisen_cpp/config/grpc/call_data_set_capture_setting.hpp +++ b/include/shisen_cpp/config/grpc/call_data_set_capture_setting.hpp @@ -2,10 +2,10 @@ #define SHISEN_CPP_CONFIG__GRPC__CALL_DATA_SET_CAPTURE_SETTING_HPP__ #include "shisen_cpp/config/grpc/call_data.hpp" -#include "shisen_interfaces/msg/set_capture.hpp" +#include "shisen_interfaces/msg/capture_setting.hpp" #include "rclcpp/rclcpp.hpp" -namespace shisen +namespace shisen_cpp { class CallDataSetCaptureSetting : CallData @@ -16,12 +16,12 @@ class CallDataSetCaptureSetting const std::string & path, rclcpp::Node::SharedPtr node); protected: - rclcpp::Node::SharedPtr node_; - rclcpp::Publisher::SharedPtr set_capture_publisher_; void AddNextToCompletionQueue() override; void WaitForRequest(); void HandleRequest(); + rclcpp::Node::SharedPtr node_; + rclcpp::Publisher::SharedPtr set_capture_publisher_; }; -} // namespace shisen +} // namespace shisen_cpp #endif // SHISEN_CPP__CONFIG__GRPC__CALL_DATA_SET_CAPTURE_SETTING_HPP__ \ No newline at end of file diff --git a/include/shisen_cpp/config/grpc/config.hpp b/include/shisen_cpp/config/grpc/config.hpp index 480b136..4f878b3 100644 --- a/include/shisen_cpp/config/grpc/config.hpp +++ b/include/shisen_cpp/config/grpc/config.hpp @@ -18,7 +18,8 @@ // #include "shisen_cpp/walking/process/kinematic.hpp" #include "shisen_interfaces/shisen.grpc.pb.h" #include "shisen_interfaces/shisen.pb.h" -#include "shisen_interfaces/msg/set_capture.hpp" +#include "shisen_interfaces/msg/capture_setting.hpp" +#include "shisen_interfaces/msg/camera_config.hpp" #include "grpc/support/log.h" #include "grpcpp/grpcpp.h" #include "nlohmann/json.hpp" @@ -26,7 +27,7 @@ using shisen_interfaces::proto::Config; -namespace shisen +namespace shisen_cpp { class ConfigGrpc { @@ -48,6 +49,6 @@ class ConfigGrpc shisen_interfaces::proto::Config::AsyncService service_; }; -} // namespace shisen +} // namespace shisen_cpp #endif // SHISEN_CPP__CONFIG__GRPC__CONFIG_HPP_ diff --git a/include/shisen_cpp/config/utils/config.hpp b/include/shisen_cpp/config/utils/config.hpp new file mode 100644 index 0000000..0ba3d88 --- /dev/null +++ b/include/shisen_cpp/config/utils/config.hpp @@ -0,0 +1,28 @@ +#ifndef SHISEN_CPP__CONFIG__UTILS__CONFIG_HPP_ +#define SHISEN_CPP__CONFIG__UTILS__CONFIG_HPP_ + +#include +#include +#include + +#include "nlohmann/json.hpp" + +namespace shisen_cpp +{ + +class Config +{ +public: + explicit Config(const std::string & path); + + std::string get_capture_setting(const std::string & key) const; + void save_capture_setting(const nlohmann::json & capture_data); + nlohmann::json get_grpc_config() const; + +private: + std::string path; +}; + +} // namespace shisen_cpp + +#endif // SHISEN_CPP__CONFIG__UTILS__CONFIG_HPP_ diff --git a/include/shisen_cpp/node/shisen_cpp_node.hpp b/include/shisen_cpp/node/shisen_cpp_node.hpp index 7ffcf17..1599034 100644 --- a/include/shisen_cpp/node/shisen_cpp_node.hpp +++ b/include/shisen_cpp/node/shisen_cpp_node.hpp @@ -24,6 +24,7 @@ #include #include +#include "shisen_cpp/config/utils/config.hpp" #include "shisen_cpp/config/grpc/config.hpp" #include "shisen_cpp/camera/node/camera_node.hpp" #include "../utility.hpp" @@ -34,7 +35,8 @@ namespace shisen_cpp class ShisenCppNode { public: - explicit ShisenCppNode(rclcpp::Node::SharedPtr node, const std::string & path, const Options & options = Options()); + explicit ShisenCppNode( + rclcpp::Node::SharedPtr node, const std::string & path, const Options & options = Options()); ~ShisenCppNode(); private: @@ -43,7 +45,7 @@ class ShisenCppNode ConfigGrpc config_grpc; - std::shared_ptr camera_node; + std::shared_ptr camera_node; }; } // namespace shisen_cpp diff --git a/src/shisen_cpp/config/grpc/call_data_base.cpp b/src/shisen_cpp/config/grpc/call_data_base.cpp index 2fca89c..84647c9 100644 --- a/src/shisen_cpp/config/grpc/call_data_base.cpp +++ b/src/shisen_cpp/config/grpc/call_data_base.cpp @@ -1,6 +1,6 @@ #include "shisen_cpp/config/grpc/call_data_base.hpp" -namespace shisen +namespace shisen_cpp { - CallDataBase::CallDataBase() {} -} // namespace shisen +CallDataBase::CallDataBase() {} +} // namespace shisen_cpp diff --git a/src/shisen_cpp/config/grpc/call_data_get_capture_setting.cpp b/src/shisen_cpp/config/grpc/call_data_get_capture_setting.cpp index 571e212..3468056 100644 --- a/src/shisen_cpp/config/grpc/call_data_get_capture_setting.cpp +++ b/src/shisen_cpp/config/grpc/call_data_get_capture_setting.cpp @@ -5,25 +5,30 @@ #include "shisen_interfaces/shisen.pb.h" #include "rclcpp/rclcpp.hpp" -namespace shisen { +namespace shisen_cpp +{ CallDataGetCaptureSetting::CallDataGetCaptureSetting( - shisen_interfaces::proto::Config::AsyncService* service, - grpc::ServerCompletionQueue* cq, const std::string& path) - : CallData(service, cq, path) { - Proceed(); + shisen_interfaces::proto::Config::AsyncService * service, grpc::ServerCompletionQueue * cq, + const std::string & path) +: CallData(service, cq, path) +{ + Proceed(); } -void CallDataGetCaptureSetting::AddNextToCompletionQueue() { - new CallDataGetCaptureSetting(service_, cq_, path_); +void CallDataGetCaptureSetting::AddNextToCompletionQueue() +{ + new CallDataGetCaptureSetting(service_, cq_, path_); } -void CallDataGetCaptureSetting::WaitForRequest() { - service_->RequestGetCaptureSetting(&ctx_, &request_, &responder_, cq_, cq_, this); +void CallDataGetCaptureSetting::WaitForRequest() +{ + service_->RequestGetCaptureSetting(&ctx_, &request_, &responder_, cq_, cq_, this); } -void CallDataGetCaptureSetting::HandleRequest() { - Config config(path_); - reply_.set_json_capture(config.get_config("capture")); - RCLCPP_INFO(rclcpp::get_logger("Get config"), "config has been sent!"); +void CallDataGetCaptureSetting::HandleRequest() +{ + Config config(path_); + reply_.set_json_capture(config.get_capture_setting("capture")); + RCLCPP_INFO(rclcpp::get_logger("Get config"), "config has been sent!"); } -} // namespace shisen +} // namespace shisen_cpp diff --git a/src/shisen_cpp/config/grpc/call_data_save_capture_setting.cpp b/src/shisen_cpp/config/grpc/call_data_save_capture_setting.cpp index 4defd14..9dd97a2 100644 --- a/src/shisen_cpp/config/grpc/call_data_save_capture_setting.cpp +++ b/src/shisen_cpp/config/grpc/call_data_save_capture_setting.cpp @@ -4,8 +4,9 @@ #include "shisen_interfaces/shisen.grpc.pb.h" #include "shisen_interfaces/shisen.pb.h" #include "rclcpp/rclcpp.hpp" +#include "nlohmann/json.hpp" -namespace shisen +namespace shisen_cpp { CallDataSaveCaptureSetting::CallDataSaveCaptureSetting( shisen_interfaces::proto::Config::AsyncService * service, grpc::ServerCompletionQueue * cq, @@ -22,7 +23,7 @@ void CallDataSaveCaptureSetting::AddNextToCompletionQueue() void CallDataSaveCaptureSetting::WaitForRequest() { - service_->RequestSaveConfig(&ctx_, &request_, &responder_, cq_, cq_, this); + service_->RequestSaveCaptureSetting(&ctx_, &request_, &responder_, cq_, cq_, this); } void CallDataSaveCaptureSetting::HandleRequest() @@ -30,10 +31,10 @@ void CallDataSaveCaptureSetting::HandleRequest() Config config(path_); try { nlohmann::json capture_data = nlohmann::json::parse(request_.json_capture()); - config.save_config(capture_data); + config.save_capture_setting(capture_data); RCLCPP_INFO(rclcpp::get_logger("Save config"), " config has been saved! "); - } catch (nlohmann::json::exception e) { + } catch (nlohmann::json::exception & e) { RCLCPP_ERROR(rclcpp::get_logger("Save config"), e.what()); } } -} // namespace shisen \ No newline at end of file +} // namespace shisen_cpp \ No newline at end of file diff --git a/src/shisen_cpp/config/grpc/call_data_set_capture_setting.cpp b/src/shisen_cpp/config/grpc/call_data_set_capture_setting.cpp index fd4d34b..901e1c1 100644 --- a/src/shisen_cpp/config/grpc/call_data_set_capture_setting.cpp +++ b/src/shisen_cpp/config/grpc/call_data_set_capture_setting.cpp @@ -5,15 +5,15 @@ #include "shisen_interfaces/shisen.pb.h" #include "rclcpp/rclcpp.hpp" -namespace shisen +namespace shisen_cpp { CallDataSetCaptureSetting::CallDataSetCaptureSetting( shisen_interfaces::proto::Config::AsyncService * service, grpc::ServerCompletionQueue * cq, const std::string & path, rclcpp::Node::SharedPtr node) : CallData(service, cq, path), node_(node) { - set_capture_publisher_ = - node_->create_publisher("shisen_cpp/config/set_capture", 10); + set_capture_publisher_ = node_->create_publisher( + "shisen_cpp/config/capture_setting", 10); Proceed(); } @@ -24,18 +24,55 @@ void CallDataSetCaptureSetting::AddNextToCompletionQueue() void CallDataSetCaptureSetting::WaitForRequest() { - service_->RequestPublishConfig(&ctx_, &request_, &responder_, cq_, cq_, this); + service_->RequestSetCaptureSetting(&ctx_, &request_, &responder_, cq_, cq_, this); } void CallDataSetCaptureSetting::HandleRequest() { + Config config(path_); try { - shisen_interfaces::msg::SetConfig msg; - msg.json_capture = request_.json_capture(); + int brightness = request_.brightness(); + int contrast = request_.contrast(); + int saturation = request_.saturation(); + int temperature = request_.temperature(); + int exposure = request_.exposure(); + int gain = request_.gain(); + + std::cout << "brightness: " << brightness << std::endl; + std::cout << "contrast: " << contrast << std::endl; + std::cout << "saturation: " << saturation << std::endl; + std::cout << "temperature: " << temperature << std::endl; + std::cout << "exposure: " << exposure << std::endl; + std::cout << "gain: " << gain << std::endl; + + shisen_interfaces::msg::CaptureSetting msg; + msg.brightness.clear(); + msg.contrast.clear(); + msg.saturation.clear(); + msg.temperature.clear(); + msg.exposure.clear(); + msg.gain.clear(); + + msg.brightness.push_back(brightness); + msg.contrast.push_back(contrast); + msg.saturation.push_back(saturation); + msg.temperature.push_back(temperature); + msg.exposure.push_back(exposure); + msg.gain.push_back(gain); + + // msg.brightness = brightness; + // msg.contrast = contrast; + // msg.saturation = saturation; + // msg.temperature = temperature; + // msg.exposure = exposure; + // msg.gain = gain; + set_capture_publisher_->publish(msg); - RCLCPP_INFO(rclcpp::get_logger("Publish config"), "config has been published! "); + RCLCPP_INFO( + rclcpp::get_logger("Publish capture setting config"), + "capture setting config has been saved!"); } catch (nlohmann::json::exception e) { RCLCPP_ERROR(rclcpp::get_logger("Publish config"), e.what()); } } -} // namespace shisen \ No newline at end of file +} // namespace shisen_cpp \ No newline at end of file diff --git a/src/shisen_cpp/config/grpc/config.cpp b/src/shisen_cpp/config/grpc/config.cpp index 513f650..9e4a671 100644 --- a/src/shisen_cpp/config/grpc/config.cpp +++ b/src/shisen_cpp/config/grpc/config.cpp @@ -1,4 +1,4 @@ -// #include "aruku/config/utils/config.hpp" +#include "shisen_cpp/config/utils/config.hpp" #include #include @@ -15,7 +15,7 @@ using grpc::ServerBuilder; using namespace std::chrono_literals; -namespace shisen +namespace shisen_cpp { ConfigGrpc::ConfigGrpc() {} ConfigGrpc::ConfigGrpc(const std::string & path) : path(path) {} @@ -64,4 +64,4 @@ void ConfigGrpc::Run(uint16_t port, const std::string & path, rclcpp::Node::Shar std::this_thread::sleep_for(200ms); } -} // namespace shisen +} // namespace shisen_cpp diff --git a/src/shisen_cpp/config/utils/config.cpp b/src/shisen_cpp/config/utils/config.cpp new file mode 100644 index 0000000..ae20b9c --- /dev/null +++ b/src/shisen_cpp/config/utils/config.cpp @@ -0,0 +1,39 @@ +#include "shisen_cpp/config/utils/config.hpp" + +#include +#include +#include + +#include "nlohmann/json.hpp" + +namespace shisen_cpp +{ +Config::Config(const std::string & path) : path(path) {} + +std::string Config::get_capture_setting(const std::string & key) const +{ + if (key == "capture") { + std::ifstream capture_file(path + "capture_settings.json"); + nlohmann::json capture_data = nlohmann::json::parse(capture_file); + return capture_data.dump(); + } + + return ""; +} + +nlohmann::json Config::get_grpc_config() const +{ + std::ifstream grpc_file(path + "grpc.json"); + nlohmann::json grpc_data = nlohmann::json::parse(grpc_file); + grpc_file.close(); + return grpc_data; +} + +void Config::save_capture_setting(const nlohmann::json & capture_data) +{ + std::ofstream capture_file(path + "capture_settings.json", std::ios::out | std::ios::trunc); + capture_file << std::setw(2) << capture_data << std::endl; + capture_file.close(); +} + +} // namespace shisen_cpp From a0f7409accbedb40183cdd154bfd8689d1317db1 Mon Sep 17 00:00:00 2001 From: mbsaloka Date: Thu, 4 Apr 2024 23:17:42 +0700 Subject: [PATCH 05/31] fix: change namespace shisen_cpp::camera --- include/shisen_cpp/node/shisen_cpp_node.hpp | 2 +- src/shisen_cpp/camera/node/camera_node.cpp | 39 +++++++------------ .../camera/provider/image_provider.cpp | 27 ++++--------- src/shisen_cpp/node/shisen_cpp_node.cpp | 13 ++----- 4 files changed, 27 insertions(+), 54 deletions(-) diff --git a/include/shisen_cpp/node/shisen_cpp_node.hpp b/include/shisen_cpp/node/shisen_cpp_node.hpp index 1599034..5e05a8f 100644 --- a/include/shisen_cpp/node/shisen_cpp_node.hpp +++ b/include/shisen_cpp/node/shisen_cpp_node.hpp @@ -45,7 +45,7 @@ class ShisenCppNode ConfigGrpc config_grpc; - std::shared_ptr camera_node; + std::shared_ptr camera_node; }; } // namespace shisen_cpp diff --git a/src/shisen_cpp/camera/node/camera_node.cpp b/src/shisen_cpp/camera/node/camera_node.cpp index 0e96e7b..998efbd 100644 --- a/src/shisen_cpp/camera/node/camera_node.cpp +++ b/src/shisen_cpp/camera/node/camera_node.cpp @@ -35,9 +35,7 @@ CameraNode::CameraNode(rclcpp::Node::SharedPtr node, const Options & options) { } -CameraNode::~CameraNode() -{ -} +CameraNode::~CameraNode() {} void CameraNode::update() { @@ -72,10 +70,7 @@ cv::Mat CameraNode::get_mat() return image_provider->get_mat(); } -const std::string & CameraNode::get_camera_prefix() const -{ - return options.camera_prefix; -} +const std::string & CameraNode::get_camera_prefix() const { return options.camera_prefix; } void CameraNode::set_provider( std::shared_ptr img_provider, @@ -86,8 +81,7 @@ void CameraNode::set_provider( // Initialize the image publisher { - image_publisher = node->create_publisher( - get_camera_prefix() + IMAGE_SUFFIX, 10); + image_publisher = node->create_publisher(get_camera_prefix() + IMAGE_SUFFIX, 10); RCLCPP_INFO_STREAM( node->get_logger(), @@ -100,13 +94,12 @@ void CameraNode::set_provider( // Initialize the camera config publisher { - camera_config_publisher = node->create_publisher( - get_camera_prefix() + CAMERA_CONFIG_SUFFIX, 10); + camera_config_publisher = + node->create_publisher(get_camera_prefix() + CAMERA_CONFIG_SUFFIX, 10); RCLCPP_INFO_STREAM( - node->get_logger(), - "Camera Config publisher initialized on `" << camera_config_publisher->get_topic_name() << - "`!"); + node->get_logger(), "Camera Config publisher initialized on `" + << camera_config_publisher->get_topic_name() << "`!"); } // Initialize the capture setting event publisher @@ -115,17 +108,17 @@ void CameraNode::set_provider( get_camera_prefix() + CAPTURE_SETTING_EVENT_SUFFIX, 10); RCLCPP_INFO_STREAM( - node->get_logger(), - "Capture setting event publisher initialized on `" << - capture_setting_event_publisher->get_topic_name() << "`!"); + node->get_logger(), "Capture setting event publisher initialized on `" + << capture_setting_event_publisher->get_topic_name() << "`!"); } // Initialize the configure capture setting service { configure_capture_setting_service = node->create_service( get_camera_prefix() + CONFIGURE_CAPTURE_SETTING_SUFFIX, - [this](ConfigureCaptureSetting::Request::SharedPtr request, - ConfigureCaptureSetting::Response::SharedPtr response) { + [this]( + ConfigureCaptureSetting::Request::SharedPtr request, + ConfigureCaptureSetting::Response::SharedPtr response) { // Configure capture setting if exist if (request->capture_setting.size() > 0) { configure_capture_setting(((CaptureSetting)request->capture_setting.front())); @@ -135,14 +128,12 @@ void CameraNode::set_provider( }); RCLCPP_INFO_STREAM( - node->get_logger(), - "Configure capture setting service initialized on `" << - configure_capture_setting_service->get_service_name() << "`!"); + node->get_logger(), "Configure capture setting service initialized on `" + << configure_capture_setting_service->get_service_name() << "`!"); } } -CaptureSetting CameraNode::on_configure_capture_setting( - const CaptureSetting & capture_setting) +CaptureSetting CameraNode::on_configure_capture_setting(const CaptureSetting & capture_setting) { auto new_capture_setting = capture_setting; diff --git a/src/shisen_cpp/camera/provider/image_provider.cpp b/src/shisen_cpp/camera/provider/image_provider.cpp index 4bf82f5..5c04049 100644 --- a/src/shisen_cpp/camera/provider/image_provider.cpp +++ b/src/shisen_cpp/camera/provider/image_provider.cpp @@ -28,7 +28,8 @@ namespace shisen_cpp::camera using Image = sensor_msgs::msg::Image; ImageProvider::ImageProvider(const Options & options) -: options(options), compression_quality(options.compression_quality), +: options(options), + compression_quality(options.compression_quality), video_capture(std::make_shared()) { // Try to open the camera @@ -40,14 +41,9 @@ ImageProvider::ImageProvider(const Options & options) video_capture->set(cv::CAP_PROP_FRAME_HEIGHT, options.height); } -ImageProvider::~ImageProvider() -{ -} +ImageProvider::~ImageProvider() {} -void ImageProvider::set_image(const Image & image) -{ - current_image_msg = image; -} +void ImageProvider::set_image(const Image & image) { current_image_msg = image; } void ImageProvider::update_mat() { @@ -76,19 +72,10 @@ void ImageProvider::set_mat(cv::Mat mat) set_image(*(ptr.toImageMsg())); } -const Image & ImageProvider::get_image() const -{ - return current_image_msg; -} +const Image & ImageProvider::get_image() const { return current_image_msg; } -cv::Mat ImageProvider::get_mat() const -{ - return (cv::Mat)current_mat_image; -} +cv::Mat ImageProvider::get_mat() const { return (cv::Mat)current_mat_image; } -std::shared_ptr ImageProvider::get_video_capture() const -{ - return video_capture; -} +std::shared_ptr ImageProvider::get_video_capture() const { return video_capture; } } // namespace shisen_cpp::camera diff --git a/src/shisen_cpp/node/shisen_cpp_node.cpp b/src/shisen_cpp/node/shisen_cpp_node.cpp index 7a10ce1..6b1eba8 100644 --- a/src/shisen_cpp/node/shisen_cpp_node.cpp +++ b/src/shisen_cpp/node/shisen_cpp_node.cpp @@ -27,7 +27,8 @@ namespace shisen_cpp { using namespace std::chrono_literals; -ShisenCppNode::ShisenCppNode(rclcpp::Node::SharedPtr node, const std::string & path, const Options & options) +ShisenCppNode::ShisenCppNode( + rclcpp::Node::SharedPtr node, const std::string & path, const Options & options) : node(node), camera_node(std::make_shared(node, options)) { auto image_provider = std::make_shared(options); @@ -37,18 +38,12 @@ ShisenCppNode::ShisenCppNode(rclcpp::Node::SharedPtr node, const std::string & p camera_node->load_configuration(path); node_timer = node->create_wall_timer( - 1s / camera_node->image_provider->options.capture_fps, - [this]() { - camera_node->update(); - } - ); + 1s / camera_node->image_provider->options.capture_fps, [this]() { camera_node->update(); }); config_grpc.Run(5050, path, node); RCLCPP_INFO(rclcpp::get_logger("GrpcServers"), "grpc running"); } -ShisenCppNode::~ShisenCppNode() -{ -} +ShisenCppNode::~ShisenCppNode() {} } // namespace shisen_cpp From b99c72572e27155ed6d74cd29844ead6122e2ce1 Mon Sep 17 00:00:00 2001 From: mbsaloka Date: Fri, 5 Apr 2024 01:59:42 +0700 Subject: [PATCH 06/31] fix: swap load_config and set_provider line --- src/shisen_cpp/node/shisen_cpp_node.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/shisen_cpp/node/shisen_cpp_node.cpp b/src/shisen_cpp/node/shisen_cpp_node.cpp index 6b1eba8..768b59a 100644 --- a/src/shisen_cpp/node/shisen_cpp_node.cpp +++ b/src/shisen_cpp/node/shisen_cpp_node.cpp @@ -33,7 +33,6 @@ ShisenCppNode::ShisenCppNode( { auto image_provider = std::make_shared(options); auto camera_config_provider = std::make_shared(options); - camera_node->load_configuration(path); camera_node->set_provider(image_provider, camera_config_provider); camera_node->load_configuration(path); From 8c21c154f2b0c61d6b325a307898aa277dbcad6d Mon Sep 17 00:00:00 2001 From: mbsaloka Date: Sat, 6 Apr 2024 16:16:41 +0700 Subject: [PATCH 07/31] fix: Fixed the save capture settings function --- data/capture_settings.json | 2 +- .../config/grpc/call_data_save_capture_setting.cpp | 7 ++++++- .../config/grpc/call_data_set_capture_setting.cpp | 2 +- src/shisen_cpp/node/shisen_cpp_node.cpp | 2 +- 4 files changed, 9 insertions(+), 4 deletions(-) diff --git a/data/capture_settings.json b/data/capture_settings.json index 6620552..ff91186 100644 --- a/data/capture_settings.json +++ b/data/capture_settings.json @@ -5,4 +5,4 @@ "temperature": 5280, "exposure": 230, "gain": 138 -} \ No newline at end of file +} diff --git a/src/shisen_cpp/config/grpc/call_data_save_capture_setting.cpp b/src/shisen_cpp/config/grpc/call_data_save_capture_setting.cpp index 9dd97a2..848e587 100644 --- a/src/shisen_cpp/config/grpc/call_data_save_capture_setting.cpp +++ b/src/shisen_cpp/config/grpc/call_data_save_capture_setting.cpp @@ -30,7 +30,12 @@ void CallDataSaveCaptureSetting::HandleRequest() { Config config(path_); try { - nlohmann::json capture_data = nlohmann::json::parse(request_.json_capture()); + // nlohmann::json capture_data = nlohmann::json::parse(request_.json_capture()); + + std::string json_string = request_.json_capture(); + std::replace(json_string.begin(), json_string.end(), '\\', ' '); + nlohmann::json capture_data = nlohmann::json::parse(json_string); + config.save_capture_setting(capture_data); RCLCPP_INFO(rclcpp::get_logger("Save config"), " config has been saved! "); } catch (nlohmann::json::exception & e) { diff --git a/src/shisen_cpp/config/grpc/call_data_set_capture_setting.cpp b/src/shisen_cpp/config/grpc/call_data_set_capture_setting.cpp index 901e1c1..94b1b8f 100644 --- a/src/shisen_cpp/config/grpc/call_data_set_capture_setting.cpp +++ b/src/shisen_cpp/config/grpc/call_data_set_capture_setting.cpp @@ -70,7 +70,7 @@ void CallDataSetCaptureSetting::HandleRequest() set_capture_publisher_->publish(msg); RCLCPP_INFO( rclcpp::get_logger("Publish capture setting config"), - "capture setting config has been saved!"); + "capture setting config has been applied!"); } catch (nlohmann::json::exception e) { RCLCPP_ERROR(rclcpp::get_logger("Publish config"), e.what()); } diff --git a/src/shisen_cpp/node/shisen_cpp_node.cpp b/src/shisen_cpp/node/shisen_cpp_node.cpp index 768b59a..2f9118b 100644 --- a/src/shisen_cpp/node/shisen_cpp_node.cpp +++ b/src/shisen_cpp/node/shisen_cpp_node.cpp @@ -39,7 +39,7 @@ ShisenCppNode::ShisenCppNode( node_timer = node->create_wall_timer( 1s / camera_node->image_provider->options.capture_fps, [this]() { camera_node->update(); }); - config_grpc.Run(5050, path, node); + config_grpc.Run(5757, path, node); RCLCPP_INFO(rclcpp::get_logger("GrpcServers"), "grpc running"); } From d3fae3579ea8c314c06637a9474fa52629c24767 Mon Sep 17 00:00:00 2001 From: mbsaloka Date: Wed, 17 Apr 2024 22:13:42 +0700 Subject: [PATCH 08/31] fix: fixed minor changes due to formatting failure --- include/shisen_cpp/node/shisen_cpp_node.hpp | 3 +- src/shisen_cpp/camera/node/camera_node.cpp | 42 +++++++++++-------- .../camera/provider/image_provider.cpp | 27 ++++++++---- src/shisen_cpp/node/shisen_cpp_node.cpp | 13 ++++-- src/shisen_cpp/utility/capture_setting.cpp | 2 +- src/shisen_cpp_main.cpp | 5 ++- 6 files changed, 60 insertions(+), 32 deletions(-) diff --git a/include/shisen_cpp/node/shisen_cpp_node.hpp b/include/shisen_cpp/node/shisen_cpp_node.hpp index 5e05a8f..ee1927a 100644 --- a/include/shisen_cpp/node/shisen_cpp_node.hpp +++ b/include/shisen_cpp/node/shisen_cpp_node.hpp @@ -35,8 +35,7 @@ namespace shisen_cpp class ShisenCppNode { public: - explicit ShisenCppNode( - rclcpp::Node::SharedPtr node, const std::string & path, const Options & options = Options()); + explicit ShisenCppNode(rclcpp::Node::SharedPtr node, const std::string & path, const Options & options = Options()); ~ShisenCppNode(); private: diff --git a/src/shisen_cpp/camera/node/camera_node.cpp b/src/shisen_cpp/camera/node/camera_node.cpp index 998efbd..b827136 100644 --- a/src/shisen_cpp/camera/node/camera_node.cpp +++ b/src/shisen_cpp/camera/node/camera_node.cpp @@ -18,13 +18,12 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. -#include - -#include #include #include #include #include +#include +#include #include namespace shisen_cpp::camera @@ -35,7 +34,9 @@ CameraNode::CameraNode(rclcpp::Node::SharedPtr node, const Options & options) { } -CameraNode::~CameraNode() {} +CameraNode::~CameraNode() +{ +} void CameraNode::update() { @@ -70,7 +71,10 @@ cv::Mat CameraNode::get_mat() return image_provider->get_mat(); } -const std::string & CameraNode::get_camera_prefix() const { return options.camera_prefix; } +const std::string & CameraNode::get_camera_prefix() const +{ + return options.camera_prefix; +} void CameraNode::set_provider( std::shared_ptr img_provider, @@ -81,7 +85,8 @@ void CameraNode::set_provider( // Initialize the image publisher { - image_publisher = node->create_publisher(get_camera_prefix() + IMAGE_SUFFIX, 10); + image_publisher = node->create_publisher( + get_camera_prefix() + IMAGE_SUFFIX, 10); RCLCPP_INFO_STREAM( node->get_logger(), @@ -94,12 +99,13 @@ void CameraNode::set_provider( // Initialize the camera config publisher { - camera_config_publisher = - node->create_publisher(get_camera_prefix() + CAMERA_CONFIG_SUFFIX, 10); + camera_config_publisher = node->create_publisher( + get_camera_prefix() + CAMERA_CONFIG_SUFFIX, 10); RCLCPP_INFO_STREAM( - node->get_logger(), "Camera Config publisher initialized on `" - << camera_config_publisher->get_topic_name() << "`!"); + node->get_logger(), + "Camera Config publisher initialized on `" << camera_config_publisher->get_topic_name() << + "`!"); } // Initialize the capture setting event publisher @@ -108,16 +114,16 @@ void CameraNode::set_provider( get_camera_prefix() + CAPTURE_SETTING_EVENT_SUFFIX, 10); RCLCPP_INFO_STREAM( - node->get_logger(), "Capture setting event publisher initialized on `" - << capture_setting_event_publisher->get_topic_name() << "`!"); + node->get_logger(), + "Capture setting event publisher initialized on `" << + capture_setting_event_publisher->get_topic_name() << "`!"); } // Initialize the configure capture setting service { configure_capture_setting_service = node->create_service( get_camera_prefix() + CONFIGURE_CAPTURE_SETTING_SUFFIX, - [this]( - ConfigureCaptureSetting::Request::SharedPtr request, + [this](ConfigureCaptureSetting::Request::SharedPtr request, ConfigureCaptureSetting::Response::SharedPtr response) { // Configure capture setting if exist if (request->capture_setting.size() > 0) { @@ -128,12 +134,14 @@ void CameraNode::set_provider( }); RCLCPP_INFO_STREAM( - node->get_logger(), "Configure capture setting service initialized on `" - << configure_capture_setting_service->get_service_name() << "`!"); + node->get_logger(), + "Configure capture setting service initialized on `" << + configure_capture_setting_service->get_service_name() << "`!"); } } -CaptureSetting CameraNode::on_configure_capture_setting(const CaptureSetting & capture_setting) +CaptureSetting CameraNode::on_configure_capture_setting( + const CaptureSetting & capture_setting) { auto new_capture_setting = capture_setting; diff --git a/src/shisen_cpp/camera/provider/image_provider.cpp b/src/shisen_cpp/camera/provider/image_provider.cpp index 5c04049..4bf82f5 100644 --- a/src/shisen_cpp/camera/provider/image_provider.cpp +++ b/src/shisen_cpp/camera/provider/image_provider.cpp @@ -28,8 +28,7 @@ namespace shisen_cpp::camera using Image = sensor_msgs::msg::Image; ImageProvider::ImageProvider(const Options & options) -: options(options), - compression_quality(options.compression_quality), +: options(options), compression_quality(options.compression_quality), video_capture(std::make_shared()) { // Try to open the camera @@ -41,9 +40,14 @@ ImageProvider::ImageProvider(const Options & options) video_capture->set(cv::CAP_PROP_FRAME_HEIGHT, options.height); } -ImageProvider::~ImageProvider() {} +ImageProvider::~ImageProvider() +{ +} -void ImageProvider::set_image(const Image & image) { current_image_msg = image; } +void ImageProvider::set_image(const Image & image) +{ + current_image_msg = image; +} void ImageProvider::update_mat() { @@ -72,10 +76,19 @@ void ImageProvider::set_mat(cv::Mat mat) set_image(*(ptr.toImageMsg())); } -const Image & ImageProvider::get_image() const { return current_image_msg; } +const Image & ImageProvider::get_image() const +{ + return current_image_msg; +} -cv::Mat ImageProvider::get_mat() const { return (cv::Mat)current_mat_image; } +cv::Mat ImageProvider::get_mat() const +{ + return (cv::Mat)current_mat_image; +} -std::shared_ptr ImageProvider::get_video_capture() const { return video_capture; } +std::shared_ptr ImageProvider::get_video_capture() const +{ + return video_capture; +} } // namespace shisen_cpp::camera diff --git a/src/shisen_cpp/node/shisen_cpp_node.cpp b/src/shisen_cpp/node/shisen_cpp_node.cpp index 2f9118b..604e7fa 100644 --- a/src/shisen_cpp/node/shisen_cpp_node.cpp +++ b/src/shisen_cpp/node/shisen_cpp_node.cpp @@ -27,8 +27,7 @@ namespace shisen_cpp { using namespace std::chrono_literals; -ShisenCppNode::ShisenCppNode( - rclcpp::Node::SharedPtr node, const std::string & path, const Options & options) +ShisenCppNode::ShisenCppNode(rclcpp::Node::SharedPtr node, const std::string & path, const Options & options) : node(node), camera_node(std::make_shared(node, options)) { auto image_provider = std::make_shared(options); @@ -37,12 +36,18 @@ ShisenCppNode::ShisenCppNode( camera_node->load_configuration(path); node_timer = node->create_wall_timer( - 1s / camera_node->image_provider->options.capture_fps, [this]() { camera_node->update(); }); + 1s / camera_node->image_provider->options.capture_fps, + [this]() { + camera_node->update(); + } + ); config_grpc.Run(5757, path, node); RCLCPP_INFO(rclcpp::get_logger("GrpcServers"), "grpc running"); } -ShisenCppNode::~ShisenCppNode() {} +ShisenCppNode::~ShisenCppNode() +{ +} } // namespace shisen_cpp diff --git a/src/shisen_cpp/utility/capture_setting.cpp b/src/shisen_cpp/utility/capture_setting.cpp index b12c436..4bfc4cb 100644 --- a/src/shisen_cpp/utility/capture_setting.cpp +++ b/src/shisen_cpp/utility/capture_setting.cpp @@ -119,4 +119,4 @@ void CaptureSetting::update_with(const CaptureSetting & capture_setting) } } -} // namespace shisen_cpp \ No newline at end of file +} // namespace shisen_cpp diff --git a/src/shisen_cpp_main.cpp b/src/shisen_cpp_main.cpp index fe72bb2..1cce2a1 100644 --- a/src/shisen_cpp_main.cpp +++ b/src/shisen_cpp_main.cpp @@ -70,7 +70,10 @@ int main(int argc, char ** argv) } } else if (pos == 0) { path = arg; - pos++; + ++pos; + }else if (pos == 1) { + options.camera_file_name = arg; + ++pos; } } } catch (...) { From 87a0083bf406433034a64fa87f964bb9856bd1b6 Mon Sep 17 00:00:00 2001 From: mbsaloka Date: Wed, 17 Apr 2024 22:22:16 +0700 Subject: [PATCH 09/31] fix: add extra line --- data/grpc.json | 2 +- include/shisen_cpp/config/grpc/call_data_base.hpp | 2 +- .../shisen_cpp/config/grpc/call_data_save_capture_setting.hpp | 2 +- .../shisen_cpp/config/grpc/call_data_set_capture_setting.hpp | 2 +- src/shisen_cpp/config/grpc/call_data_save_capture_setting.cpp | 2 +- src/shisen_cpp/config/grpc/call_data_set_capture_setting.cpp | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/data/grpc.json b/data/grpc.json index 01fbcef..a7e9c4d 100644 --- a/data/grpc.json +++ b/data/grpc.json @@ -1,3 +1,3 @@ { "port": 5757 -} \ No newline at end of file +} diff --git a/include/shisen_cpp/config/grpc/call_data_base.hpp b/include/shisen_cpp/config/grpc/call_data_base.hpp index 1a131fa..148f0aa 100644 --- a/include/shisen_cpp/config/grpc/call_data_base.hpp +++ b/include/shisen_cpp/config/grpc/call_data_base.hpp @@ -16,4 +16,4 @@ class CallDataBase }; } // namespace shisen_cpp -#endif // SHISEN_CPP__CONFIG__GRPC__CALL_DATA_BASE_HPP_ \ No newline at end of file +#endif // SHISEN_CPP__CONFIG__GRPC__CALL_DATA_BASE_HPP_ diff --git a/include/shisen_cpp/config/grpc/call_data_save_capture_setting.hpp b/include/shisen_cpp/config/grpc/call_data_save_capture_setting.hpp index ff6750c..879d896 100644 --- a/include/shisen_cpp/config/grpc/call_data_save_capture_setting.hpp +++ b/include/shisen_cpp/config/grpc/call_data_save_capture_setting.hpp @@ -22,4 +22,4 @@ class CallDataSaveCaptureSetting } // namespace shisen_cpp -#endif // SHISEN_CPP__CONFIG__GRPC__CALL_DATA_SAVE_CAPTURE_SETTING_HPP__ \ No newline at end of file +#endif // SHISEN_CPP__CONFIG__GRPC__CALL_DATA_SAVE_CAPTURE_SETTING_HPP__ diff --git a/include/shisen_cpp/config/grpc/call_data_set_capture_setting.hpp b/include/shisen_cpp/config/grpc/call_data_set_capture_setting.hpp index 2070b4f..2d79a2d 100644 --- a/include/shisen_cpp/config/grpc/call_data_set_capture_setting.hpp +++ b/include/shisen_cpp/config/grpc/call_data_set_capture_setting.hpp @@ -24,4 +24,4 @@ class CallDataSetCaptureSetting }; } // namespace shisen_cpp -#endif // SHISEN_CPP__CONFIG__GRPC__CALL_DATA_SET_CAPTURE_SETTING_HPP__ \ No newline at end of file +#endif // SHISEN_CPP__CONFIG__GRPC__CALL_DATA_SET_CAPTURE_SETTING_HPP__ diff --git a/src/shisen_cpp/config/grpc/call_data_save_capture_setting.cpp b/src/shisen_cpp/config/grpc/call_data_save_capture_setting.cpp index 848e587..3b8ffec 100644 --- a/src/shisen_cpp/config/grpc/call_data_save_capture_setting.cpp +++ b/src/shisen_cpp/config/grpc/call_data_save_capture_setting.cpp @@ -42,4 +42,4 @@ void CallDataSaveCaptureSetting::HandleRequest() RCLCPP_ERROR(rclcpp::get_logger("Save config"), e.what()); } } -} // namespace shisen_cpp \ No newline at end of file +} // namespace shisen_cpp diff --git a/src/shisen_cpp/config/grpc/call_data_set_capture_setting.cpp b/src/shisen_cpp/config/grpc/call_data_set_capture_setting.cpp index 94b1b8f..6d98c8a 100644 --- a/src/shisen_cpp/config/grpc/call_data_set_capture_setting.cpp +++ b/src/shisen_cpp/config/grpc/call_data_set_capture_setting.cpp @@ -75,4 +75,4 @@ void CallDataSetCaptureSetting::HandleRequest() RCLCPP_ERROR(rclcpp::get_logger("Publish config"), e.what()); } } -} // namespace shisen_cpp \ No newline at end of file +} // namespace shisen_cpp From e9fb63faf1dc3b4a95dac7c05e7584bf39efdee5 Mon Sep 17 00:00:00 2001 From: mbsaloka Date: Wed, 17 Apr 2024 22:31:06 +0700 Subject: [PATCH 10/31] fix: remove unused comments --- include/shisen_cpp/config/grpc/config.hpp | 1 - .../config/grpc/call_data_save_capture_setting.cpp | 2 -- .../config/grpc/call_data_set_capture_setting.cpp | 9 +-------- 3 files changed, 1 insertion(+), 11 deletions(-) diff --git a/include/shisen_cpp/config/grpc/config.hpp b/include/shisen_cpp/config/grpc/config.hpp index 4f878b3..7312b0a 100644 --- a/include/shisen_cpp/config/grpc/config.hpp +++ b/include/shisen_cpp/config/grpc/config.hpp @@ -15,7 +15,6 @@ #include "absl/strings/str_format.h" #include "shisen_cpp/config/grpc/call_data.hpp" #include "shisen_cpp/config/grpc/call_data_base.hpp" -// #include "shisen_cpp/walking/process/kinematic.hpp" #include "shisen_interfaces/shisen.grpc.pb.h" #include "shisen_interfaces/shisen.pb.h" #include "shisen_interfaces/msg/capture_setting.hpp" diff --git a/src/shisen_cpp/config/grpc/call_data_save_capture_setting.cpp b/src/shisen_cpp/config/grpc/call_data_save_capture_setting.cpp index 3b8ffec..e262f44 100644 --- a/src/shisen_cpp/config/grpc/call_data_save_capture_setting.cpp +++ b/src/shisen_cpp/config/grpc/call_data_save_capture_setting.cpp @@ -30,8 +30,6 @@ void CallDataSaveCaptureSetting::HandleRequest() { Config config(path_); try { - // nlohmann::json capture_data = nlohmann::json::parse(request_.json_capture()); - std::string json_string = request_.json_capture(); std::replace(json_string.begin(), json_string.end(), '\\', ' '); nlohmann::json capture_data = nlohmann::json::parse(json_string); diff --git a/src/shisen_cpp/config/grpc/call_data_set_capture_setting.cpp b/src/shisen_cpp/config/grpc/call_data_set_capture_setting.cpp index 6d98c8a..d125246 100644 --- a/src/shisen_cpp/config/grpc/call_data_set_capture_setting.cpp +++ b/src/shisen_cpp/config/grpc/call_data_set_capture_setting.cpp @@ -59,14 +59,7 @@ void CallDataSetCaptureSetting::HandleRequest() msg.temperature.push_back(temperature); msg.exposure.push_back(exposure); msg.gain.push_back(gain); - - // msg.brightness = brightness; - // msg.contrast = contrast; - // msg.saturation = saturation; - // msg.temperature = temperature; - // msg.exposure = exposure; - // msg.gain = gain; - + set_capture_publisher_->publish(msg); RCLCPP_INFO( rclcpp::get_logger("Publish capture setting config"), From 85bb9cc30eb31e350eeb2754b8e894b455d7384e Mon Sep 17 00:00:00 2001 From: mbsaloka Date: Fri, 19 Apr 2024 00:10:26 +0700 Subject: [PATCH 11/31] docs: add copyrights --- .../shisen_cpp/config/grpc/call_data_base.hpp | 20 +++++++++++++++++++ .../grpc/call_data_get_capture_setting.hpp | 20 +++++++++++++++++++ .../grpc/call_data_save_capture_setting.hpp | 20 +++++++++++++++++++ .../grpc/call_data_set_capture_setting.hpp | 20 +++++++++++++++++++ include/shisen_cpp/config/grpc/config.hpp | 20 +++++++++++++++++++ include/shisen_cpp/config/utils/config.hpp | 20 +++++++++++++++++++ src/shisen_cpp/config/grpc/call_data_base.cpp | 20 +++++++++++++++++++ .../grpc/call_data_get_capture_setting.cpp | 20 +++++++++++++++++++ .../grpc/call_data_save_capture_setting.cpp | 20 +++++++++++++++++++ .../grpc/call_data_set_capture_setting.cpp | 20 +++++++++++++++++++ src/shisen_cpp/config/grpc/config.cpp | 20 +++++++++++++++++++ src/shisen_cpp/config/utils/config.cpp | 20 +++++++++++++++++++ 12 files changed, 240 insertions(+) diff --git a/include/shisen_cpp/config/grpc/call_data_base.hpp b/include/shisen_cpp/config/grpc/call_data_base.hpp index 148f0aa..79a79b8 100644 --- a/include/shisen_cpp/config/grpc/call_data_base.hpp +++ b/include/shisen_cpp/config/grpc/call_data_base.hpp @@ -1,3 +1,23 @@ +// 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 SHISEN_CPP__CONFIG__GRPC__CALL_DATA_BASE_HPP_ #define SHISEN_CPP__CONFIG__GRPC__CALL_DATA_BASE_HPP_ diff --git a/include/shisen_cpp/config/grpc/call_data_get_capture_setting.hpp b/include/shisen_cpp/config/grpc/call_data_get_capture_setting.hpp index 8296368..c582489 100644 --- a/include/shisen_cpp/config/grpc/call_data_get_capture_setting.hpp +++ b/include/shisen_cpp/config/grpc/call_data_get_capture_setting.hpp @@ -1,3 +1,23 @@ +// 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 SHISEN_CPP__CONFIG__GRPC__CALL_DATA_GET_CAPTURE_SETTING_HPP__ #define SHISEN_CPP__CONFIG__GRPC__CALL_DATA_GET_CAPTURE_SETTING_HPP__ diff --git a/include/shisen_cpp/config/grpc/call_data_save_capture_setting.hpp b/include/shisen_cpp/config/grpc/call_data_save_capture_setting.hpp index 879d896..5d160f7 100644 --- a/include/shisen_cpp/config/grpc/call_data_save_capture_setting.hpp +++ b/include/shisen_cpp/config/grpc/call_data_save_capture_setting.hpp @@ -1,3 +1,23 @@ +// 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 SHISEN_CPP__CONFIG__GRPC__CALL_DATA_SAVE_CAPTURE_SETTING_HPP__ #define SHISEN_CPP__CONFIG__GRPC__CALL_DATA_SAVE_CAPTURE_SETTING_HPP__ diff --git a/include/shisen_cpp/config/grpc/call_data_set_capture_setting.hpp b/include/shisen_cpp/config/grpc/call_data_set_capture_setting.hpp index 2d79a2d..cc3cdac 100644 --- a/include/shisen_cpp/config/grpc/call_data_set_capture_setting.hpp +++ b/include/shisen_cpp/config/grpc/call_data_set_capture_setting.hpp @@ -1,3 +1,23 @@ +// 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 SHISEN_CPP_CONFIG__GRPC__CALL_DATA_SET_CAPTURE_SETTING_HPP__ #define SHISEN_CPP_CONFIG__GRPC__CALL_DATA_SET_CAPTURE_SETTING_HPP__ diff --git a/include/shisen_cpp/config/grpc/config.hpp b/include/shisen_cpp/config/grpc/config.hpp index 7312b0a..4077b08 100644 --- a/include/shisen_cpp/config/grpc/config.hpp +++ b/include/shisen_cpp/config/grpc/config.hpp @@ -1,3 +1,23 @@ +// 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 SHISEN_CPP__CONFIG__GRPC__CONFIG_HPP_ #define SHISEN_CPP__CONFIG__GRPC__CONFIG_HPP_ diff --git a/include/shisen_cpp/config/utils/config.hpp b/include/shisen_cpp/config/utils/config.hpp index 0ba3d88..675f6cd 100644 --- a/include/shisen_cpp/config/utils/config.hpp +++ b/include/shisen_cpp/config/utils/config.hpp @@ -1,3 +1,23 @@ +// 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 SHISEN_CPP__CONFIG__UTILS__CONFIG_HPP_ #define SHISEN_CPP__CONFIG__UTILS__CONFIG_HPP_ diff --git a/src/shisen_cpp/config/grpc/call_data_base.cpp b/src/shisen_cpp/config/grpc/call_data_base.cpp index 84647c9..c646a6f 100644 --- a/src/shisen_cpp/config/grpc/call_data_base.cpp +++ b/src/shisen_cpp/config/grpc/call_data_base.cpp @@ -1,3 +1,23 @@ +// 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 "shisen_cpp/config/grpc/call_data_base.hpp" namespace shisen_cpp diff --git a/src/shisen_cpp/config/grpc/call_data_get_capture_setting.cpp b/src/shisen_cpp/config/grpc/call_data_get_capture_setting.cpp index 3468056..ca78271 100644 --- a/src/shisen_cpp/config/grpc/call_data_get_capture_setting.cpp +++ b/src/shisen_cpp/config/grpc/call_data_get_capture_setting.cpp @@ -1,3 +1,23 @@ +// 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 "shisen_cpp/config/grpc/call_data_get_capture_setting.hpp" #include "shisen_cpp/config/utils/config.hpp" diff --git a/src/shisen_cpp/config/grpc/call_data_save_capture_setting.cpp b/src/shisen_cpp/config/grpc/call_data_save_capture_setting.cpp index e262f44..04832d8 100644 --- a/src/shisen_cpp/config/grpc/call_data_save_capture_setting.cpp +++ b/src/shisen_cpp/config/grpc/call_data_save_capture_setting.cpp @@ -1,3 +1,23 @@ +// 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 "shisen_cpp/config/grpc/call_data_save_capture_setting.hpp" #include "shisen_cpp/config/utils/config.hpp" diff --git a/src/shisen_cpp/config/grpc/call_data_set_capture_setting.cpp b/src/shisen_cpp/config/grpc/call_data_set_capture_setting.cpp index d125246..52247aa 100644 --- a/src/shisen_cpp/config/grpc/call_data_set_capture_setting.cpp +++ b/src/shisen_cpp/config/grpc/call_data_set_capture_setting.cpp @@ -1,3 +1,23 @@ +// 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 "shisen_cpp/config/grpc/call_data_set_capture_setting.hpp" #include "shisen_cpp/config/utils/config.hpp" diff --git a/src/shisen_cpp/config/grpc/config.cpp b/src/shisen_cpp/config/grpc/config.cpp index 9e4a671..a82845d 100644 --- a/src/shisen_cpp/config/grpc/config.cpp +++ b/src/shisen_cpp/config/grpc/config.cpp @@ -1,3 +1,23 @@ +// 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 "shisen_cpp/config/utils/config.hpp" #include diff --git a/src/shisen_cpp/config/utils/config.cpp b/src/shisen_cpp/config/utils/config.cpp index ae20b9c..a2f065d 100644 --- a/src/shisen_cpp/config/utils/config.cpp +++ b/src/shisen_cpp/config/utils/config.cpp @@ -1,3 +1,23 @@ +// 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 "shisen_cpp/config/utils/config.hpp" #include From c50289fa1595f960638be4b50a2271078d1e56cd Mon Sep 17 00:00:00 2001 From: mbsaloka Date: Fri, 19 Apr 2024 00:35:03 +0700 Subject: [PATCH 12/31] refactor: reorder include package --- include/shisen_cpp/config/grpc/call_data.hpp | 4 +-- .../grpc/call_data_save_capture_setting.hpp | 2 +- .../grpc/call_data_set_capture_setting.hpp | 6 ++--- include/shisen_cpp/config/grpc/config.hpp | 27 ++++++++++--------- include/shisen_cpp/config/utils/config.hpp | 4 +-- include/shisen_cpp/node/shisen_cpp_node.hpp | 10 +++---- .../shisen_cpp/utility/capture_setting.hpp | 3 +-- src/shisen_cpp/camera/node/camera_node.cpp | 9 ++++--- .../grpc/call_data_get_capture_setting.cpp | 3 +-- .../grpc/call_data_save_capture_setting.cpp | 5 ++-- .../grpc/call_data_set_capture_setting.cpp | 3 +-- src/shisen_cpp/config/grpc/config.cpp | 13 +++++---- src/shisen_cpp/config/utils/config.cpp | 3 +-- src/shisen_cpp/node/shisen_cpp_node.cpp | 2 +- 14 files changed, 46 insertions(+), 48 deletions(-) diff --git a/include/shisen_cpp/config/grpc/call_data.hpp b/include/shisen_cpp/config/grpc/call_data.hpp index 63078d1..75fc67c 100644 --- a/include/shisen_cpp/config/grpc/call_data.hpp +++ b/include/shisen_cpp/config/grpc/call_data.hpp @@ -21,11 +21,11 @@ #ifndef __SHISEN_CPP__CONFIG__GRPC__CALL_DATA_HPP__ #define __SHISEN_CPP__CONFIG__GRPC__CALL_DATA_HPP__ +#include "grpc/support/log.h" +#include "grpcpp/grpcpp.h" #include "shisen_cpp/config/grpc/call_data_base.hpp" #include "shisen_interfaces/shisen.grpc.pb.h" #include "shisen_interfaces/shisen.pb.h" -#include "grpc/support/log.h" -#include "grpcpp/grpcpp.h" namespace shisen_cpp { diff --git a/include/shisen_cpp/config/grpc/call_data_save_capture_setting.hpp b/include/shisen_cpp/config/grpc/call_data_save_capture_setting.hpp index 5d160f7..bea4ed7 100644 --- a/include/shisen_cpp/config/grpc/call_data_save_capture_setting.hpp +++ b/include/shisen_cpp/config/grpc/call_data_save_capture_setting.hpp @@ -21,8 +21,8 @@ #ifndef SHISEN_CPP__CONFIG__GRPC__CALL_DATA_SAVE_CAPTURE_SETTING_HPP__ #define SHISEN_CPP__CONFIG__GRPC__CALL_DATA_SAVE_CAPTURE_SETTING_HPP__ -#include "shisen_cpp/config/grpc/call_data.hpp" #include "rclcpp/rclcpp.hpp" +#include "shisen_cpp/config/grpc/call_data.hpp" namespace shisen_cpp { diff --git a/include/shisen_cpp/config/grpc/call_data_set_capture_setting.hpp b/include/shisen_cpp/config/grpc/call_data_set_capture_setting.hpp index cc3cdac..81280bd 100644 --- a/include/shisen_cpp/config/grpc/call_data_set_capture_setting.hpp +++ b/include/shisen_cpp/config/grpc/call_data_set_capture_setting.hpp @@ -18,12 +18,12 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. -#ifndef SHISEN_CPP_CONFIG__GRPC__CALL_DATA_SET_CAPTURE_SETTING_HPP__ -#define SHISEN_CPP_CONFIG__GRPC__CALL_DATA_SET_CAPTURE_SETTING_HPP__ +#ifndef SHISEN_CPP__CONFIG__GRPC__CALL_DATA_SET_CAPTURE_SETTING_HPP__ +#define SHISEN_CPP__CONFIG__GRPC__CALL_DATA_SET_CAPTURE_SETTING_HPP__ +#include "rclcpp/rclcpp.hpp" #include "shisen_cpp/config/grpc/call_data.hpp" #include "shisen_interfaces/msg/capture_setting.hpp" -#include "rclcpp/rclcpp.hpp" namespace shisen_cpp { diff --git a/include/shisen_cpp/config/grpc/config.hpp b/include/shisen_cpp/config/grpc/config.hpp index 4077b08..5754a57 100644 --- a/include/shisen_cpp/config/grpc/config.hpp +++ b/include/shisen_cpp/config/grpc/config.hpp @@ -21,28 +21,29 @@ #ifndef SHISEN_CPP__CONFIG__GRPC__CONFIG_HPP_ #define SHISEN_CPP__CONFIG__GRPC__CONFIG_HPP_ -#include -#include -#include -#include -#include -#include -#include -#include - #include "absl/flags/flag.h" #include "absl/flags/parse.h" #include "absl/strings/str_format.h" +#include "grpc/support/log.h" +#include "grpcpp/grpcpp.h" +#include "nlohmann/json.hpp" +#include "rclcpp/rclcpp.hpp" #include "shisen_cpp/config/grpc/call_data.hpp" #include "shisen_cpp/config/grpc/call_data_base.hpp" #include "shisen_interfaces/shisen.grpc.pb.h" #include "shisen_interfaces/shisen.pb.h" #include "shisen_interfaces/msg/capture_setting.hpp" #include "shisen_interfaces/msg/camera_config.hpp" -#include "grpc/support/log.h" -#include "grpcpp/grpcpp.h" -#include "nlohmann/json.hpp" -#include "rclcpp/rclcpp.hpp" + +#include +#include +#include +#include +#include +#include +#include +#include + using shisen_interfaces::proto::Config; diff --git a/include/shisen_cpp/config/utils/config.hpp b/include/shisen_cpp/config/utils/config.hpp index 675f6cd..20424b3 100644 --- a/include/shisen_cpp/config/utils/config.hpp +++ b/include/shisen_cpp/config/utils/config.hpp @@ -21,12 +21,12 @@ #ifndef SHISEN_CPP__CONFIG__UTILS__CONFIG_HPP_ #define SHISEN_CPP__CONFIG__UTILS__CONFIG_HPP_ +#include "nlohmann/json.hpp" + #include #include #include -#include "nlohmann/json.hpp" - namespace shisen_cpp { diff --git a/include/shisen_cpp/node/shisen_cpp_node.hpp b/include/shisen_cpp/node/shisen_cpp_node.hpp index ee1927a..a0bd299 100644 --- a/include/shisen_cpp/node/shisen_cpp_node.hpp +++ b/include/shisen_cpp/node/shisen_cpp_node.hpp @@ -21,13 +21,13 @@ #ifndef SHISEN_CPP__NODE__SHISEN_CPP_NODE_HPP_ #define SHISEN_CPP__NODE__SHISEN_CPP_NODE_HPP_ +#include "../utility.hpp" #include -#include - -#include "shisen_cpp/config/utils/config.hpp" -#include "shisen_cpp/config/grpc/config.hpp" #include "shisen_cpp/camera/node/camera_node.hpp" -#include "../utility.hpp" +#include "shisen_cpp/config/grpc/config.hpp" +#include "shisen_cpp/config/utils/config.hpp" + +#include namespace shisen_cpp { diff --git a/include/shisen_cpp/utility/capture_setting.hpp b/include/shisen_cpp/utility/capture_setting.hpp index a2d5fb1..27fcf15 100644 --- a/include/shisen_cpp/utility/capture_setting.hpp +++ b/include/shisen_cpp/utility/capture_setting.hpp @@ -21,9 +21,8 @@ #ifndef SHISEN_CPP__UTILITY__CAPTURE_SETTING_HPP_ #define SHISEN_CPP__UTILITY__CAPTURE_SETTING_HPP_ -#include - #include "./emptiable.hpp" +#include namespace shisen_cpp { diff --git a/src/shisen_cpp/camera/node/camera_node.cpp b/src/shisen_cpp/camera/node/camera_node.cpp index b827136..eec28cd 100644 --- a/src/shisen_cpp/camera/node/camera_node.cpp +++ b/src/shisen_cpp/camera/node/camera_node.cpp @@ -24,6 +24,9 @@ #include #include #include + +#include +#include #include namespace shisen_cpp::camera @@ -34,7 +37,7 @@ CameraNode::CameraNode(rclcpp::Node::SharedPtr node, const Options & options) { } -CameraNode::~CameraNode() +CameraNode::~CameraNode() { } @@ -71,8 +74,8 @@ cv::Mat CameraNode::get_mat() return image_provider->get_mat(); } -const std::string & CameraNode::get_camera_prefix() const -{ +const std::string & CameraNode::get_camera_prefix() const +{ return options.camera_prefix; } diff --git a/src/shisen_cpp/config/grpc/call_data_get_capture_setting.cpp b/src/shisen_cpp/config/grpc/call_data_get_capture_setting.cpp index ca78271..e9eb036 100644 --- a/src/shisen_cpp/config/grpc/call_data_get_capture_setting.cpp +++ b/src/shisen_cpp/config/grpc/call_data_get_capture_setting.cpp @@ -18,12 +18,11 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. +#include "rclcpp/rclcpp.hpp" #include "shisen_cpp/config/grpc/call_data_get_capture_setting.hpp" - #include "shisen_cpp/config/utils/config.hpp" #include "shisen_interfaces/shisen.grpc.pb.h" #include "shisen_interfaces/shisen.pb.h" -#include "rclcpp/rclcpp.hpp" namespace shisen_cpp { diff --git a/src/shisen_cpp/config/grpc/call_data_save_capture_setting.cpp b/src/shisen_cpp/config/grpc/call_data_save_capture_setting.cpp index 04832d8..4e41697 100644 --- a/src/shisen_cpp/config/grpc/call_data_save_capture_setting.cpp +++ b/src/shisen_cpp/config/grpc/call_data_save_capture_setting.cpp @@ -18,13 +18,12 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. +#include "nlohmann/json.hpp" +#include "rclcpp/rclcpp.hpp" #include "shisen_cpp/config/grpc/call_data_save_capture_setting.hpp" - #include "shisen_cpp/config/utils/config.hpp" #include "shisen_interfaces/shisen.grpc.pb.h" #include "shisen_interfaces/shisen.pb.h" -#include "rclcpp/rclcpp.hpp" -#include "nlohmann/json.hpp" namespace shisen_cpp { diff --git a/src/shisen_cpp/config/grpc/call_data_set_capture_setting.cpp b/src/shisen_cpp/config/grpc/call_data_set_capture_setting.cpp index 52247aa..7a880a0 100644 --- a/src/shisen_cpp/config/grpc/call_data_set_capture_setting.cpp +++ b/src/shisen_cpp/config/grpc/call_data_set_capture_setting.cpp @@ -18,12 +18,11 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. +#include "rclcpp/rclcpp.hpp" #include "shisen_cpp/config/grpc/call_data_set_capture_setting.hpp" - #include "shisen_cpp/config/utils/config.hpp" #include "shisen_interfaces/shisen.grpc.pb.h" #include "shisen_interfaces/shisen.pb.h" -#include "rclcpp/rclcpp.hpp" namespace shisen_cpp { diff --git a/src/shisen_cpp/config/grpc/config.cpp b/src/shisen_cpp/config/grpc/config.cpp index a82845d..04c8c6e 100644 --- a/src/shisen_cpp/config/grpc/config.cpp +++ b/src/shisen_cpp/config/grpc/config.cpp @@ -18,6 +18,12 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. +#include "rclcpp/rclcpp.hpp" +#include "shisen_cpp/config/grpc/call_data_base.hpp" +#include "shisen_cpp/config/grpc/call_data_get_capture_setting.hpp" +#include "shisen_cpp/config/grpc/call_data_save_capture_setting.hpp" +#include "shisen_cpp/config/grpc/call_data_set_capture_setting.hpp" +#include "shisen_cpp/config/grpc/config.hpp" #include "shisen_cpp/config/utils/config.hpp" #include @@ -25,13 +31,6 @@ #include #include -#include "shisen_cpp/config/grpc/call_data_base.hpp" -#include "shisen_cpp/config/grpc/call_data_get_capture_setting.hpp" -#include "shisen_cpp/config/grpc/call_data_save_capture_setting.hpp" -#include "shisen_cpp/config/grpc/call_data_set_capture_setting.hpp" -#include "shisen_cpp/config/grpc/config.hpp" -#include "rclcpp/rclcpp.hpp" - using grpc::ServerBuilder; using namespace std::chrono_literals; diff --git a/src/shisen_cpp/config/utils/config.cpp b/src/shisen_cpp/config/utils/config.cpp index a2f065d..c5777bb 100644 --- a/src/shisen_cpp/config/utils/config.cpp +++ b/src/shisen_cpp/config/utils/config.cpp @@ -18,14 +18,13 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. +#include "nlohmann/json.hpp" #include "shisen_cpp/config/utils/config.hpp" #include #include #include -#include "nlohmann/json.hpp" - namespace shisen_cpp { Config::Config(const std::string & path) : path(path) {} diff --git a/src/shisen_cpp/node/shisen_cpp_node.cpp b/src/shisen_cpp/node/shisen_cpp_node.cpp index 604e7fa..71c0568 100644 --- a/src/shisen_cpp/node/shisen_cpp_node.cpp +++ b/src/shisen_cpp/node/shisen_cpp_node.cpp @@ -18,8 +18,8 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. -#include #include "shisen_cpp/config/grpc/config.hpp" +#include #include From e787577d60409fbccd8720212b78a479babb164b Mon Sep 17 00:00:00 2001 From: mbsaloka Date: Fri, 19 Apr 2024 00:49:26 +0700 Subject: [PATCH 13/31] refactor: remove trailing spaces --- src/shisen_cpp/config/grpc/call_data_set_capture_setting.cpp | 2 +- src/shisen_cpp/node/shisen_cpp_node.cpp | 2 +- src/shisen_cpp_main.cpp | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/shisen_cpp/config/grpc/call_data_set_capture_setting.cpp b/src/shisen_cpp/config/grpc/call_data_set_capture_setting.cpp index 7a880a0..6980cb8 100644 --- a/src/shisen_cpp/config/grpc/call_data_set_capture_setting.cpp +++ b/src/shisen_cpp/config/grpc/call_data_set_capture_setting.cpp @@ -78,7 +78,7 @@ void CallDataSetCaptureSetting::HandleRequest() msg.temperature.push_back(temperature); msg.exposure.push_back(exposure); msg.gain.push_back(gain); - + set_capture_publisher_->publish(msg); RCLCPP_INFO( rclcpp::get_logger("Publish capture setting config"), diff --git a/src/shisen_cpp/node/shisen_cpp_node.cpp b/src/shisen_cpp/node/shisen_cpp_node.cpp index 71c0568..330f8d0 100644 --- a/src/shisen_cpp/node/shisen_cpp_node.cpp +++ b/src/shisen_cpp/node/shisen_cpp_node.cpp @@ -38,7 +38,7 @@ ShisenCppNode::ShisenCppNode(rclcpp::Node::SharedPtr node, const std::string & p node_timer = node->create_wall_timer( 1s / camera_node->image_provider->options.capture_fps, [this]() { - camera_node->update(); + camera_node->update(); } ); diff --git a/src/shisen_cpp_main.cpp b/src/shisen_cpp_main.cpp index 1cce2a1..e7f84f0 100644 --- a/src/shisen_cpp_main.cpp +++ b/src/shisen_cpp_main.cpp @@ -71,7 +71,7 @@ int main(int argc, char ** argv) } else if (pos == 0) { path = arg; ++pos; - }else if (pos == 1) { + } else if (pos == 1) { options.camera_file_name = arg; ++pos; } From 03d6019bd7c0836a73587b46e7838fd7c55051af Mon Sep 17 00:00:00 2001 From: mbsaloka Date: Fri, 19 Apr 2024 22:02:13 +0700 Subject: [PATCH 14/31] refactor: changes include format --- include/shisen_cpp/config/grpc/call_data.hpp | 10 +++---- .../grpc/call_data_get_capture_setting.hpp | 2 +- .../grpc/call_data_save_capture_setting.hpp | 4 +-- .../grpc/call_data_set_capture_setting.hpp | 6 ++--- include/shisen_cpp/config/grpc/config.hpp | 26 +++++++++---------- include/shisen_cpp/config/utils/config.hpp | 2 +- 6 files changed, 25 insertions(+), 25 deletions(-) diff --git a/include/shisen_cpp/config/grpc/call_data.hpp b/include/shisen_cpp/config/grpc/call_data.hpp index 75fc67c..c28d422 100644 --- a/include/shisen_cpp/config/grpc/call_data.hpp +++ b/include/shisen_cpp/config/grpc/call_data.hpp @@ -21,11 +21,11 @@ #ifndef __SHISEN_CPP__CONFIG__GRPC__CALL_DATA_HPP__ #define __SHISEN_CPP__CONFIG__GRPC__CALL_DATA_HPP__ -#include "grpc/support/log.h" -#include "grpcpp/grpcpp.h" -#include "shisen_cpp/config/grpc/call_data_base.hpp" -#include "shisen_interfaces/shisen.grpc.pb.h" -#include "shisen_interfaces/shisen.pb.h" +#include +#include +#include +#include +#include namespace shisen_cpp { diff --git a/include/shisen_cpp/config/grpc/call_data_get_capture_setting.hpp b/include/shisen_cpp/config/grpc/call_data_get_capture_setting.hpp index c582489..16a28d1 100644 --- a/include/shisen_cpp/config/grpc/call_data_get_capture_setting.hpp +++ b/include/shisen_cpp/config/grpc/call_data_get_capture_setting.hpp @@ -21,7 +21,7 @@ #ifndef SHISEN_CPP__CONFIG__GRPC__CALL_DATA_GET_CAPTURE_SETTING_HPP__ #define SHISEN_CPP__CONFIG__GRPC__CALL_DATA_GET_CAPTURE_SETTING_HPP__ -#include "shisen_cpp/config/grpc/call_data.hpp" +#include namespace shisen_cpp { diff --git a/include/shisen_cpp/config/grpc/call_data_save_capture_setting.hpp b/include/shisen_cpp/config/grpc/call_data_save_capture_setting.hpp index bea4ed7..fe1b24e 100644 --- a/include/shisen_cpp/config/grpc/call_data_save_capture_setting.hpp +++ b/include/shisen_cpp/config/grpc/call_data_save_capture_setting.hpp @@ -21,8 +21,8 @@ #ifndef SHISEN_CPP__CONFIG__GRPC__CALL_DATA_SAVE_CAPTURE_SETTING_HPP__ #define SHISEN_CPP__CONFIG__GRPC__CALL_DATA_SAVE_CAPTURE_SETTING_HPP__ -#include "rclcpp/rclcpp.hpp" -#include "shisen_cpp/config/grpc/call_data.hpp" +#include +#include namespace shisen_cpp { diff --git a/include/shisen_cpp/config/grpc/call_data_set_capture_setting.hpp b/include/shisen_cpp/config/grpc/call_data_set_capture_setting.hpp index 81280bd..2bd9be0 100644 --- a/include/shisen_cpp/config/grpc/call_data_set_capture_setting.hpp +++ b/include/shisen_cpp/config/grpc/call_data_set_capture_setting.hpp @@ -21,9 +21,9 @@ #ifndef SHISEN_CPP__CONFIG__GRPC__CALL_DATA_SET_CAPTURE_SETTING_HPP__ #define SHISEN_CPP__CONFIG__GRPC__CALL_DATA_SET_CAPTURE_SETTING_HPP__ -#include "rclcpp/rclcpp.hpp" -#include "shisen_cpp/config/grpc/call_data.hpp" -#include "shisen_interfaces/msg/capture_setting.hpp" +#include +#include +#include namespace shisen_cpp { diff --git a/include/shisen_cpp/config/grpc/config.hpp b/include/shisen_cpp/config/grpc/config.hpp index 5754a57..36cd088 100644 --- a/include/shisen_cpp/config/grpc/config.hpp +++ b/include/shisen_cpp/config/grpc/config.hpp @@ -21,19 +21,19 @@ #ifndef SHISEN_CPP__CONFIG__GRPC__CONFIG_HPP_ #define SHISEN_CPP__CONFIG__GRPC__CONFIG_HPP_ -#include "absl/flags/flag.h" -#include "absl/flags/parse.h" -#include "absl/strings/str_format.h" -#include "grpc/support/log.h" -#include "grpcpp/grpcpp.h" -#include "nlohmann/json.hpp" -#include "rclcpp/rclcpp.hpp" -#include "shisen_cpp/config/grpc/call_data.hpp" -#include "shisen_cpp/config/grpc/call_data_base.hpp" -#include "shisen_interfaces/shisen.grpc.pb.h" -#include "shisen_interfaces/shisen.pb.h" -#include "shisen_interfaces/msg/capture_setting.hpp" -#include "shisen_interfaces/msg/camera_config.hpp" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include #include #include diff --git a/include/shisen_cpp/config/utils/config.hpp b/include/shisen_cpp/config/utils/config.hpp index 20424b3..509d072 100644 --- a/include/shisen_cpp/config/utils/config.hpp +++ b/include/shisen_cpp/config/utils/config.hpp @@ -21,7 +21,7 @@ #ifndef SHISEN_CPP__CONFIG__UTILS__CONFIG_HPP_ #define SHISEN_CPP__CONFIG__UTILS__CONFIG_HPP_ -#include "nlohmann/json.hpp" +#include #include #include From c5ec62f455474ea8097217d6829e98a6baa59baa Mon Sep 17 00:00:00 2001 From: mbsaloka Date: Sat, 20 Apr 2024 00:04:01 +0700 Subject: [PATCH 15/31] fix: fixed set_capture_setting to be able to change the value of the camera_node variableres --- .../grpc/call_data_set_capture_setting.hpp | 6 ++- include/shisen_cpp/config/grpc/config.hpp | 5 +- src/shisen_cpp/camera/node/camera_node.cpp | 13 +++++ .../grpc/call_data_set_capture_setting.cpp | 49 ++++++++++--------- src/shisen_cpp/config/grpc/config.cpp | 6 +-- src/shisen_cpp/node/shisen_cpp_node.cpp | 2 +- 6 files changed, 52 insertions(+), 29 deletions(-) diff --git a/include/shisen_cpp/config/grpc/call_data_set_capture_setting.hpp b/include/shisen_cpp/config/grpc/call_data_set_capture_setting.hpp index 2bd9be0..da32e65 100644 --- a/include/shisen_cpp/config/grpc/call_data_set_capture_setting.hpp +++ b/include/shisen_cpp/config/grpc/call_data_set_capture_setting.hpp @@ -24,6 +24,9 @@ #include #include #include +#include "shisen_cpp/utility.hpp" + +#include "shisen_cpp/camera/node/camera_node.hpp" namespace shisen_cpp { @@ -33,7 +36,7 @@ class CallDataSetCaptureSetting public: CallDataSetCaptureSetting( shisen_interfaces::proto::Config::AsyncService * service, grpc::ServerCompletionQueue * cq, - const std::string & path, rclcpp::Node::SharedPtr node); + const std::string & path, rclcpp::Node::SharedPtr node, std::shared_ptr camera_node); protected: void AddNextToCompletionQueue() override; @@ -41,6 +44,7 @@ class CallDataSetCaptureSetting void HandleRequest(); rclcpp::Node::SharedPtr node_; rclcpp::Publisher::SharedPtr set_capture_publisher_; + std::shared_ptr camera_node_; }; } // namespace shisen_cpp diff --git a/include/shisen_cpp/config/grpc/config.hpp b/include/shisen_cpp/config/grpc/config.hpp index 36cd088..32771d5 100644 --- a/include/shisen_cpp/config/grpc/config.hpp +++ b/include/shisen_cpp/config/grpc/config.hpp @@ -35,6 +35,8 @@ #include #include +#include + #include #include #include @@ -57,7 +59,7 @@ class ConfigGrpc ~ConfigGrpc(); - void Run(uint16_t port, const std::string & path, rclcpp::Node::SharedPtr node); + void Run(uint16_t port, const std::string & path, rclcpp::Node::SharedPtr node, std::shared_ptr camera_node); private: std::string path; @@ -67,6 +69,7 @@ class ConfigGrpc static inline std::unique_ptr server_; std::thread thread_; shisen_interfaces::proto::Config::AsyncService service_; + std::shared_ptr camera_node_; }; } // namespace shisen_cpp diff --git a/src/shisen_cpp/camera/node/camera_node.cpp b/src/shisen_cpp/camera/node/camera_node.cpp index eec28cd..eb53656 100644 --- a/src/shisen_cpp/camera/node/camera_node.cpp +++ b/src/shisen_cpp/camera/node/camera_node.cpp @@ -193,8 +193,21 @@ CaptureSetting CameraNode::on_configure_capture_setting( void CameraNode::configure_capture_setting(const CaptureSetting & capture_setting) { // Update with configured data + + // Debug + std::cout << "[Debug From camera_node.cpp]" << std::endl; + std::cout << "brightness: " << capture_setting.brightness << std::endl; + std::cout << "contrast: " << capture_setting.contrast << std::endl; + std::cout << "saturation: " << capture_setting.saturation << std::endl; + std::cout << "temperature: " << capture_setting.temperature << std::endl; + std::cout << "exposure: " << capture_setting.exposure << std::endl; + std::cout << "gain: " << capture_setting.gain << std::endl; + + // !Debug current_capture_setting.update_with(on_configure_capture_setting(capture_setting)); capture_setting_event_publisher->publish(static_cast(current_capture_setting)); + + std::cout << "[Configure Done]" << std::endl; } void CameraNode::load_configuration(const std::string & path) diff --git a/src/shisen_cpp/config/grpc/call_data_set_capture_setting.cpp b/src/shisen_cpp/config/grpc/call_data_set_capture_setting.cpp index 6980cb8..21cb0bf 100644 --- a/src/shisen_cpp/config/grpc/call_data_set_capture_setting.cpp +++ b/src/shisen_cpp/config/grpc/call_data_set_capture_setting.cpp @@ -28,8 +28,8 @@ namespace shisen_cpp { CallDataSetCaptureSetting::CallDataSetCaptureSetting( shisen_interfaces::proto::Config::AsyncService * service, grpc::ServerCompletionQueue * cq, - const std::string & path, rclcpp::Node::SharedPtr node) -: CallData(service, cq, path), node_(node) + const std::string & path, rclcpp::Node::SharedPtr node, std::shared_ptr camera_node) +: CallData(service, cq, path), node_(node), camera_node_(camera_node) { set_capture_publisher_ = node_->create_publisher( "shisen_cpp/config/capture_setting", 10); @@ -38,7 +38,7 @@ CallDataSetCaptureSetting::CallDataSetCaptureSetting( void CallDataSetCaptureSetting::AddNextToCompletionQueue() { - new CallDataSetCaptureSetting(service_, cq_, path_, node_); + new CallDataSetCaptureSetting(service_, cq_, path_, node_, camera_node_); } void CallDataSetCaptureSetting::WaitForRequest() @@ -50,6 +50,8 @@ void CallDataSetCaptureSetting::HandleRequest() { Config config(path_); try { + CaptureSetting capture_setting; + int brightness = request_.brightness(); int contrast = request_.contrast(); int saturation = request_.saturation(); @@ -57,29 +59,30 @@ void CallDataSetCaptureSetting::HandleRequest() int exposure = request_.exposure(); int gain = request_.gain(); - std::cout << "brightness: " << brightness << std::endl; - std::cout << "contrast: " << contrast << std::endl; - std::cout << "saturation: " << saturation << std::endl; - std::cout << "temperature: " << temperature << std::endl; - std::cout << "exposure: " << exposure << std::endl; - std::cout << "gain: " << gain << std::endl; + capture_setting.brightness.set(brightness); + capture_setting.contrast.set(contrast); + capture_setting.saturation.set(saturation); + capture_setting.temperature.set(temperature); + capture_setting.exposure.set(exposure); + capture_setting.gain.set(gain); - shisen_interfaces::msg::CaptureSetting msg; - msg.brightness.clear(); - msg.contrast.clear(); - msg.saturation.clear(); - msg.temperature.clear(); - msg.exposure.clear(); - msg.gain.clear(); + camera_node_->configure_capture_setting(capture_setting); + // shisen_interfaces::msg::CaptureSetting msg; + // msg.brightness.clear(); + // msg.contrast.clear(); + // msg.saturation.clear(); + // msg.temperature.clear(); + // msg.exposure.clear(); + // msg.gain.clear(); - msg.brightness.push_back(brightness); - msg.contrast.push_back(contrast); - msg.saturation.push_back(saturation); - msg.temperature.push_back(temperature); - msg.exposure.push_back(exposure); - msg.gain.push_back(gain); + // msg.brightness.push_back(brightness); + // msg.contrast.push_back(contrast); + // msg.saturation.push_back(saturation); + // msg.temperature.push_back(temperature); + // msg.exposure.push_back(exposure); + // msg.gain.push_back(gain); - set_capture_publisher_->publish(msg); + // set_capture_publisher_->publish(msg); RCLCPP_INFO( rclcpp::get_logger("Publish capture setting config"), "capture setting config has been applied!"); diff --git a/src/shisen_cpp/config/grpc/config.cpp b/src/shisen_cpp/config/grpc/config.cpp index 04c8c6e..9a6f562 100644 --- a/src/shisen_cpp/config/grpc/config.cpp +++ b/src/shisen_cpp/config/grpc/config.cpp @@ -52,7 +52,7 @@ void ConfigGrpc::SignIntHandler(int signum) exit(signum); } -void ConfigGrpc::Run(uint16_t port, const std::string & path, rclcpp::Node::SharedPtr node) +void ConfigGrpc::Run(uint16_t port, const std::string & path, rclcpp::Node::SharedPtr node, std::shared_ptr camera_node) { Config config(path); std::string server_address = @@ -67,10 +67,10 @@ void ConfigGrpc::Run(uint16_t port, const std::string & path, rclcpp::Node::Shar std::cout << "Server listening on " << server_address << std::endl; signal(SIGINT, SignIntHandler); - thread_ = std::thread([&path, &node, this]() { + thread_ = std::thread([&path, &node, &camera_node, this]() { new CallDataGetCaptureSetting(&service_, cq_.get(), path); new CallDataSaveCaptureSetting(&service_, cq_.get(), path); - new CallDataSetCaptureSetting(&service_, cq_.get(), path, node); + new CallDataSetCaptureSetting(&service_, cq_.get(), path, node, camera_node); void * tag; // uniquely identifies a request. bool ok = true; while (true) { diff --git a/src/shisen_cpp/node/shisen_cpp_node.cpp b/src/shisen_cpp/node/shisen_cpp_node.cpp index 330f8d0..1f0a615 100644 --- a/src/shisen_cpp/node/shisen_cpp_node.cpp +++ b/src/shisen_cpp/node/shisen_cpp_node.cpp @@ -42,7 +42,7 @@ ShisenCppNode::ShisenCppNode(rclcpp::Node::SharedPtr node, const std::string & p } ); - config_grpc.Run(5757, path, node); + config_grpc.Run(5757, path, node, camera_node); RCLCPP_INFO(rclcpp::get_logger("GrpcServers"), "grpc running"); } From d9d37315c27b4069a767ad217843edc7f4033344 Mon Sep 17 00:00:00 2001 From: mbsaloka Date: Sat, 20 Apr 2024 00:36:16 +0700 Subject: [PATCH 16/31] refactor: remove unnecassary code and comments --- data/capture_settings.json | 12 ++++----- .../grpc/call_data_set_capture_setting.hpp | 7 ++--- include/shisen_cpp/config/grpc/config.hpp | 2 +- src/shisen_cpp/camera/node/camera_node.cpp | 11 -------- .../grpc/call_data_save_capture_setting.cpp | 2 +- .../grpc/call_data_set_capture_setting.cpp | 27 ++++--------------- src/shisen_cpp/config/grpc/config.cpp | 18 ++++++------- src/shisen_cpp/node/shisen_cpp_node.cpp | 4 +-- 8 files changed, 26 insertions(+), 57 deletions(-) diff --git a/data/capture_settings.json b/data/capture_settings.json index ff91186..6fcf69e 100644 --- a/data/capture_settings.json +++ b/data/capture_settings.json @@ -1,8 +1,8 @@ { - "brightness": 115, - "contrast": 100, - "saturation": 185, - "temperature": 5280, - "exposure": 230, - "gain": 138 + "brightness": 115, + "contrast": 100, + "exposure": 230, + "gain": 138, + "saturation": 185, + "temperature": 5280 } diff --git a/include/shisen_cpp/config/grpc/call_data_set_capture_setting.hpp b/include/shisen_cpp/config/grpc/call_data_set_capture_setting.hpp index da32e65..5171363 100644 --- a/include/shisen_cpp/config/grpc/call_data_set_capture_setting.hpp +++ b/include/shisen_cpp/config/grpc/call_data_set_capture_setting.hpp @@ -22,12 +22,10 @@ #define SHISEN_CPP__CONFIG__GRPC__CALL_DATA_SET_CAPTURE_SETTING_HPP__ #include +#include #include -#include #include "shisen_cpp/utility.hpp" -#include "shisen_cpp/camera/node/camera_node.hpp" - namespace shisen_cpp { class CallDataSetCaptureSetting @@ -36,14 +34,13 @@ class CallDataSetCaptureSetting public: CallDataSetCaptureSetting( shisen_interfaces::proto::Config::AsyncService * service, grpc::ServerCompletionQueue * cq, - const std::string & path, rclcpp::Node::SharedPtr node, std::shared_ptr camera_node); + const std::string & path, std::shared_ptr camera_node); protected: void AddNextToCompletionQueue() override; void WaitForRequest(); void HandleRequest(); rclcpp::Node::SharedPtr node_; - rclcpp::Publisher::SharedPtr set_capture_publisher_; std::shared_ptr camera_node_; }; } // namespace shisen_cpp diff --git a/include/shisen_cpp/config/grpc/config.hpp b/include/shisen_cpp/config/grpc/config.hpp index 32771d5..484b3a0 100644 --- a/include/shisen_cpp/config/grpc/config.hpp +++ b/include/shisen_cpp/config/grpc/config.hpp @@ -59,7 +59,7 @@ class ConfigGrpc ~ConfigGrpc(); - void Run(uint16_t port, const std::string & path, rclcpp::Node::SharedPtr node, std::shared_ptr camera_node); + void Run(uint16_t port, const std::string & path, std::shared_ptr camera_node); private: std::string path; diff --git a/src/shisen_cpp/camera/node/camera_node.cpp b/src/shisen_cpp/camera/node/camera_node.cpp index eb53656..3d859b8 100644 --- a/src/shisen_cpp/camera/node/camera_node.cpp +++ b/src/shisen_cpp/camera/node/camera_node.cpp @@ -193,17 +193,6 @@ CaptureSetting CameraNode::on_configure_capture_setting( void CameraNode::configure_capture_setting(const CaptureSetting & capture_setting) { // Update with configured data - - // Debug - std::cout << "[Debug From camera_node.cpp]" << std::endl; - std::cout << "brightness: " << capture_setting.brightness << std::endl; - std::cout << "contrast: " << capture_setting.contrast << std::endl; - std::cout << "saturation: " << capture_setting.saturation << std::endl; - std::cout << "temperature: " << capture_setting.temperature << std::endl; - std::cout << "exposure: " << capture_setting.exposure << std::endl; - std::cout << "gain: " << capture_setting.gain << std::endl; - - // !Debug current_capture_setting.update_with(on_configure_capture_setting(capture_setting)); capture_setting_event_publisher->publish(static_cast(current_capture_setting)); diff --git a/src/shisen_cpp/config/grpc/call_data_save_capture_setting.cpp b/src/shisen_cpp/config/grpc/call_data_save_capture_setting.cpp index 4e41697..e627599 100644 --- a/src/shisen_cpp/config/grpc/call_data_save_capture_setting.cpp +++ b/src/shisen_cpp/config/grpc/call_data_save_capture_setting.cpp @@ -54,7 +54,7 @@ void CallDataSaveCaptureSetting::HandleRequest() nlohmann::json capture_data = nlohmann::json::parse(json_string); config.save_capture_setting(capture_data); - RCLCPP_INFO(rclcpp::get_logger("Save config"), " config has been saved! "); + RCLCPP_INFO(rclcpp::get_logger("Save config"), "config has been saved! "); } catch (nlohmann::json::exception & e) { RCLCPP_ERROR(rclcpp::get_logger("Save config"), e.what()); } diff --git a/src/shisen_cpp/config/grpc/call_data_set_capture_setting.cpp b/src/shisen_cpp/config/grpc/call_data_set_capture_setting.cpp index 21cb0bf..fcabf43 100644 --- a/src/shisen_cpp/config/grpc/call_data_set_capture_setting.cpp +++ b/src/shisen_cpp/config/grpc/call_data_set_capture_setting.cpp @@ -28,17 +28,15 @@ namespace shisen_cpp { CallDataSetCaptureSetting::CallDataSetCaptureSetting( shisen_interfaces::proto::Config::AsyncService * service, grpc::ServerCompletionQueue * cq, - const std::string & path, rclcpp::Node::SharedPtr node, std::shared_ptr camera_node) -: CallData(service, cq, path), node_(node), camera_node_(camera_node) + const std::string & path, std::shared_ptr camera_node) +: CallData(service, cq, path), camera_node_(camera_node) { - set_capture_publisher_ = node_->create_publisher( - "shisen_cpp/config/capture_setting", 10); Proceed(); } void CallDataSetCaptureSetting::AddNextToCompletionQueue() { - new CallDataSetCaptureSetting(service_, cq_, path_, node_, camera_node_); + new CallDataSetCaptureSetting(service_, cq_, path_, camera_node_); } void CallDataSetCaptureSetting::WaitForRequest() @@ -67,25 +65,10 @@ void CallDataSetCaptureSetting::HandleRequest() capture_setting.gain.set(gain); camera_node_->configure_capture_setting(capture_setting); - // shisen_interfaces::msg::CaptureSetting msg; - // msg.brightness.clear(); - // msg.contrast.clear(); - // msg.saturation.clear(); - // msg.temperature.clear(); - // msg.exposure.clear(); - // msg.gain.clear(); - // msg.brightness.push_back(brightness); - // msg.contrast.push_back(contrast); - // msg.saturation.push_back(saturation); - // msg.temperature.push_back(temperature); - // msg.exposure.push_back(exposure); - // msg.gain.push_back(gain); - - // set_capture_publisher_->publish(msg); RCLCPP_INFO( - rclcpp::get_logger("Publish capture setting config"), - "capture setting config has been applied!"); + rclcpp::get_logger("Set config"), "config has been applied!" + ); } catch (nlohmann::json::exception e) { RCLCPP_ERROR(rclcpp::get_logger("Publish config"), e.what()); } diff --git a/src/shisen_cpp/config/grpc/config.cpp b/src/shisen_cpp/config/grpc/config.cpp index 9a6f562..9bc8d89 100644 --- a/src/shisen_cpp/config/grpc/config.cpp +++ b/src/shisen_cpp/config/grpc/config.cpp @@ -19,12 +19,12 @@ // THE SOFTWARE. #include "rclcpp/rclcpp.hpp" -#include "shisen_cpp/config/grpc/call_data_base.hpp" -#include "shisen_cpp/config/grpc/call_data_get_capture_setting.hpp" -#include "shisen_cpp/config/grpc/call_data_save_capture_setting.hpp" -#include "shisen_cpp/config/grpc/call_data_set_capture_setting.hpp" -#include "shisen_cpp/config/grpc/config.hpp" -#include "shisen_cpp/config/utils/config.hpp" +#include +#include +#include +#include +#include +#include #include #include @@ -52,7 +52,7 @@ void ConfigGrpc::SignIntHandler(int signum) exit(signum); } -void ConfigGrpc::Run(uint16_t port, const std::string & path, rclcpp::Node::SharedPtr node, std::shared_ptr camera_node) +void ConfigGrpc::Run(uint16_t port, const std::string & path, std::shared_ptr camera_node) { Config config(path); std::string server_address = @@ -67,10 +67,10 @@ void ConfigGrpc::Run(uint16_t port, const std::string & path, rclcpp::Node::Shar std::cout << "Server listening on " << server_address << std::endl; signal(SIGINT, SignIntHandler); - thread_ = std::thread([&path, &node, &camera_node, this]() { + thread_ = std::thread([&path, &camera_node, this]() { new CallDataGetCaptureSetting(&service_, cq_.get(), path); new CallDataSaveCaptureSetting(&service_, cq_.get(), path); - new CallDataSetCaptureSetting(&service_, cq_.get(), path, node, camera_node); + new CallDataSetCaptureSetting(&service_, cq_.get(), path, camera_node); void * tag; // uniquely identifies a request. bool ok = true; while (true) { diff --git a/src/shisen_cpp/node/shisen_cpp_node.cpp b/src/shisen_cpp/node/shisen_cpp_node.cpp index 1f0a615..970f180 100644 --- a/src/shisen_cpp/node/shisen_cpp_node.cpp +++ b/src/shisen_cpp/node/shisen_cpp_node.cpp @@ -18,7 +18,7 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. -#include "shisen_cpp/config/grpc/config.hpp" +#include #include #include @@ -42,7 +42,7 @@ ShisenCppNode::ShisenCppNode(rclcpp::Node::SharedPtr node, const std::string & p } ); - config_grpc.Run(5757, path, node, camera_node); + config_grpc.Run(5757, path, camera_node); RCLCPP_INFO(rclcpp::get_logger("GrpcServers"), "grpc running"); } From 23758f3388962c9ad20def4068064645838fda69 Mon Sep 17 00:00:00 2001 From: mbsaloka Date: Sat, 27 Apr 2024 17:43:25 +0700 Subject: [PATCH 17/31] refactor: add override mark and change path to constant reference --- include/shisen_cpp/config/grpc/call_data.hpp | 6 +++--- .../config/grpc/call_data_get_capture_setting.hpp | 4 ++-- .../config/grpc/call_data_save_capture_setting.hpp | 4 ++-- .../config/grpc/call_data_set_capture_setting.hpp | 7 +++---- include/shisen_cpp/config/grpc/config.hpp | 6 +----- include/shisen_cpp/config/utils/config.hpp | 2 -- src/shisen_cpp/camera/node/camera_node.cpp | 2 -- src/shisen_cpp/config/grpc/call_data_base.cpp | 2 +- .../config/grpc/call_data_get_capture_setting.cpp | 10 +++++----- .../config/grpc/call_data_save_capture_setting.cpp | 12 ++++++------ .../config/grpc/call_data_set_capture_setting.cpp | 10 +++++----- src/shisen_cpp/config/grpc/config.cpp | 2 +- src/shisen_cpp/config/utils/config.cpp | 4 ++-- 13 files changed, 31 insertions(+), 40 deletions(-) diff --git a/include/shisen_cpp/config/grpc/call_data.hpp b/include/shisen_cpp/config/grpc/call_data.hpp index c28d422..778304a 100644 --- a/include/shisen_cpp/config/grpc/call_data.hpp +++ b/include/shisen_cpp/config/grpc/call_data.hpp @@ -35,9 +35,9 @@ class CallData : public CallDataBase public: CallData( shisen_interfaces::proto::Config::AsyncService * service, grpc::ServerCompletionQueue * cq, - const std::string path); + const std::string & path); - void Proceed(); + void Proceed() override; protected: virtual void AddNextToCompletionQueue() = 0; @@ -60,7 +60,7 @@ class CallData : public CallDataBase template CallData::CallData( shisen_interfaces::proto::Config::AsyncService * service, grpc::ServerCompletionQueue * cq, - const std::string path) + const std::string & path) : status_(CREATE), service_(service), cq_(cq), responder_(&ctx_), path_(path) { } diff --git a/include/shisen_cpp/config/grpc/call_data_get_capture_setting.hpp b/include/shisen_cpp/config/grpc/call_data_get_capture_setting.hpp index 16a28d1..00df8e7 100644 --- a/include/shisen_cpp/config/grpc/call_data_get_capture_setting.hpp +++ b/include/shisen_cpp/config/grpc/call_data_get_capture_setting.hpp @@ -35,8 +35,8 @@ class CallDataGetCaptureSetting protected: void AddNextToCompletionQueue() override; - void WaitForRequest(); - void HandleRequest(); + void WaitForRequest() override; + void HandleRequest() override; }; } // namespace shisen_cpp diff --git a/include/shisen_cpp/config/grpc/call_data_save_capture_setting.hpp b/include/shisen_cpp/config/grpc/call_data_save_capture_setting.hpp index fe1b24e..8b03a87 100644 --- a/include/shisen_cpp/config/grpc/call_data_save_capture_setting.hpp +++ b/include/shisen_cpp/config/grpc/call_data_save_capture_setting.hpp @@ -36,8 +36,8 @@ class CallDataSaveCaptureSetting protected: void AddNextToCompletionQueue() override; - void WaitForRequest(); - void HandleRequest(); + void WaitForRequest() override; + void HandleRequest() override; }; } // namespace shisen_cpp diff --git a/include/shisen_cpp/config/grpc/call_data_set_capture_setting.hpp b/include/shisen_cpp/config/grpc/call_data_set_capture_setting.hpp index 5171363..8ac42a6 100644 --- a/include/shisen_cpp/config/grpc/call_data_set_capture_setting.hpp +++ b/include/shisen_cpp/config/grpc/call_data_set_capture_setting.hpp @@ -24,7 +24,7 @@ #include #include #include -#include "shisen_cpp/utility.hpp" +#include namespace shisen_cpp { @@ -38,9 +38,8 @@ class CallDataSetCaptureSetting protected: void AddNextToCompletionQueue() override; - void WaitForRequest(); - void HandleRequest(); - rclcpp::Node::SharedPtr node_; + void WaitForRequest() override; + void HandleRequest() override; std::shared_ptr camera_node_; }; } // namespace shisen_cpp diff --git a/include/shisen_cpp/config/grpc/config.hpp b/include/shisen_cpp/config/grpc/config.hpp index 484b3a0..0ef799f 100644 --- a/include/shisen_cpp/config/grpc/config.hpp +++ b/include/shisen_cpp/config/grpc/config.hpp @@ -28,6 +28,7 @@ #include #include #include +#include #include #include #include @@ -35,8 +36,6 @@ #include #include -#include - #include #include #include @@ -46,9 +45,6 @@ #include #include - -using shisen_interfaces::proto::Config; - namespace shisen_cpp { class ConfigGrpc diff --git a/include/shisen_cpp/config/utils/config.hpp b/include/shisen_cpp/config/utils/config.hpp index 509d072..41cc4a2 100644 --- a/include/shisen_cpp/config/utils/config.hpp +++ b/include/shisen_cpp/config/utils/config.hpp @@ -23,8 +23,6 @@ #include -#include -#include #include namespace shisen_cpp diff --git a/src/shisen_cpp/camera/node/camera_node.cpp b/src/shisen_cpp/camera/node/camera_node.cpp index 3d859b8..eec28cd 100644 --- a/src/shisen_cpp/camera/node/camera_node.cpp +++ b/src/shisen_cpp/camera/node/camera_node.cpp @@ -195,8 +195,6 @@ void CameraNode::configure_capture_setting(const CaptureSetting & capture_settin // Update with configured data current_capture_setting.update_with(on_configure_capture_setting(capture_setting)); capture_setting_event_publisher->publish(static_cast(current_capture_setting)); - - std::cout << "[Configure Done]" << std::endl; } void CameraNode::load_configuration(const std::string & path) diff --git a/src/shisen_cpp/config/grpc/call_data_base.cpp b/src/shisen_cpp/config/grpc/call_data_base.cpp index c646a6f..7790632 100644 --- a/src/shisen_cpp/config/grpc/call_data_base.cpp +++ b/src/shisen_cpp/config/grpc/call_data_base.cpp @@ -18,7 +18,7 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. -#include "shisen_cpp/config/grpc/call_data_base.hpp" +#include namespace shisen_cpp { diff --git a/src/shisen_cpp/config/grpc/call_data_get_capture_setting.cpp b/src/shisen_cpp/config/grpc/call_data_get_capture_setting.cpp index e9eb036..bb37da5 100644 --- a/src/shisen_cpp/config/grpc/call_data_get_capture_setting.cpp +++ b/src/shisen_cpp/config/grpc/call_data_get_capture_setting.cpp @@ -18,11 +18,11 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. -#include "rclcpp/rclcpp.hpp" -#include "shisen_cpp/config/grpc/call_data_get_capture_setting.hpp" -#include "shisen_cpp/config/utils/config.hpp" -#include "shisen_interfaces/shisen.grpc.pb.h" -#include "shisen_interfaces/shisen.pb.h" +#include +#include +#include +#include +#include namespace shisen_cpp { diff --git a/src/shisen_cpp/config/grpc/call_data_save_capture_setting.cpp b/src/shisen_cpp/config/grpc/call_data_save_capture_setting.cpp index e627599..cc10f4b 100644 --- a/src/shisen_cpp/config/grpc/call_data_save_capture_setting.cpp +++ b/src/shisen_cpp/config/grpc/call_data_save_capture_setting.cpp @@ -18,12 +18,12 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. -#include "nlohmann/json.hpp" -#include "rclcpp/rclcpp.hpp" -#include "shisen_cpp/config/grpc/call_data_save_capture_setting.hpp" -#include "shisen_cpp/config/utils/config.hpp" -#include "shisen_interfaces/shisen.grpc.pb.h" -#include "shisen_interfaces/shisen.pb.h" +#include +#include +#include +#include +#include +#include namespace shisen_cpp { diff --git a/src/shisen_cpp/config/grpc/call_data_set_capture_setting.cpp b/src/shisen_cpp/config/grpc/call_data_set_capture_setting.cpp index fcabf43..5d2b1bd 100644 --- a/src/shisen_cpp/config/grpc/call_data_set_capture_setting.cpp +++ b/src/shisen_cpp/config/grpc/call_data_set_capture_setting.cpp @@ -18,11 +18,11 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. -#include "rclcpp/rclcpp.hpp" -#include "shisen_cpp/config/grpc/call_data_set_capture_setting.hpp" -#include "shisen_cpp/config/utils/config.hpp" -#include "shisen_interfaces/shisen.grpc.pb.h" -#include "shisen_interfaces/shisen.pb.h" +#include +#include +#include +#include +#include namespace shisen_cpp { diff --git a/src/shisen_cpp/config/grpc/config.cpp b/src/shisen_cpp/config/grpc/config.cpp index 9bc8d89..cbf7108 100644 --- a/src/shisen_cpp/config/grpc/config.cpp +++ b/src/shisen_cpp/config/grpc/config.cpp @@ -18,7 +18,7 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. -#include "rclcpp/rclcpp.hpp" +#include #include #include #include diff --git a/src/shisen_cpp/config/utils/config.cpp b/src/shisen_cpp/config/utils/config.cpp index c5777bb..4e61f25 100644 --- a/src/shisen_cpp/config/utils/config.cpp +++ b/src/shisen_cpp/config/utils/config.cpp @@ -18,8 +18,8 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. -#include "nlohmann/json.hpp" -#include "shisen_cpp/config/utils/config.hpp" +#include +#include #include #include From 41c9489e5fd090591115f6e39a70e314f203492e Mon Sep 17 00:00:00 2001 From: mbsaloka Date: Sat, 27 Apr 2024 20:56:45 +0700 Subject: [PATCH 18/31] refactor: change enum CallStatus and header format --- .../shisen_cpp/camera/node/camera_node.hpp | 8 ++-- .../provider/camera_config_provider.hpp | 5 +-- .../camera/provider/image_provider.hpp | 9 ++--- include/shisen_cpp/config/grpc/call_data.hpp | 37 ++++++++++++------- include/shisen_cpp/config/grpc/config.hpp | 6 +-- include/shisen_cpp/node/shisen_cpp_node.hpp | 6 +-- include/shisen_cpp/utility/emptiable.hpp | 2 +- include/shisen_cpp/utility/emptiable.impl.hpp | 2 +- include/shisen_cpp/utility/interface.hpp | 2 +- .../viewer/consumer/image_consumer.hpp | 7 ++-- .../shisen_cpp/viewer/node/viewer_node.hpp | 8 ++-- src/shisen_cpp/config/grpc/config.cpp | 5 --- 12 files changed, 47 insertions(+), 50 deletions(-) diff --git a/include/shisen_cpp/camera/node/camera_node.hpp b/include/shisen_cpp/camera/node/camera_node.hpp index a78f07a..cd80498 100644 --- a/include/shisen_cpp/camera/node/camera_node.hpp +++ b/include/shisen_cpp/camera/node/camera_node.hpp @@ -22,15 +22,13 @@ #define SHISEN_CPP__CAMERA__NODE__CAMERA_NODE_HPP_ #include +#include +#include +#include #include #include -#include "shisen_cpp/camera/provider/camera_config_provider.hpp" -#include "shisen_cpp/camera/provider/image_provider.hpp" - -#include "shisen_cpp/utility.hpp" - namespace shisen_cpp::camera { diff --git a/include/shisen_cpp/camera/provider/camera_config_provider.hpp b/include/shisen_cpp/camera/provider/camera_config_provider.hpp index 208a895..3de6a45 100644 --- a/include/shisen_cpp/camera/provider/camera_config_provider.hpp +++ b/include/shisen_cpp/camera/provider/camera_config_provider.hpp @@ -22,13 +22,12 @@ #define SHISEN_CPP__CAMERA__PROVIDER__CAMERA_CONFIG_PROVIDER_HPP_ #include +#include +#include #include #include -#include "shisen_cpp/utility/options.hpp" -#include "shisen_interfaces/msg/camera_config.hpp" - namespace shisen_cpp::camera { diff --git a/include/shisen_cpp/camera/provider/image_provider.hpp b/include/shisen_cpp/camera/provider/image_provider.hpp index 315181e..9104bb8 100644 --- a/include/shisen_cpp/camera/provider/image_provider.hpp +++ b/include/shisen_cpp/camera/provider/image_provider.hpp @@ -24,14 +24,13 @@ #include #include #include +#include +#include +#include + #include #include -#include "sensor_msgs/msg/image.hpp" -#include "std_msgs/msg/header.hpp" - -#include "shisen_cpp/utility.hpp" - namespace shisen_cpp::camera { diff --git a/include/shisen_cpp/config/grpc/call_data.hpp b/include/shisen_cpp/config/grpc/call_data.hpp index 778304a..0bf82c8 100644 --- a/include/shisen_cpp/config/grpc/call_data.hpp +++ b/include/shisen_cpp/config/grpc/call_data.hpp @@ -27,6 +27,13 @@ #include #include +enum class CallStatus +{ + CREATE = 1, + PROCESS = 2, + FINISH = 3, +}; + namespace shisen_cpp { template @@ -42,7 +49,7 @@ class CallData : public CallDataBase protected: virtual void AddNextToCompletionQueue() = 0; - enum CallStatus { CREATE, PROCESS, FINISH }; + // enum CallStatus { CREATE, PROCESS, FINISH }; CallStatus status_; // The current serving state. @@ -61,24 +68,28 @@ template CallData::CallData( shisen_interfaces::proto::Config::AsyncService * service, grpc::ServerCompletionQueue * cq, const std::string & path) -: status_(CREATE), service_(service), cq_(cq), responder_(&ctx_), path_(path) +: status_(CallStatus::CREATE), service_(service), cq_(cq), responder_(&ctx_), path_(path) { } template void CallData::Proceed() { - if (status_ == CREATE) { - status_ = PROCESS; - WaitForRequest(); - } else if (status_ == PROCESS) { - AddNextToCompletionQueue(); - HandleRequest(); - status_ = FINISH; - responder_.Finish(reply_, grpc::Status::OK, this); - } else { - GPR_ASSERT(status_ == FINISH); - delete this; + switch (status_) { + case CallStatus::CREATE: + status_ = CallStatus::PROCESS; + WaitForRequest(); + break; + case CallStatus::PROCESS: + AddNextToCompletionQueue(); + HandleRequest(); + status_ = CallStatus::FINISH; + responder_.Finish(reply_, grpc::Status::OK, this); + break; + default: + GPR_ASSERT(status_ == CallStatus::FINISH); + delete this; + break; } } diff --git a/include/shisen_cpp/config/grpc/config.hpp b/include/shisen_cpp/config/grpc/config.hpp index 0ef799f..03f01ec 100644 --- a/include/shisen_cpp/config/grpc/config.hpp +++ b/include/shisen_cpp/config/grpc/config.hpp @@ -29,18 +29,14 @@ #include #include #include -#include -#include #include #include -#include -#include #include +#include #include #include #include -#include #include #include #include diff --git a/include/shisen_cpp/node/shisen_cpp_node.hpp b/include/shisen_cpp/node/shisen_cpp_node.hpp index a0bd299..cb6e7fe 100644 --- a/include/shisen_cpp/node/shisen_cpp_node.hpp +++ b/include/shisen_cpp/node/shisen_cpp_node.hpp @@ -23,9 +23,9 @@ #include "../utility.hpp" #include -#include "shisen_cpp/camera/node/camera_node.hpp" -#include "shisen_cpp/config/grpc/config.hpp" -#include "shisen_cpp/config/utils/config.hpp" +#include +#include +#include #include diff --git a/include/shisen_cpp/utility/emptiable.hpp b/include/shisen_cpp/utility/emptiable.hpp index a5d0373..2a73346 100644 --- a/include/shisen_cpp/utility/emptiable.hpp +++ b/include/shisen_cpp/utility/emptiable.hpp @@ -53,6 +53,6 @@ class Emptiable } // namespace shisen_cpp -#include "shisen_cpp/utility/emptiable.impl.hpp" +#include #endif // SHISEN_CPP__UTILITY__EMPTIABLE_HPP_ diff --git a/include/shisen_cpp/utility/emptiable.impl.hpp b/include/shisen_cpp/utility/emptiable.impl.hpp index 50bb759..7c5cfcf 100644 --- a/include/shisen_cpp/utility/emptiable.impl.hpp +++ b/include/shisen_cpp/utility/emptiable.impl.hpp @@ -21,7 +21,7 @@ #ifndef SHISEN_CPP__UTILITY__EMPTIABLE_IMPL_HPP_ #define SHISEN_CPP__UTILITY__EMPTIABLE_IMPL_HPP_ -#include "shisen_cpp/utility/emptiable.hpp" +#include namespace shisen_cpp { diff --git a/include/shisen_cpp/utility/interface.hpp b/include/shisen_cpp/utility/interface.hpp index 8e500e4..b5319da 100644 --- a/include/shisen_cpp/utility/interface.hpp +++ b/include/shisen_cpp/utility/interface.hpp @@ -21,9 +21,9 @@ #ifndef SHISEN_CPP__UTILITY__INTERFACE_HPP_ #define SHISEN_CPP__UTILITY__INTERFACE_HPP_ +#include #include #include -#include "sensor_msgs/msg/image.hpp" namespace shisen_cpp { diff --git a/include/shisen_cpp/viewer/consumer/image_consumer.hpp b/include/shisen_cpp/viewer/consumer/image_consumer.hpp index 43ab04e..9a5e12e 100644 --- a/include/shisen_cpp/viewer/consumer/image_consumer.hpp +++ b/include/shisen_cpp/viewer/consumer/image_consumer.hpp @@ -21,16 +21,15 @@ #ifndef SHISEN_CPP__VIEWER__CONSUMER__IMAGE_CONSUMER_HPP_ #define SHISEN_CPP__VIEWER__CONSUMER__IMAGE_CONSUMER_HPP_ -#include "sensor_msgs/msg/image.hpp" - #include #include #include +#include +#include + #include #include -#include "shisen_cpp/utility.hpp" - namespace shisen_cpp::viewer { diff --git a/include/shisen_cpp/viewer/node/viewer_node.hpp b/include/shisen_cpp/viewer/node/viewer_node.hpp index f0a6621..c3c2c42 100644 --- a/include/shisen_cpp/viewer/node/viewer_node.hpp +++ b/include/shisen_cpp/viewer/node/viewer_node.hpp @@ -22,13 +22,13 @@ #define SHISEN_CPP__VIEWER__NODE__VIEWER_NODE_HPP_ #include +#include +#include +#include + #include #include -#include "sensor_msgs/msg/image.hpp" -#include "shisen_cpp/utility.hpp" -#include "shisen_cpp/viewer/consumer/image_consumer.hpp" - namespace shisen_cpp::viewer { diff --git a/src/shisen_cpp/config/grpc/config.cpp b/src/shisen_cpp/config/grpc/config.cpp index cbf7108..7f5dacf 100644 --- a/src/shisen_cpp/config/grpc/config.cpp +++ b/src/shisen_cpp/config/grpc/config.cpp @@ -26,11 +26,6 @@ #include #include -#include -#include -#include -#include - using grpc::ServerBuilder; using namespace std::chrono_literals; From c0323c4f64d1d4c13c9fc296775c086e8850fa98 Mon Sep 17 00:00:00 2001 From: mbsaloka Date: Sun, 28 Apr 2024 15:52:12 +0700 Subject: [PATCH 19/31] refactor: change how to include utility and emptiable lib --- include/shisen_cpp/node/shisen_cpp_node.hpp | 2 +- include/shisen_cpp/utility/capture_setting.hpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/include/shisen_cpp/node/shisen_cpp_node.hpp b/include/shisen_cpp/node/shisen_cpp_node.hpp index cb6e7fe..c306c47 100644 --- a/include/shisen_cpp/node/shisen_cpp_node.hpp +++ b/include/shisen_cpp/node/shisen_cpp_node.hpp @@ -21,11 +21,11 @@ #ifndef SHISEN_CPP__NODE__SHISEN_CPP_NODE_HPP_ #define SHISEN_CPP__NODE__SHISEN_CPP_NODE_HPP_ -#include "../utility.hpp" #include #include #include #include +#include #include diff --git a/include/shisen_cpp/utility/capture_setting.hpp b/include/shisen_cpp/utility/capture_setting.hpp index 27fcf15..a41b63b 100644 --- a/include/shisen_cpp/utility/capture_setting.hpp +++ b/include/shisen_cpp/utility/capture_setting.hpp @@ -21,7 +21,7 @@ #ifndef SHISEN_CPP__UTILITY__CAPTURE_SETTING_HPP_ #define SHISEN_CPP__UTILITY__CAPTURE_SETTING_HPP_ -#include "./emptiable.hpp" +#include #include namespace shisen_cpp From 642e037876ad795f23a1d7e460add2bb0cbb8a89 Mon Sep 17 00:00:00 2001 From: mbsaloka Date: Mon, 29 Apr 2024 16:20:10 +0700 Subject: [PATCH 20/31] fix: fixing CallStatus enum --- include/shisen_cpp/config/grpc/call_data.hpp | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/include/shisen_cpp/config/grpc/call_data.hpp b/include/shisen_cpp/config/grpc/call_data.hpp index 0bf82c8..daae2bd 100644 --- a/include/shisen_cpp/config/grpc/call_data.hpp +++ b/include/shisen_cpp/config/grpc/call_data.hpp @@ -29,9 +29,9 @@ enum class CallStatus { - CREATE = 1, - PROCESS = 2, - FINISH = 3, + CREATE, + PROCESS, + FINISH, }; namespace shisen_cpp @@ -49,8 +49,6 @@ class CallData : public CallDataBase protected: virtual void AddNextToCompletionQueue() = 0; - // enum CallStatus { CREATE, PROCESS, FINISH }; - CallStatus status_; // The current serving state. shisen_interfaces::proto::Config::AsyncService * service_; @@ -86,8 +84,7 @@ void CallData::Proceed() status_ = CallStatus::FINISH; responder_.Finish(reply_, grpc::Status::OK, this); break; - default: - GPR_ASSERT(status_ == CallStatus::FINISH); + case CallStatus::FINISH: delete this; break; } From 0451e17ea47f5c3cca2706e55e8688685149d4d7 Mon Sep 17 00:00:00 2001 From: mbsaloka Date: Mon, 29 Apr 2024 16:20:41 +0700 Subject: [PATCH 21/31] feat: create get_image service --- CMakeLists.txt | 7 +- .../config/grpc/call_data_get_image.hpp | 45 +++++++++++++ .../config/grpc/call_data_get_image.cpp | 65 +++++++++++++++++++ src/shisen_cpp/config/grpc/config.cpp | 2 + 4 files changed, 116 insertions(+), 3 deletions(-) create mode 100644 include/shisen_cpp/config/grpc/call_data_get_image.hpp create mode 100644 src/shisen_cpp/config/grpc/call_data_get_image.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 0cf32e5..8398ee9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -38,8 +38,9 @@ add_library(${PROJECT_NAME} SHARED "src/${PROJECT_NAME}/viewer/consumer/image_consumer.cpp" "src/${PROJECT_NAME}/viewer/node/viewer_node.cpp" "src/${PROJECT_NAME}/config/grpc/config.cpp" - "src/${PROJECT_NAME}/config/grpc/call_data_base.cpp" + "src/${PROJECT_NAME}/config/grpc/call_data_base.cpp" "src/${PROJECT_NAME}/config/grpc/call_data_get_capture_setting.cpp" + "src/${PROJECT_NAME}/config/grpc/call_data_get_image.cpp" "src/${PROJECT_NAME}/config/grpc/call_data_set_capture_setting.cpp" "src/${PROJECT_NAME}/config/grpc/call_data_save_capture_setting.cpp" ) @@ -52,9 +53,9 @@ target_include_directories(${PROJECT_NAME} PUBLIC ament_target_dependencies(${PROJECT_NAME} keisan OpenCV rclcpp shisen_interfaces sensor_msgs cv_bridge std_msgs) -target_link_libraries(${PROJECT_NAME} +target_link_libraries(${PROJECT_NAME} gRPC::grpc++_reflection - gRPC::grpc++ + gRPC::grpc++ ) install(TARGETS ${PROJECT_NAME} diff --git a/include/shisen_cpp/config/grpc/call_data_get_image.hpp b/include/shisen_cpp/config/grpc/call_data_get_image.hpp new file mode 100644 index 0000000..bd2bff6 --- /dev/null +++ b/include/shisen_cpp/config/grpc/call_data_get_image.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 SHISEN_CPP__CONFIG__GRPC__CALL_DATA_GET_IMAGE_HPP__ +#define SHISEN_CPP__CONFIG__GRPC__CALL_DATA_GET_IMAGE_HPP__ + +#include +#include + +namespace shisen_cpp +{ +class CallDataGetImage +: CallData +{ +public: + CallDataGetImage( + shisen_interfaces::proto::Config::AsyncService * service, grpc::ServerCompletionQueue * cq, + const std::string & path, std::shared_ptr camera_node); + +protected: + void AddNextToCompletionQueue() override; + void WaitForRequest() override; + void HandleRequest() override; + std::shared_ptr camera_node_; +}; +} // namespace shisen_cpp + +#endif // SHISEN_CPP__CONFIG__GRPC__CALL_DATA_GET_IMAGE_HPP__ diff --git a/src/shisen_cpp/config/grpc/call_data_get_image.cpp b/src/shisen_cpp/config/grpc/call_data_get_image.cpp new file mode 100644 index 0000000..f0ad044 --- /dev/null +++ b/src/shisen_cpp/config/grpc/call_data_get_image.cpp @@ -0,0 +1,65 @@ +// 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 +#include +#include +#include + +namespace shisen_cpp +{ +CallDataGetImage::CallDataGetImage( + shisen_interfaces::proto::Config::AsyncService * service, grpc::ServerCompletionQueue * cq, + const std::string & path, std::shared_ptr camera_node) +: CallData(service, cq, path), camera_node_(camera_node) +{ + Proceed(); +} + +void CallDataGetImage::AddNextToCompletionQueue() +{ + new CallDataGetImage(service_, cq_, path_, camera_node_); +} + +void CallDataGetImage::WaitForRequest() +{ + service_->RequestGetImage(&ctx_, &request_, &responder_, cq_, cq_, this); +} + +void CallDataGetImage::HandleRequest() +{ + sensor_msgs::msg::Image image; + image = camera_node_->image_provider->get_image(); + + int width = image.width; + int height = image.height; + int step = image.step; + std::string encoding = image.encoding; + std::string data(image.data.begin(), image.data.end()); + + reply_.set_width(width); + reply_.set_height(height); + reply_.set_step(step); + reply_.set_encoding(encoding); + reply_.set_data(data); + + RCLCPP_INFO(rclcpp::get_logger("Get image"), "image has been sent!"); +} +} // namespace shisen_cpp diff --git a/src/shisen_cpp/config/grpc/config.cpp b/src/shisen_cpp/config/grpc/config.cpp index 7f5dacf..354ef23 100644 --- a/src/shisen_cpp/config/grpc/config.cpp +++ b/src/shisen_cpp/config/grpc/config.cpp @@ -21,6 +21,7 @@ #include #include #include +#include #include #include #include @@ -66,6 +67,7 @@ void ConfigGrpc::Run(uint16_t port, const std::string & path, std::shared_ptr Date: Mon, 29 Apr 2024 17:14:00 +0700 Subject: [PATCH 22/31] refactor: remove unnecessary headers --- include/shisen_cpp/config/grpc/call_data.hpp | 2 -- .../config/grpc/call_data_save_capture_setting.hpp | 1 - .../config/grpc/call_data_set_capture_setting.hpp | 1 - include/shisen_cpp/config/grpc/config.hpp | 12 ------------ include/shisen_cpp/config/utils/config.hpp | 2 -- src/shisen_cpp/config/utils/config.cpp | 1 - 6 files changed, 19 deletions(-) diff --git a/include/shisen_cpp/config/grpc/call_data.hpp b/include/shisen_cpp/config/grpc/call_data.hpp index daae2bd..10a7730 100644 --- a/include/shisen_cpp/config/grpc/call_data.hpp +++ b/include/shisen_cpp/config/grpc/call_data.hpp @@ -21,8 +21,6 @@ #ifndef __SHISEN_CPP__CONFIG__GRPC__CALL_DATA_HPP__ #define __SHISEN_CPP__CONFIG__GRPC__CALL_DATA_HPP__ -#include -#include #include #include #include diff --git a/include/shisen_cpp/config/grpc/call_data_save_capture_setting.hpp b/include/shisen_cpp/config/grpc/call_data_save_capture_setting.hpp index 8b03a87..47fc6a1 100644 --- a/include/shisen_cpp/config/grpc/call_data_save_capture_setting.hpp +++ b/include/shisen_cpp/config/grpc/call_data_save_capture_setting.hpp @@ -21,7 +21,6 @@ #ifndef SHISEN_CPP__CONFIG__GRPC__CALL_DATA_SAVE_CAPTURE_SETTING_HPP__ #define SHISEN_CPP__CONFIG__GRPC__CALL_DATA_SAVE_CAPTURE_SETTING_HPP__ -#include #include namespace shisen_cpp diff --git a/include/shisen_cpp/config/grpc/call_data_set_capture_setting.hpp b/include/shisen_cpp/config/grpc/call_data_set_capture_setting.hpp index 8ac42a6..07ae0fa 100644 --- a/include/shisen_cpp/config/grpc/call_data_set_capture_setting.hpp +++ b/include/shisen_cpp/config/grpc/call_data_set_capture_setting.hpp @@ -21,7 +21,6 @@ #ifndef SHISEN_CPP__CONFIG__GRPC__CALL_DATA_SET_CAPTURE_SETTING_HPP__ #define SHISEN_CPP__CONFIG__GRPC__CALL_DATA_SET_CAPTURE_SETTING_HPP__ -#include #include #include #include diff --git a/include/shisen_cpp/config/grpc/config.hpp b/include/shisen_cpp/config/grpc/config.hpp index 03f01ec..71627cf 100644 --- a/include/shisen_cpp/config/grpc/config.hpp +++ b/include/shisen_cpp/config/grpc/config.hpp @@ -21,24 +21,12 @@ #ifndef SHISEN_CPP__CONFIG__GRPC__CONFIG_HPP_ #define SHISEN_CPP__CONFIG__GRPC__CONFIG_HPP_ -#include -#include -#include -#include #include -#include -#include #include #include #include -#include -#include -#include -#include -#include #include -#include #include namespace shisen_cpp diff --git a/include/shisen_cpp/config/utils/config.hpp b/include/shisen_cpp/config/utils/config.hpp index 41cc4a2..f8e9187 100644 --- a/include/shisen_cpp/config/utils/config.hpp +++ b/include/shisen_cpp/config/utils/config.hpp @@ -23,8 +23,6 @@ #include -#include - namespace shisen_cpp { diff --git a/src/shisen_cpp/config/utils/config.cpp b/src/shisen_cpp/config/utils/config.cpp index 4e61f25..854ad28 100644 --- a/src/shisen_cpp/config/utils/config.cpp +++ b/src/shisen_cpp/config/utils/config.cpp @@ -18,7 +18,6 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. -#include #include #include From 4ca8815d19ddaffde35f3e8357a2bdb047d57c04 Mon Sep 17 00:00:00 2001 From: mbsaloka Date: Wed, 1 May 2024 00:33:28 +0700 Subject: [PATCH 23/31] fix: convert image data to bytes before sending reply --- .../config/grpc/call_data_get_image.hpp | 2 +- .../grpc/call_data_set_capture_setting.hpp | 2 +- .../config/grpc/call_data_get_image.cpp | 25 +++++++++---------- .../grpc/call_data_set_capture_setting.cpp | 2 +- 4 files changed, 15 insertions(+), 16 deletions(-) diff --git a/include/shisen_cpp/config/grpc/call_data_get_image.hpp b/include/shisen_cpp/config/grpc/call_data_get_image.hpp index bd2bff6..a9c1187 100644 --- a/include/shisen_cpp/config/grpc/call_data_get_image.hpp +++ b/include/shisen_cpp/config/grpc/call_data_get_image.hpp @@ -32,7 +32,7 @@ class CallDataGetImage public: CallDataGetImage( shisen_interfaces::proto::Config::AsyncService * service, grpc::ServerCompletionQueue * cq, - const std::string & path, std::shared_ptr camera_node); + const std::string & path, const std::shared_ptr& camera_node); protected: void AddNextToCompletionQueue() override; diff --git a/include/shisen_cpp/config/grpc/call_data_set_capture_setting.hpp b/include/shisen_cpp/config/grpc/call_data_set_capture_setting.hpp index 07ae0fa..d06499c 100644 --- a/include/shisen_cpp/config/grpc/call_data_set_capture_setting.hpp +++ b/include/shisen_cpp/config/grpc/call_data_set_capture_setting.hpp @@ -33,7 +33,7 @@ class CallDataSetCaptureSetting public: CallDataSetCaptureSetting( shisen_interfaces::proto::Config::AsyncService * service, grpc::ServerCompletionQueue * cq, - const std::string & path, std::shared_ptr camera_node); + const std::string & path, const std::shared_ptr& camera_node); protected: void AddNextToCompletionQueue() override; diff --git a/src/shisen_cpp/config/grpc/call_data_get_image.cpp b/src/shisen_cpp/config/grpc/call_data_get_image.cpp index f0ad044..ccbef66 100644 --- a/src/shisen_cpp/config/grpc/call_data_get_image.cpp +++ b/src/shisen_cpp/config/grpc/call_data_get_image.cpp @@ -18,6 +18,7 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. +#include #include #include #include @@ -27,7 +28,7 @@ namespace shisen_cpp { CallDataGetImage::CallDataGetImage( shisen_interfaces::proto::Config::AsyncService * service, grpc::ServerCompletionQueue * cq, - const std::string & path, std::shared_ptr camera_node) + const std::string & path, const std::shared_ptr& camera_node) : CallData(service, cq, path), camera_node_(camera_node) { Proceed(); @@ -45,20 +46,18 @@ void CallDataGetImage::WaitForRequest() void CallDataGetImage::HandleRequest() { - sensor_msgs::msg::Image image; - image = camera_node_->image_provider->get_image(); + cv::Mat image = camera_node_->image_provider->get_mat(); + if (image.empty()) { + RCLCPP_WARN(rclcpp::get_logger("Get image"), "Empty image!"); + return; + } - int width = image.width; - int height = image.height; - int step = image.step; - std::string encoding = image.encoding; - std::string data(image.data.begin(), image.data.end()); + std::vector image_bytes; + cv::imencode(".jpg", image, image_bytes); - reply_.set_width(width); - reply_.set_height(height); - reply_.set_step(step); - reply_.set_encoding(encoding); - reply_.set_data(data); + reply_.set_data(image_bytes.data(), image_bytes.size()); + reply_.set_height(image.rows); + reply_.set_width(image.cols); RCLCPP_INFO(rclcpp::get_logger("Get image"), "image has been sent!"); } diff --git a/src/shisen_cpp/config/grpc/call_data_set_capture_setting.cpp b/src/shisen_cpp/config/grpc/call_data_set_capture_setting.cpp index 5d2b1bd..3694783 100644 --- a/src/shisen_cpp/config/grpc/call_data_set_capture_setting.cpp +++ b/src/shisen_cpp/config/grpc/call_data_set_capture_setting.cpp @@ -28,7 +28,7 @@ namespace shisen_cpp { CallDataSetCaptureSetting::CallDataSetCaptureSetting( shisen_interfaces::proto::Config::AsyncService * service, grpc::ServerCompletionQueue * cq, - const std::string & path, std::shared_ptr camera_node) + const std::string & path, const std::shared_ptr& camera_node) : CallData(service, cq, path), camera_node_(camera_node) { Proceed(); From b3e8b525039e369d24c20a1c7631a87232f6636d Mon Sep 17 00:00:00 2001 From: mbsaloka Date: Wed, 1 May 2024 00:45:11 +0700 Subject: [PATCH 24/31] fix: remove debug line --- src/shisen_cpp/config/grpc/call_data_get_image.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/shisen_cpp/config/grpc/call_data_get_image.cpp b/src/shisen_cpp/config/grpc/call_data_get_image.cpp index ccbef66..e73dd18 100644 --- a/src/shisen_cpp/config/grpc/call_data_get_image.cpp +++ b/src/shisen_cpp/config/grpc/call_data_get_image.cpp @@ -58,7 +58,5 @@ void CallDataGetImage::HandleRequest() reply_.set_data(image_bytes.data(), image_bytes.size()); reply_.set_height(image.rows); reply_.set_width(image.cols); - - RCLCPP_INFO(rclcpp::get_logger("Get image"), "image has been sent!"); } } // namespace shisen_cpp From a9d9ec89bfb21907dc19e929e4e8cb8c4a9760bc Mon Sep 17 00:00:00 2001 From: mbsaloka Date: Wed, 1 May 2024 22:10:07 +0700 Subject: [PATCH 25/31] refactor: tidy up the code and change the way to include headers --- include/shisen_cpp/shisen_cpp.hpp | 14 +++++++------- include/shisen_cpp/utility.hpp | 8 ++++---- .../grpc/call_data_set_capture_setting.cpp | 19 ++++++------------- 3 files changed, 17 insertions(+), 24 deletions(-) diff --git a/include/shisen_cpp/shisen_cpp.hpp b/include/shisen_cpp/shisen_cpp.hpp index 11b1474..6eb85ca 100644 --- a/include/shisen_cpp/shisen_cpp.hpp +++ b/include/shisen_cpp/shisen_cpp.hpp @@ -21,13 +21,13 @@ #ifndef SHISEN_CPP__SHISEN_CPP_HPP_ #define SHISEN_CPP__SHISEN_CPP_HPP_ -#include "./camera/node/camera_node.hpp" -#include "./camera/provider/image_provider.hpp" -#include "./camera/provider/camera_config_provider.hpp" -#include "./node/shisen_cpp_node.hpp" -#include "./viewer/consumer/image_consumer.hpp" -#include "./viewer/node/viewer_node.hpp" +#include +#include +#include +#include +#include +#include -#include "./utility.hpp" +#include #endif // SHISEN_CPP__SHISEN_CPP_HPP_ diff --git a/include/shisen_cpp/utility.hpp b/include/shisen_cpp/utility.hpp index d4e3daf..ba1a6e1 100644 --- a/include/shisen_cpp/utility.hpp +++ b/include/shisen_cpp/utility.hpp @@ -21,9 +21,9 @@ #ifndef SHISEN_CPP__UTILITY_HPP_ #define SHISEN_CPP__UTILITY_HPP_ -#include "./utility/capture_setting.hpp" -#include "./utility/emptiable.hpp" -#include "./utility/interface.hpp" -#include "./utility/options.hpp" +#include +#include +#include +#include #endif // SHISEN_CPP__UTILITY_HPP_ diff --git a/src/shisen_cpp/config/grpc/call_data_set_capture_setting.cpp b/src/shisen_cpp/config/grpc/call_data_set_capture_setting.cpp index 3694783..de3a206 100644 --- a/src/shisen_cpp/config/grpc/call_data_set_capture_setting.cpp +++ b/src/shisen_cpp/config/grpc/call_data_set_capture_setting.cpp @@ -50,19 +50,12 @@ void CallDataSetCaptureSetting::HandleRequest() try { CaptureSetting capture_setting; - int brightness = request_.brightness(); - int contrast = request_.contrast(); - int saturation = request_.saturation(); - int temperature = request_.temperature(); - int exposure = request_.exposure(); - int gain = request_.gain(); - - capture_setting.brightness.set(brightness); - capture_setting.contrast.set(contrast); - capture_setting.saturation.set(saturation); - capture_setting.temperature.set(temperature); - capture_setting.exposure.set(exposure); - capture_setting.gain.set(gain); + capture_setting.brightness.set(request_.brightness()); + capture_setting.contrast.set(request_.contrast()); + capture_setting.saturation.set(request_.saturation()); + capture_setting.temperature.set(request_.temperature()); + capture_setting.exposure.set(request_.exposure()); + capture_setting.gain.set(request_.gain()); camera_node_->configure_capture_setting(capture_setting); From 62f304c07b95b57ac36a767424fc6a62ed12aee3 Mon Sep 17 00:00:00 2001 From: mbsaloka Date: Tue, 7 May 2024 21:24:31 +0700 Subject: [PATCH 26/31] feat: add _exported to cmakelist --- CMakeLists.txt | 68 +++++++++++++++---- .../config/grpc/call_data_get_image.cpp | 2 - src/shisen_cpp_main.cpp | 2 +- 3 files changed, 57 insertions(+), 15 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 8398ee9..d5c575d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -25,24 +25,37 @@ find_package(std_msgs REQUIRED) find_package(Protobuf CONFIG REQUIRED) message(STATUS "Using protobuf ${Protobuf_VERSION}") -install(DIRECTORY "include" DESTINATION ".") +# Find gRPC installation +# Looks for gRPCConfig.cmake file installed by gRPC's cmake installation. +find_package(gRPC CONFIG REQUIRED) +message(STATUS "Using gRPC ${gRPC_VERSION}") add_library(${PROJECT_NAME} SHARED - "src/${PROJECT_NAME}/config/utils/config.cpp" "src/${PROJECT_NAME}/camera/node/camera_node.cpp" "src/${PROJECT_NAME}/camera/provider/camera_config_provider.cpp" "src/${PROJECT_NAME}/camera/provider/image_provider.cpp" - "src/${PROJECT_NAME}/utility/capture_setting.cpp" - "src/${PROJECT_NAME}/utility/interface.cpp" - "src/${PROJECT_NAME}/node/shisen_cpp_node.cpp" - "src/${PROJECT_NAME}/viewer/consumer/image_consumer.cpp" - "src/${PROJECT_NAME}/viewer/node/viewer_node.cpp" "src/${PROJECT_NAME}/config/grpc/config.cpp" "src/${PROJECT_NAME}/config/grpc/call_data_base.cpp" "src/${PROJECT_NAME}/config/grpc/call_data_get_capture_setting.cpp" "src/${PROJECT_NAME}/config/grpc/call_data_get_image.cpp" - "src/${PROJECT_NAME}/config/grpc/call_data_set_capture_setting.cpp" "src/${PROJECT_NAME}/config/grpc/call_data_save_capture_setting.cpp" + "src/${PROJECT_NAME}/config/grpc/call_data_set_capture_setting.cpp" + "src/${PROJECT_NAME}/config/utils/config.cpp" + "src/${PROJECT_NAME}/utility/capture_setting.cpp" + "src/${PROJECT_NAME}/utility/interface.cpp" + "src/${PROJECT_NAME}/node/shisen_cpp_node.cpp" + "src/${PROJECT_NAME}/viewer/consumer/image_consumer.cpp" + "src/${PROJECT_NAME}/viewer/node/viewer_node.cpp" +) + +add_library(${PROJECT_NAME}_exported SHARED + "src/${PROJECT_NAME}/camera/node/camera_node.cpp" + "src/${PROJECT_NAME}/camera/provider/camera_config_provider.cpp" + "src/${PROJECT_NAME}/camera/provider/image_provider.cpp" + "src/${PROJECT_NAME}/utility/capture_setting.cpp" + "src/${PROJECT_NAME}/utility/interface.cpp" + "src/${PROJECT_NAME}/viewer/consumer/image_consumer.cpp" + "src/${PROJECT_NAME}/viewer/node/viewer_node.cpp" ) target_include_directories(${PROJECT_NAME} PUBLIC @@ -50,19 +63,50 @@ target_include_directories(${PROJECT_NAME} PUBLIC $ $) +target_include_directories(${PROJECT_NAME}_exported PUBLIC + $ + $ + $) + ament_target_dependencies(${PROJECT_NAME} - keisan OpenCV rclcpp shisen_interfaces sensor_msgs cv_bridge std_msgs) + keisan + OpenCV + rclcpp + shisen_interfaces + sensor_msgs + cv_bridge + std_msgs + gRPC) + +ament_target_dependencies(${PROJECT_NAME}_exported + keisan + OpenCV + rclcpp + shisen_interfaces + sensor_msgs + cv_bridge + std_msgs) target_link_libraries(${PROJECT_NAME} gRPC::grpc++_reflection gRPC::grpc++ ) +install(DIRECTORY "include" DESTINATION ".") + install(TARGETS ${PROJECT_NAME} - EXPORT export_${PROJECT_NAME} +EXPORT export_${PROJECT_NAME} + ARCHIVE DESTINATION "lib" + LIBRARY DESTINATION "lib" + RUNTIME DESTINATION "bin" + INCLUDES DESTINATION "include") + +install(TARGETS ${PROJECT_NAME}_exported +EXPORT export_${PROJECT_NAME}_exported ARCHIVE DESTINATION "lib" LIBRARY DESTINATION "lib" - RUNTIME DESTINATION "bin") + RUNTIME DESTINATION "bin" + INCLUDES DESTINATION "include") target_compile_options(${PROJECT_NAME} PRIVATE -fPIC) @@ -101,6 +145,6 @@ endif() ament_export_dependencies(keisan OpenCV rclcpp shisen_interfaces sensor_msgs cv_bridge std_msgs) ament_export_include_directories("include") -ament_export_libraries(${PROJECT_NAME}) +ament_export_libraries(${PROJECT_NAME}_exported) ament_package() diff --git a/src/shisen_cpp/config/grpc/call_data_get_image.cpp b/src/shisen_cpp/config/grpc/call_data_get_image.cpp index e73dd18..714f82c 100644 --- a/src/shisen_cpp/config/grpc/call_data_get_image.cpp +++ b/src/shisen_cpp/config/grpc/call_data_get_image.cpp @@ -56,7 +56,5 @@ void CallDataGetImage::HandleRequest() cv::imencode(".jpg", image, image_bytes); reply_.set_data(image_bytes.data(), image_bytes.size()); - reply_.set_height(image.rows); - reply_.set_width(image.cols); } } // namespace shisen_cpp diff --git a/src/shisen_cpp_main.cpp b/src/shisen_cpp_main.cpp index e7f84f0..9a978e1 100644 --- a/src/shisen_cpp_main.cpp +++ b/src/shisen_cpp_main.cpp @@ -30,7 +30,7 @@ int main(int argc, char ** argv) shisen_cpp::Options options; options.field_of_view = 78; - std::string path = ""; + std::string path = "./src/shisen_cpp/data/"; const char * help_message = "Usage: ros2 run shisen_cpp camera [path] [options] [--camera-prefix prefix]\n" From b25c50d85b605c4e877f3461fba10cf578327797 Mon Sep 17 00:00:00 2001 From: mbsaloka Date: Thu, 9 May 2024 01:56:15 +0700 Subject: [PATCH 27/31] feat: add try catch on grpc code --- .../grpc/call_data_get_capture_setting.cpp | 8 ++++++-- .../config/grpc/call_data_get_image.cpp | 20 +++++++++++-------- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/src/shisen_cpp/config/grpc/call_data_get_capture_setting.cpp b/src/shisen_cpp/config/grpc/call_data_get_capture_setting.cpp index bb37da5..2f9b7e2 100644 --- a/src/shisen_cpp/config/grpc/call_data_get_capture_setting.cpp +++ b/src/shisen_cpp/config/grpc/call_data_get_capture_setting.cpp @@ -47,7 +47,11 @@ void CallDataGetCaptureSetting::WaitForRequest() void CallDataGetCaptureSetting::HandleRequest() { Config config(path_); - reply_.set_json_capture(config.get_capture_setting("capture")); - RCLCPP_INFO(rclcpp::get_logger("Get config"), "config has been sent!"); + try { + reply_.set_json_capture(config.get_capture_setting("capture")); + RCLCPP_INFO(rclcpp::get_logger("Get config"), "config has been sent!"); + } catch (nlohmann::json::exception & e) { + RCLCPP_ERROR(rclcpp::get_logger("Publish config"), e.what()); + } } } // namespace shisen_cpp diff --git a/src/shisen_cpp/config/grpc/call_data_get_image.cpp b/src/shisen_cpp/config/grpc/call_data_get_image.cpp index 714f82c..47a9dfb 100644 --- a/src/shisen_cpp/config/grpc/call_data_get_image.cpp +++ b/src/shisen_cpp/config/grpc/call_data_get_image.cpp @@ -46,15 +46,19 @@ void CallDataGetImage::WaitForRequest() void CallDataGetImage::HandleRequest() { - cv::Mat image = camera_node_->image_provider->get_mat(); - if (image.empty()) { - RCLCPP_WARN(rclcpp::get_logger("Get image"), "Empty image!"); - return; - } + try { + cv::Mat image = camera_node_->image_provider->get_mat(); + if (image.empty()) { + RCLCPP_WARN(rclcpp::get_logger("Get image"), "Empty image!"); + return; + } - std::vector image_bytes; - cv::imencode(".jpg", image, image_bytes); + std::vector image_bytes; + cv::imencode(".jpg", image, image_bytes); - reply_.set_data(image_bytes.data(), image_bytes.size()); + reply_.set_data(image_bytes.data(), image_bytes.size()); + } catch(const std::exception& e) { + RCLCPP_ERROR(rclcpp::get_logger("Publish config"), e.what()); + } } } // namespace shisen_cpp From 3ab4433b6dc79e676f70d60e962f875006c22207 Mon Sep 17 00:00:00 2001 From: mbsaloka Date: Fri, 31 May 2024 14:01:36 +0700 Subject: [PATCH 28/31] fix: remove data configuration --- data/capture_settings.json | 8 -------- data/grpc.json | 3 --- 2 files changed, 11 deletions(-) delete mode 100644 data/capture_settings.json delete mode 100644 data/grpc.json diff --git a/data/capture_settings.json b/data/capture_settings.json deleted file mode 100644 index 6fcf69e..0000000 --- a/data/capture_settings.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "brightness": 115, - "contrast": 100, - "exposure": 230, - "gain": 138, - "saturation": 185, - "temperature": 5280 -} diff --git a/data/grpc.json b/data/grpc.json deleted file mode 100644 index a7e9c4d..0000000 --- a/data/grpc.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "port": 5757 -} From 4cd3548acfb552628af194ded4a34c3ecb34a786 Mon Sep 17 00:00:00 2001 From: mbsaloka Date: Fri, 31 May 2024 14:02:13 +0700 Subject: [PATCH 29/31] fix: remove call_data_base constructor --- .../shisen_cpp/config/grpc/call_data_base.hpp | 2 -- src/shisen_cpp/config/grpc/call_data_base.cpp | 26 ------------------- 2 files changed, 28 deletions(-) delete mode 100644 src/shisen_cpp/config/grpc/call_data_base.cpp diff --git a/include/shisen_cpp/config/grpc/call_data_base.hpp b/include/shisen_cpp/config/grpc/call_data_base.hpp index 79a79b8..c99c03d 100644 --- a/include/shisen_cpp/config/grpc/call_data_base.hpp +++ b/include/shisen_cpp/config/grpc/call_data_base.hpp @@ -26,8 +26,6 @@ namespace shisen_cpp class CallDataBase { public: - CallDataBase(); - virtual void Proceed() = 0; protected: diff --git a/src/shisen_cpp/config/grpc/call_data_base.cpp b/src/shisen_cpp/config/grpc/call_data_base.cpp deleted file mode 100644 index 7790632..0000000 --- a/src/shisen_cpp/config/grpc/call_data_base.cpp +++ /dev/null @@ -1,26 +0,0 @@ -// 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 - -namespace shisen_cpp -{ -CallDataBase::CallDataBase() {} -} // namespace shisen_cpp From 5d8c2c64efc2ea3096628eaca74c8cb693a12969 Mon Sep 17 00:00:00 2001 From: mbsaloka Date: Mon, 3 Jun 2024 23:51:23 +0700 Subject: [PATCH 30/31] fix: remove port parameter --- CMakeLists.txt | 1 - include/shisen_cpp/config/grpc/config.hpp | 2 +- src/shisen_cpp/config/grpc/config.cpp | 2 +- src/shisen_cpp/node/shisen_cpp_node.cpp | 2 +- 4 files changed, 3 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index d5c575d..fa76690 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -35,7 +35,6 @@ add_library(${PROJECT_NAME} SHARED "src/${PROJECT_NAME}/camera/provider/camera_config_provider.cpp" "src/${PROJECT_NAME}/camera/provider/image_provider.cpp" "src/${PROJECT_NAME}/config/grpc/config.cpp" - "src/${PROJECT_NAME}/config/grpc/call_data_base.cpp" "src/${PROJECT_NAME}/config/grpc/call_data_get_capture_setting.cpp" "src/${PROJECT_NAME}/config/grpc/call_data_get_image.cpp" "src/${PROJECT_NAME}/config/grpc/call_data_save_capture_setting.cpp" diff --git a/include/shisen_cpp/config/grpc/config.hpp b/include/shisen_cpp/config/grpc/config.hpp index 71627cf..d0b2221 100644 --- a/include/shisen_cpp/config/grpc/config.hpp +++ b/include/shisen_cpp/config/grpc/config.hpp @@ -39,7 +39,7 @@ class ConfigGrpc ~ConfigGrpc(); - void Run(uint16_t port, const std::string & path, std::shared_ptr camera_node); + void Run(const std::string & path, std::shared_ptr camera_node); private: std::string path; diff --git a/src/shisen_cpp/config/grpc/config.cpp b/src/shisen_cpp/config/grpc/config.cpp index 354ef23..a6095ba 100644 --- a/src/shisen_cpp/config/grpc/config.cpp +++ b/src/shisen_cpp/config/grpc/config.cpp @@ -48,7 +48,7 @@ void ConfigGrpc::SignIntHandler(int signum) exit(signum); } -void ConfigGrpc::Run(uint16_t port, const std::string & path, std::shared_ptr camera_node) +void ConfigGrpc::Run(const std::string & path, std::shared_ptr camera_node) { Config config(path); std::string server_address = diff --git a/src/shisen_cpp/node/shisen_cpp_node.cpp b/src/shisen_cpp/node/shisen_cpp_node.cpp index 970f180..0f4e62e 100644 --- a/src/shisen_cpp/node/shisen_cpp_node.cpp +++ b/src/shisen_cpp/node/shisen_cpp_node.cpp @@ -42,7 +42,7 @@ ShisenCppNode::ShisenCppNode(rclcpp::Node::SharedPtr node, const std::string & p } ); - config_grpc.Run(5757, path, camera_node); + config_grpc.Run(path, camera_node); RCLCPP_INFO(rclcpp::get_logger("GrpcServers"), "grpc running"); } From e50302a8b44153e6d904bbda6d58cc2f33b7d8f6 Mon Sep 17 00:00:00 2001 From: mbsaloka Date: Thu, 6 Jun 2024 21:56:35 +0700 Subject: [PATCH 31/31] fix: rollback to previous commit --- src/shisen_cpp/camera/node/camera_node.cpp | 37 ---------------------- 1 file changed, 37 deletions(-) diff --git a/src/shisen_cpp/camera/node/camera_node.cpp b/src/shisen_cpp/camera/node/camera_node.cpp index eec28cd..961f53e 100644 --- a/src/shisen_cpp/camera/node/camera_node.cpp +++ b/src/shisen_cpp/camera/node/camera_node.cpp @@ -234,41 +234,4 @@ void CameraNode::load_configuration(const std::string & path) configure_capture_setting(capture_setting); } -void CameraNode::load_configuration(const std::string & path) -{ - std::string ss = path + "capture_settings.json"; - - std::ifstream input(ss, std::ifstream::in); - if (!input.is_open()) { - throw std::runtime_error("Unable to open `" + ss + "`!"); - } - - nlohmann::json config = nlohmann::json::parse(input); - - CaptureSetting capture_setting; - - // Get all config - for (auto & item : config.items()) { - try { - if (item.key() == "brightness") { - capture_setting.brightness.set(item.value()); - } else if (item.key() == "contrast") { - capture_setting.contrast.set(item.value()); - } else if (item.key() == "saturation") { - capture_setting.saturation.set(item.value()); - } else if (item.key() == "temperature") { - capture_setting.temperature.set(item.value()); - } else if (item.key() == "exposure") { - capture_setting.exposure.set(item.value()); - } else if (item.key() == "gain") { - capture_setting.gain.set(item.value()); - } - } catch (nlohmann::json::parse_error & ex) { - throw std::runtime_error("Parse error at byte `" + std::to_string(ex.byte) + "`!"); - } - } - - configure_capture_setting(capture_setting); -} - } // namespace shisen_cpp::camera