コード例 #1
0
        public static double[] FitLorenzianToSlaveData(CavityScanData data, double limitLow, double limitHigh)
        {
            double[] voltages = data.parameters.CalculateRampVoltages();

            LorentzianFitter lorentzianFitter = new LorentzianFitter();

            // takes the parameters (in this order, in the double[])
            // N: background
            // Q: signal
            // c: centre
            // w: width

            dataPoint max = getMax(data.SlavePhotodiodeData);
            dataPoint min = getMin(data.SlavePhotodiodeData);

            lorentzianFitter.Fit(voltages, data.SlavePhotodiodeData,
                                 new double[] { min.value, max.value - min.value,
                                                voltages[max.index], (data.parameters.High - data.parameters.Low) / 10, });

            double[] coefficients = lorentzianFitter.Parameters;

            fitFailSafe(coefficients, limitLow, limitHigh);

            return(new double[] { coefficients[3], coefficients[2], coefficients[1], coefficients[0] }); //to be consistent with old convention.
        }
コード例 #2
0
ファイル: Controller.cs プロジェクト: bharath87/EDMSuite
 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);
 }
コード例 #3
0
        public static double[] FitLorenzianToSlaveData(CavityScanData data, double limitLow, double limitHigh)
        {
            double[] voltages = data.parameters.CalculateRampVoltages();

            LorentzianFitter lorentzianFitter = new LorentzianFitter();

            // takes the parameters (in this order, in the double[])
            // N: background
            // Q: signal
            // c: centre
            // w: width

            dataPoint max = getMax(data.SlavePhotodiodeData);
            dataPoint min = getMin(data.SlavePhotodiodeData);
            lorentzianFitter.Fit(voltages, data.SlavePhotodiodeData,
                new double[] {min.value, max.value - min.value,
                    voltages[max.index], (data.parameters.High - data.parameters.Low)/10,
                });

            double[] coefficients = lorentzianFitter.Parameters;

            fitFailSafe(coefficients, limitLow, limitHigh);

            return new double[] { coefficients[3], coefficients[2], coefficients[1], coefficients[0] }; //to be consistent with old convention.
        }
コード例 #4
0
        public static double[] FitLorenzianToSlaveData(CavityScanData data, double limitLow, double limitHigh)
        {
            double mse = 0;
            double[] voltages = data.parameters.CalculateRampVoltages();
            double[] coefficients = new double[] {(data.parameters.High - data.parameters.Low)/10, voltages[ArrayOperation.GetIndexOfMax(data.SlavePhotodiodeData)],
                ArrayOperation.GetMax(data.SlavePhotodiodeData) - ArrayOperation.GetMin(data.SlavePhotodiodeData), 0};
            CurveFit.NonLinearFit(voltages, data.SlavePhotodiodeData, new ModelFunctionCallback(lorentzianNarrow),
                    coefficients, out mse, 4000);
            fitFailSafe(coefficients, limitLow, limitHigh);

            return coefficients;
        }
コード例 #5
0
        public static double[] FitLorenzianToSlaveData(CavityScanData data, double limitLow, double limitHigh)
        {
            double mse = 0;

            double[] voltages     = data.parameters.CalculateRampVoltages();
            double[] coefficients = new double[] { (data.parameters.High - data.parameters.Low) / 10, voltages[ArrayOperation.GetIndexOfMax(data.SlavePhotodiodeData)],
                                                   ArrayOperation.GetMax(data.SlavePhotodiodeData) - ArrayOperation.GetMin(data.SlavePhotodiodeData), 0 };
            CurveFit.NonLinearFit(voltages, data.SlavePhotodiodeData, new ModelFunctionCallback(lorentzianNarrow),
                                  coefficients, out mse, 4000);
            fitFailSafe(coefficients, limitLow, limitHigh);

            return(coefficients);
        }
コード例 #6
0
ファイル: Controller.cs プロジェクト: bharath87/EDMSuite
        /// <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);
        }
コード例 #7
0
ファイル: Controller.cs プロジェクト: ColdMatter/EDMSuite
        /// <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;
        }
コード例 #8
0
ファイル: Controller.cs プロジェクト: ColdMatter/EDMSuite
 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);
 }
コード例 #9
0
ファイル: Controller.cs プロジェクト: bharath87/EDMSuite
        /// <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();
        }