Skip to content

Commit

Permalink
Merge pull request #5 from ichiro-its/feature/create-grpc-service
Browse files Browse the repository at this point in the history
 [Sprint 22 / PD-368] - [Feature] Create gRPC Service on Akushon ROS
  • Loading branch information
marfanr authored May 29, 2024
2 parents 43d3200 + 7fdf0b7 commit 9a6f72e
Show file tree
Hide file tree
Showing 2 changed files with 94 additions and 0 deletions.
51 changes: 51 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,62 @@ endif()
find_package(ament_cmake REQUIRED)
find_package(rosidl_default_generators REQUIRED)

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

find_package(gRPC CONFIG REQUIRED)
message(STATUS "Using gRPC ${gRPC_VERSION}")

# Generated sources
file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/proto)
add_custom_command(
OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/proto/akushon.pb.cc"
"${CMAKE_CURRENT_BINARY_DIR}/proto/akushon.pb.h"
"${CMAKE_CURRENT_BINARY_DIR}/proto/akushon.grpc.pb.cc"
"${CMAKE_CURRENT_BINARY_DIR}/proto/akushon.grpc.pb.h"
COMMAND $<TARGET_FILE:protobuf::protoc>
ARGS --grpc_out "${CMAKE_CURRENT_BINARY_DIR}/proto"
--cpp_out "${CMAKE_CURRENT_BINARY_DIR}/proto"
-I ${CMAKE_CURRENT_SOURCE_DIR}/proto
--plugin=protoc-gen-grpc=$<TARGET_FILE:gRPC::grpc_cpp_plugin>
${CMAKE_CURRENT_SOURCE_DIR}/proto/akushon.proto
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/proto/akushon.proto)

add_library(akushon_proto
${CMAKE_CURRENT_BINARY_DIR}/proto/akushon.pb.cc
${CMAKE_CURRENT_BINARY_DIR}/proto/akushon.pb.h
${CMAKE_CURRENT_BINARY_DIR}/proto/akushon.grpc.pb.cc
${CMAKE_CURRENT_BINARY_DIR}/proto/akushon.grpc.pb.h)

target_compile_options(akushon_proto PRIVATE -fPIC)
target_compile_features(akushon_proto PUBLIC cxx_std_17)

target_link_libraries(akushon_proto
protobuf::libprotobuf
)

rosidl_generate_interfaces(${PROJECT_NAME}
"msg/RunAction.msg"
"msg/Status.msg"
"srv/GetActions.srv"
"srv/SaveActions.srv")

ament_export_dependencies(rosidl_default_runtime)
ament_export_targets(akushon_proto HAS_LIBRARY_TARGET)

install (
DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/proto/
DESTINATION include/${PROJECT_NAME}
)

install (
TARGETS akushon_proto
EXPORT akushon_proto
ARCHIVE DESTINATION lib
LIBRARY DESTINATION lib
RUNTIME DESTINATION bin
INCLUDES DESTINATION include
)

ament_package()
43 changes: 43 additions & 0 deletions proto/akushon.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
syntax = "proto3";

package akushon_interfaces.proto;

service Config {
rpc GetConfig (Empty) returns (ConfigActions) {}

rpc SaveConfig (ConfigActions) returns (Empty) {}

rpc PublishSetJoints (SetJointsData) returns (Empty) {}

rpc RunAction (ConfigRunAction) returns (Empty) {}

rpc SetTorques (SetTorquesData) returns (Empty) {}

rpc SubscribeCurrentJoints (Empty) returns (CurrentJoints) {}
}

message Empty {}

message ConfigActions {
string json_actions = 1;
}

message SetJointsData {
int32 control_type = 1;
string joints_actions = 2;
}

message ConfigRunAction {
int32 control_type = 1;
string action_name = 2;
string json_action = 3;
}

message SetTorquesData {
string ids = 1;
bool torque_enable = 2;
}

message CurrentJoints {
string msg_joints = 1;
}

0 comments on commit 9a6f72e

Please sign in to comment.