diff options
Diffstat (limited to 'examples')
-rw-r--r-- | examples/lock_eit.py | 52 |
1 files changed, 38 insertions, 14 deletions
diff --git a/examples/lock_eit.py b/examples/lock_eit.py index f1cba3c..d68c31a 100644 --- a/examples/lock_eit.py +++ b/examples/lock_eit.py @@ -15,6 +15,7 @@ import qolab.gui.web as gui from qolab.hardware import BasicInstrument from qolab.hardware.scope import SDS1104X from qolab.hardware.rf_generator import AgilentE8257D +from qolab.hardware.lockin import SRS_SR865A from qolab.feedback import PID from qolab.data import TraceSetSameX, TraceXY, Trace @@ -23,6 +24,13 @@ l.setLevel(logging.INFO) logger = logging.getLogger('Magnetometer') logger.setLevel(logging.INFO) +def getConfig(apparatus): + config = apparatus.config.copy() + ai = apparatus.instruments + for n, i in ai.items(): + config[n]=i.getConfig() + return config + def initLog(): errorTrace = Trace("error") errorTrace.config['unit']='V' @@ -47,12 +55,21 @@ def initLog(): feedbackLog.x = timeTrace feedbackLog.y = feedbackTrace + eitTrace = Trace("eit") + eitTrace.config['unit']='V' + eitLog = TraceXY("eit") + eitLog.config['type'] = 'timestamp' + eitLog.x = timeTrace + eitLog.y = eitTrace + log = TraceSetSameX("timelog") log.config['type'] = 'timestamp' log.addTrace(errorLog) log.addTrace(freqLog) log.addTrace(feedbackLog) + log.addTrace(eitLog) + log.config['tags']['apparatus']=getConfig(apparatus) return log async def feedbackLoop(apparatus, nsteps): @@ -65,13 +82,16 @@ async def feedbackLoop(apparatus, nsteps): def adjustRFandLog(apparatus): timenow = time.time() - scope = apparatus.scope - rfgen = apparatus.rfgen - pid = apparatus.pid + ai = apparatus.instruments + scope = ai['scope'] + rfgen = ai['rfgen'] + pid = ai['pid'] log = apparatus.gui_log.traces ch1=scope.getTrace(1, decimate=False) + ch3=scope.getTrace(3, decimate=False) err = np.mean(ch1.y.values) + eit = np.mean(ch3.y.values) fdbck = pid.feedback(err) freq0 = rfgen.getFreqFixed() @@ -83,6 +103,7 @@ def adjustRFandLog(apparatus): log.addPointToTrace(err, "error") log.addPointToTrace(freq0, "frequency") log.addPointToTrace(fdbck, "feedback") + log.addPointToTrace(eit, "eit") freqZero = 6834686400 @@ -105,6 +126,8 @@ async def main(): scope = SDS1104X(instr_scope) instr_rfgen=rm.open_resource('TCPIP::192.168.0.114::INSTR') rfgen = AgilentE8257D(instr_rfgen) + instr_lockin=rm.open_resource('TCPIP::192.168.0.51::INSTR') + lockin = SRS_SR865A(instr_lockin) print('------ Header start -------------') print(str.join('\n', scope.getHeader())) print(str.join('\n', rfgen.getHeader())) @@ -113,29 +136,30 @@ async def main(): # traces = scope.getAllTraces() pid = PID(100,400,0, sign=-1) - apparatus.scope = scope - apparatus.rfgen = rfgen - apparatus.pid = pid + apparatus.instruments={} + ai = apparatus.instruments + ai['rfgen'] = rfgen + ai['lockin'] = lockin + ai['pid'] = pid + ai['scope'] = scope apparatus.state = None apparatus.runStatus = False - d={} - d['scope'] = scope.getConfig() - d['rfgen'] = rfgen.getConfig() + d=getConfig(apparatus) instruments_config=gui.QOLDictionary(a=wp, name='Instruments configs', container=d) SweepSpan = 10000 - apparatus.rfgen.stopFrequencySweep() - apparatus.rfgen.setFreqFixed(freqDeltaM2) - # apparatus.rfgen.setFreqFixed(freqZero) + ai['rfgen'].stopFrequencySweep() + ai['rfgen'].setFreqFixed(freqDeltaM2) + # ai['rfgen'].setFreqFixed(freqZero) logger.info('========== Initial lock ===========') apparatus.state = 'Initial lock' update_webpage(apparatus=apparatus) apparatus.gui_log.setTraces( initLog() ) - apparatus.pid.reset() + ai['pid'].reset() apparatus.runStatus = True res = await asyncio.gather( feedbackLoop(apparatus, nsteps=100) @@ -145,7 +169,7 @@ async def main(): apparatus.state = 'Long term lock' update_webpage(apparatus=apparatus) apparatus.gui_log.setTraces( initLog() ) - apparatus.pid.reset() + ai['pid'].reset() apparatus.runStatus = True res = await asyncio.gather( feedbackLoop(apparatus, nsteps=100000) |