Skip to content

Commit

Permalink
Merge pull request #5 from ichiro-its/feature/using-grpc
Browse files Browse the repository at this point in the history
[Sprint 22 / PD-50] - [Feature] Add implementation GRPC
  • Loading branch information
marfanr authored Jun 5, 2024
2 parents aebc923 + d3d5a0a commit 24ab058
Show file tree
Hide file tree
Showing 2 changed files with 100 additions and 1 deletion.
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()
47 changes: 47 additions & 0 deletions proto/aruku.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
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) {}

rpc SetAppStatus (AppStatus) 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;
}

message AppStatus {
bool action_manager_status = 1;
}

0 comments on commit 24ab058

Please sign in to comment.