37 from python_qt_binding
import loadUi
39 from QtGui
import QIcon, QColor, QPainter, QFont
40 from QtWidgets
import QMessageBox, QWidget
41 from QtCore
import QRectF, QTimer
42 from sr_robot_msgs.msg
import Biotac, BiotacAll
43 from sr_utilities.hand_finder
import HandFinder
47 _nb_electrodes_biotac = 19
48 _nb_electrodes_biotac_sp = 24
53 "sr_gui_biotac/sensing_electrodes_x_locations",
54 [6.45, 3.65, 3.65, 6.45, 3.65, 6.45, 0.00, 1.95, -1.95,
55 0.00, -6.45, - 3.65, -3.65, -6.45, -3.65, -6.45, 0.00,
59 "sr_gui_biotac/sensing_electrodes_y_locations",
60 [7.58, 11.28, 14.78, 16.58, 19.08, 21.98, 4.38, 6.38, 6.38,
61 8.38, 7.58, 11.28, 14.78, 16.58, 19.08, 21.98, 11.38,
66 "sr_gui_biotac/excitation_electrodes_x_locations",
67 [6.45, 3.75, -3.75, -6.45])
70 "sr_gui_biotac/excitation_electrodes_y_locations",
71 [12.48, 24.48, 24.48, 12.48])
75 "sr_gui_biotac/sensing_electrodes_x_locations",
76 [5.00, 3.65, 6.45, 4.40, 2.70, 6.45, 4.40, 1.50, 4.00, 4.50,
77 -5.00, - 3.65, -6.45, -4.40, -2.70, -6.45, -4.40, -1.50, -4.00, -4.50,
78 0.00, 1.95, -1.95, 0.00])
81 "sr_gui_biotac/sensing_electrodes_y_locations",
82 [4.38, 6.38, 14.78, 15.50, 18.50, 19.08, 20.00, 21.00, 23.00, 25.00,
83 4.38, 6.38, 14.78, 15.50, 18.50, 19.08, 20.00, 21.00, 23.00, 25.00,
84 7.38, 11.50, 11.50, 15.20])
88 "sr_gui_biotac/excitation_electrodes_x_locations",
89 [5.30, 6.00, -5.30, -6.00])
92 "sr_gui_biotac/excitation_electrodes_y_locations",
93 [9.00, 22.00, 9.00, 22.00])
102 "sr_gui_biotac/display_location_scale_factor",
112 rospy.logerr(
"Number of electrodes %d not matching known biotac models. expected: %d or %d",
145 threshold = (0.0, 1000.0, 2000.0, 3000.0, 4095.0)
147 if value <= threshold[0]:
150 elif value < threshold[1]:
153 g = 255 * ((value - threshold[0]) / (threshold[1] - threshold[0]))
156 elif value < threshold[2]:
158 r = 255 * ((threshold[2] - value) / (threshold[2] - threshold[1]))
162 elif value < threshold[3]:
166 b = 255 * ((value - threshold[2]) / (threshold[3] - threshold[2]))
168 elif value < threshold[4]:
171 g = 255 * ((threshold[4] - value) / (threshold[4] - threshold[3]))
174 return QColor(r, g, b)
177 name = self._widget.btSelect.currentText()
178 fingers = [
"FF",
"MF",
"RF",
"LF",
"TH"]
179 return fingers.index(name)
181 def draw_electrode(self, painter, elipse_x, elipse_y, text_x, text_y,
187 painter.setBrush(colour)
188 painter.drawEllipse(rect)
193 painter.drawText(rect, text)
196 painter = QPainter(self._widget.scrollAreaWidgetContents)
203 value = self.latest_data.tactiles[which_tactile].electrodes[n]
204 eval(
"self._widget.lcdE%02d.display(%d)" % (n + 1, value))
227 colour = QColor(127, 127, 127)
233 colour,
"X" + str(n + 1))
235 self._widget.update()
239 rospy.Subscriber(prefix +
"tactile", BiotacAll, self.
tactile_cb)
243 "sr_gui_biotac/electrode_display_width",
246 "sr_gui_biotac/electrode_display_height", 45)
248 self.
factor = rospy.get_param(
249 "sr_gui_biotac/display_location_scale_factor",
253 "sr_gui_biotac/x_display_offset", [200, 12.5, 4.5,
258 "sr_gui_biotac/y_display_offset", [-50, 4.0, 4.0, 4.0])
260 "sr_gui_biotac/electrode_label_font_sizes", [24,
264 if self._hand_parameters.mapping:
266 self._hand_parameters.mapping.values()[0] +
'/')
272 super(SrGuiBiotac, self).
__init__(context)
273 self.setObjectName(
'SrGuiBiotac')
287 ui_file = os.path.join(rospkg.RosPack().get_path(
'sr_gui_biotac'),
288 'uis',
'SrGuiBiotac.ui')
290 self._widget.setObjectName(
'SrBiotacUi')
295 self.timer.timeout.connect(self._widget.scrollAreaWidgetContents.update)
296 self._widget.scrollAreaWidgetContents.paintEvent = self.
paintEvent 300 for hand
in self._hand_parameters.mapping:
301 self._widget.select_prefix.addItem(
302 self._hand_parameters.mapping[hand])
303 if not self._hand_parameters.mapping:
304 rospy.logerr(
"No hand detected")
306 self.
_widget,
"warning",
"No hand is detected")
308 self._widget.select_prefix.setCurrentIndex(0)
311 self._widget.connect(self._widget.select_prefix, 312 SIGNAL("activated(QString)"), 313 self.subscribe_to_topic) 319 context.add_widget(self.
_widget)
def get_electrode_colour_from_value(self, value)
int _nb_electrodes_biotac_sp
def assign_electrodes(self, nb_electrodes)
excitation_electrodes_v1_y
def subscribe_to_topic(self, prefix)
def biotac_id_from_dropdown(self)
int _nb_electrodes_biotac
def draw_electrode(self, painter, elipse_x, elipse_y, text_x, text_y, colour, text)
def paintEvent(self, paintEvent)
excitation_electrodes_v1_x
excitation_electrodes_v2_x
def define_electrodes(self)
excitation_electrodes_v2_y
def __init__(self, context)
def tactile_cb(self, msg)