ros2_python/Ros2 개념

ros2_QoSProfile 관련설명

알 수 없는 사용자 2022. 7. 5. 13:30

ros2에서 qos


개념

https://docs.ros.org/en/humble/Concepts/About-Quality-of-Service-Settings.html

 

About Quality of Service settings — ROS 2 Documentation: Humble documentation

Overview ROS 2 offers a rich variety of Quality of Service (QoS) policies that allow you to tune communication between nodes. With the right set of Quality of Service policies, ROS 2 can be as reliable as TCP or as best-effort as UDP, with many, many possi

docs.ros.org

 

 

신경 써줘야 할 부분이 Reliability 인데.

reliable as TCP        TCP 통신인 RELIABLE

 - best-effort as UDP   UDP 통신인 BEST_EFFORT

서로 pub sub 하기 위해서는 통신 방식을 맞춰줘야 한다. (default는 RELIABLE )

- 통신 가능한지에 대한 

 

ROS1 은 UDP 통신 없고 TCP 통신만 있다. (TCPROS)따라서 ROS1 -> ROS2 버전업을 하려면 ROS2의 네트워크 구성(QoS)을 ROS1과 유사하게 해야함.

ex) 

  • History
    • Keep last: only store up to N samples, configurable via the queue depth option.
  • Depth
    • 10 -> Queue size: only honored if the “history” policy was set to “keep last”.
  • Reliability
    • Reliable: guarantee that samples are delivered, may retry multiple times.
  • Durability
    • Volatile: no attempt is made to persist samples.
  • Deadline
    • 설정 X (자동으로 default 되게끔 설정안하면 된다. )
  • Lifespan
    • 설정 X (자동으로 default 되게끔 설정안하면 된다. )
  • Liveliness
    • 설정 X (자동으로 default 되게끔 설정안하면 된다. )
  • Lease Duration
    • 설정 X (자동으로 default 되게끔 설정안하면 된다. )

 

ros2의 QoS를 사용하려면 History  와 Depth 값을 지정해줘야한다. 나머지는 옵션으로 넣어도 안넣어도 됨

QoS policies

The base QoS profile currently includes settings for the following policies:

  • History
    • Keep last: only store up to N samples, configurable via the queue depth option.
    • Keep all: store all samples, subject to the configured resource limits of the underlying middleware.
  • Depth
    • Queue size: only honored if the “history” policy was set to “keep last”.
  • Reliability
    • Best effort: attempt to deliver samples, but may lose them if the network is not robust.
    • Reliable: guarantee that samples are delivered, may retry multiple times.
  • Durability
    • Transient local: the publisher becomes responsible for persisting samples for “late-joining” subscriptions.
    • Volatile: no attempt is made to persist samples.
  • Deadline
    • Duration: the expected maximum amount of time between subsequent messages being published to a topic
  • Lifespan
    • Duration: the maximum amount of time between the publishing and the reception of a message without the message being considered stale or expired (expired messages are silently dropped and are effectively never received).
  • Liveliness
    • Automatic: the system will consider all of the node’s publishers to be alive for another “lease duration” when any one of its publishers has published a message.
    • Manual by topic: the system will consider the publisher to be alive for another “lease duration” if it manually asserts that it is still alive (via a call to the publisher API).
  • Lease Duration
    • Duration: the maximum period of time a publisher has to indicate that it is alive before the system considers it to have lost liveliness (losing liveliness could be an indication of a failure).

다른부분은 참고 사이트에서 확인.

python에 ros 라이브러리 qos.py 의 QoSProfile 클래스를 보면 config에 따라 옵션이 바뀜을 확인할 수 있다.

from rclpy.qos import QoSProfile

 

 

 


쓰는방법

from rclpy.qos import QoSProfile
self.qos_profile = QoSProfile(10)

제대로 쓸꺼면
self.qos_profile = QoSProfile(depth=10, history=1)
이런식으로 지정하면 된다.

 

@@@@@.create_subscription(
    self._type,
    self._topic_name,
    _callback_def,
    self.qos_profile)

이런식으로 설정한다.

QoSProfile 을 가져와서 거기에 config 값을 넣고

.create_subscription이나

@@@@@@.create_publisher(String, 'topic', self.qos_profile)

.create_publisher에

self.qos_profile 이런식으로 인자값으로 넘겨줌