ros2 rclpy: Get client to request a message from a server

asked 2020-05-21 09:01:10 -0600

CraigH92 gravatar image

I have some ros2 nodes that act as servers, publishing the state of my robots. They only publish messages when the state of the robot changes.

I also have a ros2 node acting as a client/server, that subscribes to the topics provided by the servers, and publishes a "Condition" based on the combined state of the whole system.

The problem is that when this condition server first starts, it does not know the states of the other robots because they only publish messages when they change state.

How can I get the condition server to do a single poll of the robot state when it first starts up?

Something like:

sub = self.create_subscription(RobotState, "robot_one_position", callback, 10)
sub.poll_once() #This will ask for a RobotState message, and then pass that to the callback.

Thanks.

edit retag flag offensive close merge delete

Comments

The problem is that when this condition server first starts, it does not know the states of the other robots because they only publish messages when they change state.

This sounds like something which could be solved with latching, which will allow late joiners to receive the last message published on a topic no matter when it was published (ie: the late joiner doesn't have to have been online & subscribed).

Your two publishers must publish "the first time" they start, correct?

In ROS 2, I believe this can be achieved by configuring both Publishers and Subscribers with a transient local durability QoS. See ros2/ros2#464 for a discussion about this, ros2/geometry2#160 for how TF2 does this in ROS 2 and About Quality of Service settings for information about the different QoS policies.

gvdhoorn gravatar image gvdhoorn  ( 2020-05-21 09:10:44 -0600 )edit
1

Latching sounds like a perfect solution. Your right, I will just make sure my two publishers publish a message when they first start.

I will have a look at the transient local durability QoS. Thank you!

CraigH92 gravatar image CraigH92  ( 2020-05-21 10:02:57 -0600 )edit