Bläddra i källkod

add dedicated classes to do the all kinds of special work ,such as focus,locate,photo,etc. only in EDS task.

gsp 4 år sedan
förälder
incheckning
dd900c85ad

+ 2 - 0
HOZProject/FormHOZMain.cs

@@ -328,7 +328,9 @@ namespace HOZProject
 
 
                 log = NLog.LogManager.GetCurrentClassLogger();
+
                 ConfigurationParameter();
+
                 this.Left = this.Location.X + logwin.Width / 2;
             }
             catch (Exception ex)

+ 62 - 8
MeasureThread/Focus.cs

@@ -22,7 +22,53 @@ namespace MeasureThread
             this.iSEM = iSEM ?? throw new ArgumentNullException(nameof(iSEM));
             this.log = log ?? throw new ArgumentNullException(nameof(log));
         }
+        public bool DoFocusByNewMagnification(float newMag)
+        {
+
+            // set magnification
+            bool mRetMag = iSEM.SetMagnification(newMag);
+
+            Thread.Sleep(500);
+            // 
+           
+
+            // set the window of focusing.
+            iSEM.SetReduced(prm.reduceWindowPos.X, prm.reduceWindowPos.Y, (int)prm.reduceWinWidth, (int)prm.reduceWinHeight);
 
+            iSEM.CmdFocusScanSpeed("CMD_SCANRATE5");//
+            if (prm.IfAutoBrightnessAndContrast)
+            {
+                iSEM.SetAutoVideoBrightnessAndContrast();
+                Thread.Sleep(5000);
+            }
+            else
+            {
+                iSEM.SetAutoVideoOff();
+                Thread.Sleep(200);
+                iSEM.SetBrightness(prm.brightness);//50.0f
+                Thread.Sleep(200);
+                iSEM.SetContrast(prm.contrast);//30.0f
+                Thread.Sleep(200);
+            }
+            if (!ImageFocus1(true))
+            {
+                log.Error("自动对焦失败,程序退出。", false);
+
+                return false;
+            }
+
+            iSEM.CloseReduced();
+            Thread.Sleep(200);
+
+            iSEM.SetAutoVideoBrightnessAndContrast();
+
+            float cycle_time = iSEM.GetCycleTime();
+            Thread.Sleep(1000 + Convert.ToInt32(cycle_time));
+
+            return true;
+
+
+        }
         public bool DoFocus()
         {
             
@@ -42,19 +88,27 @@ namespace MeasureThread
             //}
             Thread.Sleep(500);
             // 
-            if (!TiltCorrection(54.0f))
+            if (!TiltCorrection(prm.tiltCorrAngle))
             {               
                 return false;
             }
-            if (!iSEM.SetWorkingDistance(prm.workingDis/1000))
+             float wd = iSEM.GetWorkingDistance();
+
+           float offsetWd = Math.Abs(prm.workingDis - wd*1000);
+            if (offsetWd > 0.5)//如果相差0.5mm以上,则重新设置,否则不动
             {
-                //log.Error("测量线程报错:重新设置到标准工作距离失败。", false);
-                return false;
+                if (!iSEM.SetWorkingDistance(prm.workingDis / 1000))
+                {
+
+                    return false;
+                }
+
             }
+     
             // set the window of focusing.
-            iSEM.SetReduced(402, 128, 400, 400);
+            iSEM.SetReduced(prm .reduceWindowPos.X, prm.reduceWindowPos.Y, (int)prm.reduceWinWidth, (int)prm .reduceWinHeight);
 
-            iSEM.CmdFocusScanSpeed(prm.ScanSpeed);//
+            iSEM.CmdFocusScanSpeed("CMD_SCANRATE5");//
             if (prm.IfAutoBrightnessAndContrast)
             {
                 iSEM.SetAutoVideoBrightnessAndContrast();
@@ -71,7 +125,7 @@ namespace MeasureThread
             }
             if (!ImageFocus1(true))
             {
-                log.Error("测量线程报错:拉直操作自动对焦失败,程序退出。", false);
+                log.Error("自动对焦失败,程序退出。", false);
                 
                 return false;
             }
@@ -82,7 +136,7 @@ namespace MeasureThread
             iSEM.SetAutoVideoBrightnessAndContrast();
            
            float cycle_time = iSEM.GetCycleTime();
-            Thread.Sleep(100 + Convert.ToInt32(cycle_time));
+            Thread.Sleep(1000 + Convert.ToInt32(cycle_time));
 
             return true;
         }

