Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 import os, rospy, rospkg
00020
00021 from qt_gui.plugin import Plugin
00022 from python_qt_binding import loadUi
00023
00024 from QtCore import QEvent, QObject, Qt, QTimer, Slot
00025 from QtGui import QWidget, QShortcut, QColor, QTreeWidgetItem, QFileDialog, QMessageBox
00026 from QtCore import QVariant
00027 from sr_gui_hand_calibration.sr_hand_calibration_model import HandCalibration
00028
00029 class SrHandCalibration(Plugin):
00030 """
00031 A rosgui plugin for calibrating the Shadow EtherCAT Hand
00032 """
00033
00034 def __init__(self, context):
00035 super(SrHandCalibration, self).__init__(context)
00036 self.setObjectName('SrHandCalibration')
00037
00038 self._publisher = None
00039 self._widget = QWidget()
00040
00041 ui_file = os.path.join(rospkg.RosPack().get_path('sr_gui_hand_calibration'), 'uis', 'SrHandCalibration.ui')
00042 loadUi(ui_file, self._widget)
00043 self._widget.setObjectName('SrHandCalibrationUi')
00044 context.add_widget(self._widget)
00045
00046 self._widget.tree_calibration.setColumnCount(4)
00047 self._widget.tree_calibration.setHeaderLabels(["Finger", "Joint", "Raw Value", "Calibrated Value"])
00048
00049 self.hand_model = None
00050
00051 self._widget.btn_save.clicked.connect(self.btn_save_clicked_)
00052 self._widget.btn_load.clicked.connect(self.btn_load_clicked_)
00053 self._widget.btn_joint_0s.clicked.connect(self.btn_joint_0s_clicked_)
00054
00055 self.populate_tree()
00056
00057 def populate_tree(self):
00058 """
00059 Create tree with calibrations
00060 """
00061 self._widget.tree_calibration.clear()
00062
00063 self.hand_model = HandCalibration( tree_widget = self._widget.tree_calibration, progress_bar = self._widget.progress )
00064 if not self.hand_model.is_active:
00065 self.close_plugin()
00066 return
00067
00068 self._widget.tree_calibration.expandAll()
00069
00070 for col in range(0, self._widget.tree_calibration.columnCount()):
00071 self._widget.tree_calibration.resizeColumnToContents(col)
00072
00073 def btn_save_clicked_(self):
00074 """
00075 Save calibration to a yaml file.
00076 sr_ethercat_hand_config package must be installed
00077 """
00078 path_to_config = "~"
00079
00080 config_dir = rospy.get_param('config_dir', '')
00081 try:
00082 path_to_config = os.path.join(rospkg.RosPack().get_path('sr_ethercat_hand_config'), 'calibrations', config_dir)
00083 except:
00084 rospy.logwarn("couldnt find the sr_ethercat_hand_config package")
00085
00086 filter_files = "*.yaml"
00087 filename, _ = QFileDialog.getOpenFileName(self._widget.tree_calibration, self._widget.tr('Save Calibration'),
00088 self._widget.tr(path_to_config),
00089 self._widget.tr(filter_files))
00090
00091 if filename == "":
00092 return
00093
00094 if not self.hand_model.is_calibration_complete():
00095 btn_pressed = QMessageBox.warning(self._widget.tree_calibration, "Warning", "Are you sure you want to save this incomplete calibration? The uncalibrated values will be saved as a flat map (the calibrated value will always be 0)",
00096 buttons = QMessageBox.Ok | QMessageBox.Cancel)
00097
00098 if btn_pressed == QMessageBox.Cancel:
00099 return
00100 self.hand_model.save( filename )
00101
00102 def btn_load_clicked_(self):
00103 """
00104 Load calibration from a yaml file.
00105 sr_ethercat_hand_config package must be installed
00106 """
00107 path_to_config = "~"
00108
00109 config_dir = rospy.get_param('config_dir', '')
00110 try:
00111 path_to_config = os.path.join(rospkg.RosPack().get_path('sr_ethercat_hand_config'), 'calibrations', config_dir)
00112 except:
00113 rospy.logwarn("couldn't find the sr_ethercat_hand_config package")
00114
00115 filter_files = "*.yaml"
00116 filename, _ = QFileDialog.getOpenFileName(self._widget.tree_calibration, self._widget.tr('Load Calibration'),
00117 self._widget.tr(path_to_config),
00118 self._widget.tr(filter_files))
00119
00120 if filename == "":
00121 return
00122
00123 self.hand_model.load( filename )
00124
00125 def btn_joint_0s_clicked_(self):
00126 """
00127 calibrate the first joint of each finger
00128 """
00129 self.hand_model.calibrate_joint0s( self._widget.btn_joint_0s )
00130
00131 def _unregisterPublisher(self):
00132 if self._publisher is not None:
00133 self._publisher.unregister()
00134 self._publisher = None
00135
00136 self.hand_model.unregister()
00137
00138 def shutdown_plugin(self):
00139 self._unregisterPublisher()
00140
00141 def save_settings(self, global_settings, perspective_settings):
00142 pass
00143
00144 def restore_settings(self, global_settings, perspective_settings):
00145 pass