0
$\begingroup$

Rosanswers logo

Hi all, I am using ROS kinetic on Ubuntu 16.04. I have a topic that I publish movement instructions to. At some point in my code I want to make a long rospy.sleep but sometimes I will publish to the topic right before I will go to sleep, and thus when I continue after the sleep the first message in the queue of the topic is going to be the old message, which is irrelevant by now. I want to remove all messages from my topics queue right before sleeping or right after continuing after the sleep, but I couldn't figure out how I flush all messages from the topic.

I am sorry if this question is trivial, but I can't find an answer to it in the forums or docs. I saw this post:
https://answers.ros.org/question/37148/flush-subscription/
but my queue size is already set to 1, my problem is I don't even want that 1 thing in the queue, I want to totally empty it out manually.

Thanks in advance for any help available.


Originally posted by oha on ROS Answers with karma: 35 on 2018-06-30

Post score: 0


Original comments

Comment by NEngelhard on 2018-06-30:
Do the messages you publish have a timestamp? (Which message type do you use?)

Comment by oha on 2018-06-30:
i am sending geometry_msgs/Twist messages. I am using the /cmd_vel topic provided by ardrone_autonomy package. I do not know of a timestamp. I think my problem also happens to the std_msgs/Empty message I send to the takeoff topic.

$\endgroup$

1 Answer 1

0
$\begingroup$

Rosanswers logo

I think you should change your system architecture. If you want to be able to ignore movements commands, you should rather implement a service or an action that someone can call. If your robot does not want to move, he can tell so when answering the service or action. In case you really need to use with the topics, think about shutting them them down while sleeping to that the sender knows that it makes no sense to send a message.


Originally posted by NEngelhard with karma: 3519 on 2018-06-30

This answer was ACCEPTED on the original site

Post score: 0


Original comments

Comment by oha on 2018-07-02:
thanks, my code is too far in right now for me to overhaul it to change architecture, but I will keep this in mind for future things I do. I will try to shutdown the topics and restart them, seems weird that there is no mechanism to delete from them, even just making a dummy subscriber or something

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.