Esempio n. 1
0
        private void BtnSanp_Click(object sender, EventArgs e)
        {
            string     strCamName = "Top";
            CameraBase cameraBase = CameraMgr.GetInstance().GetCamera(strCamName);

            cameraBase.StopGrap();
            cameraBase.BindWindow(visionControl1);
            cameraBase.SetTriggerMode(CameraModeType.Software);
            CameraMgr.GetInstance().GetCamera(strCamName).StartGrab();
            CameraMgr.GetInstance().GetCamera(strCamName).GarbBySoftTrigger();
        }
Esempio n. 2
0
        private void ContinuousSnap_Click(object sender, EventArgs e)
        {
            string     strCamName = "Top";
            CameraBase cameraBase = CameraMgr.GetInstance().GetCamera(strCamName);

            cameraBase.StopGrap();
            cameraBase.SetTriggerMode(CameraModeType.Software);

            double valexposure = cameraBase.GetExposureTime();
            double valgain     = cameraBase.GetGain();

            cameraBase.BindWindow(visionControl1);
            cameraBase.SetAcquisitionMode();
            cameraBase.StartGrab();
        }
Esempio n. 3
0
        public StationStep StepGoSnap(VisionControl visionControl, bool bmanual = false)
        {
            StationStep step = StationStep.Step_Stop;

            //拍照识别是否有料,计算偏差(6月后做)
            ParamSetMgr.GetInstance().SetBoolParam("启动点胶", true);
            //开始点胶(优先实现画轨迹)
            //获取当前夹取位置是A工位还是B工位
            int StationIndex = TableData.GetInstance().GetSocketNum(1, 0.5) - 1;

            PathHelper.Disp_ID = StationIndex;
            string stationAAName = StationIndex == 0 ? "A" : "B";

            ParamSetMgr.GetInstance().SetBoolParam($"{stationAAName}工位点胶", true);
            double     CenterX      = ParamSetMgr.GetInstance().GetDoubleParam("产品点胶X轴半径");
            double     CenterY      = ParamSetMgr.GetInstance().GetDoubleParam("产品点胶Y轴半径");
            double     DelZ         = ParamSetMgr.GetInstance().GetDoubleParam("点胶Z轴上升高度偏差");
            int        DispDelay    = ParamSetMgr.GetInstance().GetIntParam("出胶延迟");
            double     DispRunAngle = ParamSetMgr.GetInstance().GetDoubleParam("画胶角度");
            double     DispEndAngle = ParamSetMgr.GetInstance().GetDoubleParam("收胶角度");
            bool       DispEnable   = ParamSetMgr.GetInstance().GetBoolParam("屏蔽点胶");
            bool       DispPhoto    = ParamSetMgr.GetInstance().GetBoolParam("点胶相机拍照定位");
            double     SafeZ        = GetStationPointDic()[$"安全位置"].pointZ;
            double     X            = 0;
            double     Y            = 0;
            double     DispPhotoX   = GetStationPointDic()[$"{stationAAName}工位拍照位"].pointX;
            double     DispPhotoY   = GetStationPointDic()[$"{stationAAName}工位拍照位"].pointY;
            double     DispPhotoZ   = GetStationPointDic()[$"{stationAAName}工位拍照位"].pointZ;
            double     DispPosX     = GetStationPointDic()[$"{stationAAName}工位点胶位"].pointX;
            double     DispPosY     = GetStationPointDic()[$"{stationAAName}工位点胶位"].pointY;
            double     DispPosZ     = GetStationPointDic()[$"{stationAAName}工位点胶位"].pointZ;
            double     x1           = GetStationPointDic()["安全位置"].pointX;
            CameraBase cam          = null;

            if (!ParamSetMgr.GetInstance().GetBoolParam("屏蔽上相机"))
            {
                cam = CameraMgr.GetInstance().GetCamera("Top");
                cam.BindWindow(visionControl);
                Task.Run(() =>
                {
                    cam.StopGrap();
                    cam.SetTriggerMode(CameraModeType.Software);
                    cam.SetGain(ParamSetMgr.GetInstance().GetIntParam("点胶相机增益"));
                    cam.SetExposureTime(ParamSetMgr.GetInstance().GetIntParam("点胶相机曝光"));
                    cam.StartGrab();
                });
            }
            IOMgr.GetInstace().WriteIoBit($"相机光源", true);
retry_uplens:
            IOMgr.GetInstace().WriteIoBit($"{stationAAName}Lens升降气缸", true);
            WaranResult waranResult1 = CheckIobyName($"{stationAAName}Lens上升到位", true, $"{stationAAName}Lens上升到位", bmanual);

            if (waranResult1 == WaranResult.Retry)
            {
                goto retry_uplens;
            }
            MoveSigleAxisPosWaitInpos(AxisZ, SafeZ, (double)SpeedType.High, 0.005, bmanual, this);
            MoveY(DispPhotoY, SpeedType.High);

            MoveMulitAxisPosWaitInpos(new int[] { AxisX, AxisZ }, new double[] { DispPhotoX, DispPhotoZ }, new double[] { (double)SpeedType.High, (double)SpeedType.High }, 0.005, bmanual, this);
            HObject img = null;



            if (!ParamSetMgr.GetInstance().GetBoolParam("屏蔽上相机"))
            {
                img = cam.GetImage();
                if (img == null || !img.IsInitialized())
                {
                    img = cam.GetImage();
                }
                else
                {
                    ImageHelper.Instance.SaveImage($"{PathHelper.ImagePathDisp}{DateTime.Now.ToString("HHmmssfff")}.bmp", "bmp", img.Clone());
                }
            }


            IOMgr.GetInstace().WriteIoBit($"相机光源", false);
            //去画胶
            Task.Run(() =>
            {
                if (ParamSetMgr.GetInstance().GetBoolParam("是否选择程控电源"))
                {
                    double valueVoltage = ParamSetMgr.GetInstance().GetDoubleParam("程控电源电压");
                    OtherDevices.ckPower.SetVoltage(StationIndex + 1, valueVoltage);
                    double valueCurrent = ParamSetMgr.GetInstance().GetDoubleParam("程控电源电流");
                    OtherDevices.ckPower.SetCurrent(StationIndex + 1, valueCurrent);
                }
                IOMgr.GetInstace().WriteIoBit($"{stationAAName}模组上电", true);
                IOMgr.GetInstace().WriteIoBit($"12V开启", ParamSetMgr.GetInstance().GetBoolParam("是否开启非程控12V"));
            });
            if (DispEnable)
            {
                step = StationStep.Step_CheckIpos;
                MoveSigleAxisPosWaitInpos(AxisZ, SafeZ, (double)SpeedType.High, 0.005, bmanual, this);
                TableData.GetInstance().SetStationResult("A_UnLoadLoad", true);
                TableData.GetInstance().SetStationResult("B_UnLoadLoad", true);
                return(step);
            }
            if (DispPhoto)
            {
                ////MoveY(DispPhotoY, SpeedType.High);
                ////MoveMulitAxisPosWaitInpos(new int[] { AxisX, AxisZ }, new double[] { DispPhotoX, DispPhotoZ }, new double[] { (double)SpeedType.High, (double)SpeedType.High }, 0.005, bmanual, this);

                //拍照计算 +半径
                double CenterdelX = 0;
                double CenterdelY = 0;
                X        = CenterX + CenterdelX;
                Y        = CenterdelY;
                DispPosX = DispPhotoX - X;
                DispPosY = DispPhotoY + CenterdelY;
            }
            else
            {
                X = CenterX;
                Y = 0;
            }
            //  IOMgr.GetInstace().WriteIoBit("点胶机", false);
            bool brtnExc = true;

            MotionMgr.GetInstace().AddAxisToGroup("点胶群组", 2, new int[] { AxisX, AxisY });

            MoveY(DispPosY, SpeedType.High);
            MoveMulitAxisPosWaitInpos(new int[] { AxisX, AxisZ }, new double[] { DispPosX, DispPosZ + DelZ + 10 }, new double[] { (double)SpeedType.High, (double)SpeedType.High }, 0.005, bmanual, this);

            //    MoveMulitAxisPosWaitInpos(new int[] { AxisX }, new double[] { DispPosX }, new double[] { (double)SpeedType.High }, 0.005, bmanual, this);
            IOMgr.GetInstace().WriteIoBit("点胶机", false);
            MoveMulitAxisPosWaitInpos(new int[] { AxisZ }, new double[] { DispPosZ + DelZ }, new double[] { (double)SpeedType.High }, 0.005, bmanual, this);
            if (ParamSetMgr.GetInstance().GetStringParam("点胶轨迹") == "Circle")
            {
                DateTime dateTime = DateTime.Now;
                if (DispDelay >= 0)
                {
                    IOMgr.GetInstace().WriteIoBit("点胶机", true);
                    Thread.Sleep(DispDelay);
                }
                else
                {
                    Task.Run(() =>
                    {
                        while (true)
                        {
                            if ((DateTime.Now - dateTime).TotalSeconds > Math.Abs(DispDelay) / 1000.0)
                            {
                                IOMgr.GetInstace().WriteIoBit("点胶机", true);
                                break;
                            }
                            Thread.Sleep(10);
                        }
                    });
                }



                //走

                brtnExc &= MotionMgr.GetInstace().ClearBufMove("点胶群组");
                brtnExc &= MotionMgr.GetInstace().RestGpErr("点胶群组");
                //  GpState gps = MotionMgr.GetInstace().GetGpState("点胶群组");
                brtnExc &= MotionMgr.GetInstace().AddBufMove("点胶群组", BufMotionType.buf_Arc2dAbsAngleCW, 1, 2, (double)SpeedType.Mid, (double)SpeedType.Mid, new double[2] {
                    X, Y
                }, new double[2] {
                    DispPosZ, 0
                });
                brtnExc &= MotionMgr.GetInstace().BufTrans("点胶群组");//M314没有buf运动,所以放在这里star
                brtnExc &= MotionMgr.GetInstace().BufStart("点胶群组");
                Thread.Sleep(400);
                if (!WaitXY(DispPosX, DispPosY))
                {
                    IOMgr.GetInstace().WriteIoBit("点胶机", false);
                    return(step);
                }
                IOMgr.GetInstace().WriteIoBit("点胶机", false);
            }
            else
            {
                IOMgr.GetInstace().WriteIoBit("点胶机", true);
                Thread.Sleep(DispDelay);
                MoveY(DispPosY + CenterY * 10, SpeedType.Mid);
                MoveMulitAxisPosWaitInpos(new int[] { AxisX }, new double[] { DispPosX + CenterX * 2 }, new double[] { (double)SpeedType.Mid }, 0.005, bmanual, this);
                MoveY(DispPosY - CenterY * 10, SpeedType.Mid);
                MoveMulitAxisPosWaitInpos(new int[] { AxisX }, new double[] { DispPosX }, new double[] { (double)SpeedType.Mid }, 0.005, bmanual, this);
                MoveY(DispPosY, SpeedType.Mid);
                IOMgr.GetInstace().WriteIoBit("点胶机", false);
            }
            IOMgr.GetInstace().WriteIoBit($"相机光源", true);

            MoveMulitAxisPosWaitInpos(new int[] { AxisZ }, new double[] { DispPosZ + 3 }, new double[] { (double)SpeedType.Mid }, 0.005, bmanual, this);

            MoveMulitAxisPosWaitInpos(new int[] { AxisZ }, new double[] { DispPosZ + 10 }, new double[] { (double)SpeedType.High }, 0.005, bmanual, this);
            if (!ParamSetMgr.GetInstance().GetBoolParam("屏蔽上相机"))
            {
                MoveMulitAxisPosWaitInpos(new int[] { AxisX, AxisZ }, new double[] { DispPhotoX, DispPhotoZ }, new double[] { (double)SpeedType.High, (double)SpeedType.High }, 0.005, bmanual, this);
                // MoveSigleAxisPosWaitInpos(AxisX, DispPhotoX, (double)SpeedType.High, 0.005, bmanual, this);
                MoveY(DispPhotoY, SpeedType.High);
                HObject img2 = cam.GetImage();
                if (img2 == null || !img2.IsInitialized())
                {
                    img2 = cam.GetImage();
                }
                else
                {
                    ImageHelper.Instance.SaveImage($"{PathHelper.ImagePathDisp}{DateTime.Now.ToString("HHmmssfff")}.bmp", "bmp", img2.Clone());
                }
            }
            IOMgr.GetInstace().WriteIoBit($"相机光源", false);

            MoveMulitAxisPosWaitInpos(new int[] { AxisZ }, new double[] { SafeZ }, new double[] { (double)SpeedType.High }, 0.005, bmanual, this);
            MoveSigleAxisPosWaitInpos(AxisX, x1, (double)SpeedType.High, 0.005, bmanual, this);
            step = StationStep.Step_CheckIpos;
            //if (DialogResult.OK!= MessageBox.Show("请确定点胶效果是否OK,OK按确定", "Info", MessageBoxButtons.OKCancel, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1, MessageBoxOptions.DefaultDesktopOnly))
            //{
            //    ParamSetMgr.GetInstance().SetBoolParam("重新上料", true);
            //    return step;
            //}
            ParamSetMgr.GetInstance().SetBoolParam("重新上料", false);
            SocketMgr.GetInstance().SetSocketState(SocketNumOfUnloadLoad, SocketState.Have);
            TableData.GetInstance().SetStationResult("A_UnLoadLoad", true);
            TableData.GetInstance().SetStationResult("B_UnLoadLoad", true);
            ParamSetMgr.GetInstance().SetBoolParam("点胶完成", true);
            return(step);
        }