/// <summary>
 /// R轴运行速度 乘以比例
 /// </summary>
 /// <param name="velMode"></param>
 /// <returns></returns>
 private Variable.VelMode ConvertReal2Pulse(Variable.VelMode velMode)
 {
     Variable.VelMode a = new Variable.VelMode();
     a.LowVel  = velMode.LowVel * (this.r_ratio) * (this.low_ratio);
     a.HighVel = velMode.HighVel * (this.r_ratio) * (this.high_ratio);
     a.Acc     = velMode.Acc * (this.r_ratio) * (this.acc_ratio);
     a.Dec     = velMode.Dec * (this.r_ratio) * (this.dec_ratio);
     return(a);
 }
        /// <summary>
        /// 设置轴速度
        /// </summary>
        /// <param name="velmode">速度模式</param>
        /// <returns></returns>
        public short AxisSetValue(Variable.VelMode velmode) // 設定速度,加速度範圍
        {
            short rtn = (short)Motion.mAcm_SetProperty(ipAxisHandle[AxisNo - 1], (uint)PropertyID.PAR_AxVelLow, ref velmode.LowVel, (uint)Marshal.SizeOf(typeof(double)));

            rtn += (short)Motion.mAcm_SetProperty(ipAxisHandle[AxisNo - 1], (uint)PropertyID.PAR_AxVelHigh, ref velmode.HighVel, (uint)Marshal.SizeOf(typeof(double)));
            rtn += (short)Motion.mAcm_SetProperty(ipAxisHandle[AxisNo - 1], (uint)PropertyID.PAR_AxAcc, ref velmode.Acc, (uint)Marshal.SizeOf(typeof(double)));
            rtn += (short)Motion.mAcm_SetProperty(ipAxisHandle[AxisNo - 1], (uint)PropertyID.PAR_AxDec, ref velmode.Dec, (uint)Marshal.SizeOf(typeof(double)));
            return(rtn);
        }
        /// <summary>
        /// 轴Jog运动
        /// </summary>
        /// <param name="LowVel">最低速度</param>
        /// <param name="HighVel">最高速度</param>
        /// <param name="acc">加速度</param>
        /// <param name="dec">减速度</param>
        /// <param name="isDirPositive">正负方向</param>
        /// <returns></returns>
        public short AxisMoveJog(Variable.VelMode velmode, bool isDirPositive)
        {
            short rtn = AxisSetValue(velmode);

            if (isDirPositive)
            {
                rtn += (short)Motion.mAcm_AxMoveVel(ipAxisHandle[AxisNo - 1], 0);
            }
            else
            {
                rtn += (short)Motion.mAcm_AxMoveVel(ipAxisHandle[AxisNo - 1], 1);
            }
            return(rtn);
        }
示例#4
0
        private void CalPasueHeight(Z_RunParam zParam, ref PointF cur, ref Variable.VelMode vel)
        {
            zParam.MoveTrim(zParam.MoveDir * 0.5, vel);
            Thread.Sleep(500);

            if (!zParam.Check_vaccum.GetIO())
            {
                this.CalPasueHeight(zParam, ref cur, ref vel);
            }
            else
            {
                return;
            }
        }
示例#5
0
 private void bAutoSet_Click(object sender, EventArgs e)
 {
     if (MessageBox.Show("是否以当前位置为贴附点进行,贴附高度确认!!", "Tips", MessageBoxButtons.YesNo) == DialogResult.Yes)
     {
         PointF cur = new PointF();
         cur.X = (float)Form_Main.Instance.X.Pos;
         cur.Y = (float)Form_Main.Instance.Y.Pos;
         Variable.VelMode vel = new Variable.VelMode(0, 100, 300, 300);
         for (uint nz = 0; nz < Variable.NOZZLE_NUM; ++nz)
         {
             Form_Main.Instance.XYGoPosTillStop(30000, Form_Main.Instance.NozzleToCamPoint(cur, (int)nz), vel);
             Z_RunParam zparam = Form_Main.Instance.Z_RunParamMap[nz];
             zparam.XI_vaccum.SetIO();
             this.CalPasueHeight(zparam, ref cur, ref vel);
             Thread.Sleep(500);
             var ctl = (TextBox)(this.Controls.Find($"tZ{nz + 1}", true)[0]);
             ctl.Text = zparam.Pos.ToString("f3");
             zparam.GoSafePos(vel);
             Thread.Sleep(2000);
             zparam.XI_vaccum.ResetIO();
         }
     }
 }
        /// <summary>
        /// R轴运动到一个位置直到停止
        /// </summary>
        /// <param name="Timeout_Millsecond"></param>
        /// <param name="deg"></param>
        /// <param name="velMode"></param>
        /// <returns></returns>
        public short RGoPosTillStop(double Timeout_Millsecond, double deg, Variable.VelMode velMode)
        {
            Stopwatch a   = new Stopwatch();
            double    mm  = deg * (this.r_ratio);
            short     rtn = 0;

            Variable.VelMode newVel = this.ConvertReal2Pulse(velMode);
            rAxis.AxisMoveTrap_Abs(mm, newVel.LowVel, newVel.HighVel, newVel.Acc, newVel.Dec);
            a.Start();

            while (Math.Abs(deg - this.RPos) > 0.02)
            {
                rtn += rAxis.GetAxisSts();

                if (a.ElapsedMilliseconds > Timeout_Millsecond)
                {
                    rAxis.StopAxis();
                    rtn = 1;
                    break;
                }
                Thread.Sleep(100);
            }
            return(rtn);
        }
