Skip to content

Commit

Permalink
Fixed sensorpendulum app in the Physics section
Browse files Browse the repository at this point in the history
Made compatible with non-blocking calls defined in PSL.Peripherals.I2C .
Bug fixes in template file.
included saveData button to UI
Fixes fossasia#93
  • Loading branch information
jithinbp committed May 6, 2017
1 parent 44be83c commit 7f6a1a2
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 53 deletions.
22 changes: 15 additions & 7 deletions psl_res/GUI/D_PHYSICS/B_physics/Y_sensorpendulum.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from __future__ import print_function
from PSL_Apps.utilitiesClass import utilitiesClass

from .templates import template_transient
from templates import ui_template_transient as template_transient
from PSL.SENSORS import MPU6050
import numpy as np
from PyQt4 import QtGui,QtCore
Expand Down Expand Up @@ -42,7 +42,8 @@ def __init__(self, parent=None,**kwargs):
self.plot1.setLabel('bottom','Time -->', units='S',**labelStyle)

self.tg=2000
self.tgLabel.setText(str(2000*self.tg*1e-3)+'mS')
self.samples = 1000
self.tgLabel.setText(str(self.samples*self.tg*1e-3)+'mS')
self.curveGx = self.addCurve(self.plot1,'Gx')
self.curveGy = self.addCurve(self.plot1,'Gy')
self.curveGz = self.addCurve(self.plot1,'Gz')
Expand All @@ -67,13 +68,16 @@ def __init__(self, parent=None,**kwargs):
self.Params=[]

def run(self):
self.I.I2C.__captureStart__(self.IMU.ADDRESS,0x3B,14,2000,self.tg,'int')
print ("Sleeping for",self.I.I2C.total_samples*self.I.I2C.tg*1e-3+10,"mS")
self.loop=self.delayedTask(self.I.I2C.total_samples*self.I.I2C.tg*1e-3+10,self.plotData)
t = self.I.I2C.__captureStart__(self.IMU.ADDRESS,0x3B,14,self.samples,self.tg)
self.plot1.setXRange(0,t); self.plot1.setLimits(xMin = 0,xMax=t)

print ("Sleeping for",t,"S",t)
self.loop=self.delayedTask(t*1e3,self.plotData) #t+10uS per sample

def plotData(self):
data = self.I.I2C.__retrievebuffer__()
self.t,self.Ax,self.Ay,self.Az,T,self.Gx,self.Gy,self.Gz = self.I.I2C.__dataProcessor__(data)
self.t,self.Ax,self.Ay,self.Az,T,self.Gx,self.Gy,self.Gz = self.I.I2C.__dataProcessor__(data,'int')
print (len(self.t),len(self.Ax))
self.curveAx.setData(self.t*1e-6,self.Ax)
self.curveAy.setData(self.t*1e-6,self.Ay)
self.curveAz.setData(self.t*1e-6,self.Az)
Expand All @@ -86,7 +90,7 @@ def plotData(self):
def setTimebase(self,T):
self.tgs = [1000,2000,3000,4000,5000,6000,7000,8000,9000,10000]
self.tg = self.tgs[T]
self.tgLabel.setText(str(2000*self.tg*1e-3)+'mS')
self.tgLabel.setText(str(self.samples*self.tg*1e-3)+'mS')

def fit(self):
if(not len(self.t)):return
Expand All @@ -111,6 +115,10 @@ def fit(self):

def showData(self):
self.displayDialog('nothing')

def saveData(self):
self.saveDataWindow([self.curveGx,self.curveGy,self.curveGz,self.curveAx,self.curveAy,self.curveAz],self.plot1)


if __name__ == "__main__":
from PSL import sciencelab
Expand Down
46 changes: 12 additions & 34 deletions psl_res/GUI/D_PHYSICS/B_physics/templates/template_transient.ui
Original file line number Diff line number Diff line change
Expand Up @@ -93,20 +93,6 @@
<enum>QFrame::Raised</enum>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<widget class="QPushButton" name="pushButton_4">
<property name="text">
<string>0 -&gt; 5 V</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QPushButton" name="pushButton">
<property name="text">
<string>5 -&gt; 0 V</string>
</property>
</widget>
</item>
<item row="1" column="0" colspan="2">
<widget class="QFrame" name="frame_6">
<property name="frameShape">
Expand Down Expand Up @@ -154,6 +140,13 @@
</layout>
</widget>
</item>
<item row="0" column="0">
<widget class="QPushButton" name="pushButton_4">
<property name="text">
<string>Acquire</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
Expand Down Expand Up @@ -394,31 +387,15 @@
<sender>pushButton_4</sender>
<signal>clicked()</signal>
<receiver>MainWindow</receiver>
<slot>ZeroToFive()</slot>
<hints>
<hint type="sourcelabel">
<x>31</x>
<y>52</y>
</hint>
<hint type="destinationlabel">
<x>78</x>
<y>-9</y>
</hint>
</hints>
</connection>
<connection>
<sender>pushButton</sender>
<signal>clicked()</signal>
<receiver>MainWindow</receiver>
<slot>FiveToZero()</slot>
<slot>run()</slot>
<hints>
<hint type="sourcelabel">
<x>182</x>
<x>77</x>
<y>51</y>
</hint>
<hint type="destinationlabel">
<x>186</x>
<y>-19</y>
<x>-34</x>
<y>58</y>
</hint>
</hints>
</connection>
Expand All @@ -431,5 +408,6 @@
<slot>saveData()</slot>
<slot>ZeroToFive()</slot>
<slot>FiveToZero()</slot>
<slot>run()</slot>
</slots>
</ui>
19 changes: 7 additions & 12 deletions psl_res/GUI/D_PHYSICS/B_physics/templates/ui_template_transient.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