+ 2 - 0
MeasureThread/IFocus.cs

@@ -10,6 +10,7 @@ namespace MeasureThread
     interface IFocus
     {
         bool DoFocus();
+        bool DoFocusByNewMagnification(float newMag);
         void setFocusParam(Focusparam param);
     }
 
@@ -27,5 +28,6 @@ namespace MeasureThread
         public float contrast;
         public int delayTime;//ms
         public string ScanSpeed;
+        public float tiltCorrAngle;
     }
 }

+ 164 - 9
MeasureThread/Locate.cs

@@ -11,10 +11,27 @@ namespace MeasureThread
 {
     class Locate : ILocate
     {
+        struct PositionRecord
+        {
+           public float xs;
+           public float ys;
+           public float xpCur;
+           public float ypCur;
+            public float magCur;
+        }
+        private PositionRecord pr=new PositionRecord();
         NLog.Logger log;
         private LocateParam prm;
         private ISEMControl iSEM;
+        const float Z_Min = 0;
+        const float Z_Max = 0.05f;
+        public Locate(ISEMControl iSEM)
+        {
+            this.log = NLog.LogManager.GetCurrentClassLogger();
 
+           
+            this.iSEM = iSEM ?? throw new ArgumentNullException(nameof(iSEM));
+        }
         public Locate( LocateParam prm, ISEMControl iSEM)
         {
             this.log = NLog.LogManager.GetCurrentClassLogger();
@@ -23,15 +40,157 @@ namespace MeasureThread
             this.prm = prm ?? throw new ArgumentNullException(nameof(prm));
             this.iSEM = iSEM ?? throw new ArgumentNullException(nameof(iSEM));
         }
+        public void RecordCurrentBeamShiftAndStagePosition()
+        {
+            #region 记录初始设置的BeamShift的百分比和样品台XY位置
+            pr. xs = iSEM.GetBeamShiftX();
+            Thread.Sleep(200);
+            pr. ys = iSEM.GetBeamShiftY();
+            Thread.Sleep(200);
+            pr. xpCur = iSEM.GetStageAtX();
+            Thread.Sleep(200);
+            pr. ypCur = iSEM.GetStageAtY();
+            Thread.Sleep(200);
+            pr.magCur = iSEM.GetMagnification();
+            Thread.Sleep(500);
+            log.Info("原来的光束偏移量x = " + pr.xs.ToString()
+                + "y=" + pr.ys.ToString() + ","
+                + "原来样品台的位置x= " +pr. xpCur.ToString()
+                + "y=" + pr.ypCur.ToString(), true);
+            #endregion
+
+        }
+        public void RestoreLastBeamShiftAndStagePosition()
+        {
+            #region 恢复到拍照的状态
+            log.Info("恢复到拍照的状态!");
+            iSEM.SetStageGotoX(pr.xpCur);
+            while (true)
+            {
+                Thread.Sleep(1000);
+
+                if (iSEM.GetStageIs() == 0)
+                {
+                    break;
+                }
+            }
+            iSEM.SetStageGotoY(pr.ypCur);
+            while (true)
+            {
+                Thread.Sleep(1000);
+
+                if (iSEM.GetStageIs() == 0)
+                {
+                    break;
+                }
+            }
+
+            //恢复原来的放大倍数
+            log.Info("恢复原来的放大倍数! " + pr.magCur);
+            if (!iSEM.SetMagnification(pr.magCur))
+            {
+                log.Error("恢复放大倍数失败", false);
+                return;
+            }
+            float cycle_time = iSEM.GetCycleTime();
+            Thread.Sleep(100 + Convert.ToInt32(cycle_time));
+
+            //set = MParam.Photograph_Magnification;
+            //current = iSEM.GetMagnification();
+            //while (Math.Abs(current - set) > 1)
+            //{
+            //    iSEM.SetMagnification(set);
+            //    Thread.Sleep(200);
+            //    current = iSEM.GetMagnification();
+            //}
+
+
+            //恢复BeamShift的百分比值
+            iSEM.SetBeamShiftX(pr.xs);
+            Thread.Sleep(200);
+            iSEM.SetBeamShiftY(pr.ys);
+            Thread.Sleep(200);
+
+            #endregion
+
+        }
+        public enum ZAxisDirection
+        {
+            up=0,
+            down=1
+        }
+        public bool MoveZAxis(float value, ZAxisDirection d )
+        {
+            if (value < Z_Min || value> Z_Max)
+            {
+                log.Info("Z轴位置设置超出范围.", true);
+                return false;
+            }
+            float curZ = iSEM.GetStageAtZ();
+            float targetZ;
+            if (d == ZAxisDirection.up)
+            {
+                targetZ = curZ + value;
+            }
+            else
+            {
+                targetZ = curZ - value;
+            }
+
+            log.Info("将Z轴位置指定到:" + value.ToString(), true);
+            if (!iSEM.SetStageGotoZ(targetZ))
+            {
+                log.Error("样品台Z轴移到位置失败", false);
+                return false;
+            }
+
+
+            while (true)
+            {
+                Thread.Sleep(500);
+                if (iSEM.GetStageIs() == 0)
+                {
+                    break;
+                }
+            }
+            return true;
+        }
+
+        public bool MoveZAxisByAbs(float value)
+        {
+            if (value < Z_Min || value > Z_Max)
+            {
+                log.Info("Z轴位置设置超出范围.", true);
+                return false;
+            }
+         
+
+            log.Info("将Z轴位置指定到:" + value.ToString(), true);
+            if (!iSEM.SetStageGotoZ(value))
+            {
+                log.Error("样品台Z轴移到位置失败", false);
+                return false;
+            }
+
+
+            while (true)
+            {
+                Thread.Sleep(2000);
+                if (iSEM.GetStageIs() == 0)
+                {
+                    break;
+                }
+            }
+            return true;
+        }
 
-       
         //移动到像素位置,这里要靠移动样品台实现,当位移量小于3um时,不予移动
         bool MoveToPixByMoveStage(float xc, float yc)
         {
             //单位是m/pix
             float XpixSize = iSEM.GetPixelSize();
             log.Info("X像素尺寸=" + XpixSize.ToString() + "m/pixel", true);
-            float YpixSize = iSEM.GetPixelSize()/prm.PixelSize_Y_cur;///(float)MParam.PixelSizeCor);
+            float YpixSize = iSEM.GetPixelSize();///(float)MParam.PixelSizeCor);
             log.Info("Y像素尺寸=" + YpixSize.ToString() + "m/pixel", true);
 
             Thread.Sleep(500);
@@ -60,9 +219,6 @@ namespace MeasureThread
 
             log.Info("目标位置(" + xpNew.ToString() + "," + ypNew.ToString() + "),单位m", true);
 
-            //计算光束偏移值:
-            //if (deltX >= 0.000003 || deltX <= 0.000003)//大于3um使用移动样品台实现
-            {
                 log.Info("X方向移动样品台", true);
 
                 if (!iSEM.SetStageGotoX(xpNew))
@@ -79,10 +235,9 @@ namespace MeasureThread
                         break;
                     }
                 }
-            }
+          
 
-            //if (deltY >= 0.000003 || deltY <= -0.000003)//大于3um使用移动样品台实现
-            {
+        
                 log.Info("Y方向移动样品台", true);
 
                 if (!iSEM.SetStageGotoY(ypNew))
@@ -99,7 +254,7 @@ namespace MeasureThread
                         break;
                     }
                 }
