public SetMasterFitTextBox ( double value ) : void | ||
value | double | |
return | void |
/// <summary> /// The main loop. Reads the analog inputs, fits to the data and (when locked) adjusts the slave laser voltage. /// </summary> private void mainLoop() { fits = new Dictionary <string, double[]>(); //Somewhere to store the fits for an iteration. readParametersFromUI(); //This isn't part of the loop. Do an initial setup of the parameters. ScanParameters sp = createInitialScanParameters(); double masterVoltage = 0; setupMasterVoltageOut(); writeMasterVoltageOut(0); disposeMasterVoltageOut(); initializeAIHardware(sp); CavityScanData scanData; int count = 0; while (TCLState != ControllerState.STOPPED) { scanData = acquireAI(sp); if (scanData != null) { plotCavity(scanData); if ((scanData.GetCavityData())[sp.Steps - 1] < (double)Environs.Hardware.GetInfo("TCL_MAX_INPUT_VOLTAGE")) // if the cavity ramp voltage exceeds the input voltage - do nothing { if (checkRampChannel() == true) { //if the cavity length is locked, use the set point to determine what voltage to output if (ui.masterLockEnableCheck.Checked == true) { fits["masterFits"] = fitMaster(scanData); plotMaster(scanData, fits["masterFits"]); masterVoltage = calculateMasterVoltageShift(masterVoltage) + masterVoltage; setupMasterVoltageOut(); //write difference to analog output writeMasterVoltageOut(masterVoltage); ui.SetVtoOffsetVoltage(masterVoltage); ui.SetMasterFitTextBox(fits["masterFits"][1] - masterVoltage); disposeMasterVoltageOut(); } //if the cavity length is not locked, allow the voltage out to be scanned else { plotMaster(scanData); setupMasterVoltageOut(); masterVoltage = ui.GetVtoOffsetVoltage(); writeMasterVoltageOut(masterVoltage); disposeMasterVoltageOut(); } } foreach (KeyValuePair <string, SlaveLaser> pair in SlaveLasers) { string slName = pair.Key; SlaveLaser sl = pair.Value; //Some rearrangements to fit only when log fit slave lasers parameters on and/or lock slave lasers on. plotSlaveNoFit(slName, scanData); switch (sl.lState) { case SlaveLaser.LaserState.FREE: break; case SlaveLaser.LaserState.LOCKING: fits[slName + "Fits"] = fitSlave(slName, scanData); plotSlave(slName, scanData, fits[slName + "Fits"]); sl.CalculateLaserSetPoint(fits["masterFits"], fits[slName + "Fits"]); sl.Lock(); RefreshErrorGraph(slName); count = 0; break; case SlaveLaser.LaserState.LOCKED: fits[slName + "Fits"] = fitSlave(slName, scanData); plotSlave(slName, scanData, fits[slName + "Fits"]); plotError(slName, new double[] { getErrorCount(slName) }, new double[] { fits[slName + "Fits"][1] - fits["masterFits"][1] - sl.LaserSetPoint }); sl.RefreshLock(fits["masterFits"], fits[slName + "Fits"]); RefreshLockParametersOnUI(sl.Name); incrementCounter(slName); count++; break; } if (ui.logCheckBox.Checked) { double[] masterFitParams; double[] slaveFitParams; if (!fits.TryGetValue("masterFits", out masterFitParams)) { masterFitParams = new double[4] { 0, 0, 0, 0 }; } if (!fits.TryGetValue(slName + "Fits", out slaveFitParams)) { slaveFitParams = new double[4] { 0, 0, 0, 0 }; } ; serializer.AddData(new TCLDataLog(DateTime.Now, slName, masterFitParams[1], slaveFitParams[1], sl.VoltageToLaser)); } } } else { Console.WriteLine("Cavity ramp voltage out of range"); Thread.Sleep(100); } } } endRamping(); }
/// <summary> /// The main loop. Reads the analog inputs, fits to the data and (when locked) adjusts the slave laser voltage. /// </summary> private void mainLoop() { fits = new Dictionary <string, double[]>(); //Somewhere to store the fits for an iteration. readParametersFromUI(); //This isn't part of the loop. Do an initial setup of the parameters. ScanParameters sp = createInitialScanParameters(); double masterVoltage = 0; setupMasterVoltageOut(); writeMasterVoltageOut(0); disposeMasterVoltageOut(); initializeAIHardware(sp); CavityScanData scanData; int count = 0; while (TCLState != ControllerState.STOPPED) { scanData = acquireAI(sp); if (scanData != null) { plotCavity(scanData); if ((scanData.GetCavityData())[sp.Steps - 1] < (double)Environs.Hardware.GetInfo("TCL_MAX_INPUT_VOLTAGE")) // if the cavity ramp voltage exceeds the input voltage - do nothing { fits["masterFits"] = fitMaster(scanData); plotMaster(scanData, fits["masterFits"]); if (ui.masterLockEnableCheck.Checked == true && checkRampChannel() == true) { masterVoltage = calculateMasterVoltageShift(masterVoltage) + masterVoltage; setupMasterVoltageOut(); //write difference to analog output writeMasterVoltageOut(masterVoltage); ui.SetVtoOffsetVoltage(Math.Round(masterVoltage, 4)); ui.SetMasterFitTextBox(Math.Round((fits["masterFits"][1] - masterVoltage), 4)); disposeMasterVoltageOut(); } foreach (KeyValuePair <string, SlaveLaser> pair in SlaveLasers) { string slName = pair.Key; SlaveLaser sl = pair.Value; //Some rearrangements to fit only when log fit slave lasers parameters on and/or lock slave lasers on. plotSlaveNoFit(slName, scanData); if (ui.logCheckBox.Checked == true) { fits[slName + "Fits"] = fitSlave(slName, scanData); plotSlave(slName, scanData, fits[slName + "Fits"]); using (StreamWriter writer = new StreamWriter(Environs.FileSystem.Paths["transferCavityData"] + "log.txt", true)) { writer.WriteLine(slName + "," + DateTime.Now.ToString("h:mm:ss.ff t") + "," + Math.Round(fits["masterFits"][1], 5).ToString() + "," + Math.Round(fits[slName + "Fits"][1], 5).ToString() + "," + Math.Round(sl.VoltageToLaser, 5).ToString()); } } switch (sl.lState) { case SlaveLaser.LaserState.FREE: break; case SlaveLaser.LaserState.LOCKING: fits[slName + "Fits"] = fitSlave(slName, scanData); plotSlave(slName, scanData, fits[slName + "Fits"]); sl.CalculateLaserSetPoint(fits["masterFits"], fits[slName + "Fits"]); sl.Lock(); //RefreshErrorGraph(slName); count = 0; break; case SlaveLaser.LaserState.LOCKED: fits[slName + "Fits"] = fitSlave(slName, scanData); plotSlave(slName, scanData, fits[slName + "Fits"]); plotError(slName, new double[] { getErrorCount(slName) }, new double[] { fits[slName + "Fits"][1] - fits["masterFits"][1] - sl.LaserSetPoint }); sl.RefreshLock(fits["masterFits"], fits[slName + "Fits"]); RefreshLockParametersOnUI(sl.Name); incrementCounter(slName); count++; break; } } } else { Console.WriteLine("Cavity ramp voltage out of range"); Thread.Sleep(100); } } } endRamping(); }
/// <summary> /// The main loop. Reads the analog inputs, fits to the data and (when locked) adjusts the slave laser voltage. /// </summary> private void mainLoop() { fits = new Dictionary <string, double[]>(); //Somewhere to store the fits for an iteration. readParametersFromUI(); //This isn't part of the loop. Do an initial setup of the parameters. ScanParameters sp = createInitialScanParameters(); double masterVoltage = 0; setupMasterVoltageOut(); writeMasterVoltageOut(0); disposeMasterVoltageOut(); DateTime previousTime = DateTime.Now; Stopwatch stopWatch = new Stopwatch(); stopWatch.Start(); initializeAIHardware(sp); CavityScanData scanData = new CavityScanData(sp.Steps, aiChannels, config.Lasers, config.Cavity, config.MasterLaser); int count = 0; while (TCLState != ControllerState.STOPPED) { updateTime(stopWatch); stopWatch.Reset(); stopWatch.Start(); double[] lastCav = scanData.GetCavityData(); scanData = acquireAI(sp); if (ui.scanAvCheckBox.Checked == true) { scanData.SetAverageCavityData(lastCav); } if (scanData != null) { if (!ui.dissableGUIupdateCheckBox.Checked) { plotCavity(scanData); } ; if ((scanData.GetCavityData())[sp.Steps - 1] < config.MaxInputVoltage) // if the cavity ramp voltage exceeds the input voltage - do nothing { if (checkRampChannel() == true) { switch (MasterLaser.lState) { case MasterLaser.LaserState.FREE: plotMaster(scanData); masterVoltage = ui.GetVtoOffsetVoltage(); setupMasterVoltageOut(); writeMasterVoltageOut(masterVoltage); disposeMasterVoltageOut(); break; case MasterLaser.LaserState.LOCKING: fits["masterFits"] = fitMaster(scanData); plotMaster(scanData, fits["masterFits"]); masterVoltage = calculateNewMasterVoltage(masterVoltage); //write difference to analog output setupMasterVoltageOut(); writeMasterVoltageOut(masterVoltage); ui.SetVtoOffsetVoltage(masterVoltage); ui.SetMasterFitTextBox(fits["masterFits"][1] - masterVoltage); disposeMasterVoltageOut(); MasterLaser.Lock(); break; case MasterLaser.LaserState.LOCKED: if (ui.fastFitCheckBox.Checked) { fits["masterFits"] = fastfitMaster(scanData, fits["masterFits"]); } else { fits["masterFits"] = fitMaster(scanData); } if (!ui.dissableGUIupdateCheckBox.Checked) { plotMaster(scanData, fits["masterFits"]); } ; masterVoltage = calculateNewMasterVoltage(masterVoltage); //write difference to analog output setupMasterVoltageOut(); writeMasterVoltageOut(masterVoltage); ui.SetVtoOffsetVoltage(masterVoltage); ui.SetMasterFitTextBox(fits["masterFits"][1] - masterVoltage); disposeMasterVoltageOut(); break; } } foreach (KeyValuePair <string, SlaveLaser> pair in SlaveLasers) { string slName = pair.Key; SlaveLaser sl = pair.Value; //Some rearrangements to fit only when log fit slave lasers parameters on and/or lock slave lasers on. switch (sl.lState) { case SlaveLaser.LaserState.FREE: plotSlaveNoFit(slName, scanData); //RefreshVoltageOnUI(slName); break; case SlaveLaser.LaserState.LOCKING: fits[slName + "Fits"] = fitSlave(slName, scanData); plotSlave(slName, scanData, fits[slName + "Fits"]); sl.CalculateLaserSetPoint(fits["masterFits"], fits[slName + "Fits"]); sl.Lock(); //RefreshVoltageOnUI(slName); RefreshErrorGraph(slName); count = 0; break; case SlaveLaser.LaserState.LOCKED: if (ui.fastFitCheckBox.Checked) { fits[slName + "Fits"] = fastfitSlave(slName, scanData, fits[slName + "Fits"]); } else { fits[slName + "Fits"] = fitSlave(slName, scanData); } if (!ui.dissableGUIupdateCheckBox.Checked) { plotSlave(slName, scanData, fits[slName + "Fits"]); } ; if (!ui.dissableGUIupdateCheckBox.Checked) { plotError(slName, new double[] { getErrorCount(slName) }, new double[] { fits[slName + "Fits"][1] - fits["masterFits"][1] - sl.LaserSetPoint }); } ; sl.RefreshLock(fits["masterFits"], fits[slName + "Fits"]); RefreshLockParametersOnUI(sl.Name); RefreshErrorParametersOnUI(sl.Name); incrementCounter(slName); count++; break; } if (ui.logCheckBox.Checked) { double[] masterFitParams; double[] slaveFitParams; if (!fits.TryGetValue("masterFits", out masterFitParams)) { masterFitParams = new double[4] { 0, 0, 0, 0 }; } if (!fits.TryGetValue(slName + "Fits", out slaveFitParams)) { slaveFitParams = new double[4] { 0, 0, 0, 0 }; } ; serializer.AddData(new TCLDataLog(DateTime.Now, slName, masterFitParams[1], slaveFitParams[1], sl.VoltageToLaser)); } } } else { Console.WriteLine("Cavity ramp voltage out of range"); Thread.Sleep(100); } } } endRamping(); }