Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[jsk_rqt_plugins] add service_type and support Trigger for rqt service button #791

Merged
merged 2 commits into from Nov 18, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
29 changes: 23 additions & 6 deletions jsk_rqt_plugins/src/jsk_rqt_plugins/button_general.py
Expand Up @@ -26,6 +26,7 @@
from std_msgs.msg import Bool
from std_msgs.msg import Time
from std_srvs.srv import Empty
from std_srvs.srv import Trigger

if LooseVersion(python_qt_binding.QT_BINDING_VERSION).version[0] >= 5:
from python_qt_binding.QtWidgets import QAction
Expand Down Expand Up @@ -183,8 +184,18 @@ def setupButtons(self, yaml_file):
if button_data.has_key("name"):
name = button_data['name']
button.setText(name)
if button_data.has_key('service_type'):
if button_data['service_type'] == 'Trigger':
service_type = Trigger
elif button_data['service_type'] == 'Empty':
service_type = Empty
else:
raise Exception("Unsupported service type: {}".format(
button_data['service_type']))
else:
service_type = Empty
button.clicked.connect(
self.buttonCallback(button_data['service']))
self.buttonCallback(button_data['service'], service_type))
if self.button_type == "push":
button.setToolButtonStyle(
QtCore.Qt.ToolButtonTextUnderIcon)
Expand All @@ -200,16 +211,22 @@ def setupButtons(self, yaml_file):
self.layout.addWidget(group)
self.setLayout(self.layout)

def buttonCallback(self, service_name):
def buttonCallback(self, service_name, service_type):
"""
return function as callback
"""
return lambda x: self.buttonCallbackImpl(service_name)
return lambda x: self.buttonCallbackImpl(service_name, service_type)

def buttonCallbackImpl(self, service_name):
srv = rospy.ServiceProxy(service_name, Empty)
def buttonCallbackImpl(self, service_name, service_type=Empty):
srv = rospy.ServiceProxy(service_name, service_type)
try:
srv()
res = srv()
if hasattr(res, 'success'):
success = res.success
if not success:
self.showError(
"Succeeded to call {}, but service response is res.success=False"
.format(service_name))
except rospy.ServiceException as e:
self.showError("Failed to call %s" % service_name)

Expand Down