ros2 transient_local durability (late joiners policy) does not work when using ros2 topic echo

asked 2020-06-01 11:04:00 -0600

CraigH92 gravatar image

I have a node that publishes a message when the publisher is first created:

class IntrabayDoorSimPublisher(Node):       

    """
    Constructed with a doorSim, which it wraps and publishes the current state to a ros topic
    """

    def __init__(self, doorSim : IntrabayDoorSimulator):

        super().__init__('intrabay_door_sim_publisher_nodelet')

        self.__doorSim = doorSim

        latching_qos = QoSProfile(depth=1, durability=QoSDurabilityPolicy.RMW_QOS_POLICY_DURABILITY_TRANSIENT_LOCAL)

        self.__publisher = self.create_publisher(DoorState, 'intrabay_door_state', qos_profile=latching_qos)
        self.__doorSim.addOnChangedSlot(lambda newState : self.pub_callback()) #callback is called when doorsim changes state
        self.pub_callback() # call the publish function at least once so the initial condition of doorsim is published

    def pub_callback(self):
        msg = DoorState()

        msg.door_state = int(self.__doorSim.getDoorState())

        self.get_logger().info("publishing: " + str(self.__doorSim.getDoorState()))
        self.__publisher.publish(msg)

If I then type into a console (after the node has been started):

ros2 topic echo --qos-durability=transient_local /acf/intrabay_door_state acf_interfaces/msg/DoorState

The message does not appear. If I type this in before the node has been started, and then start the node, the message does appear.

If I create my own node that subscribes to the intrabay_door_state topic with a transient_local QoS, then this node can retrieve the door state even if it starts after the publishing node.

So why does the 'ros2 topic echo' command not work? I thought the transient_local QoS policy allows late joiners (the echo node) to receive the last published message?

If this is not possible with 'ros2 topic echo' How can I use the command line tools to get the last published message from my node?

Thanks!

edit retag flag offensive close merge delete

Comments

1

For reference the issue that you opened: https://github.com/ros2/ros2cli/issue...

Mbuijs gravatar image Mbuijs  ( 2020-06-10 02:34:43 -0600 )edit