diff options
author | Eugeniy E. Mikhailov <evgmik@gmail.com> | 2021-12-14 00:21:07 -0500 |
---|---|---|
committer | Eugeniy E. Mikhailov <evgmik@gmail.com> | 2021-12-14 00:21:07 -0500 |
commit | 41e4076479ad136e0bb4855c2c5ea2bd8b481c74 (patch) | |
tree | 343e7657763f10e76815b31687354b309ab54097 /examples | |
parent | d6ab6f0f86d6c6a76adf166aa79deb649dd0384a (diff) | |
download | qolab-41e4076479ad136e0bb4855c2c5ea2bd8b481c74.tar.gz qolab-41e4076479ad136e0bb4855c2c5ea2bd8b481c74.zip |
added an example
Diffstat (limited to 'examples')
-rw-r--r-- | examples/lock_eit.py | 79 |
1 files changed, 79 insertions, 0 deletions
diff --git a/examples/lock_eit.py b/examples/lock_eit.py new file mode 100644 index 0000000..90732d8 --- /dev/null +++ b/examples/lock_eit.py @@ -0,0 +1,79 @@ +import pyvisa +import numpy as np +import matplotlib as mpl +import matplotlib.pyplot as plt +import time + +from qolab.hardware.scope import SDS1104X +from qolab.hardware.rf_generator import AgilentE8257D +from qolab.feedback import PID +from qolab.data import TraceSetSameX, TraceXY, Trace + +def adjustRF(pid, scope, rfgen): + errorTrace = Trace("error") + errorTrace.config['unit']='V' + timeTrace = Trace("time") + timeTrace.config['unit']='S' + + errorLog = TraceXY("error") + errorLog.x = timeTrace + errorLog.y = errorTrace + + log = TraceSetSameX("timelog") + log.addTrace(errorLog) + + + # while True: + for i in range(0,100): + timenow = time.time() + + ch1=scope.getTrace(1, decimate=False) + err = np.mean(ch1.y.values) + fdbck = pid.feedback(err) + + freq0 = rfgen.getFreqFixed() + freq = freq0 + fdbck + rfgen.setFreqFixed(freq) + print(f'error = {err}, feedback = {fdbck}, request freq = {freq}') + + log.addPointToTrace(timenow) + log.addPointToTrace(err, "error") + plt.clf() + log.plot() + time.sleep(.01) + + return log + + + +if __name__ == '__main__': + print("testing") + rm = pyvisa.ResourceManager() + instr_scope=rm.open_resource('TCPIP::192.168.0.61::INSTR') + scope = SDS1104X(instr_scope) + instr_rfgen=rm.open_resource('TCPIP::192.168.0.114::INSTR') + rfgen = AgilentE8257D(instr_rfgen) + print('------ Header start -------------') + print(str.join('\n', scope.getHeader())) + print(str.join('\n', rfgen.getHeader())) + print('------ Header ends -------------') + ch1 = scope.getTrace(1) + traces = scope.getAllTraces() + + freqZero = 6834687190 + freqDeltaM2 = 6835387164 + SweepSpan = 10000 + + rfgen.stopFrequencySweep() + rfgen.setFreqFixed(freqDeltaM2+100) + + pid = PID(100,400,0, sign=-1) + log=adjustRF(pid, scope, rfgen) + + + + + + + + |