A class to represent the laser you are trying to lock. It knows how to calculate what voltage to send to the laser based on the fit coefficients from the data, and it knows how to control the laser (through a helper interface only).
示例#1
0
 public Cavity(TCLSingleCavityConfig config)
 {
     Name   = config.Name;
     Master = new MasterLaser(config.RampOffset, config.MasterLaser, this);
     if (config.DefaultGains.ContainsKey("Master"))
     {
         Master.Gain = config.DefaultGains["Master"];
     }
     else
     {
         Master.Gain = 1.0;
     }
     SlaveLasers = new Dictionary <string, SlaveLaser>();
     foreach (KeyValuePair <string, string> entry in config.SlaveLasers)
     {
         string     laser = entry.Key;
         SlaveLaser slave = new SlaveLaser(laser, entry.Value, this);
         slave.FSRCalibration = config.FSRCalibrations[entry.Key];
         if (config.DefaultGains.ContainsKey(laser))
         {
             slave.Gain = config.DefaultGains[laser];
         }
         else
         {
             slave.Gain = 0.0;
         }
         if (config.BlockChannels.ContainsKey(laser))
         {
             slave.BlockChannel = config.BlockChannels[laser];
         }
         SlaveLasers.Add(laser, slave);
     }
 }
示例#2
0
        public void DisengageLock(string cavityName, string slaveName)
        {
            SlaveLaser laser = Cavities[cavityName].SlaveLasers[slaveName];

            laser.DisengageLock();
            ui.UpdateSlaveUIState(cavityName, slaveName, laser.lState);
        }
示例#3
0
        public void EngageLock(string cavityName, string slaveName)
        {
            SlaveLaser laser = Cavities[cavityName].SlaveLasers[slaveName];

            laser.ArmLock();
            ui.UpdateSlaveUIState(cavityName, slaveName, laser.lState);
            ui.ClearErrorGraph(cavityName, slaveName);
        }
示例#4
0
        public void AddSlaveLaserPanel(SlaveLaser sl)
        {
            string           title  = sl.Name;
            TabPage          newTab = new TabPage(title);
            LockControlPanel panel  = new LockControlPanel(title, sl.LowerVoltageLimit, sl.UpperVoltageLimit, sl.Gain, this, this.controller);

            slaveLasersTab.TabPages.Add(newTab);
            newTab.Controls.Add(panel);
            slaveLasersTab.Enabled = true;
            SlaveLaserPanels.Add(title, panel);
        }
示例#5
0
 public void AddSlaveLaser(SlaveLaser sl)
 {
     string title = sl.Name;
     TabPage newTab = new TabPage(title);
     LockControlPanel panel = new LockControlPanel(title,sl.LowerVoltageLimit,sl.UpperVoltageLimit);
     panel.controller = this.controller;
     slaveLasersTab.TabPages.Add(newTab);
     newTab.Controls.Add(panel);
     slaveLasersTab.Enabled = true;
     slaveLasers.Add(title, panel);
 }
示例#6
0
        /// <summary>
        /// The function which gets called at the end, after breaking out of the while loop.
        /// </summary>
        private void endRamping()
        {
            tcl.DisposeAITask();
            foreach (KeyValuePair <string, SlaveLaser> pair in SlaveLasers)
            {
                string     slName = pair.Key;
                SlaveLaser sl     = pair.Value;

                if (sl.lState != SlaveLaser.LaserState.FREE)
                {
                    sl.VoltageToLaser = 0.0;
                    sl.DisengageLock();
                    sl.DisposeLaserControl();
                }
            }
        }
示例#7
0
 private void updateGUIForSlaveLaser(SlaveLaser laser, double[] rampData)
 {
     double[] laserScanData = laser.LatestScanData;
     if (laser.Fit != null)
     {
         double[] fitPoints = CavityScanFitHelper.CreatePointsFromFit(rampData, laser.Fit);
         ui.DisplaySlaveData(laser.ParentCavity.Name, laser.Name, rampData, laserScanData, fitPoints);
         if (laser.LockCount > 0)
         {
             ui.SetLaserVoltageTextBox(laser.ParentCavity.Name, laser.Name, laser.CurrentVoltage);
             bool laserInNormalOperatingRange = laser.CurrentVoltage <laser.UpperVoltageLimit && laser.CurrentVoltage> laser.LowerVoltageLimit;
             bool laserIsLocked = laser.lState == Laser.LaserState.LOCKED;
             ui.SetLaserOperatingLED(laser.ParentCavity.Name, laser.Name, laserIsLocked, laserInNormalOperatingRange);
             List <double> errorList   = laser.OldFrequencyErrors;
             double        standardDev = Math.Sqrt(errorList.Average(x => x * x));
             ui.SetLaserSDTextBox(laser.ParentCavity.Name, laser.Name, standardDev);
             ui.AppendToErrorGraph(laser.ParentCavity.Name, laser.Name, laser.LockCount, laser.FrequencyError);
         }
     }
     else
     {
         ui.DisplaySlaveData(laser.ParentCavity.Name, laser.Name, rampData, laserScanData);
     }
 }
示例#8
0
        /// <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();
        }
示例#9
0
 /// <summary>
 /// The controller needs to be able to change the UI. Enabling buttons, changing the values in text boxes...
 /// </summary>
 /// <param name="name"></param>
 /// <param name="state"></param>
 public void UpdateUIState(string name, SlaveLaser.LaserState state)
 {
     ui.UpdateUIState(name, state);
 }
示例#10
0
        /// <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();
        }
示例#11
0
 internal void UpdateUIState(string name, SlaveLaser.LaserState state)
 {
     slaveLasers[name].UpdateUIState(state);
 }
示例#12
0
        /// <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();
        }
示例#13
0
        public void UpdateUIState(SlaveLaser.LaserState state)
        {
            switch (state)
            {
                case SlaveLaser.LaserState.FREE:
                    lockEnableCheck.Enabled = true;
                    VoltageToLaserTextBox.Enabled = true;
                    LaserSetPointTextBox.Enabled = false;
                    GainTextbox.Enabled = true;
                    lockedLED.Value = false;
                    VoltageTrackBar.Enabled = true;
                    fsrTextBox.Enabled = true;
                    break;

                case SlaveLaser.LaserState.LOCKING:
                    VoltageToLaserTextBox.Enabled = false;
                    GainTextbox.Enabled = false;
                    lockedLED.Value = false;
                    VoltageTrackBar.Enabled = false;
                    fsrTextBox.Enabled = false;
                    break;

                case SlaveLaser.LaserState.LOCKED:
                    lockedLED.Value = true;
                    break;

            }
        }