jhelovuo / ros2-client

ROS2 client library based on RustDDS
68 stars 15 forks source link

First 2 messages are sent and never received. Why? #25

Open fgadaleta opened 7 months ago

fgadaleta commented 7 months ago

https://github.com/jhelovuo/ros2-client/blame/db85ada1b9b507c2d4173cb9f8ffba8c42841b23/examples/talker/main.rs#L56C4-L56C4

jhelovuo commented 7 months ago

First 2 messages are sent and never received. Why?

Most likely this is due to too relaxed QoS settings.

When both ROS 2 Nodes (under the hood: DDS DomainParticipants) are running, it takes some seconds for Discovery to operate and match (connect) the Publisher to Subscriber. Samples sent during this time are lost.

If you want to receive samples published before the match was made, use e.g. the following QoS:

let reliable_qos = ros2::QosPolicyBuilder::new()
      .history(policy::History::KeepLast { depth: 10 })
      .reliability(policy::Reliability::Reliable {
        max_blocking_time: ros2::Duration::from_millis(100),
      })
      .durability(policy::Durability::TransientLocal)
      .build();

Important elements here are Reliable, TransientLocal, and some reasonable History depth.

Please report if this works for you.

fgadaleta commented 7 months ago

I tried to "play" with such settings on the publisher QoS without success. Without durability the listener receives after ~3 seconds (and misses all the messages until then) With durability the listener blocks after 4 messages.

jhelovuo commented 7 months ago

You need to set reliability = Reliable at both Publisher and Subscriber.

By the DDS specification, using Reliable Publisher and BestEffort Subscriber will match and transmit data, but the connection is BestEffort, and the samples sent during Discovery process are lost.