ROS写srv且自动建立h头文件
这里是教程
写ros的srv
新建包
mkdir -p ROSworkspace/second_ws/src
cd ROSworkspace/second_ws
catkin_make
新建srv的pkg
cd src
catkin_create_pkg service_demo roscpp rospy std_msgs
cd service_demo
mkdir srv
gedit Greeting.srv
里面的内容为
string name
int32 age
---
string feedback
然后要修改CMakeList.txt和package.xml
Package.xml
在里面新增
<build_depend>message_generation</build_depend>
<exec_depend>message_runtime</exec_depend>
CMakeList.txt
在里面修改:
find_package(catkin REQUIRED COMPONENTS
roscpp
rospy
std_msgs
message_generation
)
add_service_files(
FILES
Greeting.srv
)
generate_messages(
# DEPENDENCIES
# std_msgs
)
catkin_package(
# INCLUDE_DIRS include
# LIBRARIES service_demo
# CATKIN_DEPENDS roscpp rospy std_msgs
# DEPENDS system_lib
LIBRARIES service_demo
CATKIN_DEPENDS message_runtime
)
在最后一行加上
include_directories(include ${catkin_INCLUDE_DIRS})
最后一步
回到second_ws的目录下
catkin_make
这样在devel的include里就会有service_demo
而且里面自动生成三个头文件