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

How to read a topic last value from a Python script?

asked 2013-08-13 04:35:29 -0500

Arn-O gravatar image

updated 2014-01-28 17:17:39 -0500

ngrennan gravatar image


I'm working on a teleop program in Python. I want to change a joint position and add an offset read from the keyboard.

So I need to read a topic value to add the offset and send the command with the target value. Of course I have read the tutorial about the subscriber in Python. My requirement is slightly different. I do not want to process a piece of code each time a value is published. I do not even need a fresh value, since I consider that the last published one is sufficient.

So is there a way to get this last published value using rospy?

Thanks for your help.

edit retag flag offensive close merge delete

2 Answers

Sort by » oldest newest most voted

answered 2013-08-13 23:43:13 -0500

dornhege gravatar image

It depends.

1) Just have a subscriber and record the last published value manually.

2) If you have access to the publisher code, make the publisher latched. This will always keep the last published value and send it to any new subscribers.

edit flag offensive delete link more


Thx for your answer. I finally used the solution 1.

Arn-O gravatar image Arn-O  ( 2013-08-14 07:02:48 -0500 )edit

Ahhhh, “latching” was the missing link for me. 🤯 Or QoS/“durability” in ros2. Thank you! See:

colllin gravatar image colllin  ( 2021-02-03 09:59:03 -0500 )edit

answered 2013-08-13 22:03:39 -0500

Arn-O gravatar image

I will finally use the callback function to maintain a global variable.

edit flag offensive delete link more

Question Tools

1 follower


Asked: 2013-08-13 04:35:29 -0500

Seen: 1,917 times

Last updated: Aug 13 '13