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
54 changes: 53 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,43 @@ 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/aruku.pb.cc"
"${CMAKE_CURRENT_BINARY_DIR}/proto/aruku.pb.h"
"${CMAKE_CURRENT_BINARY_DIR}/proto/aruku.grpc.pb.cc"
"${CMAKE_CURRENT_BINARY_DIR}/proto/aruku.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/aruku.proto
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/proto/aruku.proto)


add_library(aruku_proto SHARED
"${CMAKE_CURRENT_BINARY_DIR}/proto/aruku.pb.cc"
"${CMAKE_CURRENT_BINARY_DIR}/proto/aruku.pb.h"
"${CMAKE_CURRENT_BINARY_DIR}/proto/aruku.grpc.pb.cc"
"${CMAKE_CURRENT_BINARY_DIR}/proto/aruku.grpc.pb.h"
)

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

target_link_libraries(aruku_proto PUBLIC
protobuf::libprotobuf
)

rosidl_generate_interfaces(${PROJECT_NAME}
"msg/Point2.msg"
"msg/SetConfig.msg"
Expand All @@ -24,5 +61,20 @@ rosidl_generate_interfaces(${PROJECT_NAME}
"srv/GetConfig.srv"
"srv/SaveConfig.srv")

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

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

ament_export_dependencies(rosidl_default_runtime protobuf gRPC)
ament_export_targets(aruku_proto HAS_LIBRARY_TARGET)
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