ROS2学习之路之msg、srv、action创建

创建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>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值