Skip to content
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 18 commits into from
May 3, 2024
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 32 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,38 @@ find_package(std_msgs REQUIRED)
find_package(tachimawari REQUIRED)
find_package(tachimawari_interfaces REQUIRED)

find_package(Protobuf CONFIG REQUIRED)
message(STATUS "Using protobuf ${Protobuf_VERSION}")

# 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}")
set(_GRPC_CPP_PLUGIN_EXECUTABLE $<TARGET_FILE:gRPC::grpc_cpp_plugin>)
marfanr marked this conversation as resolved.
Show resolved Hide resolved

add_library(${PROJECT_NAME} SHARED
"src/${PROJECT_NAME}/action/model/action_name.cpp"
"src/${PROJECT_NAME}/action/model/action.cpp"
"src/${PROJECT_NAME}/config/grpc/call_data.cpp"
"src/${PROJECT_NAME}/action/model/pose.cpp"
"src/${PROJECT_NAME}/action/node/action_manager.cpp"
"src/${PROJECT_NAME}/action/node/action_node.cpp"
"src/${PROJECT_NAME}/action/process/interpolator.cpp"
"src/${PROJECT_NAME}/action/process/joint_process.cpp"
"src/${PROJECT_NAME}/config/node/config_node.cpp"
"src/${PROJECT_NAME}/config/utils/config.cpp"
"src/${PROJECT_NAME}/node/akushon_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_config.cpp"
"src/${PROJECT_NAME}/config/grpc/call_data_save_config.cpp"
"src/${PROJECT_NAME}/config/grpc/call_data_publish_set_joints.cpp"
"src/${PROJECT_NAME}/config/grpc/call_data_publish_set_torques.cpp"
"src/${PROJECT_NAME}/config/grpc/call_data_subscribe_current_joints.cpp"
"src/${PROJECT_NAME}/config/grpc/call_data_run_action.cpp"
"src/${PROJECT_NAME}/node/akushon_node.cpp"
)

target_include_directories(${PROJECT_NAME} PUBLIC
target_include_directories(${PROJECT_NAME} PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>)

Expand All @@ -45,15 +64,24 @@ ament_target_dependencies(${PROJECT_NAME}
rclcpp_action
std_msgs
tachimawari
tachimawari_interfaces)
tachimawari_interfaces
gRPC)

target_link_libraries(${PROJECT_NAME}
gRPC::grpc++_reflection
gRPC::grpc++
)
marfanr marked this conversation as resolved.
Show resolved Hide resolved

install(DIRECTORY "include" DESTINATION ".")

install(TARGETS ${PROJECT_NAME}
EXPORT export_${PROJECT_NAME}
ARCHIVE DESTINATION "lib"
LIBRARY DESTINATION "lib"
RUNTIME DESTINATION "bin")
RUNTIME DESTINATION "bin"
INCLUDES DESTINATION "include")

target_compile_options(${PROJECT_NAME} PRIVATE -fPIC)

add_executable(action "src/action_main.cpp")
target_include_directories(action PUBLIC
Expand Down
59 changes: 59 additions & 0 deletions include/akushon/config/grpc/call_data.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
// Copyright (c) 2023 Ichiro ITS
marfanr marked this conversation as resolved.
Show resolved Hide resolved
//
// 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_interfaces/akushon.grpc.pb.h"
#include "akushon_interfaces/akushon.pb.h"
#include "grpc/support/log.h"
#include "grpcpp/grpcpp.h"
#include "akushon/config/grpc/call_data_base.hpp"

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_;
};
} // namespace akushon

#endif // AKUSHON__CONFIG__GRPC__CALL_DATA_HPP_
38 changes: 38 additions & 0 deletions include/akushon/config/grpc/call_data_base.hpp
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__
43 changes: 43 additions & 0 deletions include/akushon/config/grpc/call_data_get_config.hpp
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_
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing EoL.

47 changes: 47 additions & 0 deletions include/akushon/config/grpc/call_data_publish_set_joints.hpp
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_
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing EoL

47 changes: 47 additions & 0 deletions include/akushon/config/grpc/call_data_publish_set_torques.hpp
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_
47 changes: 47 additions & 0 deletions include/akushon/config/grpc/call_data_run_action.hpp
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
Loading
Loading