-            }
+          
 
             return true;
         }

+ 47 - 71
MeasureThread/Measure.cs

@@ -433,7 +433,7 @@ namespace MeasureThread
         const String ElyCrossSection = @"CrossSection.ely"; //切割
 
         const float fMin = (float)0.0000002; //单位是米
-        const float fSateyZ = (float)0.03;//单位是米
+        const float fSateyZ = (float)0.007;//单位是米
 
         public Boolean key_stop = false;
 
@@ -682,7 +682,8 @@ namespace MeasureThread
                     //0、先移动Z轴到比较低的位置上。
                     if (MParam.Tilt)//如果是倾斜样品台,移动Z轴
                     {
-                        if (!iSEM.SetStageGotoZ(fSateyZ))
+                        Locate lo = new Locate(iSEM);
+                        if (!lo.MoveZAxis(fSateyZ, Locate.ZAxisDirection.down))
                         {
                             arg.State = false;
                             arg.Message = "样品台移动到观测点:" + m_cutHoles[i] + "的位置失败。";
@@ -3668,7 +3669,7 @@ namespace MeasureThread
                                     Segment segment = new Segment();
                                     segment.X = LinesStartPoint[i].X;
                                     segment.Y = LinesStartPoint[i].Y + j;
-                                    segment.Length = 1;
+                                    segment.Length = 2;
                                     segments.Add(segment);
                                 }
                                 listFeature.Add(segments);
@@ -3918,12 +3919,13 @@ namespace MeasureThread
                 reduceWinWidth = 600,
                 ScanSpeed = MParam.ScanSpeedFocus,
                 IfAutoBrightnessAndContrast = true,
-                 delayTime=500,
-                  voltage=7000,
-                   Iprobe=0.5f,
-                    workingDis=10,//unit mm
-                     brightness =50,
-                     contrast =29,
+                delayTime = 500,
+                voltage = 7000,
+                Iprobe = 0.5f,
+                workingDis = 10,//unit mm
+                brightness = 50,
+                contrast = 29,
+                tiltCorrAngle = 36,
             };
           
          
