srv:
1. describe a service. request와 response로 구성된다
2. srv 파일들은 패키지의 srv 폴더 안에 저장된다.
3. request와 response는 '---'로 구분된다
srv 파일 예시:
int 64 A
int 64 B
---
int64 Sum
srv 사용법:
1. srv 만들기
1) 패키지 안에 srv폴더를 생성하여 새로운 srv 파일 추가
*edit 프로그램(visual code 등)에서 폴더에다 생성하는게 쉬움
$ roscd beginner_tutorials
$ mkdir srv
*
튜토리얼에서는 새로운 srv definition을 생성하기보다는, 다른 패키지에 존재하는 srv 폴더를 복붙
roscp 사용
$ roscp [package_name] [file_to_copy_path] [copy_path]
$ roscp rospy_tutorials AddTwoInts.srv srv/AddTwoInts.srv
2) package.xml 수정(msg파일 추가할때와 동일)
<build_depend>message_generation</build_depend>
<exec_depend>message_runtime</exec_depend>
3) CMakeLists.txt 수정
# Do not just add this line to your CMakeLists.txt, modify the existing line
find_package(catkin REQUIRED COMPONENTS
roscpp
rospy
std_msgs
message_generation
)
add_service_files(
FILES
AddTwoInts.srv
)
2. rossrv 사용하기
1) 패키지 이름을 알 때
$ rossrv show <service type>
$ rossrv show beginner_tutorials/AddTwoInts
->
int64 a
int64 b
---
int64 sum
2) 패키지 이름을 안 적을 때
$ rossrv show AddTwoInts
->
[beginner_tutorials/AddTwoInts]:
int64 a
int64 b
---
int64 sum
commandtool -h를 애용하자
rosmsg -h
rossrv -h
'ROS' 카테고리의 다른 글
ROS_Study: Recording and playing back data (1) | 2023.12.08 |
---|---|
ROS_Study: Writing a Simple Publisher and Subscriber(Python) (2) | 2023.11.22 |
ROS_Study: Creatomg a ROS msg and srv(Only msg) (0) | 2023.11.22 |
ROS_Study: Understanding ROS Services and Parameters (0) | 2023.11.22 |
ROS_Study: Understanding ROS Topics (0) | 2023.11.22 |