示例#1
0
        private void bCal_Click(object sender, EventArgs e)
        {
            Form_Main.Instance.imageSet.Image.WriteBmpFile("D://1.bmp");
            Thread.Sleep(50);
            double value = 0;

            VisionHelper.GetImageDefinitionValue("D://1.bmp", out value);
            this.tAppend.AppendText($"清晰度:{value} \n");
        }
示例#2
0
        private void bAutoCal_Click(object sender, EventArgs e)
        {
            this.bAutoCal.Enabled = false;
            Count = 0;
            double last  = 0;
            double value = 0;

            Variable.VelMode vel = new Variable.VelMode(0, 100, 300, 300);
            AutoTimer.Start();
            int    JumpCount = 0;
            double MoveTirm  = 1;
            double MaxValue  = 0;
            double MaxZ      = 0;
            bool   first     = true;

            if (this.cb_SelectNz.SelectedIndex >= 0)
            {
                Form_Main.Instance.imageSet.Image.WriteBmpFile("D://1.bmp");
                int Dir = 1; // 正向寻找

                Thread.Sleep(100);
                Application.DoEvents();
                VisionHelper.GetImageDefinitionValue("D://1.bmp", out last);
                Form_Main.Instance.Z_RunParamMap[(uint)this.cb_SelectNz.SelectedIndex].MoveTrim(Dir * MoveTirm, vel);
                MaxValue = last;
                MaxZ     = Form_Main.Instance.Z_RunParamMap[(uint)this.cb_SelectNz.SelectedIndex].Pos;
                while (Count < 120)
                {
                    Thread.Sleep(100);
                    Application.DoEvents();
                    Form_Main.Instance.imageSet.Image.WriteBmpFile("D://1.bmp");

                    Thread.Sleep(100);
                    Application.DoEvents();
                    VisionHelper.GetImageDefinitionValue("D://1.bmp", out value);

                    if (value > MaxValue)
                    {
                        MaxValue = value;
                        MaxZ     = Form_Main.Instance.Z_RunParamMap[(uint)this.cb_SelectNz.SelectedIndex].Pos;
                    }

                    if (value > last)
                    {
                        Form_Main.Instance.Z_RunParamMap[(uint)this.cb_SelectNz.SelectedIndex].MoveTrim(Dir * MoveTirm, vel);
                        Thread.Sleep(100);
                    }
                    else
                    {
                        Dir = -1 * Dir;

                        if (!first)
                        {
                            JumpCount++;
                            if (JumpCount > 3)
                            {
                                JumpCount = 0;
                                MoveTirm  = MoveTirm / 2;
                                if (MoveTirm < 0.1)
                                {
                                    // Find OK
                                    break;
                                }
                            }
                        }
                        first = false;
                    }

                    last = value;
                    this.tAppend.AppendText($"清晰度:{value} \n");
                }

                Thread.Sleep(100);
                Form_Main.Instance.Z_RunParamMap[(uint)this.cb_SelectNz.SelectedIndex].StopAxis();
                Form_Main.Instance.Z_RunParamMap[(uint)this.cb_SelectNz.SelectedIndex].CleSts();
                Form_Main.Instance.Z_RunParamMap[(uint)this.cb_SelectNz.SelectedIndex].GoPos(MaxZ, vel);
            }

            AutoTimer.Stop();

            this.bAutoCal.Enabled = true;
        }