ros編寫自定義的服務(.srv)
阿新 • • 發佈:2019-01-01
1、編寫自定義的服務檔案(即.srv)檔案。
2、儲存,catkin_make編譯,要生成可以被#include "包/AddTwoInts.h",注意CMakeList.txt檔案的配置
cmake_minimum_required(VERSION 2.8.3) project(learing_communication) ## Compile as C++11, supported in ROS Kinetic and newer # add_compile_options(-std=c++11) ## Find catkin macros and libraries ## if COMPONENTS list like find_package(catkin REQUIRED COMPONENTS xyz) ## is used, also find other catkin packages find_package(catkin REQUIRED COMPONENTS roscpp rospy std_msgs message_generation ) ## Generate messages in the 'msg' folder add_message_files( FILES Person.msg # Message2.msg ) ## Generate services in the 'srv' folder add_service_files( FILES AddTwoInts.srv # Service1.srv # Service2.srv ) ## Generate actions in the 'action' folder # add_action_files( # FILES # Action1.action # Action2.action # ) ## Generate added messages and services with any dependencies listed here generate_messages( DEPENDENCIES std_msgs #message_generation ) add_executable(talker src/talker.cpp) target_link_libraries(talker ${catkin_LIBRARIES}) add_dependencies(talker ${PROJECT_NAME}_generate_messages_cpp) add_executable(listener src/listener.cpp) target_link_libraries(listener ${catkin_LIBRARIES}) add_dependencies(listener ${PROJECT_NAME}_generate_messages_cpp) add_executable(server src/server.cpp) target_link_libraries(server ${catkin_LIBRARIES}) add_dependencies(server ${PROJECT_NAME}_gencpp) add_executable(client src/client.cpp) target_link_libraries(client ${catkin_LIBRARIES}) add_dependencies(client ${PROJECT_NAME}_gencpp)
3、現在就可以在你其他節點中以#include "包/AddTwoInts.h"的形式引用了。
注意:對於AddTwoInts.h 是有AddTwoInts.srv檔案在編譯後自動生成的