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.
EDIT: @gvdhoorn: thanks for your reply!
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?