示例#7
0
        public virtual short ChangePos(double mm, Variable.VelMode velMode)
        {
            VelMode newVel = this.ConvertReal2Pulse(velMode);

            return(this.AxisChangePos(mm, velMode));
        }
 /// <summary>
 /// R 到指定角度 附带初始值
 /// </summary>
 /// <param name="angle"></param>
 /// <param name="velMode"></param>
 /// <returns></returns>
 public short RGoPosWithInit(double angle, Variable.VelMode velMode)
 {
     //angle = this.DegreeNormal(angle);
     Variable.VelMode newVel = this.ConvertReal2Pulse(velMode);
     return(rAxis.AxisMoveTrap_Abs(angle * (this.r_ratio), newVel.LowVel, newVel.HighVel, newVel.Acc, newVel.Dec));
 }
 /// <summary>
 /// 移动到初始位置
 /// </summary>
 /// <param name="velMode"></param>
 /// <returns></returns>
 public short RGoInitPos(Variable.VelMode velMode)
 {
     return(this.RGoPos(this.init_pos, velMode));
 }
 /// <summary>
 /// R轴回原点
 /// </summary>
 /// <param name="homemode"></param>
 /// <param name="velMode"></param>
 /// <param name="IsDirP"></param>
 /// <returns></returns>
 public short RGoHome(Axis.HomeMode homemode, Variable.VelMode velMode, bool IsDirP)
 {
     Variable.VelMode newVel = this.ConvertReal2Pulse(velMode);
     return(rAxis.AxisGoHome(homemode, IsDirP, newVel.LowVel, newVel.HighVel, newVel.Acc, newVel.Dec));
 }
 /// <summary>
 /// R轴 JOG 运动
 /// </summary>
 /// <param name="velMode"></param>
 /// <param name="Dir_Pos"></param>
 /// <returns></returns>
 public short RJog(Variable.VelMode velMode, bool Dir_Pos)
 {
     Variable.VelMode newVel = this.ConvertReal2Pulse(velMode);
     return(rAxis.AxisMoveJog(newVel.LowVel, newVel.HighVel, newVel.Acc, newVel.Dec, Dir_Pos));
 }
