3
# Copyright 2011 Shadow Robot Company Ltd.
5
# This program is free software: you can redistribute it and/or modify it
6
# under the terms of the GNU General Public License as published by the Free
7
# Software Foundation, either version 2 of the License, or (at your option)
10
# This program is distributed in the hope that it will be useful, but WITHOUT
11
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15
# You should have received a copy of the GNU General Public License along
16
# with this program. If not, see <http://www.gnu.org/licenses/>.
19
from __future__ import division
22
from rosgui.QtBindingHelper import loadUi
23
from QtCore import QEvent, QObject, Qt, QTimer, Slot
24
from QtGui import QDockWidget, QShortcut, QColor, QTreeWidgetItem, QFileDialog, QMessageBox
25
from QtCore import QVariant
28
roslib.load_manifest('sr_gui_hand_calibration')
31
from sr_hand_calibration_model import HandCalibration
33
class SrHandCalibration(QObject):
35
def __init__(self, parent, plugin_context):
36
super(SrHandCalibration, self).__init__(parent)
37
self.setObjectName('SrHandCalibration')
39
self._publisher = None
40
main_window = plugin_context.main_window()
41
self._widget = QDockWidget(main_window)
43
ui_file = os.path.join(os.path.dirname(os.path.realpath(__file__)), '../uis/SrHandCalibration.ui')
44
loadUi(ui_file, self._widget)
45
self._widget.setObjectName('SrHandCalibrationUi')
46
if plugin_context.serial_number() > 1:
47
self._widget.setWindowTitle(self._widget.windowTitle() + (' (%d)' % plugin_context.serial_number()))
48
main_window.addDockWidget(Qt.RightDockWidgetArea, self._widget)
50
# trigger deleteLater for plugin when _widget is closed
51
self._widget.installEventFilter(self)
53
self._widget.tree_calibration.setColumnCount(4)
54
self._widget.tree_calibration.setHeaderLabels(["Finger", "Joint", "Raw Value", "Calibrated Value"])
56
self.hand_model = None
58
self._widget.btn_save.clicked.connect(self.btn_save_clicked_)
59
self._widget.btn_load.clicked.connect(self.btn_load_clicked_)
60
self._widget.btn_joint_0s.clicked.connect(self.btn_joint_0s_clicked_)
66
def populate_tree(self):
67
self._widget.tree_calibration.clear()
69
self.hand_model = HandCalibration( tree_widget = self._widget.tree_calibration, progress_bar = self._widget.progress )
70
if not self.hand_model.is_active:
74
self._widget.tree_calibration.expandAll()
76
for col in range(0, self._widget.tree_calibration.columnCount()):
77
self._widget.tree_calibration.resizeColumnToContents(col)
79
def btn_save_clicked_(self):
82
path_to_config = roslib.packages.get_pkg_dir("sr_robot_lib") + "/config"
84
rospy.logwarn("couldnt find the sr_edc_controller_configuration package")
86
filter_files = "*.yaml"
87
filename, _ = QFileDialog.getOpenFileName(self._widget.tree_calibration, self._widget.tr('Save Controller Settings'),
88
self._widget.tr(path_to_config),
89
self._widget.tr(filter_files))
94
if not self.hand_model.is_calibration_complete():
95
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)",
96
buttons = QMessageBox.Ok | QMessageBox.Cancel)
98
if btn_pressed == QMessageBox.Cancel:
100
self.hand_model.save( filename )
102
def btn_load_clicked_(self):
105
path_to_config = roslib.packages.get_pkg_dir("sr_robot_lib") + "/config"
107
rospy.logwarn("couldnt find the sr_edc_controller_configuration package")
109
filter_files = "*.yaml"
110
filename, _ = QFileDialog.getOpenFileName(self._widget.tree_calibration, self._widget.tr('Save Controller Settings'),
111
self._widget.tr(path_to_config),
112
self._widget.tr(filter_files))
117
self.hand_model.load( filename )
119
def btn_joint_0s_clicked_(self):
120
self.hand_model.calibrate_joint0s( self._widget.btn_joint_0s )
122
def _unregisterPublisher(self):
123
if self._publisher is not None:
124
self._publisher.unregister()
125
self._publisher = None
127
self.hand_model.unregister()
129
def eventFilter(self, obj, event):
130
if obj is self._widget and event.type() == QEvent.Close:
131
# TODO: ignore() should not be necessary when returning True
135
return QObject.eventFilter(self, obj, event)
137
def close_plugin(self):
138
self._unregisterPublisher()
140
self._widget.deleteLater()
142
def save_settings(self, global_settings, perspective_settings):
143
print "saving settings"
144
#topic = self._widget.topic_line_edit.text()
145
#perspective_settings.set_value('topic', topic)
147
def restore_settings(self, global_settings, perspective_settings):
148
print "restoring settings"
149
#topic = perspective_settings.value('topic', '/cmd_vel')