# Is it possible to run a timer inside an action server?

Hi all,

my question is rather theoretical and it's about best practice, I hope what I'm thinking about it's not completely useless.

Let me introduce you the problem.

Basically, I have a node which is in charge of doing two things:

• publishing velocity commands to /cmd_vel

• listening to /joint_states topic

This node is not a controller (as one would expect). The velocity commands are defined a-priori and the subscriber to the /joint_states topic is used to track the robot trajectory. In fact, the publisher spins at 100Hz while the listener at ~50Hz (which is the frequency of the /joint_states topic). To do so, the publisher is implemented with a timer, the listener with a subscriber and I use an asynchronous spinner to run them both in the same node:

  ros::AsyncSpinner spinner(4);
spinner.start();
ros::waitForShutdown();


So far so good. Now, imagine I want to implement a safety layer. That is, while tracking the robot trajectory I detect that the robot reached a forbidden position and I want to halt the robot by stopping publishing velocity commands.

My idea was to implement it with an action server. In particular, a server with the GoalCallbackMethod (for the /joint_states topic). Therefore, my question is: can I use a ros::Timer inside the action server class? If possible, what I have to do in order to run the server callback and the timer callback asynchronously? An asynchronous spinner is enough?

Any suggestion would be appreciated!

Thanks.

Regarding the last question, my idea was that the action server publishes as feedback the robot pose. Then, the client cancels the goal if the robot reached a forbidden position. Does it make sense to you?

edit retag close merge delete

Sort by » oldest newest most voted

Therefore, my question is: can I use a ros::Timer inside the action server class?

Yes (at least, if you're referring to your own action server class here, not something like SimpleActionServer).

If possible, what I have to do in order to run the server callback and the timer callback asynchronously? An asynchronous spinner is enough?

It should be, yes.

If it doesn't work, post back here.

So far so good. Now, imagine I want to implement a safety layer. That is, while tracking the robot trajectory I detect that the robot reached a forbidden position and I want to halt the robot by stopping publishing velocity commands.

are you describing a valve here? So your node receives velocity commands, checks whether everything is ok. If ok, forward, if not ok, stop forwarding.

Edit:

Regarding the last question, my idea was that the action server publishes as feedback the robot pose. Then, the client cancels the goal if the robot reached a forbidden position. Does it make sense to you?

not really, but it probably does to you, so that is fine.

if the node is not a controller, where does it get its velocity commands from? And if the feedback of the robot is joint_states, couldn't your client subscribe to that topic? Or are you looking at Cartesian poses here? In that case: TF?

more