feat:完善了自动标定车间的环境
This commit is contained in:
@@ -0,0 +1,49 @@
|
||||
cmake_minimum_required(VERSION 3.8)
|
||||
project(agv_calib_brain)
|
||||
|
||||
# 1. 寻找 ROS 2 依赖
|
||||
find_package(ament_cmake REQUIRED)
|
||||
find_package(rclcpp REQUIRED)
|
||||
|
||||
# 2. 寻找 gRPC 和 Protobuf 依赖
|
||||
find_package(Protobuf REQUIRED)
|
||||
find_package(gRPC REQUIRED)
|
||||
|
||||
# 3. 设置 Proto 文件路径与自动生成的源码输出路径
|
||||
set(PROTO_DIR "${CMAKE_CURRENT_SOURCE_DIR}/proto")
|
||||
set(PROTO_FILE "${PROTO_DIR}/agv_calib_control.proto")
|
||||
set(PROTO_OUT_DIR "${CMAKE_CURRENT_BINARY_DIR}/grpc_gen")
|
||||
file(MAKE_DIRECTORY ${PROTO_OUT_DIR})
|
||||
|
||||
# 4. 自动生成 gRPC C++ 源码 (每次 colcon build 自动执行)
|
||||
find_program(GRPC_CPP_PLUGIN_EXECUTABLE grpc_cpp_plugin)
|
||||
add_custom_command(
|
||||
OUTPUT "${PROTO_OUT_DIR}/agv_calib_control.pb.cc"
|
||||
"${PROTO_OUT_DIR}/agv_calib_control.pb.h"
|
||||
"${PROTO_OUT_DIR}/agv_calib_control.grpc.pb.cc"
|
||||
"${PROTO_OUT_DIR}/agv_calib_control.grpc.pb.h"
|
||||
COMMAND protoc
|
||||
ARGS --proto_path="${PROTO_DIR}"
|
||||
--cpp_out="${PROTO_OUT_DIR}"
|
||||
--grpc_out="${PROTO_OUT_DIR}"
|
||||
--plugin=protoc-gen-grpc="${GRPC_CPP_PLUGIN_EXECUTABLE}"
|
||||
"${PROTO_FILE}"
|
||||
DEPENDS "${PROTO_FILE}"
|
||||
)
|
||||
|
||||
# 5. 将生成的网络源码打包成独立的 C++ 库
|
||||
add_library(agv_grpc_proto_lib SHARED
|
||||
"${PROTO_OUT_DIR}/agv_calib_control.pb.cc"
|
||||
"${PROTO_OUT_DIR}/agv_calib_control.grpc.pb.cc"
|
||||
)
|
||||
target_include_directories(agv_grpc_proto_lib PUBLIC "${PROTO_OUT_DIR}")
|
||||
target_link_libraries(agv_grpc_proto_lib gRPC::grpc++ protobuf::libprotobuf)
|
||||
|
||||
# 6. 编译您的 ROS 2 节点主程序
|
||||
add_executable(brain_node src/brain_node.cpp)
|
||||
ament_target_dependencies(brain_node rclcpp)
|
||||
# 🚨 必须链接刚才生成的 gRPC 库
|
||||
target_link_libraries(brain_node agv_grpc_proto_lib)
|
||||
|
||||
install(TARGETS brain_node DESTINATION lib/${PROJECT_NAME})
|
||||
ament_package()
|
||||
Reference in New Issue
Block a user