-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Sprint 22 / PD-368] - [Feature] Create gRPC Service on Akushon ROS2 #37
Merged
Merged
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
3d38f81
feat/add-grpc
marfanr f356700
feat:add implementation for new proto update
marfanr 41d7535
Fix/forgot to enable the new RPC
marfanr a2129a0
Fix/fix json format for ids in SetTorques RPC
marfanr 7e8f0c7
Fix/forgot to register a RPC
marfanr 0291a4b
Fix/fix json parsing problem
marfanr 1c7559c
feat: refractor akushon
marfanr a327149
feat: move proto compile part to akushon interfaces
marfanr 1d11b8e
feat: fix problem on running grpc
marfanr 1e8d44d
feat: refractor and resolve pull request
marfanr 998e4cd
feat: refractor and resolve pull request
marfanr 0bac70d
feat: remove proto compile part from CMakeLists
marfanr c07f360
feat: refractor and resolve pull request
marfanr e40d1de
feat: refractor and resolve pull request
marfanr 8d1c0dc
feat: forgot remove call_data.cpp from CMakeLists.txt after remove th…
marfanr a59058c
feat: remove unused include header on config.hpp
marfanr 0a702dd
feat: remove unused on CMakeLists.txt
marfanr 39b8583
Merge branch 'master' into feature/add-grpc
borednuna File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
// Copyright (c) 2024 Ichiro ITS | ||
// | ||
// Permission is hereby granted, free of charge, to any person obtaining a copy | ||
// of this software and associated documentation files (the "Software"), to deal | ||
// in the Software without restriction, including without limitation the rights | ||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
// copies of the Software, and to permit persons to whom the Software is | ||
// furnished to do so, subject to the following conditions: | ||
// | ||
// The above copyright notice and this permission notice shall be included in | ||
// all copies or substantial portions of the Software. | ||
// | ||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | ||
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
// THE SOFTWARE. | ||
|
||
#ifndef AKUSHON__CONFIG__GRPC__CALL_DATA_HPP_ | ||
#define AKUSHON__CONFIG__GRPC__CALL_DATA_HPP_ | ||
|
||
#include "akushon/config/grpc/call_data_base.hpp" | ||
#include "akushon_interfaces/akushon.grpc.pb.h" | ||
#include "akushon_interfaces/akushon.pb.h" | ||
#include "grpc/support/log.h" | ||
#include "grpcpp/grpcpp.h" | ||
|
||
namespace akushon | ||
{ | ||
template <class ConfigRequest, class ConfigReply> | ||
class CallData : CallDataBase | ||
{ | ||
public: | ||
CallData( | ||
akushon_interfaces::proto::Config::AsyncService * service, grpc::ServerCompletionQueue * cq, | ||
const std::string & path); | ||
void Proceed() override; | ||
|
||
protected: | ||
virtual void AddNextToCompletionQueue() = 0; | ||
|
||
enum class CallStatus { CREATE, PROCESS, FINISH }; | ||
|
||
CallStatus status_; // The current serving state. | ||
|
||
akushon_interfaces::proto::Config::AsyncService * service_; | ||
|
||
const std::string & path_; | ||
|
||
grpc::ServerCompletionQueue * cq_; | ||
grpc::ServerContext ctx_; | ||
ConfigRequest request_; | ||
ConfigReply reply_; | ||
grpc::ServerAsyncResponseWriter<ConfigReply> responder_; | ||
}; | ||
|
||
template <class ConfigRequest, class ConfigReply> | ||
CallData<ConfigRequest, ConfigReply>::CallData( | ||
akushon_interfaces::proto::Config::AsyncService * service, grpc::ServerCompletionQueue * cq, | ||
const std::string & path) | ||
: status_(CallStatus::CREATE), service_(service), cq_(cq), responder_(&ctx_), path_(path) | ||
{ | ||
} | ||
|
||
template <class ConfigRequest, class ConfigReply> | ||
void CallData<ConfigRequest, ConfigReply>::Proceed() | ||
{ | ||
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: | ||
delete this; | ||
break; | ||
} | ||
} | ||
|
||
} // namespace akushon | ||
|
||
#endif // AKUSHON__CONFIG__GRPC__CALL_DATA_HPP_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// Copyright (c) 2023 Ichiro ITS | ||
// | ||
// Permission is hereby granted, free of charge, to any person obtaining a copy | ||
// of this software and associated documentation files (the "Software"), to deal | ||
// in the Software without restriction, including without limitation the rights | ||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
// copies of the Software, and to permit persons to whom the Software is | ||
// furnished to do so, subject to the following conditions: | ||
// | ||
// The above copyright notice and this permission notice shall be included in | ||
// all copies or substantial portions of the Software. | ||
// | ||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | ||
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
// THE SOFTWARE. | ||
|
||
#ifndef __AKUSHON__CONFIG__GRPC__CALL_DATA_BASE_HPP__ | ||
#define __AKUSHON__CONFIG__GRPC__CALL_DATA_BASE_HPP__ | ||
namespace akushon | ||
{ | ||
class CallDataBase | ||
{ | ||
public: | ||
CallDataBase(); | ||
|
||
virtual void Proceed() = 0; | ||
|
||
protected: | ||
virtual void WaitForRequest() = 0; | ||
virtual void HandleRequest() = 0; | ||
}; | ||
} // namespace akushon | ||
|
||
#endif // __AKUSHON__CONFIG__GRPC__CALL_DATA_BASE_HPP__ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
// Copyright (c) 2023 Ichiro ITS | ||
// | ||
// Permission is hereby granted, free of charge, to any person obtaining a copy | ||
// of this software and associated documentation files (the "Software"), to deal | ||
// in the Software without restriction, including without limitation the rights | ||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
// copies of the Software, and to permit persons to whom the Software is | ||
// furnished to do so, subject to the following conditions: | ||
// | ||
// The above copyright notice and this permission notice shall be included in | ||
// all copies or substantial portions of the Software. | ||
// | ||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | ||
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
// THE SOFTWARE. | ||
|
||
#ifndef AKUSHON__CONFIG__GRPC__CALL_DATA_GET_CONFIG_HPP_ | ||
#define AKUSHON__CONFIG__GRPC__CALL_DATA_GET_CONFIG_HPP_ | ||
|
||
#include "akushon/config/grpc/call_data.hpp" | ||
|
||
namespace akushon | ||
{ | ||
class CallDataGetConfig | ||
: CallData<akushon_interfaces::proto::Empty, akushon_interfaces::proto::ConfigActions> | ||
{ | ||
public: | ||
CallDataGetConfig( | ||
akushon_interfaces::proto::Config::AsyncService * service, grpc::ServerCompletionQueue * cq, | ||
const std::string& path); | ||
|
||
protected: | ||
void AddNextToCompletionQueue() override; | ||
void WaitForRequest() override; | ||
void HandleRequest() override; | ||
}; | ||
} // namespace akushon | ||
|
||
#endif // AKUSHON__CONFIG__GRPC__CALL_DATA_GET_CONFIG_HPP_ | ||
47 changes: 47 additions & 0 deletions
47
include/akushon/config/grpc/call_data_publish_set_joints.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// Copyright (c) 2023 Ichiro ITS | ||
// | ||
// Permission is hereby granted, free of charge, to any person obtaining a copy | ||
// of this software and associated documentation files (the "Software"), to deal | ||
// in the Software without restriction, including without limitation the rights | ||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
// copies of the Software, and to permit persons to whom the Software is | ||
// furnished to do so, subject to the following conditions: | ||
// | ||
// The above copyright notice and this permission notice shall be included in | ||
// all copies or substantial portions of the Software. | ||
// | ||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | ||
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
// THE SOFTWARE. | ||
|
||
#ifndef AKUSHON__CONFIG__GRPC__CALL_DATA_PUBLISH_SET_JOINTS_HPP_ | ||
#define AKUSHON__CONFIG__GRPC__CALL_DATA_PUBLISH_SET_JOINTS_HPP_ | ||
|
||
#include "akushon/config/grpc/call_data.hpp" | ||
#include "tachimawari_interfaces/msg/set_joints.hpp" | ||
#include "rclcpp/rclcpp.hpp" | ||
|
||
namespace akushon | ||
{ | ||
class CallDataPublishSetJoints | ||
: CallData<akushon_interfaces::proto::SetJointsData, akushon_interfaces::proto::Empty> | ||
{ | ||
public: | ||
CallDataPublishSetJoints( | ||
akushon_interfaces::proto::Config::AsyncService * service, grpc::ServerCompletionQueue * cq, | ||
const std::string& path, rclcpp::Node::SharedPtr& node); | ||
|
||
protected: | ||
void AddNextToCompletionQueue() override; | ||
void WaitForRequest() override; | ||
void HandleRequest() override; | ||
rclcpp::Node::SharedPtr node_; | ||
rclcpp::Publisher<tachimawari_interfaces::msg::SetJoints>::SharedPtr set_joints_publisher_; | ||
}; | ||
} // namespace akushon | ||
|
||
#endif // AKUSHON__CONFIG__GRPC__CALL_DATA_PUBLISH_SET_JOINTS_HPP_ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing EoL |
47 changes: 47 additions & 0 deletions
47
include/akushon/config/grpc/call_data_publish_set_torques.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// Copyright (c) 2023 Ichiro ITS | ||
// | ||
// Permission is hereby granted, free of charge, to any person obtaining a copy | ||
// of this software and associated documentation files (the "Software"), to deal | ||
// in the Software without restriction, including without limitation the rights | ||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
// copies of the Software, and to permit persons to whom the Software is | ||
// furnished to do so, subject to the following conditions: | ||
// | ||
// The above copyright notice and this permission notice shall be included in | ||
// all copies or substantial portions of the Software. | ||
// | ||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | ||
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
// THE SOFTWARE. | ||
|
||
#ifndef AKUSHON__CONFIG__GRPC__CALL_DATA_PUBLISH_SET_TORQUES_HPP_ | ||
#define AKUSHON__CONFIG__GRPC__CALL_DATA_PUBLISH_SET_TORQUES_HPP_ | ||
|
||
#include "akushon/config/grpc/call_data.hpp" | ||
#include "tachimawari_interfaces/msg/set_torques.hpp" | ||
#include "rclcpp/rclcpp.hpp" | ||
|
||
namespace akushon | ||
{ | ||
class CallDataPublishSetTorques | ||
: CallData<akushon_interfaces::proto::SetTorquesData, akushon_interfaces::proto::Empty> | ||
{ | ||
public: | ||
CallDataPublishSetTorques( | ||
akushon_interfaces::proto::Config::AsyncService * service, grpc::ServerCompletionQueue * cq, | ||
const std::string& path, rclcpp::Node::SharedPtr& node); | ||
|
||
protected: | ||
virtual void AddNextToCompletionQueue() override; | ||
virtual void WaitForRequest() override; | ||
virtual void HandleRequest() override; | ||
marfanr marked this conversation as resolved.
Show resolved
Hide resolved
|
||
rclcpp::Node::SharedPtr node_; | ||
rclcpp::Publisher<tachimawari_interfaces::msg::SetTorques>::SharedPtr set_torque_publisher_; | ||
}; | ||
} // namespace akushon | ||
|
||
#endif // AKUSHON__CONFIG__GRPC__CALL_DATA_PUBLISH_SET_TORQUES_HPP_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// Copyright (c) 2023 Ichiro ITS | ||
// | ||
// Permission is hereby granted, free of charge, to any person obtaining a copy | ||
// of this software and associated documentation files (the "Software"), to deal | ||
// in the Software without restriction, including without limitation the rights | ||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
// copies of the Software, and to permit persons to whom the Software is | ||
// furnished to do so, subject to the following conditions: | ||
// | ||
// The above copyright notice and this permission notice shall be included in | ||
// all copies or substantial portions of the Software. | ||
// | ||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | ||
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
// THE SOFTWARE. | ||
|
||
#ifndef AKUSHON__CONFIG__GRPC__CALL_DATA_RUN_ACTION_HPP_ | ||
#define AKUSHON__CONFIG__GRPC__CALL_DATA_RUN_ACTION_HPP_ | ||
|
||
#include "akushon/config/grpc/call_data.hpp" | ||
#include "akushon_interfaces/msg/run_action.hpp" | ||
#include "rclcpp/rclcpp.hpp" | ||
|
||
namespace akushon | ||
{ | ||
class CallDataRunAction | ||
: CallData<akushon_interfaces::proto::ConfigRunAction, akushon_interfaces::proto::Empty> | ||
{ | ||
public: | ||
CallDataRunAction( | ||
akushon_interfaces::proto::Config::AsyncService * service, grpc::ServerCompletionQueue * cq, | ||
const std::string& path, rclcpp::Node::SharedPtr& node); | ||
|
||
protected: | ||
void AddNextToCompletionQueue() override; | ||
void WaitForRequest() override; | ||
void HandleRequest() override; | ||
rclcpp::Node::SharedPtr node_; | ||
rclcpp::Publisher<akushon_interfaces::msg::RunAction>::SharedPtr run_action_publisher_; | ||
}; | ||
} // namespace akushon | ||
|
||
#endif // AKUSHON__CONFIG__GRPC__CALL_DATA_RUN_ACTION_HPP_ | ||
marfanr marked this conversation as resolved.
Show resolved
Hide resolved
|
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing EoL.