private void displayData(ScanParameters sp, CavityScanData data) { ui.ScatterGraphPlot(ui.SlaveLaserIntensityScatterGraph, ui.SlaveDataPlot, sp.CalculateRampVoltages(), data.SlavePhotodiodeData); ui.ScatterGraphPlot(ui.MasterLaserIntensityScatterGraph, ui.MasterDataPlot, sp.CalculateRampVoltages(), data.MasterPhotodiodeData); }
private ScanParameters createInitialScanParameters() { ScanParameters sp = new ScanParameters(); sp.Steps = numberOfPoints; sp.Low = ScanOffset - scanWidth; sp.High = ScanOffset + scanWidth; sp.SleepTime = 0; return(sp); }
/// <summary> /// This adjusts the scan range of the next scan, so that the HeNe peak stays in the middle of the scan. /// It modifies the scan parameters that are passed to it. /// </summary> private double calculateNewScanCentre(ScanParameters scanParameters, double[] fitCoefficients) { double newCentroid = new double(); if (fitCoefficients[1] - scanWidth > LOWER_CC_VOLTAGE_LIMIT && fitCoefficients[1] + scanWidth < UPPER_CC_VOLTAGE_LIMIT && fitCoefficients[1] < scanParameters.High && fitCoefficients[1] > scanParameters.Low) //Only change limits if fits are reasonable. { newCentroid = fitCoefficients[1]; } else { newCentroid = scanParameters.High - scanWidth; } Console.WriteLine(newCentroid); return(newCentroid); }
private void displaySlaveFit(ScanParameters sp, double[] fitCoefficients) { double[] fitPoints = new double[sp.Steps]; double[] ramp = sp.CalculateRampVoltages(); double n = fitCoefficients[3]; double q = fitCoefficients[2]; double c = fitCoefficients[1]; double w = fitCoefficients[0]; for (int i = 0; i < sp.Steps; i++) { if (w == 0) { w = 0.001; // watch out for divide by zero } fitPoints[i] = n + q * (1 / (1 + (((ramp[i] - c) * (ramp[i] - c)) / ((w / 2) * (w / 2))))); } ui.ScatterGraphPlot(ui.SlaveLaserIntensityScatterGraph, ui.SlaveFitPlot, ramp, fitPoints); }
/// <summary> /// A function to scan across the voltage range set by the limits high and low. /// Reads from the two photodiodes and spits out an array. /// The basic unit of the program. /// </summary> private CavityScanData scan(ScanParameters sp) { CavityScanData scanData = new CavityScanData(sp.Steps, 2); scanData.parameters = sp; double[] voltages = sp.CalculateRampVoltages(); tcl.ScanCavity(voltages, false); tcl.StartScan(); Thread.Sleep(1); tcl.SendScanTriggerAndWaitUntilDone(); scanData.PhotodiodeData = tcl.ReadPhotodiodes(sp.Steps); tcl.StopScan(); return(scanData); }
/// <summary> /// A function to scan across the voltage range set by the limits high and low. /// Reads from the two photodiodes and spits out an array. /// The basic unit of the program. /// </summary> private CavityScanData scan(ScanParameters sp) { CavityScanData scanData = new CavityScanData(sp.Steps, 2); scanData.parameters = sp; double[] voltages = sp.CalculateRampVoltages(); tcl.ScanCavity(voltages, false); tcl.StartScan(); Thread.Sleep(1); tcl.SendScanTriggerAndWaitUntilDone(); scanData.PhotodiodeData = tcl.ReadPhotodiodes(sp.Steps); tcl.StopScan(); return scanData; }
private void displaySlaveFit(ScanParameters sp, double[] fitCoefficients) { double[] fitPoints = new double[sp.Steps]; double[] ramp = sp.CalculateRampVoltages(); double n = fitCoefficients[3]; double q = fitCoefficients[2]; double c = fitCoefficients[1]; double w = fitCoefficients[0]; for (int i = 0; i < sp.Steps; i++) { if (w == 0) w = 0.001; // watch out for divide by zero fitPoints[i] = n + q * (1 / (1 + (((ramp[i] - c) * (ramp[i] - c)) / ((w / 2) * (w / 2))))); } ui.ScatterGraphPlot(ui.SlaveLaserIntensityScatterGraph, ui.SlaveFitPlot, ramp, fitPoints); }
private ScanParameters createInitialScanParameters() { ScanParameters sp = new ScanParameters(); sp.Steps = numberOfPoints; sp.Low = ScanOffset - scanWidth; sp.High = ScanOffset + scanWidth; sp.SleepTime = 0; return sp; }
/// <summary> /// This adjusts the scan range of the next scan, so that the HeNe peak stays in the middle of the scan. /// It modifies the scan parameters that are passed to it. /// </summary> private double calculateNewScanCentre(ScanParameters scanParameters, double[] fitCoefficients) { double newCentroid = new double(); if (fitCoefficients[1] - scanWidth > LOWER_CC_VOLTAGE_LIMIT && fitCoefficients[1] + scanWidth < UPPER_CC_VOLTAGE_LIMIT && fitCoefficients[1] < scanParameters.High && fitCoefficients[1] > scanParameters.Low) //Only change limits if fits are reasonable. { newCentroid = fitCoefficients[1]; } else { newCentroid = scanParameters.High - scanWidth; } Console.WriteLine(newCentroid); return newCentroid; }
/// <summary> /// The main loop. Scans the cavity, looks at photodiodes, corrects the cavity scan range for the next /// scan and locks the laser. /// It does a first scan of the data before starting. /// It then enters a loop where the next scan is prepared. The preparation varies depending on /// the ControllerState. Once all the preparation is done, the next scan is started. And so on. /// </summary> private void rampLoop() { readParametersFromUI(); ScanParameters sp = createInitialScanParameters(); initializeHardware(); CavityScanData scanData = scan(sp); double[] masterDataFit; double[] slaveDataFit; System.IO.StreamWriter file = new System.IO.StreamWriter("c:\\cavityData.txt"); while (State != ControllerState.STOPPED) { displayData(sp, scanData); masterDataFit = CavityScanFitHelper.FitLorenzianToMasterData(scanData, sp.Low, sp.High); saveFitData(file, masterDataFit[1]); displayMasterFit(sp, masterDataFit); slaveDataFit = CavityScanFitHelper.FitLorenzianToSlaveData(scanData, sp.Low, sp.High); saveFitData(file, slaveDataFit[1]); displaySlaveFit(sp, slaveDataFit); switch (State) { case ControllerState.FREERUNNING: releaseLaser(); break; case ControllerState.CAVITYSTABILIZED: ScanOffset = calculateNewScanCentre(sp, masterDataFit); sp.High = ScanOffset + scanWidth; sp.Low = ScanOffset - scanWidth; setToLaserEngaged(); break; case ControllerState.LASERLOCKING: ScanOffset = calculateNewScanCentre(sp, masterDataFit); sp.High = ScanOffset + scanWidth; sp.Low = ScanOffset - scanWidth; LaserSetPoint = CalculateLaserSetPoint(masterDataFit, slaveDataFit); State = ControllerState.LASERLOCKED; ui.updateUIState(State); break; case ControllerState.LASERLOCKED: ScanOffset = calculateNewScanCentre(sp, masterDataFit); sp.High = ScanOffset + scanWidth; sp.Low = ScanOffset - scanWidth; LaserSetPoint = tweakSetPoint(LaserSetPoint); //does nothing if not tweaked /*Console.WriteLine("width=" + slaveDataFit[0].ToString() + ", centre =" + slaveDataFit[1].ToString() + ", amp=" + slaveDataFit[2].ToString() + ", offset=" + slaveDataFit[3].ToString());*/ double shift = calculateDeviationFromSetPoint(LaserSetPoint, masterDataFit, slaveDataFit); VoltageToLaser = calculateNewVoltageToLaser(VoltageToLaser, shift); break; } if (lState == LaserState.BUSY) { tcl.SetLaserVoltage(VoltageToLaser); } scanData = scan(sp); } file.Close(); finalizeRamping(); }