2
Help us understand the problem. What are the problem?

posted at

updated at

ROS Python でService Call するまでの流れ

はじめに

roscore実行時自動で出てくる/rosout/get_loggers/rosout/set_logger_levelの2つのサービスを例にROS PythonからServiceを呼ぶ時の手順をまとめました。

サービスについて調べる

1.まず,Service名の確認

$ rosservice list
/rosout/get_loggers
/rosout/set_logger_level

2.次に,Serviceの型その型を定義しているパッケージの確認
Serviceの型のスラッシュの前部分,今回はroscppであることが判明した。

$ rosservice type /rosout/get_loggers
roscpp/GetLoggers

$ rosservice type /rosout/set_logger_level
roscpp/SetLoggerLevel

3.最後に,Serviceの型の構成を確認

$ rossrv show roscpp/GetLoggers
---
roscpp/Logger[] loggers
  string name
  string level

$ rossrv show roscpp/SetLoggerLevel
string logger
string level
---

Pythonからの呼び出し

  • サービス名が"/rosout/get_loggers"のサービスを呼び出す

Screenshot from 2021-04-16 20-02-46.png

get_loggers.py
#!/usr/bin/env python

import rospy
from roscpp.srv import GetLoggers 

rospy.wait_for_service('/rosout/get_loggers')

get_loggers = rospy.ServiceProxy('/rosout/get_loggers', GetLoggers)

response = get_loggers()

print(response)
  • サービス名が"/rosout/set_logger_level"のサービスを呼び出す

Screenshot from 2021-04-16 20-02-37.png

set_logger_level.py

#!/usr/bin/env python

import rospy
from roscpp.srv import SetLoggerLevel

rospy.wait_for_service('/rosout/set_logger_level')

set_logger_level = rospy.ServiceProxy('/rosout/set_logger_level', SetLoggerLevel)

set_logger_level("rosout","DEBUG")

参考

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
2
Help us understand the problem. What are the problem?