Vector3 linear
float32[] ranges
fieldtype1 fieldname1
fieldtype2 fieldname2
fieldtype3 fieldname3
$ ros2 interface show geometry_msgs/msg/Twist
$ ros2 interface show geometry_msgs/msg/Vector3
geometry_msgs/msgs/Twist 메시지 =
float64 자료형의 linear.x, linear.y, linear.z, angular.x, angular.y, angular.z
ros2 interface [something]
$ ros2 interface proto geometry_msgs/msg/Twist
"linear:
x: 0.0
y: 0.0
z: 0.0
angular:
x: 0.0
y: 0.0
z: 0.0
"
$ ros2 interface show turtlesim/srv/Spawn.srv
float32 x
float32 y
float32 theta
string name
---
string name
$ ros2 interface show turtlesim/action/RotateAbsolute.action
float32 theta # 목표
---
float32 delta # 결과
---
float32 remaining # 피드백
$ cd ~/robot_ws/src
$ ros2 pkg create --build-type ament_cmake msg_srv_action_interface_example
$ cd msg_srv_action_interface_example
$ mkdir msg srv action
msg 인터페이스
ArithmeticArgument.msg
# Messages
builtin_interfaces/Time stamp
float32 argument_a
float32 argument_b
# Constants
int8 PLUS = 1
int8 MINUS = 2
int8 MULTIPLY = 3
int8 DIVISION = 4
# Request
int8 arithmetic_operator
---
# Response
float32 arithmetic_result
action 인터페이스
ArithmeticChecker.action
# Constants
int8 PLUS = 1
int8 MINUS = 2
int8 MULTIPLY = 3
int8 DIVISION = 4
# Request
int8 arithmetic_operator
---
# Response
float32 arithmetic_result
패키지 설정 파일(package.xml) 작성 / 수정
<?xml version="1.0"?>
<?xml-model href="http://download.ros.org/schema/package_format3.xsd" schematypens="http://www.w3.org/2001/XMLSchema"?>
<package format="3">
<name>msg_srv_action_interface_example</name>
<version>0.2.0</version>
<description>
ROS 2 example for message, service and action interface
</description>
<maintainer email="passionvirus@gmail.com">Pyo</maintainer>
<license>Apache 2.0</license>
<author email="passionvirus@gmail.com">Pyo</author>
<author email="routiful@gmail.com">Darby Lim</author>
<buildtool_depend>ament_cmake</buildtool_depend>
**<buildtool_depend>rosidl_default_generators</buildtool_depend> # 인터페이스 전용 패키지에서 필수적인 의존성 패키지
<exec_depend>builtin_interfaces</exec_depend>
<exec_depend>rosidl_default_runtime</exec_depend>**
<member_of_group>rosidl_interface_packages</member_of_group>
<export>
<build_type>ament_cmake</build_type>
</export>
</package>
빌드 설정 파일(CMakeLists.txt) 작성/수정
set
명령어로 msg, srv, action 파일을 지정해주고 rosidl_generate_interfaces
에 해당 셋들을 기입################################################################################
# Set minimum required version of cmake, project name and compile options
################################################################################
cmake_minimum_required(VERSION 3.5)
project(msg_srv_action_interface_example)
if(NOT CMAKE_CXX_STANDARD)
set(CMAKE_CXX_STANDARD 14)
endif()
if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wpedantic")
endif()
################################################################################
# Find and load build settings from external packages
################################################################################
find_package(ament_cmake REQUIRED)
find_package(builtin_interfaces REQUIRED)
find_package(rosidl_default_generators REQUIRED)
################################################################################
# Declare ROS messages, services and actions
################################################################################
**set(msg_files
"msg/ArithmeticArgument.msg"
)
set(srv_files
"srv/ArithmeticOperator.srv"
)
set(action_files
"action/ArithmeticChecker.action"
)
rosidl_generate_interfaces(${PROJECT_NAME}
${msg_files}
${srv_files}
${action_files}
DEPENDENCIES builtin_interfaces
)**
################################################################################
# Macro for ament package
################################################################################
ament_export_dependencies(rosidl_default_runtime)
ament_package()
$ cd ~/ros2_bashing
$ colcon build --symlink-install --packages-select msg_srv_action_interface_example
~/ros2_bashing/install/msg_srv_action_interface_example
├── include
│ └── msg_srv_action_interface_example
│ ├── action
│ ├── msg
│ └── srv
├── lib
│ └── python3.6
│ └── site-packages
│ └── msg_srv_action_interface_example
│ ├── action
│ ├── msg
│ └── srv
└── share
└── msg_srv_action_interface_example
├── action
├── msg
└── srv