@@ -3981,7 +3983,7 @@ namespace MeasureThread
                     Thread.Sleep(200);
                     //20201128陈工要求,谭博返回角度*0.7
 
-                    iSEM.SetScanRotation(Convert.ToSingle(degree * MParam.ScanRotCor));
+                    iSEM.SetScanRotation(Convert.ToSingle(degree * 0.7));
                     Thread.Sleep(200);
 
                     arg.State = true;
@@ -4054,7 +4056,8 @@ namespace MeasureThread
                 #endregion
                 if (state == 1 && ct.Count != 0 && mag.Count != 0)
                 {
-
+                    Locate recordPostion = new Locate(iSEM);
+                    recordPostion.RecordCurrentBeamShiftAndStagePosition();
                     //找到放大倍数最大值
                     magMax = mag[0];
                     for (int m = 1; m < mag.Count; m++)
@@ -4084,34 +4087,34 @@ namespace MeasureThread
                     {
                         mag = magMax / 4,
                         reduceWindowPos = new System.Drawing.Point(402, 128),
-                        reduceWinHeight = 480,
-                        reduceWinWidth = 450,
+                        reduceWinHeight = 600,
+                        reduceWinWidth = 600,
                         ScanSpeed = MParam.ScanSpeedFocus,
-                        IfAutoBrightnessAndContrast = true,
+                        IfAutoBrightnessAndContrast = false,
                         delayTime = 500,
                         voltage = 7000,
                         Iprobe = 0.5f,
                         workingDis = 10 ,
-                        brightness = 50,
-                        contrast = 29,
+                        brightness = 49.4f,
+                        contrast = 30.1f,
+                         tiltCorrAngle =36,
                     };
                                                                                           
-                    log.Info("自动对焦开始!", true);
-                    Focus f1 = new Focus(fprm, iSEM);
+                    log.Info("自动对焦1开始!", true);
+                    Focus f1 = new Focus(fprm1, iSEM);
                     f1.DoFocus();
 
-                    fprm.mag = magMax / 2;
 
-                   
+                    log.Info("自动对焦2开始!", true);
+
+                    f1.DoFocusByNewMagnification(magMax / 2);
 
-                    log.Info("自动对焦开始!", true);
-                    Focus f2= new Focus(fprm, iSEM);
-                    f2.DoFocus();
                     #endregion
 
 
                     log.Warn("对焦完成,开始用能谱拍摄观测点照片!并分析图片以获得Xray点位置!");
-                   
+
+                    recordPostion.RestoreLastBeamShiftAndStagePosition();
 
                     log.Warn("移动到指定观测点!并准备打Xray");
                     LocateParam locp = new LocateParam()
@@ -4135,21 +4138,14 @@ namespace MeasureThread
                 log.Info("开始拍照,设置放大倍数" + mag[0]);
                 if (!iSEM.SetMagnification(mag[0]))
                 {
-                    log.Error("移动到第一个点位置拍照失败", false);
+                    log.Error("设置放大倍数失败", false);
                     return false;
                 }
 
-                Thread.Sleep(100 + Convert.ToInt32(cycle_time));
+                Thread.Sleep(300 + Convert.ToInt32(cycle_time));
 
-               float set = mag[0];
-               float current = iSEM.GetMagnification();
-                //while (Math.Abs(current - set) > 1)
-                //{
-                //    iSEM.SetMagnification(set);
-                //    Thread.Sleep(200);
-                //    current = iSEM.GetMagnification();
-                //}
-                Thread.Sleep(200);
+               
+             
 
                 //add by zjx 2020-12-21 根据客户的需求修改图片的名称
                 String fileName7 = data_path + "\\EDS\\" + MParam.Firm + "-" + mag[0].ToString() + "-" + m_cutHoles[m_nWorkHoleNo].HoleName + "-0-" + ImageNameTwo_1;
@@ -4211,28 +4207,9 @@ namespace MeasureThread
         public bool EDS_Analysis()
         {
             //1.先降Z轴  37.241左右使工作距离从5mm 变为 10mm,这样方便能谱工作,麻烦是需要从新对焦。由于移动样品台会有误差,容易造成图像偏移,最好从新定位
-            if (MParam.EDSZ < Z_Min || MParam.EDSZ > Z_Max)
-            {
-                log.Info("Z轴位置设置超出范围.", true);
-                return false;
-            }
-            log.Info("将Z轴位置指定到:" + MParam.EDSZ.ToString(), true);
-            if (!iSEM.SetStageGotoZ(MParam.EDSZ))
-            {
-                log.Error("测量线程报错:样品台Z回到安全位置失败", false);
-                return false;
-            }
-
-
-            while (true)
-            {
-                Thread.Sleep(2000);
-                if (iSEM.GetStageIs() == 0)
-                {
-                    break;
-                }
-            }
-
+            Locate lo = new Locate(iSEM);
+            
+            lo.MoveZAxisByAbs(MParam.EDSZ);          
 
             //判断是否停止进程
             if (key_stop)
@@ -4241,32 +4218,34 @@ namespace MeasureThread
                 return false;
             }
             SendMsg("4-0");
-            Thread.Sleep(200);
+           
             //2.角度改为54度
             iSEM.SetScanRotationOff();
 
+
+            Thread.Sleep(200);
+
             Focusparam focusPrm = new Focusparam()
             {
-                
+
                 voltage = 7000,
                 Iprobe = 0.5F,
                 IfAutoBrightnessAndContrast = true,
                 ScanSpeed = MParam.ScanSpeedHigh,
                 mag = 600,
                 reduceWindowPos = new System.Drawing.Point(256, 192),
-                reduceWinWidth = 512,
-                reduceWinHeight = 512,
+                reduceWinWidth = 400,
+                reduceWinHeight = 400,
                 workingDis = 10,//unit:mm
-                brightness=50,
-                contrast=29
-            };
-
-           SendMsg("4-1");
+                brightness = 50,
+                contrast = 29,
+                tiltCorrAngle =54,
+                 
+            };          
             Focus f = new Focus(focusPrm, iSEM);
             f.DoFocus();
 