示例#12
0
        /// <summary>
        /// 获得一个位置的CPK数据
        /// </summary>
        /// <param name="point">位置</param>
        /// <param name="cpkIni">配置信息</param>
        /// <param name="variable">速度</param>
        /// <param name="result">CPK 数据</param>
        /// <returns></returns>
        public static bool GetCPK(IniFile cpkIni, Variable.VelMode variable, double gain, double offset, int cycle, ref CPK_ResultItem result)
        {
            if (result == null)
            {
                return(false);
            }

            // 移动到目标位
            Form_Main.Instance.XYGoPosTillStop(20 * 1000, result.Pos, variable);

            Thread.Sleep(100);
            // 获得上相机图像
            VisionImage image = Form_Main.Instance.GrabImage2View(Camera.CAM.Top);

            if (image == null)
            {
                return(false);
            }

            for (int i = 0; i < cycle; ++i)
            {
                image = Form_Main.Instance.GainOffset(image, gain, offset);
            }

            // 初定位 寻找模板

            try
            {
                // NI 视觉检测方法
                List <PointContour> crossList = new List <PointContour>();
                List <LineContour>  lineList  = new List <LineContour>();
                for (int i = 0; i < 4; ++i) // 找4个角
                {
                    PointContour cross = new PointContour();
                    LineContour  line1 = new LineContour(); // 水平线
                    LineContour  line2 = new LineContour(); // 垂直线

                    bool rtn = false;
                    for (int retry = 0; retry < 3; retry++)
                    {
                        rtn = FindCorss(i, cpkIni, ref cross, ref line1, ref line2);
                        if (rtn)
                        {
                            break;
                        }
                    }

                    if (!rtn)
                    {
                        return(false);
                    }

                    //crossList.Add(cross);

                    lineList.Add(line1);
                    lineList.Add(line2);

                    PointContour center1 = new PointContour((line1.Start.X + line1.End.X) / 2.0, (line1.Start.Y + line1.End.Y) / 2.0);
                    PointContour center2 = new PointContour((line2.Start.X + line2.End.X) / 2.0, (line2.Start.Y + line2.End.Y) / 2.0);
                    crossList.Add(center1);
                    crossList.Add(center2);
                }

                if (lineList.Count != 8)
                {
                    return(false);
                }

                LineContour orgHLine = lineList[0]; // 基准水平线
                LineContour orgVLine = lineList[1]; // 基准垂直线

                //PointContour top =  crossList[1]; // 顶点
                //PointContour leftBottom = crossList[2]; // 左下角
                //PointContour rightTop = crossList[3]; // 右上角
                PointContour topV       = crossList[3];
                PointContour topH       = crossList[2];
                PointContour leftBottom = crossList[5];
                PointContour rightTop   = crossList[6];

                PointContour cross1 = Algorithms.FindIntersectionPoint(orgVLine, new LineContour(topV, new PointContour(topV.X + 10, topV.Y)));
                PointContour cross2 = Algorithms.FindIntersectionPoint(orgHLine, new LineContour(topH, new PointContour(topH.X, topH.Y + 10)));
                PointContour cross3 = Algorithms.FindIntersectionPoint(orgVLine, new LineContour(leftBottom, new PointContour(leftBottom.X + 10, leftBottom.Y)));
                PointContour cross4 = Algorithms.FindIntersectionPoint(orgHLine, new LineContour(rightTop, new PointContour(rightTop.X, rightTop.Y + 10)));

                PointF xy = new PointF();
                xy.X = (float)Form_Main.Instance.X.Pos;
                xy.Y = (float)Form_Main.Instance.Y.Pos;

                PointF tv = Form_Main.Instance.Point2CCDCenter(xy, topV, CAM.Top, 0);
                PointF th = Form_Main.Instance.Point2CCDCenter(xy, topH, CAM.Top, 0);
                PointF l  = Form_Main.Instance.Point2CCDCenter(xy, leftBottom, CAM.Top, 0);
                PointF r  = Form_Main.Instance.Point2CCDCenter(xy, rightTop, CAM.Top, 0);
                PointF c1 = Form_Main.Instance.Point2CCDCenter(xy, cross1, CAM.Top, 0);
                PointF c2 = Form_Main.Instance.Point2CCDCenter(xy, cross2, CAM.Top, 0);
                PointF c3 = Form_Main.Instance.Point2CCDCenter(xy, cross3, CAM.Top, 0);
                PointF c4 = Form_Main.Instance.Point2CCDCenter(xy, cross4, CAM.Top, 0);

                result.X1 = Math.Abs(tv.X - c1.X);
                result.Y1 = Math.Abs(th.Y - c2.Y);
                result.X2 = Math.Abs(l.X - c3.X);
                result.Y2 = Math.Abs(r.Y - c4.Y);
                Form_Main.Instance.imageSet.Image.Overlays.Default.AddLine(new LineContour(cross1, topV));
                Form_Main.Instance.imageSet.Image.Overlays.Default.AddLine(new LineContour(cross2, topH));
                Form_Main.Instance.imageSet.Image.Overlays.Default.AddLine(new LineContour(cross3, leftBottom));
                Form_Main.Instance.imageSet.Image.Overlays.Default.AddLine(new LineContour(cross4, rightTop));

                Form_Main.Instance.imageSet.Image.Overlays.Default.AddText("X1: " + result.X1.ToString(), topV, Rgb32Value.BlueColor, new OverlayTextOptions("Consolas", 24));
                Form_Main.Instance.imageSet.Image.Overlays.Default.AddText("Y1: " + result.Y1.ToString(), topH, Rgb32Value.BlueColor, new OverlayTextOptions("Consolas", 24));
                Form_Main.Instance.imageSet.Image.Overlays.Default.AddText("X2: " + result.X2.ToString(), leftBottom, Rgb32Value.BlueColor, new OverlayTextOptions("Consolas", 24));
                Form_Main.Instance.imageSet.Image.Overlays.Default.AddText("Y2: " + result.Y2.ToString(), rightTop, Rgb32Value.BlueColor, new OverlayTextOptions("Consolas", 24));
            }
            catch { }

            return(false);
        }
示例#13
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;
        }