27 from python_qt_binding
import loadUi
29 from QtCore
import Qt, QEvent, QObject
33 from QtWidgets
import *
37 from cyberglove_calibrer
import *
38 from cyberglove_mapper
import *
41 rootPath = os.path.join(
42 rospkg.RosPack().get_path(
'sr_gui_cyberglove_calibrator'))
43 noimage_path = rootPath +
'/images/image-missing.png' 49 Stores the description / images path for a given step. 61 Displays the description / images for the current step. 65 QtWidgets.QWidget.__init__(self, parent=parent)
69 self.
layout = QtWidgets.QVBoxLayout()
72 self.text_description.setMaximumHeight(60)
76 self.image_description.setMinimumSize(170, 170)
79 self.frame.setLayout(self.
layout)
80 layout = QtWidgets.QHBoxLayout()
81 layout.addWidget(self.
frame)
82 self.setLayout(layout)
86 self.text_description.setText(description.text)
87 index = description.current_substep
88 self.image_description.setPixmap(
89 QtGui.QPixmap(description.image_path[index]))
90 self.image_description.repaint()
97 The user can select the step to calibrate through this widget. 101 QtWidgets.QWidget.__init__(self, parent=parent)
111 self.layout.setSpacing(5)
114 self.title.setText(
"Calibration Steps - 2 substeps by steps")
118 self.
list = QtWidgets.QListWidget()
121 self.list.itemClicked[
'QListWidgetItem*'].connect(self.
step_choosed)
122 self.list.setViewMode(QtWidgets.QListView.ListMode)
123 self.list.setResizeMode(QtWidgets.QListView.Adjust)
125 self.list.setCurrentRow(0)
126 first_item = self.list.item(0)
127 first_item.setSelected(
True)
130 self.layout.addWidget(self.
title)
131 self.layout.addWidget(self.
list)
133 self.frame.setLayout(self.
layout)
134 layout = QtWidgets.QHBoxLayout()
135 layout.addWidget(self.
frame)
137 self.setLayout(layout)
141 step_name = str(item.text())
144 if not second_substep:
151 description = self.
steps[name].step_description[index]
153 self.step_describer.set_description(
159 steps = self.calibrer.calibration_steps
161 base_image_path = rootPath +
'/images/step' 163 item = QtWidgets.QListWidgetItem(step.step_name)
164 if first_item
is None:
166 self.list.addItem(item)
167 self.
steps[step.step_name] = step
170 description.image_path = [
171 base_image_path + str(index) +
"-a.jpeg", base_image_path + str(index) +
"-b.jpeg"]
181 description = self.
steps[
184 self.step_describer.set_description(
198 Displays which joints have been calibrated. 202 QtWidgets.QWidget.__init__(self, parent=parent)
206 self.layout.setHorizontalSpacing(5)
207 self.layout.setVerticalSpacing(5)
209 green = QtGui.QColor(126, 255, 0)
210 red = QtGui.QColor(255, 36, 0)
211 orange = QtGui.QColor(255, 138, 0)
214 self.green_palette.setBrush(QtGui.QPalette.Window, green)
216 self.red_palette.setBrush(QtGui.QPalette.Window, red)
218 self.orange_palette.setBrush(QtGui.QPalette.Window, orange)
222 rows = [0, 0, 0, 0, 0, 0]
226 for joint
in joint_names:
227 if "index" in joint.lower():
229 elif "middle" in joint.lower():
231 elif "ring" in joint.lower():
232 if "pinkie" in joint.lower():
236 elif "pinkie" in joint.lower():
238 elif "thumb" in joint.lower():
246 subframe = QtWidgets.QFrame()
247 layout = QtWidgets.QHBoxLayout()
248 name = QtWidgets.QLabel()
250 layout.addWidget(name)
251 subframe.setLayout(layout)
253 subframe.setAutoFillBackground(
True)
256 self.layout.addWidget(subframe, row, col)
260 self.frame.setLayout(self.
layout)
261 layout = QtWidgets.QVBoxLayout()
262 layout.addWidget(self.
frame)
264 self.setLayout(layout)
288 The plugin used to calibrate the glove. 290 name =
"Cyberglove Calibrator" 293 super(SrGuiCybergloveCalibrator, self).
__init__(context)
294 self.setObjectName(
'SrGuiCybergloveCalibrator')
296 rospkg.RosPack().get_path(
'sr_visualization_icons'),
'/icons')
298 ui_file = os.path.join(rospkg.RosPack().get_path(
299 'sr_gui_cyberglove_calibrator'),
'uis',
'SrGuiCybergloveCalibrator.ui')
302 context.add_widget(self.
_widget)
310 if rospy.has_param(
'cyberglove/cyberglove_joint_number'):
311 self.
nb_sensors = rospy.get_param(
'cyberglove/cyberglove_joint_number')
317 self.joint_names.sort()
320 subframe = QtWidgets.QFrame()
321 sublayout = QtWidgets.QHBoxLayout()
330 btn_frame = QtWidgets.QFrame()
331 btn_layout = QtWidgets.QVBoxLayout()
332 btn_layout.setSpacing(25)
333 btn_calibrate = QtWidgets.QPushButton()
334 btn_calibrate.setText(
"Calibrate")
335 btn_calibrate.setToolTip(
"Calibrate the current selected step")
336 btn_calibrate.setIcon(
337 QtGui.QIcon(rootPath +
'/images/icons/calibrate.png'))
338 btn_layout.addWidget(btn_calibrate)
341 self.btn_save.setText(
"Save")
342 self.btn_save.setToolTip(
"Save the current calibration")
343 self.btn_save.setIcon(QtGui.QIcon(rootPath +
'/images/icons/save.png'))
344 self.btn_save.setDisabled(
True)
346 self.btn_save.clicked.connect(self.
save_calib)
347 btn_load = QtWidgets.QPushButton()
348 btn_load.setText(
"Load")
349 btn_load.setToolTip(
"Load a Glove calibration")
350 btn_load.setIcon(QtGui.QIcon(rootPath +
'/images/icons/load.png'))
351 btn_layout.addWidget(btn_load)
353 btn_frame.setLayout(btn_layout)
354 sublayout.addWidget(btn_frame)
355 subframe.setLayout(sublayout)
356 self.layout.addWidget(subframe)
361 self.step_selector.calibrate_current_step()
364 if self.calibrer.is_step_done(name) == 0.5:
365 self.glove_calibrating_widget.set_half_calibrated([name])
366 elif self.calibrer.is_step_done(name) == 1.0:
367 self.glove_calibrating_widget.set_calibrated([name])
369 if self.calibrer.all_steps_done():
370 range_errors = self.calibrer.check_ranges()
371 if len(range_errors) != 0:
372 QtWidgets.QMessageBox.warning(self.
_widget,
"%d ensor range error(s) reported." % len(range_errors),
373 "\n".join(range_errors),
374 QtWidgets.QMessageBox.Ok,
375 QtWidgets.QMessageBox.Ok)
377 self.btn_save.setEnabled(
True)
381 (filename, dummy) = QtWidgets.QFileDialog.getSaveFileName(
382 self.
_widget,
'Save Calibration',
'')
386 write_output = self.calibrer.write_calibration_file(filename)
388 if write_output == -1:
389 error =
"Calibration has not been finished, output not written." 390 elif write_output == -2:
391 error =
"Error writing file." 393 if error
is not None:
394 QtWidgets.QMessageBox.critical(self.
_widget,
"Error writing config!",
396 QtWidgets.QMessageBox.Ok,
397 QtWidgets.QMessageBox.Ok)
398 elif QtWidgets.QMessageBox.question(self.
_widget,
399 "Load new Calibration",
400 "Do you want to load the new calibration file?",
401 QtWidgets.QMessageBox.Yes | QtWidgets.QMessageBox.No,
402 QtWidgets.QMessageBox.No) == QtWidgets.QMessageBox.Yes:
407 if filename
is False:
411 (filename, dummy) = QtWidgets.QFileDialog.getOpenFileName(
412 self.
_widget,
'Open Calibration',
'')
416 if self.calibrer.load_calib(str(filename)) == 0:
419 QtWidgets.QMessageBox.information(self.
_widget,
"Calibration successfully loaded",
420 "Calibration successfully loaded.",
421 QtWidgets.QMessageBox.Ok,
422 QtWidgets.QMessageBox.Ok)
424 QtWidgets.QMessageBox.information(self.
_widget,
"Calibration loading failed",
425 "Calibration loading failed",
426 QtWidgets.QMessageBox.Ok,
427 QtWidgets.QMessageBox.Ok)
def set_description(self, description)
def __init__(self, parent)
def step_choosed(self, item, first_time=False, second_substep=False)
def calibrate_current_step(self)
def load_calib(self, filename="")
def refresh_list(self, value=0)
def __init__(self, context)
def __init__(self, parent, calibrer)
def calibrate_current_step(self)