ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
1

QOS python code for create_subscriber

asked 2020-08-31 14:42:30 -0600

maxbback gravatar image

updated 2020-09-01 02:10:49 -0600

gvdhoorn gravatar image

Hi I have tried various code snippets but have not been able to create correct code for sensor QOS definition for a service I am writing in python

    self.speed_subscription = self.create_subscription(
        Int32,
        'distance',
        self.speed_listener_callback,1)
        # self.listener_callback,rmw_qos_profile_sensor_data)

So I like to replace the 1 with sensor profile for QOS

Any hints is appreciated

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
3

answered 2021-01-05 03:23:15 -0600

SmallJoeMan gravatar image

updated 2021-01-05 03:30:29 -0600

I've pull this from my code I use to get images from the RS camera (which requires a non-default QoS policy).

from rclpy.node import Node
from rclpy.qos import QoSProfile, QoSReliabilityPolicy, QoSHistoryPolicy

class MyNode(Node):
    def __init__(self):
        qos_profile = QoSProfile(
            reliability=QoSReliabilityPolicy.RMW_QOS_POLICY_RELIABILITY_BEST_EFFORT,
            history=QoSHistoryPolicy.RMW_QOS_POLICY_HISTORY_KEEP_LAST,
            depth=1
        )

        sub = Subscriber(
            self,
            Image,
            "rgb_img",
            qos_profile=qos_profile
        )
        sub.registerCallback(self._on_rgb)

    def _on_rgb(self, msg):
        ...
edit flag offensive delete link more
1

answered 2021-01-05 02:11:00 -0600

doronhi gravatar image
from rclpy import qos
self.speed_subscription = self.create_subscription(
    Int32,
    'distance',
    self.speed_listener_callback,qos.qos_profile_sensor_data)
edit flag offensive delete link more

Question Tools

2 followers

Stats

Asked: 2020-08-31 14:42:30 -0600

Seen: 10,841 times

Last updated: Jan 05 '21