一.server.cpp:
二.client.cpp
三.在包下创建srv文件夹,在其中创建一个gps.srv文件:
float32 x
float32 y
---
float32 sum
四.Cmakelist.txt:
find_package(catkin REQUIRED COMPONENTS
roscpp
rospy
std_msgs
message_generation
)
add_service_files(
FILES
gps.srv
)
generate_messages(
DEPENDENCIES
std_msgs
)
add_executable(server src/server.cpp)
target_link_libraries(server ${catkin_LIBRARIES} )
add_dependencies(server ${PROJECT_NAME}_gencpp)
add_executable(client src/client.cpp)
add_dependencies(client ${PROJECT_NAME}_gencpp )
target_link_libraries(client ${catkin_LIBRARIES} )
五.package.xml:
<build_depend>message_generation</build_depend>
<exec_depend>message_runtime</exec_depend>