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

how to clear rospy publisher/subscriber's queue

asked 2020-06-04 13:44:30 -0600

azerila gravatar image

Is there a way to empty what a publisher or subscriber has in its queue in rospy ?

something like resetting it so that it throws away what it has in its queue.

edit retag flag offensive close merge delete

Comments

Hi @azerila, To avoid an xy-problem, can you provide more background info about what you want to achieve with that?

Weasfas gravatar image Weasfas  ( 2020-06-05 06:08:48 -0600 )edit

Hi @Weasfas, I have a robot simulator which uses publisher and subscriber to publish robot states and subscribe robot's commands. When I reset the simulator it seems to me that what was left in the queue of the the publisher's and subscribers remain to be applied which will cause not to restart the simulator from the very initial state of it.

azerila gravatar image azerila  ( 2020-06-05 08:34:29 -0600 )edit

1 Answer

Sort by ยป oldest newest most voted
0

answered 2020-06-06 05:20:10 -0600

Weasfas gravatar image

Ok, I assume the simulator is Gazebo, that can be reset using the rosservice call /gazebo/reset_simulation service. From this line of gazebo_ros_packages I asume that with a reset you are only reseting the World not the Entities, however the code is calling a Reset function on the pointer world object that based on this, it is reseting time and model poses, configurations in simulation. As far as I understand is not aproblem of your command publisher but the state of the simulation when calling the reset service.

As I see, when calling the reset service this saves the simulation state, reset the world and apply the state saved earlier, leaving all simulation entities with the same state just before calling the reset. This is because the /joint_states topic stops publishing joint states after the call of the reset and then resumes the publication when revecives a new command. This post made a good point about the reseting the simulation and I believe is the way to go.

Furthermore, this behaviour is considerided kind of an issue with Gazebo. As for the way of reseting the publisher I do not know a proper way of doing that but generally most people just implement a function that sets all values in the command message to 0 or the initial ones.

edit flag offensive delete link more

Question Tools

2 followers

Stats

Asked: 2020-06-04 13:44:30 -0600

Seen: 1,217 times

Last updated: Jun 06 '20