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

Using a service to perform an action. Is it the wrong way around?

asked 2014-05-21 23:14:31 -0500

paturdc gravatar image

I have two different pieces of hardware (grippers) that are run by an action server. Their behavior is slightly different, and I need to write a piece of software that can run both grippers using the same syntax. So I need something like

open_gripper(distance)

close_gripper(distance)

and just need to specify somewhere which piece of hardware we are using.

Now someone suggested using a service to perform the action - the service performs the action in the appropriate way, and returns some feedback, and responds to the main program.

However, I'm still not sure when is the right time to use actions, and when is the right time to use a service. Based on what I've read, this seems like an upside down approach, but I'm not sure. Are there any examples of this sort of setup, or is it considered bad form?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2018-07-03 21:04:20 -0500

130s gravatar image

updated 2018-07-03 21:05:11 -0500

Now someone suggested using a service to perform the action - the service performs the action in the appropriate way, and returns some feedback, and responds to the main program.

Took me awhile to understand what you mean by above, but I think you mean "'an end client' calls ROS Service, then Service server calls ROS Action, and return Action's output via ROS Service' return value".

If that's correct, I think that's a legit usecase in certain situation e.g. when the end client doesn't have an access to the existing Action Server (although I've never done that). You can run Action Client somehow in your ROS Service' callback, then once the Action Client returns the value, re-pack the value to the ROS Service and return it.

Following can be a simple pseudo-code in Python that I modified the code from the Service' tutorial:

#!/usr/bin/env python
import actionlib
from beginner_tutorials.srv import *
import rospy

def handle_add_two_ints(req):
    # Call action client's sendGoal

    # Return with the output action client received.

def add_two_ints_server():
    rospy.init_node('add_two_ints_server')
    s = rospy.Service('add_two_ints', AddTwoInts, handle_add_two_ints)
:
edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2014-05-21 23:14:31 -0500

Seen: 268 times

Last updated: Jul 03 '18