aboutsummaryrefslogtreecommitdiff
path: root/examples/lock_eit.py
diff options
context:
space:
mode:
authorEugeniy E. Mikhailov <evgmik@gmail.com>2021-12-15 15:09:11 -0500
committerEugeniy E. Mikhailov <evgmik@gmail.com>2021-12-15 15:09:11 -0500
commit7bc86375cc79c0d7aa4485677ee92778d53dc8c9 (patch)
treef8e95d827ff603c864789667309bd035e08d80d5 /examples/lock_eit.py
parent462151d1544adffcbfe2eb67d2776d4e5e1aced0 (diff)
downloadqolab-7bc86375cc79c0d7aa4485677ee92778d53dc8c9.tar.gz
qolab-7bc86375cc79c0d7aa4485677ee92778d53dc8c9.zip
redid acquisition with async
Diffstat (limited to 'examples/lock_eit.py')
-rw-r--r--examples/lock_eit.py36
1 files changed, 24 insertions, 12 deletions
diff --git a/examples/lock_eit.py b/examples/lock_eit.py
index 5dd8ceb..c29f1df 100644
--- a/examples/lock_eit.py
+++ b/examples/lock_eit.py
@@ -2,6 +2,8 @@ import pyvisa
import numpy as np
import matplotlib as mpl
import matplotlib.pyplot as plt
+
+import asyncio
import time
from qolab.hardware import BasicInstrument
@@ -38,11 +40,12 @@ def initLog():
log.addTrace(feedbackLog)
return log
-def feedbackLoop(apparatus, nsteps):
+async def feedbackLoop(apparatus, nsteps):
# while True:
for i in range(0,nsteps):
adjustRFandLog(apparatus)
- apparatus.runStatus = True
+ await asyncio.sleep(0.001)
+ apparatus.runStatus = False
def adjustRFandLog(apparatus):
timenow = time.time()
@@ -59,7 +62,7 @@ def adjustRFandLog(apparatus):
freq0 = rfgen.getFreqFixed()
freq = freq0 + fdbck
rfgen.setFreqFixed(freq)
- print(f'error = {err}, feedback = {fdbck}, request freq = {freq}')
+ # print(f'error = {err}, feedback = {fdbck}, request freq = {freq}')
log.addPointToTrace(timenow)
log.addPointToTrace(err, "error")
@@ -74,11 +77,12 @@ def updateLogPlot(apparatus):
plt.pause(.0001)
print(f're-plotting')
-def updateLogPlotLoop(apparatus):
+async def updateLogPlotLoop(apparatus):
while True:
updateLogPlot(apparatus)
if not apparatus.runStatus:
break
+ await asyncio.sleep(1)
def updateLogFile(apparatus):
log = apparatus.log
@@ -87,16 +91,18 @@ def updateLogFile(apparatus):
log.save(logFileName, item_format='.15e')
print(f'Saving to {logFileName}')
-def updateLogFileLoop(apparatus):
+async def updateLogFileLoop(apparatus):
while True:
updateLogFile(apparatus)
if not apparatus.runStatus:
break
+ await asyncio.sleep(10)
freqZero = 6834687190
freqDeltaM2 = 6835387164
-def main():
+
+async def main():
apparatus = BasicInstrument()
apparatus.config['Device type'] = 'QOL VAMPIRE HighPower magnetometer'
apparatus.config['Device model'] = 'v0.1'
@@ -129,22 +135,26 @@ def main():
SweepSpan = 10000
apparatus.rfgen.stopFrequencySweep()
apparatus.rfgen.setFreqFixed(freqDeltaM2+100)
- apparatus.logFileName = apparatus.getNextDataFile()
- print(apparatus.logFileName)
# initial lock
apparatus.logFileName = None
apparatus.pid.reset()
apparatus.runStatus = True
- feedbackLoop(apparatus, nsteps=10)
+ # feedbackLoop(apparatus, nsteps=10)
+ res = await asyncio.gather( feedbackLoop(apparatus, nsteps=100), updateLogPlotLoop(apparatus), updateLogFileLoop(apparatus) )
+ print(apparatus.logFileName)
updateLogPlot(apparatus)
# long term lock
+ apparatus.log = initLog()
apparatus.logFileName = None
- apparatus.pid.reset()
+ apparatus.logFileName = apparatus.getNextDataFile()
+ # apparatus.pid.reset()
apparatus.runStatus = True
- feedbackLoop(apparatus, nsteps=100)
+ # feedbackLoop(apparatus, nsteps=100)
+ res = await asyncio.gather( feedbackLoop(apparatus, nsteps=1000), updateLogPlotLoop(apparatus), updateLogFileLoop(apparatus) )
+ print(apparatus.logFileName)
updateLogPlot(apparatus)
# apparatus.log.save(apparatus.logFileName, item_format='.15e')
@@ -155,7 +165,9 @@ def main():
if __name__ == '__main__':
mpl.use("TkAgg")
- apparatus=main()
+ # apparatus=main()
+ apparatus = asyncio.run(main())
+