创建msg文件
test.msg
#path for a given robot
int32 robot_id #TODO: Deprecate this
int32 goal_id #TODO: Deprecate this
string id
创建srv文件
test.srv
#request client写入数据,请求到srv中
int32[] goal_ids
string id
---
#response srv返回结果
bool success
创建action文件
test.action
#Define the goal
int32 id
---
#Define the result
bool error
---
#Define a feedback message
int32 state
float32 remaining_distance
CMakeLists.txt
cmake_minimum_required(VERSION 3.5)
project(msg_srv)
# Default to C99
if(NOT CMAKE_C_STANDARD)
set(CMAKE_C_STANDARD 99)
endif()
# Default to C++14
if(NOT CMAKE_CXX_STANDARD)
set(CMAKE_CXX_STANDARD 14)
endif()
if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
add_compile_options(-Wall -Wno-unused-parameter -Wextra -Wpedantic)
endif()
set(CMAKE_BUILD_TYPE Release)
# find dependencies
find_package(ament_cmake REQUIRED)
find_package(rosidl_default_generators REQUIRED)
find_package(std_msgs REQUIRED)
find_package(nav_msgs REQUIRED)
find_package(geometry_msgs REQUIRED)
rosidl_generate_interfaces(
${PROJECT_NAME}
"action/Test.action"
"msg/Test.msg"
"srv/Test.srv"
DEPENDENCIES
std_msgs
nav_msgs
geometry_msgs)
if(BUILD_TESTING)
find_package(ament_lint_auto REQUIRED)
# the following line skips the linter which checks for copyrights uncomment the line when a copyright and license is not present in all source files
# set(ament_cmake_copyright_FOUND TRUE) the following line skips cpplint (only works in a git repo) uncomment the line when this package is not in a
ament_lint_auto_find_test_dependencies()
endif()
install(DIRECTORY include/#${PROJECT_NAME}/
DESTINATION include/${PROJECT_NAME}
FILES_MATCHING PATTERN "*.h"
PATTERN ".svn" EXCLUDE
)
ament_package()
package.xml
<?xml version="1.0"?>
<package format="3">
<name>msg_srv</name>
<version>0.0.0</version>
<description>The msg_srv package</description>
<maintainer email="XMJ@qq.com">xiaomoji</maintainer>
<license>TODO: License declaration</license>
<buildtool_depend>ament_cmake</buildtool_depend>
<depend>std_msgs</depend>
<depend>nav_msgs</depend>
<depend>geometry_msgs</depend>
<exec_depend>rosidl_default_runtime</exec_depend>
<build_depend>rosidl_default_generators</build_depend>
<member_of_group>rosidl_interface_packages</member_of_group>
<test_depend>ament_lint_auto</test_depend>
<test_depend>ament_lint_common</test_depend>
<export>
<build_type>ament_cmake</build_type>
</export>
</package>