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

Revision history [back]

@sloretz is right, just here to add some code for better understanding, future viewers.

So if your publisher is using

rclcpp::SensorDataQoS()

Then in your python subscriber subscribe with same QOS setting, for example I subscribe to NavsatFix message with following;

import rclpy
from rclpy.node import Node
from rclpy.qos import qos_profile_sensor_data

from sensor_msgs.msg import NavSatFix

def __init__(self):
    super().__init__('gps_waypoint_collector')

    self.subscription = self.create_subscription(
        NavSatFix,
        '/gps/fix',
        self.listener_callback, qos_profile_sensor_data
    )
    self.subscription  # prevent unused variable warning


def listener_callback(self, msg):
    print(msg.latitude, msg.longitude, msg.altitude)