3 from get_diagnostic_data
import *
4 from analysis_test
import Diagnostic
6 import matplotlib.pyplot
as plt
8 from scipy.stats
import scoreatpercentile
10 from python_qt_binding
import loadUi
11 from python_qt_binding.QtCore
import qWarning, Qt
12 from python_qt_binding.QtGui
import QWidget, QPushButton, QFileDialog, QLabel
17 super(DiagnosticToolWidget, self).
__init__()
18 ui_file = os.path.join(os.path.dirname(os.path.realpath(__file__)),
'pr2_diagnostic_widget.ui')
20 self.setObjectName(
'DiagnosticToolWidget')
26 self.
r_arm_actuators = [
'r_wrist_r_motor',
'r_wrist_l_motor',
'r_forearm_roll_motor',
'r_upper_arm_roll_motor',
'r_elbow_flex_motor',
'r_shoulder_lift_motor',
'r_shoulder_pan_motor']
27 self.
l_arm_actuators = [
'l_wrist_r_motor',
'l_wrist_l_motor',
'l_forearm_roll_motor',
'l_upper_arm_roll_motor',
'l_elbow_flex_motor',
'l_shoulder_lift_motor',
'l_shoulder_pan_motor']
43 self.analyzeData.clicked[bool].connect(self.
analyze_data)
44 self.loadFile.clicked[bool].connect(self.
load_file)
48 for joint
in templist:
49 self.jointWidget.addItem(str(joint))
52 rospy.Subscriber(
"joy", Joy, callback)
56 for joint
in self.jointWidget.selectedItems():
58 self.jointnames.append(joint.text())
61 self.jointLabel.setText(
'Joints: ' + str(self.
jointnames))
62 self.jointLabel.setWordWrap(
True)
65 if state == Qt.Checked:
72 self.jointLabel.setText(
'Joints: ' + str(self.
jointnames))
73 self.jointLabel.setWordWrap(
True)
76 if state == Qt.Checked:
83 self.jointLabel.setText(
'Joints: ' + str(self.
jointnames))
84 self.jointLabel.setWordWrap(
True)
87 if state == Qt.Checked:
94 self.jointLabel.setText(
'Joints: ' + str(self.
jointnames))
95 self.jointLabel.setWordWrap(
True)
98 if state == Qt.Checked:
104 if state == Qt.Checked:
113 self.leftArm.setChecked(
False)
114 self.rightArm.setChecked(
False)
115 self.head.setChecked(
False)
120 self.jointLabel.setText(
'Joints: ' + str(self.
jointnames))
121 self.jointLabel.setWordWrap(
True)
126 self.fileLabel.setText(
'Files: ')
127 for fig_name
in self.
plots:
133 self.jointLabel.setText(
'Joints: ' + str(self.
jointnames))
134 self.jointLabel.setWordWrap(
True)
136 folder = str(datetime.datetime.now())
137 folder = folder.split(
" ")
138 folder =
"_".join(folder)
140 os.system(
"mkdir %s" %(folder))
141 os.chdir(os.getcwd() +
'/' + folder)
147 print "Press X to start or for next joint" 150 print "start moving %s for about 5 seconds" %(actuator_name)
152 print "press circle when your done" 156 print "Finshed getting data" 159 for fig_name
in self.
plots:
164 diagnostic = Diagnostic()
169 actuator_name = os.path.basename(filename)
171 print "\n" + str(actuator_name)
172 stream = file(filename,
'r') 173 samples = load(stream) 175 encoder_position = [] 177 measured_motor_voltage = [] 178 executed_current = [] 179 measured_current = [] 182 for s
in samples.sample_buffer:
183 velocity.append(s.velocity)
184 encoder_position.append(s.encoder_position)
185 supply_voltage.append(s.supply_voltage)
186 measured_motor_voltage.append(s.measured_motor_voltage)
187 executed_current.append(s.executed_current)
188 measured_current.append(s.measured_current)
189 timestamp.append(s.timestamp)
191 velocity = numpy.array(velocity)
192 encoder_position = numpy.array(encoder_position)
194 supply_voltage = numpy.array(supply_voltage)
195 measured_motor_voltage = numpy.array(measured_motor_voltage)
196 executed_current = numpy.array(executed_current)
197 measured_current = numpy.array(measured_current)
199 acceleration = diagnostic.get_acceleration(velocity, timestamp)
201 spikes = acceleration * (velocity[:-1])
203 (result1, outlier_limit_neg, outlier_limit_pos) = diagnostic.check_for_spikes(spikes, actuator_name, debug_info)
204 result2 = diagnostic.check_for_unplugged(velocity, measured_motor_voltage, actuator_name, debug_info)
205 result3 = diagnostic.check_for_open(velocity, measured_motor_voltage, actuator_name, debug_info)
206 result = result1
or result2
or result3
210 param = (actuator_name,velocity,spikes,acceleration,outlier_limit_neg,outlier_limit_pos,supply_voltage,measured_motor_voltage,executed_current,measured_current, result1, result2, result3)
211 self.plots.append(actuator_name +
'_1')
212 self.plots.append(actuator_name +
'_2')
213 diagnostic.plot(param)
215 param = (actuator_name,velocity,spikes,acceleration,outlier_limit_neg,outlier_limit_pos,supply_voltage,measured_motor_voltage,executed_current,measured_current, result1, result2, result3)
216 self.plots.append(actuator_name +
'_1')
217 self.plots.append(actuator_name +
'_2')
218 diagnostic.plot(param)
223 filename = QFileDialog.getOpenFileName(self, self.tr(
"Open File"),
"../", self.tr(
"Yaml (*.yaml)"))
224 if os.path.basename(filename[0].encode(
"ascii")) ==
"":
227 self.filelist.append(filename[0])
228 self.filenames.append(os.path.basename(filename[0].encode(
"ascii")))
229 self.fileLabel.setText(
'Files: ' + str(self.
filenames))
230 self.fileLabel.setWordWrap(
True)
233 directory = QFileDialog.getExistingDirectory(self, self.tr(
"Open Directory"),
"../")
237 temp = [f.encode(
"ascii")
for f
in os.listdir(directory)]
238 self.filenames.extend(temp)
239 temp = [directory +
'/' + filepath
for filepath
in os.listdir(directory)]
240 self.filelist.extend(temp)
241 self.fileLabel.setText(
'Files: ' + str(self.
filenames))
242 self.fileLabel.setWordWrap(
True)
def start_diag_controller(actuator_name)
def get_diag_data(actuator_name)