# Form implementation generated from reading ui file 'psl_res/GUI/D_PHYSICS/B_physics/templates/template_transient.ui'
#
# Created: Mon Jul 11 21:45:33 2016
# by: PyQt4 UI code generator 4.10.4
# Created: Sat May 6 17:48:08 2017
# by: PyQt4 UI code generator 4.11.3
#
# WARNING! All changes made in this file will be lost!

Expand Down Expand Up @@ -66,12 +66,6 @@ def setupUi(self, MainWindow):
self.frame_3.setObjectName(_fromUtf8("frame_3"))
self.gridLayout = QtGui.QGridLayout(self.frame_3)
self.gridLayout.setObjectName(_fromUtf8("gridLayout"))
self.pushButton_4 = QtGui.QPushButton(self.frame_3)
self.pushButton_4.setObjectName(_fromUtf8("pushButton_4"))
self.gridLayout.addWidget(self.pushButton_4, 0, 0, 1, 1)
self.pushButton = QtGui.QPushButton(self.frame_3)
self.pushButton.setObjectName(_fromUtf8("pushButton"))
self.gridLayout.addWidget(self.pushButton, 0, 1, 1, 1)
self.frame_6 = QtGui.QFrame(self.frame_3)
self.frame_6.setFrameShape(QtGui.QFrame.StyledPanel)
self.frame_6.setFrameShadow(QtGui.QFrame.Raised)
Expand All @@ -90,6 +84,9 @@ def setupUi(self, MainWindow):
self.horizontalSlider.setObjectName(_fromUtf8("horizontalSlider"))
self.horizontalLayout_2.addWidget(self.horizontalSlider)
self.gridLayout.addWidget(self.frame_6, 1, 0, 1, 2)
self.pushButton_4 = QtGui.QPushButton(self.frame_3)
self.pushButton_4.setObjectName(_fromUtf8("pushButton_4"))
self.gridLayout.addWidget(self.pushButton_4, 0, 0, 1, 1)
self.horizontalLayout.addWidget(self.frame_3)
self.frame_5 = QtGui.QFrame(self.frame)
self.frame_5.setFrameShape(QtGui.QFrame.StyledPanel)
Expand Down Expand Up @@ -176,17 +173,15 @@ def setupUi(self, MainWindow):
QtCore.QObject.connect(self.pushButton_6, QtCore.SIGNAL(_fromUtf8("clicked()")), MainWindow.showData)
QtCore.QObject.connect(self.horizontalSlider, QtCore.SIGNAL(_fromUtf8("valueChanged(int)")), MainWindow.setTimebase)
QtCore.QObject.connect(self.pushButton_7, QtCore.SIGNAL(_fromUtf8("clicked()")), MainWindow.saveData)
QtCore.QObject.connect(self.pushButton_4, QtCore.SIGNAL(_fromUtf8("clicked()")), MainWindow.ZeroToFive)
QtCore.QObject.connect(self.pushButton, QtCore.SIGNAL(_fromUtf8("clicked()")), MainWindow.FiveToZero)
QtCore.QObject.connect(self.pushButton_4, QtCore.SIGNAL(_fromUtf8("clicked()")), MainWindow.run)
QtCore.QMetaObject.connectSlotsByName(MainWindow)

def retranslateUi(self, MainWindow):
MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow", None))
self.widgetFrameOuter.setProperty("class", _translate("MainWindow", "PeripheralCollection", None))
self.frame.setProperty("class", _translate("MainWindow", "PeripheralCollectionInner", None))
self.pushButton_4.setText(_translate("MainWindow", "0 -> 5 V", None))
self.pushButton.setText(_translate("MainWindow", "5 -> 0 V", None))
self.tgLabel.setText(_translate("MainWindow", "time: mS", None))
self.pushButton_4.setText(_translate("MainWindow", "Acquire", None))
self.pushButton_5.setText(_translate("MainWindow", "Fit selected region", None))
self.pushButton_6.setText(_translate("MainWindow", "Show Fit Params", None))
self.pushButton_7.setText(_translate("MainWindow", "Save Data", None))
Expand Down

0 comments on commit 7f6a1a2

Please sign in to comment.