Ask Your Question

ROS2 Subscription Callback not called with GAZEBO

asked 2020-02-24 13:27:36 -0500

GeorgNo gravatar image

updated 2020-02-24 14:08:00 -0500

gvdhoorn gravatar image


I am having a problem on my first ROS2 node. I setup the turtlebot3 packages using this link (only Remote PC since I don't have a robot). Started the GAZEBO simulation using these instructions. After I run ros2 launch turtlebot3_gazebo I can do ros2 topic echo /scan and receive data.

After this I created a colcon pkg using this tutorial and wrote following code:

import rclpy   
from rclpy.node import Node   
from sensor_msgs.msg import LaserScan   

class Platooning(Node):
    def __init__(self):
        # ROS Stuff #
        self.get_logger().info("Started init Node")
        self.sub_lidar = self.create_subscription(LaserScan, "/scan", self.lidar_callback, 10)
        self.get_logger().info("Finished init node {}".format(self.get_name()))
    def lidar_callback(self, msg):
        self.get_logger().info("I heard: {}".format(msg))

def main(args=None):
    control = Platooning()
    except Exception as e:
        print("Exception: {}".format(e))

if __name__ == '__main__':

I build the package using colcon build --symlink-install --packages-select platooning and start it using ros2 run platooning main.

The lidar_callback functions does not print anything using just gazebo, but as soon as I do ros2 topic pub /scan sensor_msgs/msg/LaserScan -1 the lidar_callback is executed.

Can somebody please help me?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2020-06-17 02:17:05 -0500

GeorgNo gravatar image

The problem was that the subscriber had a wrong quality of service profile.

Here the fix:

from rclpy.qos import qos_profile_sensor_data
self.sub_lidar = self.create_subscription(LaserScan, "/scan", self.lidar_callback, qos_profile=qos_profile_sensor_data)
edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2020-02-24 13:27:36 -0500

Seen: 254 times

Last updated: Jun 17 '20