26 from python_qt_binding
import loadUi
29 from QtCore
import Qt, QThread, QPoint
30 from QtWidgets
import QWidget, QMessageBox, QFrame, \
31 QHBoxLayout, QCheckBox, QLabel
32 from QtGui
import QColor
34 from std_srvs.srv
import Empty
35 from diagnostic_msgs.msg
import DiagnosticArray
36 from sr_utilities.hand_finder
import HandFinder
41 motor_finished = QtCore.pyqtSignal(
'QPoint')
42 failed = QtCore.pyqtSignal(
'QString')
44 def __init__(self, parent, nb_motors_to_program, prefix):
45 QThread.__init__(self,
None)
52 for motor
in self.parent.motors:
53 if motor.checkbox.checkState() == Qt.Checked:
56 "resetting: sr_hand_robot/" + self.
prefix +
57 "reset_motor_" + motor.motor_name)
59 'sr_hand_robot/' + self.
prefix +
'reset_motor_' +
60 motor.motor_name, Empty)
62 except rospy.ServiceException, e:
63 self.
failed[
'QString'].emit(
"Service did not process request: %s" % str(e))
66 programmed_motors += 1
72 def __init__(self, parent, motor_name, motor_index):
73 QFrame.__init__(self, parent)
80 self.
checkbox = QCheckBox(motor_name +
" [" + str(motor_index) +
"]",
85 self.revision_label.setToolTip(
"Svn Revision")
88 self.setLayout(self.
layout)
94 A gui plugin for resetting motors on the shadow hand. 98 super(SrGuiMotorResetter, self).
__init__(context)
99 self.setObjectName(
'SrGuiMotorResetter')
104 ui_file = os.path.join(
105 rospkg.RosPack().get_path(
'sr_gui_motor_resetter'),
'uis',
106 'SrGuiMotorResetter.ui')
108 self._widget.setObjectName(
'SrMotorResetterUi')
109 context.add_widget(self.
_widget)
112 self.
diag_sub = rospy.Subscriber(
"diagnostics", DiagnosticArray,
116 hand_parameters = self._hand_finder.get_hand_parameters()
118 for hand
in hand_parameters.mapping:
119 self._widget.select_prefix.addItem(hand_parameters.mapping[hand])
120 if not hand_parameters.mapping:
121 rospy.logerr(
"No hand detected")
123 self.
_widget,
"warning",
"No hand is detected")
125 self._widget.select_prefix.setCurrentIndex(0)
126 self.
_prefix = hand_parameters.mapping.values()[0] +
"/" 128 self._widget.select_prefix.currentIndexChanged[
'QString'].connect(
135 self.progress_bar.hide()
141 self._widget.btn_select_none.pressed.connect(
143 self._widget.btn_reset_motors.pressed.connect(
148 for i
in reversed(range(self.motors_frame.layout().count())):
149 self.motors_frame.layout().itemAt(i).widget().setParent(
None)
152 if rospy.has_param(self.
_prefix +
"joint_to_motor_mapping"):
153 joint_to_motor_mapping = rospy.get_param(
154 self.
_prefix +
"joint_to_motor_mapping")
158 self.
_prefix +
"joint_to_motor_mapping parameter." 159 " Make sure the etherCAT Hand node is running")
163 [
"FFJ0",
"FFJ1",
"FFJ2",
"FFJ3",
"FFJ4"],
164 [
"MFJ0",
"MFJ1",
"MFJ2",
"MFJ3",
"MFJ4"],
165 [
"RFJ0",
"RFJ1",
"RFJ2",
"RFJ3",
"RFJ4"],
166 [
"LFJ0",
"LFJ1",
"LFJ2",
"LFJ3",
"LFJ4",
"LFJ5"],
167 [
"THJ1",
"THJ2",
"THJ3",
"THJ4",
"THJ5"],
173 index_jtm_mapping = 0
174 for finger
in joint_names:
176 for joint_name
in finger:
177 motor_index = joint_to_motor_mapping[index_jtm_mapping]
178 if motor_index != -1:
180 self.motors_frame.layout().addWidget(motor, row, col)
181 self.motors.append(motor)
183 index_jtm_mapping += 1
187 for status
in msg.status:
189 if motor.motor_name
in status.name
and self._prefix.replace(
190 "/",
"")
in status.name:
191 for key_values
in status.values:
192 if "Firmware svn revision" in key_values.key:
193 server_current_modified = key_values.value.split(
196 if server_current_modified[0] \
199 server_current_modified[0].strip())
201 palette = motor.revision_label.palette()
203 motor.revision_label.foregroundRole(),
205 if server_current_modified[0].strip() != \
206 server_current_modified[1].strip():
208 motor.revision_label.foregroundRole(),
209 QColor(255, 170, 23))
210 motor.revision_label.setPalette(palette)
212 if "True" in server_current_modified[2]:
214 motor.revision_label.foregroundRole(),
216 motor.revision_label.setText(
217 "svn: " + server_current_modified[
219 motor.revision_label.setPalette(palette)
221 motor.revision_label.setText(
222 " svn: " + server_current_modified[1])
223 motor.revision_label.setPalette(palette)
227 motor.checkbox.setCheckState(Qt.Checked)
231 motor.checkbox.setCheckState(Qt.Unchecked)
234 print(
"Reset motors pressed")
235 self.progress_bar.reset()
236 nb_motors_to_program = 0
238 if motor.checkbox.checkState() == Qt.Checked:
239 nb_motors_to_program += 1
240 if nb_motors_to_program == 0:
241 QMessageBox.warning(self.
_widget,
"Warning",
242 "No motors selected for resetting.")
244 self.progress_bar.setMaximum(nb_motors_to_program)
253 self._widget.setCursor(Qt.WaitCursor)
254 self.motors_frame.setEnabled(
False)
255 self._widget.btn_select_all.setEnabled(
False)
256 self._widget.btn_select_none.setEnabled(
False)
257 self.progress_bar.show()
258 self._widget.btn_reset_motors.hide()
260 self.motor_flasher.start()
263 self.progress_bar.setValue(int(point.x()))
266 self.motors_frame.setEnabled(
True)
267 self._widget.btn_select_all.setEnabled(
True)
268 self._widget.btn_select_none.setEnabled(
True)
269 self._widget.setCursor(Qt.ArrowCursor)
270 self.progress_bar.hide()
271 self._widget.btn_reset_motors.show()
274 QMessageBox.warning(self.
motors_frame,
"Warning", message)
278 self._publisher.unregister()
291 self._prefix = str(prefix) +
"/" 292 self.populate_motors()
def save_settings(self, global_settings, perspective_settings)
def on_select_none_pressed(self)
def failed_programming_motors(self, message)
def _unregisterPublisher(self)
def restore_settings(self, global_settings, perspective_settings)
def on_reset_motors_pressed(self)
def prefix_selected(self, prefix)
def __init__(self, context)
def __init__(self, parent, nb_motors_to_program, prefix)
def populate_motors(self)
def one_motor_finished(self, point)
def finished_programming_motors(self)
def diagnostics_callback(self, msg)
def on_select_all_pressed(self)
def __init__(self, parent, motor_name, motor_index)
def shutdown_plugin(self)