Skip to content
This repository was archived by the owner on Apr 8, 2024. It is now read-only.

Commit bd556ee

Browse files
committed
Add service connection icon to handeye_dashboard
1 parent 15b0ee7 commit bd556ee

File tree

3 files changed

+47
-17
lines changed

3 files changed

+47
-17
lines changed
Loading
Loading

grasp_utils/handeye_dashboard/src/handeye_dashboard/handeye_calibration.py

Lines changed: 47 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,10 @@
1616
from rqt_gui_py.plugin import Plugin
1717
from python_qt_binding import QtCore
1818
from python_qt_binding.QtGui import QIcon, QImage, QPixmap, QStandardItem, \
19-
QIntValidator, QStandardItemModel
19+
QPen, QBrush, QPainter, QIntValidator, QStandardItemModel
2020
from python_qt_binding.QtWidgets import (QComboBox, QAction, QToolBar, QStatusBar,
21-
QLineEdit, QWidget, QVBoxLayout,
22-
QLabel, QTextEdit, QFrame,
23-
QHBoxLayout, QTreeView)
21+
QLineEdit, QWidget, QVBoxLayout, QLabel,
22+
QTextEdit, QFrame, QHBoxLayout, QTreeView)
2423

2524
class bcolors:
2625
HEADER = '\033[95m'
@@ -74,11 +73,6 @@ def __init__(self, context):
7473
self.widget.setObjectName(self.PLUGIN_TITLE)
7574
self.widget.setWindowTitle(self.PLUGIN_TITLE)
7675

77-
# parameter
78-
self.cli_param = self.node.create_client(SetParameters, '/grasp_modbus_server/set_parameters')
79-
while not self.cli_param.wait_for_service(timeout_sec=1.0):
80-
self.node.get_logger().info('service not available, waiting again...')
81-
8276
# Data
8377
self.Tsamples = []
8478

@@ -95,12 +89,27 @@ def __init__(self, context):
9589
'Clear the record data.', self.widget)
9690
path = path_pkg + '/share/handeye_dashboard/images/UR5.png'
9791
self.execut_action = QAction(QIcon(QPixmap.fromImage(QImage(path))),
98-
'EStart the publishing the TF.', self.widget)
92+
'Start the publishing the TF.', self.widget)
93+
self.path_red_icon = path_pkg + '/share/handeye_dashboard/images/red_circle_icon.png'
94+
self.path_green_icon = path_pkg + '/share/handeye_dashboard/images/green_circle_icon.png'
95+
self.parameter_action = QAction(QIcon(QPixmap.fromImage(QImage(self.path_red_icon))),
96+
'Connect to parameter service.', self.widget)
97+
self.tf_action = QAction(QIcon(QPixmap.fromImage(QImage(self.path_red_icon))),
98+
'Connect to tf service.', self.widget)
99+
99100
self.toolbar = QToolBar()
100101
self.toolbar.addAction(self.snapshot_action)
101102
self.toolbar.addAction(self.calibrate_action)
102103
self.toolbar.addAction(self.clear_action)
103104
self.toolbar.addAction(self.execut_action)
105+
self.parameter_label = QLabel(self.widget)
106+
self.parameter_label.setText("Parameter service: ")
107+
self.toolbar.addWidget(self.parameter_label)
108+
self.toolbar.addAction(self.parameter_action)
109+
self.tf_label = QLabel(self.widget)
110+
self.tf_label.setText("tf service: ")
111+
self.toolbar.addWidget(self.tf_label)
112+
self.toolbar.addAction(self.tf_action)
104113

105114
# Toolbar0
106115
self.l0 = QLabel(self.widget)
@@ -207,16 +216,37 @@ def __init__(self, context):
207216
self.calibrate_action.triggered.connect(self.calibration)
208217
self.clear_action.triggered.connect(self.clear)
209218
self.execut_action.triggered.connect(self.execution)
219+
self.parameter_action.triggered.connect(self.parameter_connect)
220+
self.tf_action.triggered.connect(self.tf_connect)
210221

211222
# Package path
212223
self.path_pkg = path_pkg
213224

214-
# Set up TF
215-
self.cli = self.node.create_client(HandeyeTF, 'handeye_tf_service')
216-
while not self.cli.wait_for_service(timeout_sec=1.0):
217-
self.node.get_logger().info('service not available, waiting again...')
225+
# Set up TF service client
226+
self.client_tf = self.node.create_client(HandeyeTF, 'handeye_tf_service')
227+
self.tf_action.setIcon(QIcon(QPixmap.fromImage(QImage(self.path_red_icon))) \
228+
if not self.client_tf.wait_for_service(timeout_sec=0.5) \
229+
else QIcon(QPixmap.fromImage(QImage(self.path_green_icon))))
218230
self.req = HandeyeTF.Request()
219231

232+
# Set up parameter service client
233+
self.client_param = self.node.create_client(SetParameters, '/grasp_modbus_server/set_parameters')
234+
self.parameter_action.setIcon(QIcon(QPixmap.fromImage(QImage(self.path_red_icon))) \
235+
if not self.client_param.wait_for_service(timeout_sec=0.5) \
236+
else QIcon(QPixmap.fromImage(QImage(self.path_green_icon))))
237+
238+
def tf_connect(self):
239+
self.client_tf = self.node.create_client(HandeyeTF, 'handeye_tf_service')
240+
self.tf_action.setIcon(QIcon(QPixmap.fromImage(QImage(self.path_red_icon))) \
241+
if not self.client_tf.wait_for_service(timeout_sec=0.5) \
242+
else QIcon(QPixmap.fromImage(QImage(self.path_green_icon))))
243+
244+
def parameter_connect(self):
245+
self.client_param = self.node.create_client(SetParameters, '/grasp_modbus_server/set_parameters')
246+
self.parameter_action.setIcon(QIcon(QPixmap.fromImage(QImage(self.path_red_icon))) \
247+
if not self.client_param.wait_for_service(timeout_sec=0.5) \
248+
else QIcon(QPixmap.fromImage(QImage(self.path_green_icon))))
249+
220250
def clear(self):
221251
# >>> Clear the recorded samples
222252
self.textedit.append('Clearing the recorded data ...')
@@ -229,7 +259,7 @@ def get_tf_transform(self, frame_id, child_frame_id):
229259
self.req.transform.child_frame_id = child_frame_id
230260
self.req.publish.data = False
231261

232-
future = self.cli.call_async(self.req)
262+
future = self.client_tf.call_async(self.req)
233263
rclpy.spin_until_future_complete(self.node, future)
234264

235265
transform = TransformStamped()
@@ -247,7 +277,7 @@ def publish_tf_transform(self, transform_to_publish):
247277
self.req.publish.data = True
248278
self.req.transform = transform_to_publish
249279

250-
future = self.cli.call_async(self.req)
280+
future = self.client_tf.call_async(self.req)
251281
rclpy.spin_until_future_complete(self.node, future)
252282

253283
try:
@@ -330,7 +360,7 @@ def execution(self):
330360
param.value.integer_value = 4
331361
req.parameters.append(param)
332362

333-
future = self.cli_param.call_async(req)
363+
future = self.client_param.call_async(req)
334364
rclpy.spin_until_future_complete(self.node, future)
335365

336366
# >>> Publish the camera-robot transform

0 commit comments

Comments
 (0)