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-50] - [Feature] Add implementation GRPC #5

Merged
merged 10 commits into from
Jun 5, 2024
57 changes: 57 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,47 @@ 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}")

set(_PROTOBUF_LIBPROTOBUF protobuf::libprotobuf)
set(_REFLECTION gRPC::grpc++_reflection)
set(_PROTOBUF_PROTOC $<TARGET_FILE:protobuf::protoc>)

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

set(_GRPC_GRPCPP gRPC::grpc++)
set(_GRPC_CPP_PLUGIN_EXECUTABLE $<TARGET_FILE:gRPC::grpc_cpp_plugin>)

# Proto file
get_filename_component(aruku_proto "./proto/aruku.proto" ABSOLUTE)
threeal marked this conversation as resolved.
Show resolved Hide resolved
get_filename_component(aruku_proto_path "${aruku_proto}" PATH)
threeal marked this conversation as resolved.
Show resolved Hide resolved

# Generated sources
add_custom_command(
OUTPUT "${${CMAKE_CURRENT_BINARY_DIR}/aruku.pb.cc}" "${${CMAKE_CURRENT_BINARY_DIR}/aruku.pb.h}" "${${CMAKE_CURRENT_BINARY_DIR}/aruku.pb.h}" "${${CMAKE_CURRENT_BINARY_DIR}/aruku.grpc.pb.h}"
COMMAND ${_PROTOBUF_PROTOC}
threeal marked this conversation as resolved.
Show resolved Hide resolved
ARGS --grpc_out "${CMAKE_CURRENT_BINARY_DIR}"
--cpp_out "${CMAKE_CURRENT_BINARY_DIR}"
-I "${aruku_proto_path}"
--plugin=protoc-gen-grpc="${_GRPC_CPP_PLUGIN_EXECUTABLE}"
threeal marked this conversation as resolved.
Show resolved Hide resolved
"${aruku_proto}"
DEPENDS "${aruku_proto}")

add_library(aruku_proto
${${CMAKE_CURRENT_BINARY_DIR}/aruku.pb.cc}
${${CMAKE_CURRENT_BINARY_DIR}/aruku.pb.h}
${${CMAKE_CURRENT_BINARY_DIR}/aruku.pb.h}
${${CMAKE_CURRENT_BINARY_DIR}/aruku.grpc.pb.h})
threeal marked this conversation as resolved.
Show resolved Hide resolved

target_link_libraries(aruku_proto
${_REFLECTION}
${_GRPC_GRPCPP}
${_PROTOBUF_LIBPROTOBUF}
threeal marked this conversation as resolved.
Show resolved Hide resolved
)

rosidl_generate_interfaces(${PROJECT_NAME}
"msg/Point2.msg"
"msg/SetConfig.msg"
Expand All @@ -25,4 +66,20 @@ rosidl_generate_interfaces(${PROJECT_NAME}
"srv/SaveConfig.srv")

ament_export_dependencies(rosidl_default_runtime)
ament_export_targets(aruku_proto HAS_LIBRARY_TARGET)

install (
DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
DESTINATION include
)

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

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

package aruku_interfaces.proto;

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

rpc SaveConfig (ConfigWalking) returns (Empty) {}

rpc PublishConfig (ConfigWalking) returns (Empty){}

rpc SetMainConfig (SetWalking) returns (Empty) {}
}

message Empty {}

message Point2 {
double x = 1;
double y = 2;
}

message ConfigWalking {
string json_kinematic = 1;
string json_walking = 2;
}

message SetWalking {
bool run = 1;
double x_move = 2;
double y_move = 3;
double a_move = 4;
bool aim_on = 5;
}

message Status {
bool is_running = 1;
double x_amplitude = 2;
double y_amplitude = 3;
double a_amplitude = 4;
Point2 odometry = 5;
}

Loading