From 8c007756a78b49ac5d18a474f250eb853aa09a91 Mon Sep 17 00:00:00 2001 From: marfannr Date: Sun, 16 Jun 2024 21:18:32 +0700 Subject: [PATCH 1/3] feat: add config for grpc port on akushon --- include/akushon/config/grpc/config.hpp | 3 ++- include/akushon/config/utils/config.hpp | 3 +++ src/akushon/action/node/action_manager.cpp | 4 ++++ src/akushon/config/grpc/config.cpp | 18 +++++++++++------- src/akushon/config/node/config_node.cpp | 2 +- src/akushon/config/utils/config.cpp | 12 +++++++++++- 6 files changed, 32 insertions(+), 10 deletions(-) diff --git a/include/akushon/config/grpc/config.hpp b/include/akushon/config/grpc/config.hpp index a0c8cc7..273ee0d 100644 --- a/include/akushon/config/grpc/config.hpp +++ b/include/akushon/config/grpc/config.hpp @@ -42,7 +42,8 @@ class ConfigGrpc ~ConfigGrpc(); - void Run(uint16_t port, const std::string & path, rclcpp::Node::SharedPtr & node, + void Run( + const std::string & path, rclcpp::Node::SharedPtr & node, const std::shared_ptr & action_manager); private: diff --git a/include/akushon/config/utils/config.hpp b/include/akushon/config/utils/config.hpp index 20e53d5..864f7dd 100644 --- a/include/akushon/config/utils/config.hpp +++ b/include/akushon/config/utils/config.hpp @@ -23,6 +23,7 @@ #include #include +#include "nlohmann/json.hpp" namespace akushon { @@ -35,6 +36,8 @@ class Config std::string get_config() const; void save_config(const std::string & actions_data); + nlohmann::json get_grpc_config() const; + private: std::string path; }; diff --git a/src/akushon/action/node/action_manager.cpp b/src/akushon/action/node/action_manager.cpp index 9b8b727..7021954 100644 --- a/src/akushon/action/node/action_manager.cpp +++ b/src/akushon/action/node/action_manager.cpp @@ -76,6 +76,10 @@ void ActionManager::load_config(const std::string & path) } try { + if (name == "grpc") { + printf("skipping grpc.json\n"); + continue; + } std::ifstream file(file_name); nlohmann::json action_data = nlohmann::json::parse(file); diff --git a/src/akushon/config/grpc/config.cpp b/src/akushon/config/grpc/config.cpp index f2315dc..44e1a9d 100644 --- a/src/akushon/config/grpc/config.cpp +++ b/src/akushon/config/grpc/config.cpp @@ -25,15 +25,15 @@ #include #include -#include "akushon/config/utils/config.hpp" -#include "rclcpp/rclcpp.hpp" #include "akushon/config/grpc/call_data_get_config.hpp" #include "akushon/config/grpc/call_data_load_config.hpp" -#include "akushon/config/grpc/call_data_save_config.hpp" #include "akushon/config/grpc/call_data_publish_set_joints.hpp" #include "akushon/config/grpc/call_data_publish_set_torques.hpp" -#include "akushon/config/grpc/call_data_subscribe_current_joints.hpp" #include "akushon/config/grpc/call_data_run_action.hpp" +#include "akushon/config/grpc/call_data_save_config.hpp" +#include "akushon/config/grpc/call_data_subscribe_current_joints.hpp" +#include "akushon/config/utils/config.hpp" +#include "rclcpp/rclcpp.hpp" using grpc::ServerBuilder; using namespace std::chrono_literals; @@ -49,10 +49,13 @@ ConfigGrpc::~ConfigGrpc() cq_->Shutdown(); } -void ConfigGrpc::Run(uint16_t port, const std::string& path, rclcpp::Node::SharedPtr& node, - const std::shared_ptr& action_manager) +void ConfigGrpc::Run( + const std::string & path, rclcpp::Node::SharedPtr & node, + const std::shared_ptr & action_manager) { - std::string server_address = absl::StrFormat("0.0.0.0:%d", port); + 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()); @@ -85,6 +88,7 @@ void ConfigGrpc::Run(uint16_t port, const std::string& path, rclcpp::Node::Share } }); std::this_thread::sleep_for(200ms); + async_server.detach(); } } // namespace akushon diff --git a/src/akushon/config/node/config_node.cpp b/src/akushon/config/node/config_node.cpp index 553bfcc..a1c475f 100644 --- a/src/akushon/config/node/config_node.cpp +++ b/src/akushon/config/node/config_node.cpp @@ -51,7 +51,7 @@ ConfigNode::ConfigNode(rclcpp::Node::SharedPtr node, const std::string & path, response->status = "SAVED"; } ); - config_grpc.Run(5060, path, node, action_manager); + config_grpc.Run(path, node, action_manager); RCLCPP_INFO(rclcpp::get_logger("GrpcServers"), "grpc running"); } diff --git a/src/akushon/config/utils/config.cpp b/src/akushon/config/utils/config.cpp index 462eaab..2c4dd2a 100644 --- a/src/akushon/config/utils/config.cpp +++ b/src/akushon/config/utils/config.cpp @@ -25,7 +25,6 @@ #include "akushon/action/model/action_name.hpp" #include "akushon/config/utils/config.hpp" -#include "nlohmann/json.hpp" namespace akushon { @@ -47,6 +46,9 @@ std::string Config::get_config() const for (auto i = path.size(); i < file_name.size() - 5; i++) { action_name += file_name[i]; } + if (action_name == "grpc") { + continue; + } std::cout << action_name << " | "; std::ifstream file(action_file.path()); @@ -61,6 +63,14 @@ std::string Config::get_config() const return actions_list.dump(); } +nlohmann::json Config::get_grpc_config() const +{ + std::ifstream grpc_file(this->path + "grpc.json"); + nlohmann::json grpc_data = nlohmann::json::parse(grpc_file); + grpc_file.close(); + return grpc_data; +} + void Config::save_config(const std::string & actions_data) { nlohmann::json actions_list = nlohmann::json::parse(actions_data); From c1493fcbfbd7ac540e6f48f19c138f5807129fea Mon Sep 17 00:00:00 2001 From: marfannr Date: Mon, 17 Jun 2024 01:11:45 +0700 Subject: [PATCH 2/3] feat: change using constant reference node --- include/akushon/action/model/action_name.hpp | 6 ++++++ .../grpc/call_data_publish_set_joints.hpp | 2 +- .../grpc/call_data_publish_set_torques.hpp | 2 +- .../config/grpc/call_data_run_action.hpp | 2 +- .../call_data_subscribe_current_joints.hpp | 2 +- include/akushon/config/grpc/config.hpp | 2 +- include/akushon/config/utils/config.hpp | 2 +- src/akushon/action/model/action_name.cpp | 18 ++++++++++++------ src/akushon/action/node/action_manager.cpp | 2 +- .../grpc/call_data_publish_set_joints.cpp | 2 +- .../grpc/call_data_publish_set_torques.cpp | 2 +- .../config/grpc/call_data_run_action.cpp | 2 +- .../call_data_subscribe_current_joints.cpp | 2 +- src/akushon/config/grpc/config.cpp | 2 +- 14 files changed, 30 insertions(+), 18 deletions(-) diff --git a/include/akushon/action/model/action_name.hpp b/include/akushon/action/model/action_name.hpp index 245b3de..4320e4a 100644 --- a/include/akushon/action/model/action_name.hpp +++ b/include/akushon/action/model/action_name.hpp @@ -47,6 +47,12 @@ class ActionName static const char * RIGHT_SIDEKICK; static const char * KEEPER_SIT; static const char * KEEPER_UP; + static const char * MIDDOWN_KEEPER; + static const char * MIDUP_KEEPER; + static const char * KEEPER_LEFT; + static const char * KEEPER_RIGHT; + static const char * KEEPER_LEFT_UP; + static const char * KEEPER_RIGHT_UP; static const std::map map; }; diff --git a/include/akushon/config/grpc/call_data_publish_set_joints.hpp b/include/akushon/config/grpc/call_data_publish_set_joints.hpp index 3622f9e..fe342f1 100644 --- a/include/akushon/config/grpc/call_data_publish_set_joints.hpp +++ b/include/akushon/config/grpc/call_data_publish_set_joints.hpp @@ -33,7 +33,7 @@ class CallDataPublishSetJoints public: CallDataPublishSetJoints( akushon_interfaces::proto::Config::AsyncService * service, grpc::ServerCompletionQueue * cq, - const std::string& path, rclcpp::Node::SharedPtr& node); + const std::string& path, const rclcpp::Node::SharedPtr& node); protected: void AddNextToCompletionQueue() override; diff --git a/include/akushon/config/grpc/call_data_publish_set_torques.hpp b/include/akushon/config/grpc/call_data_publish_set_torques.hpp index 1cba37e..0395c1f 100644 --- a/include/akushon/config/grpc/call_data_publish_set_torques.hpp +++ b/include/akushon/config/grpc/call_data_publish_set_torques.hpp @@ -33,7 +33,7 @@ class CallDataPublishSetTorques public: CallDataPublishSetTorques( akushon_interfaces::proto::Config::AsyncService * service, grpc::ServerCompletionQueue * cq, - const std::string& path, rclcpp::Node::SharedPtr& node); + const std::string& path, const rclcpp::Node::SharedPtr& node); protected: virtual void AddNextToCompletionQueue() override; diff --git a/include/akushon/config/grpc/call_data_run_action.hpp b/include/akushon/config/grpc/call_data_run_action.hpp index 026051b..e61a19e 100644 --- a/include/akushon/config/grpc/call_data_run_action.hpp +++ b/include/akushon/config/grpc/call_data_run_action.hpp @@ -33,7 +33,7 @@ class CallDataRunAction public: CallDataRunAction( akushon_interfaces::proto::Config::AsyncService * service, grpc::ServerCompletionQueue * cq, - const std::string& path, rclcpp::Node::SharedPtr& node); + const std::string& path, const rclcpp::Node::SharedPtr& node); protected: void AddNextToCompletionQueue() override; diff --git a/include/akushon/config/grpc/call_data_subscribe_current_joints.hpp b/include/akushon/config/grpc/call_data_subscribe_current_joints.hpp index 4e00f1e..28a0260 100644 --- a/include/akushon/config/grpc/call_data_subscribe_current_joints.hpp +++ b/include/akushon/config/grpc/call_data_subscribe_current_joints.hpp @@ -34,7 +34,7 @@ class CallDataSubscribeCurrentJoints public: CallDataSubscribeCurrentJoints( akushon_interfaces::proto::Config::AsyncService * service, grpc::ServerCompletionQueue * cq, - const std::string& path, rclcpp::Node::SharedPtr& node); + const std::string& path, const rclcpp::Node::SharedPtr& node); protected: void AddNextToCompletionQueue() override; diff --git a/include/akushon/config/grpc/config.hpp b/include/akushon/config/grpc/config.hpp index 273ee0d..3f90067 100644 --- a/include/akushon/config/grpc/config.hpp +++ b/include/akushon/config/grpc/config.hpp @@ -43,7 +43,7 @@ class ConfigGrpc ~ConfigGrpc(); void Run( - const std::string & path, rclcpp::Node::SharedPtr & node, + const std::string & path, const rclcpp::Node::SharedPtr & node, const std::shared_ptr & action_manager); private: diff --git a/include/akushon/config/utils/config.hpp b/include/akushon/config/utils/config.hpp index 864f7dd..3c26ecf 100644 --- a/include/akushon/config/utils/config.hpp +++ b/include/akushon/config/utils/config.hpp @@ -22,8 +22,8 @@ #define AKUSHON__CONFIG__UTILS__CONFIG_HPP_ #include +#include #include -#include "nlohmann/json.hpp" namespace akushon { diff --git a/src/akushon/action/model/action_name.cpp b/src/akushon/action/model/action_name.cpp index 8548cc8..b8d279d 100644 --- a/src/akushon/action/model/action_name.cpp +++ b/src/akushon/action/model/action_name.cpp @@ -45,13 +45,19 @@ const char * ActionName::LEFTWARD_UP = "leftward_up"; const char * ActionName::RIGHTWARD_UP = "rightward_up"; const char * ActionName::RIGHT_KICK = "right_kick"; const char * ActionName::LEFT_KICK = "left_kick"; -const char * ActionName::RIGHT_KICK_SHORT = "right_kick_short"; -const char * ActionName::LEFT_KICK_SHORT = "left_kick_short"; -const char * ActionName::RIGHT_KICK_WIDE = "right_kick_wide"; -const char * ActionName::LEFT_KICK_WIDE = "left_kick_wide"; -const char * ActionName::LEFT_SIDEKICK = "left_sidekick"; -const char * ActionName::RIGHT_SIDEKICK = "right_sidekick"; +const char * ActionName::RIGHT_KICK_SHORT = "right_kick"; +const char * ActionName::LEFT_KICK_SHORT = "walk_ready"; +const char * ActionName::RIGHT_KICK_WIDE = "right_kick"; +const char * ActionName::LEFT_KICK_WIDE = "left_kick"; +const char * ActionName::LEFT_SIDEKICK = "left_kick"; +const char * ActionName::RIGHT_SIDEKICK = "right_kick"; const char * ActionName::KEEPER_SIT = "keeper_sit"; const char * ActionName::KEEPER_UP = "keeper_up"; +const char * ActionName::MIDDOWN_KEEPER = "middown_keeper"; +const char * ActionName::MIDUP_KEEPER = "midup_keeper"; +const char * ActionName::KEEPER_LEFT = "left_keeper"; +const char * ActionName::KEEPER_RIGHT = "right_keeper"; +const char * ActionName::KEEPER_LEFT_UP = "leftup_keeper"; +const char * ActionName::KEEPER_RIGHT_UP = "rightup_keeper"; } // namespace akushon diff --git a/src/akushon/action/node/action_manager.cpp b/src/akushon/action/node/action_manager.cpp index 7021954..5995986 100644 --- a/src/akushon/action/node/action_manager.cpp +++ b/src/akushon/action/node/action_manager.cpp @@ -77,7 +77,7 @@ void ActionManager::load_config(const std::string & path) try { if (name == "grpc") { - printf("skipping grpc.json\n"); + std::cout << "skipping grpc.json" << std::endl; continue; } std::ifstream file(file_name); diff --git a/src/akushon/config/grpc/call_data_publish_set_joints.cpp b/src/akushon/config/grpc/call_data_publish_set_joints.cpp index 2d89890..a18d734 100644 --- a/src/akushon/config/grpc/call_data_publish_set_joints.cpp +++ b/src/akushon/config/grpc/call_data_publish_set_joints.cpp @@ -26,7 +26,7 @@ namespace akushon { CallDataPublishSetJoints::CallDataPublishSetJoints( akushon_interfaces::proto::Config::AsyncService * service, grpc::ServerCompletionQueue * cq, - const std::string& path, rclcpp::Node::SharedPtr& node) + const std::string& path, const rclcpp::Node::SharedPtr& node) : CallData(service, cq, path), node_(node) { set_joints_publisher_ = diff --git a/src/akushon/config/grpc/call_data_publish_set_torques.cpp b/src/akushon/config/grpc/call_data_publish_set_torques.cpp index 2f9f79f..d65c4d5 100644 --- a/src/akushon/config/grpc/call_data_publish_set_torques.cpp +++ b/src/akushon/config/grpc/call_data_publish_set_torques.cpp @@ -27,7 +27,7 @@ namespace akushon { CallDataPublishSetTorques::CallDataPublishSetTorques( akushon_interfaces::proto::Config::AsyncService * service, grpc::ServerCompletionQueue * cq, - const std::string& path, rclcpp::Node::SharedPtr& node) + const std::string& path, const rclcpp::Node::SharedPtr& node) : CallData(service, cq, path), node_(node) { set_torque_publisher_ = diff --git a/src/akushon/config/grpc/call_data_run_action.cpp b/src/akushon/config/grpc/call_data_run_action.cpp index a6d5510..71beadd 100644 --- a/src/akushon/config/grpc/call_data_run_action.cpp +++ b/src/akushon/config/grpc/call_data_run_action.cpp @@ -26,7 +26,7 @@ namespace akushon { CallDataRunAction::CallDataRunAction( akushon_interfaces::proto::Config::AsyncService * service, grpc::ServerCompletionQueue * cq, - const std::string& path, rclcpp::Node::SharedPtr& node) + const std::string& path, const rclcpp::Node::SharedPtr& node) : CallData(service, cq, path), node_(node) { run_action_publisher_ = diff --git a/src/akushon/config/grpc/call_data_subscribe_current_joints.cpp b/src/akushon/config/grpc/call_data_subscribe_current_joints.cpp index 778f267..11b6610 100644 --- a/src/akushon/config/grpc/call_data_subscribe_current_joints.cpp +++ b/src/akushon/config/grpc/call_data_subscribe_current_joints.cpp @@ -30,7 +30,7 @@ namespace akushon { CallDataSubscribeCurrentJoints::CallDataSubscribeCurrentJoints( akushon_interfaces::proto::Config::AsyncService * service, grpc::ServerCompletionQueue * cq, - const std::string& path, rclcpp::Node::SharedPtr& node) + const std::string& path, const rclcpp::Node::SharedPtr& node) : CallData(service, cq, path), node_(node) { current_joint_subscription_ = diff --git a/src/akushon/config/grpc/config.cpp b/src/akushon/config/grpc/config.cpp index 44e1a9d..d217824 100644 --- a/src/akushon/config/grpc/config.cpp +++ b/src/akushon/config/grpc/config.cpp @@ -50,7 +50,7 @@ ConfigGrpc::~ConfigGrpc() } void ConfigGrpc::Run( - const std::string & path, rclcpp::Node::SharedPtr & node, + const std::string & path, const rclcpp::Node::SharedPtr & node, const std::shared_ptr & action_manager) { Config config(path); From b7edebcaab908d91e91235de818ea0f14745fdcc Mon Sep 17 00:00:00 2001 From: marfannr Date: Sat, 22 Jun 2024 16:33:30 +0700 Subject: [PATCH 3/3] feat: resolve request to change --- src/akushon/config/grpc/config.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/akushon/config/grpc/config.cpp b/src/akushon/config/grpc/config.cpp index d217824..99b42a6 100644 --- a/src/akushon/config/grpc/config.cpp +++ b/src/akushon/config/grpc/config.cpp @@ -23,6 +23,7 @@ #include #include #include +#include #include #include "akushon/config/grpc/call_data_get_config.hpp" @@ -33,7 +34,6 @@ #include "akushon/config/grpc/call_data_save_config.hpp" #include "akushon/config/grpc/call_data_subscribe_current_joints.hpp" #include "akushon/config/utils/config.hpp" -#include "rclcpp/rclcpp.hpp" using grpc::ServerBuilder; using namespace std::chrono_literals;