-
-
+            SendMsg("4-1");
             log.Warn("开始梯形移到视野中心!");
            
             if (!EDS_FindCross())
@@ -4274,7 +4253,6 @@ namespace MeasureThread
                 return false;
             }
             SendMsg("4-3");
-            Thread.Sleep(500);
             //7.调用171步过程
 
             log.Warn("开始打能谱图和打Xray!");
@@ -4284,8 +4262,6 @@ namespace MeasureThread
             {
                 return false;
             }
-            //SendMsg("4-3");//向界面发送指令:移动到拍摄点位置
-            Thread.Sleep(200);
             return true;
         }
 

+ 1 - 1
MeasureThread/Photo.cs

@@ -55,7 +55,7 @@ namespace MeasureThread
             }
             iSEM.CmdFocusScanSpeed(prm.scanSpeedAfter);//CmdFocusRate(4);
             cycle_time = iSEM.GetCycleTime();
-            Thread.Sleep(Convert.ToInt32(cycle_time) + 100);
+            Thread.Sleep(Convert.ToInt32(cycle_time) + 1000);
            
             return true;
         }

+ 1 - 1
OxfordTest/Form1.cs

@@ -283,7 +283,7 @@ namespace OxfordTest
             
             long[] XrayData = new long[2000];
             Dictionary<string, double> listElement = new Dictionary<string, double>();
-            iExtender.XrayPointCollecting(200,44, 55, out XrayData, out listElement);
+            iExtender.XrayPointCollecting(2000,Convert.ToInt32(txtpx1.Text), Convert.ToInt32(txtpy1.Text), out XrayData, out listElement);
 
             ShowData(XrayData, listElement);
             li++;