예제 #1
0
파일: DoProductProcess.cs 프로젝트: Gz1d/Gz
 public void NewDoProject(LD.Config.PlcDataItem PlcItem, Object Obj)
 {
     LD.Common.PlcDevice plcDevice = PlcItem.PlcDevice;
     if (plcDevice == LD.Common.PlcDevice.ArtTestCameraStart)  //
     {
         //读取机台编号
         int StageNum = (int)LD.Logic.PlcHandle.Instance.ReadValue(LD.Common.PlcDevice.ArtTestStageNumRead);
         //读取拍照位编号
         int GrabNum = (int)LD.Logic.PlcHandle.Instance.ReadValue(LD.Common.PlcDevice.ArtTestGrabNum);
         //获取视觉示教的定位参数
         NowProjectPara = ProjectParaManager.Instance.GetProjectPara(StageNum);
         //获取当前拍照点的视觉坐标
         NowVisionPara = NowProjectPara.GetVisionPara(GrabNum);
         NowVisionProcess.SetVisionPara(NowVisionPara);
         NowVisionProcess.Do();
         FirstLocalResult = NowVisionProcess.MyLocalResult;
         St_VectorAngle PosToRot      = NowVisionProcess.PosToRot;
         St_VectorAngle TeachPosToRot = NowVisionProcess.TeachPosToRot;
         St_VectorAngle AddVector     = new St_VectorAngle();
         MyVisionBase.VectorAngleToMotionXYTh(PosToRot, TeachPosToRot, out AddVector);
         LD.Logic.PlcHandle.Instance.WriteValue(LD.Common.PlcDevice.ArtTestAddX, -AddVector.Col);
         LD.Logic.PlcHandle.Instance.WriteValue(LD.Common.PlcDevice.ArtTestAddY, AddVector.Row);
         LD.Logic.PlcHandle.Instance.WriteValue(LD.Common.PlcDevice.ArtTestAddTheta, -AddVector.Angle);
         ViewControl view1 = DisplaySystem.GetViewControl(CameraTest.UpCam1);
     }
 }
예제 #2
0
        public bool  StartGrabImg()
        {
            //1.打开光源
            FileLib.Logger.Pop("  打开光源:", false, "FOF运行日志");
            foreach (LightPara item in MyVisionPara.camLightPara.lightPara)
            {
                LightCtrlManager.Instance.SetLightValue(item);
            }
            //2.采图
            FileLib.Logger.Pop("  开始采图:", false, "FOF运行日志");
            if (GrabImg != null)
            {
                GrabImg.Dispose();
            }
            CameraCtrl.Instance.SetExpos(MyVisionPara.camLightPara.CamName, MyVisionPara.camLightPara.Exposure);
            CameraCtrl.Instance.GrabImg(MyVisionPara.camLightPara.CamName, out GrabImg);
            ViewControl view0 = new ViewControl();

            view0 = DisplaySystem.GetViewControl(CameraTest.UpCam2);
            if (MyVisionPara.camLightPara.CamName == CameraEnum.Cam2)
            {
                view0 = DisplaySystem.GetViewControl(CameraTest.UpCam3);
            }
            view0.ResetView();
            view0.Refresh();

            //3.关闭光源
            LightCtrlManager.Instance.SetAllLightTo0();
            FileLib.Logger.Pop("  关闭光源:", false, "FOF运行日志");
            return(true);
        }
예제 #3
0
 private void FrmImageParaTeach_Load(object sender, EventArgs e)
 {
     view1 = DisplaySystem.GetViewControl("Local");
     DisplaySystem.AddPanelForCCDView("Local", panel1);
     InitSubFrmList();
     SwitchSubFrm(SubFormIndex);
     SwitchStepButton(SubFormIndex);
 }
예제 #4
0
파일: FrmCali9PtPara.cs 프로젝트: Gz1d/Gz
 public FrmCali9PtPara(CaliParam CaliParaIn)
 {
     InitializeComponent();
     TeachCaliPara = CaliParaIn;
     MotionManager.Instance.SetCoordi(TeachCaliPara.coordi);
     view1 = DisplaySystem.GetViewControl("Cali");
     DisplaySystem.AddPanelForCCDView("Cali", panel1);
     this.LocalModelCbx.Items.Clear();
     foreach (LocalModelEnum temp in Enum.GetValues(typeof(LocalModelEnum)))
     {
         this.LocalModelCbx.Items.Add(temp);
     }
     LocalModelCbx.SelectedIndex = (int)TeachCaliPara.localPara.localSetting.localModel;
 }
예제 #5
0
파일: FrmAutoFocus.cs 프로젝트: Gz1d/Gz
 private void FrmAutoFocus_Load(object sender, EventArgs e)
 {
     view = DisplaySystem.GetViewControl("FocusPanel");
     DisplaySystem.AddPanelForCCDView("FocusPanel", panel1);
     CamCbx.SelectedIndex       = 0;
     LightPanelCbx.SelectedItem = 0;
     ////增加处理,显示
     //view.Repaint();
     //view.ResetView();
     //view.Refresh();
     //view.AddViewImage(img);
     //view.Repaint();
     ColorPanelCbx.SelectedItem = 0;
     this.FormClosing          += MyFormClosing;
 }
예제 #6
0
파일: FrmCameraManager.cs 프로젝트: Gz1d/Gz
 private void FrmCameraManager_Load(object sender, EventArgs e)
 {
     view = DisplaySystem.GetViewControl("CameraManager");
     DisplaySystem.AddPanelForCCDView("CameraManager", panel1);
     this.cameraNameDataGridViewTextBoxColumn.Items.Clear();
     foreach (CameraEnum temp in Enum.GetValues(typeof(CameraEnum)))
     {
         this.cameraNameDataGridViewTextBoxColumn.Items.Add(temp);
     }
     this.CameInterfaceDataGridViewTextBoxColumn.Items.Clear();
     foreach (CamInterfaceEnum temp in Enum.GetValues(typeof(CamInterfaceEnum)))
     {
         this.CameInterfaceDataGridViewTextBoxColumn.Items.Add(temp);
     }
     this.CamParaDgv.DataSource = CameraParaManager.Instance.CameraParaList;
 }
예제 #7
0
파일: DoProductProcess.cs 프로젝트: Gz1d/Gz
        /// <summary>
        /// 扎针定位
        /// </summary>
        /// <param name="PlcItem"></param>
        /// <param name="Obj"></param>
        public void DoProject(LD.Config.PlcDataItem PlcItem, Object Obj)
        {
            LD.Common.PlcDevice plcDevice = PlcItem.PlcDevice;
            if (plcDevice == LD.Common.PlcDevice.V_01_TriggerGrab)  //
            {
                NowVisionProcess = new DoVisionProcess();
                //起始信号清零
                LD.Logic.PlcHandle.Instance.WriteValue(LD.Common.PlcDevice.V_01_TriggerGrab, 0);
                FileLib.Logger.Pop("接受到PLC信号,开始扎针对位", false, "运行日志");
                short  ClearValue = 1;
                object obj        = new object();
                while (true)
                {
                    obj        = LD.Logic.PlcHandle.Instance.ReadValue(LD.Common.PlcDevice.V_01_TriggerGrab);
                    ClearValue = (short)obj;
                    if (ClearValue == 0)
                    {
                        break;
                    }
                    else
                    {
                        System.Threading.Thread.Sleep(10);
                    }
                }
                System.Threading.Thread.Sleep(1);
                //读取机台编号
                int StageNum = (int)LD.Logic.PlcHandle.Instance.ReadValue(LD.Common.PlcDevice.ArtTestStageNumRead);
                FileLib.Logger.Pop("  读取机台编号:" + StageNum.ToString(), false, "运行日志");
                System.Threading.Thread.Sleep(1);
                //读取拍照位编号
                short GrabNum = (short)LD.Logic.PlcHandle.Instance.ReadValue(LD.Common.PlcDevice.ArtTestGrabNum);
                System.Threading.Thread.Sleep(1);
                //获取视觉示教的定位参数
                NowProjectPara = ProjectParaManager.Instance.GetProjectPara(StageNum);
                //获取当前拍照点的视觉坐标
                NowVisionPara = NowProjectPara.GetVisionPara(GrabNum);
                NowVisionProcess.SetVisionPara(NowVisionPara);
                NowVisionProcess.Do();
                if (GrabNum == 0)
                {
                    FirstLocalResult = NowVisionProcess.MyLocalResult;
                    FileLib.Logger.Pop(" 左边拍照定位完成,开始右边拍照定位:", false, "运行日志");
                }
                else
                {
                    SecondLocalResult = NowVisionProcess.MyLocalResult;
                    //示教点到旋转中心的坐标
                    Point2Db TeachPt2d1 = new Point2Db(FirstLocalResult.TeachPosToRot.Col, FirstLocalResult.TeachPosToRot.Row);
                    Point2Db TeachPt2d2 = new Point2Db(SecondLocalResult.TeachPosToRot.Col, SecondLocalResult.TeachPosToRot.Row);
                    FileLib.Logger.Pop(" 示教产品到旋转中心的坐标(左右两点):" + TeachPt2d1.Col.ToString("f3") + "  " + TeachPt2d1.Row.ToString("f3") + "  "
                                       + TeachPt2d2.Col.ToString("f3") + "  " + TeachPt2d2.Row.ToString("f3"), false, "运行日志");
                    //当前产品到旋转中心的坐标
                    Point2Db NowPosPt2d1 = new Point2Db(FirstLocalResult.PosToRot.Col, FirstLocalResult.PosToRot.Row);
                    Point2Db NowPosPt2d2 = new Point2Db(SecondLocalResult.PosToRot.Col, SecondLocalResult.PosToRot.Row);
                    FileLib.Logger.Pop(" 当前产品到旋转中心的坐标(左右两点):" + NowPosPt2d1.Col.ToString("f3") + "  " + NowPosPt2d1.Row.ToString("f3") + "  "
                                       + NowPosPt2d2.Col.ToString("f3") + "  " + NowPosPt2d2.Row.ToString("f3"), false, "运行日志");
                    List <Point2Db> TeachPtList = new List <Point2Db>();
                    List <Point2Db> NowPtList   = new List <Point2Db>();
                    //当前产品移动到产品示教时的位置,先计算出偏移矩阵
                    TeachPtList.Add(TeachPt2d1);
                    TeachPtList.Add(TeachPt2d2);
                    NowPtList.Add(NowPosPt2d1);
                    NowPtList.Add(NowPosPt2d2);
                    MyHomMat2D NowHomat = new MyHomMat2D();
                    bool       IsTrue   = false;
                    MyVisionBase.VectorToRigidHomMat(NowPtList, TeachPtList, out NowHomat, out IsTrue);
                    double AddX = 0, AddY = 0, AddTheta = 0;
                    MyVisionBase.CalculateThreeTapePos(NowPosPt2d1, NowPosPt2d2, TeachPt2d1, TeachPt2d2, out AddX, out AddY, out AddTheta);
                    FileLib.Logger.Pop(" 计算出的偏移补偿量:" + AddX.ToString("f3") + "  " + AddY.ToString("f3") + "  " + AddTheta.ToString("f3"), false, "运行日志");
                    ///再根据偏移矩阵计算出偏移量
                    double AddX1 = 0, AddY1 = 0, AddTheta1 = 0;
                    MyVisionBase.HomMat2dToAffinePara(NowHomat, out AddTheta1, out AddY1, out AddX1);
                    ViewControl view1 = DisplaySystem.GetViewControl(CameraTest.UpCam1);
                    view1.SetString(500, 500, "red", "   AddX: " + AddX.ToString("f4") + " mm ");
                    view1.SetString(500, 600, "red", "   AddY: " + AddY.ToString("f4") + " mm ");
                    view1.SetString(500, 700, "red", "   AddTheta: " + AddTheta.ToString("f4") + " 度 ");
                    ///
                    double addx0     = -AddX * 1000;
                    double addy0     = AddY * 1000;
                    double addtheta0 = AddTheta * 1000;
                    int    addx      = (int)addx0;
                    int    addy      = (int)addy0;
                    int    addtheta  = (int)addtheta0;
                    NowVisionPara = NowProjectPara.GetVisionPara(0);
                    int offsetx     = (int)(NowVisionPara.localPara.localSetting.Offset_x * 1000);
                    int offsety     = (int)(NowVisionPara.localPara.localSetting.Offset_y * 1000);
                    int offsettheta = (int)(NowVisionPara.localPara.localSetting.Offset_theta * 1000);

                    int newAddX     = addx + offsetx;
                    int NewAddY     = addy + offsety;
                    int NewAddTheta = -addtheta + offsettheta;
                    if (StageNum == 0 || StageNum == 2)//左边两个平台X轴为正常方向,后面两个平台为反方向
                    {
                        newAddX = addx + offsetx;
                    }
                    else
                    {
                        newAddX = -addx + offsetx;
                    }
                    LD.Logic.PlcHandle.Instance.WriteValue(LD.Common.PlcDevice.ArtTestAddX, newAddX);
                    System.Threading.Thread.Sleep(5);
                    LD.Logic.PlcHandle.Instance.WriteValue(LD.Common.PlcDevice.ArtTestAddY, NewAddY);
                    System.Threading.Thread.Sleep(5);
                    LD.Logic.PlcHandle.Instance.WriteValue(LD.Common.PlcDevice.ArtTestAddTheta, NewAddTheta);//图像坐标系为逆时针,机械坐标系为顺时针
                    System.Threading.Thread.Sleep(5);
                    int    ReadAddX     = 0;
                    int    ReadAddY     = 0;
                    int    ReadAddTheta = 0;
                    object ObjRead      = 0;
                    int    WriteCount   = 0;
                    while (true)
                    {
                        ObjRead = LD.Logic.PlcHandle.Instance.ReadValue(LD.Common.PlcDevice.ArtTestAddX);
                        System.Threading.Thread.Sleep(5);
                        ReadAddX = (int)ObjRead;
                        ObjRead  = LD.Logic.PlcHandle.Instance.ReadValue(LD.Common.PlcDevice.ArtTestAddY);
                        System.Threading.Thread.Sleep(5);
                        ReadAddY = (int)ObjRead;
                        ObjRead  = LD.Logic.PlcHandle.Instance.ReadValue(LD.Common.PlcDevice.ArtTestAddTheta);
                        System.Threading.Thread.Sleep(5);
                        ReadAddTheta = (int)ObjRead;
                        if (ReadAddX == newAddX && ReadAddY == NewAddY && ReadAddTheta == NewAddTheta)
                        {
                            FileLib.Logger.Pop(" 补偿值成功写入", false, "运行日志");
                            break;
                        }
                        else
                        {
                            WriteCount++;
                            if (WriteCount % 10 == 0)
                            {
                                LD.Logic.PlcHandle.Instance.WriteValue(LD.Common.PlcDevice.ArtTestAddX, newAddX);
                                System.Threading.Thread.Sleep(5);
                                LD.Logic.PlcHandle.Instance.WriteValue(LD.Common.PlcDevice.ArtTestAddY, NewAddY);
                                System.Threading.Thread.Sleep(5);
                                LD.Logic.PlcHandle.Instance.WriteValue(LD.Common.PlcDevice.ArtTestAddTheta, NewAddTheta);//图像坐标系为逆时针,机械坐标系为顺时针
                                System.Threading.Thread.Sleep(5);
                            }
                            if (WriteCount > 300)
                            {
                                break;
                            }
                        }
                    }
                    if (SecondLocalResult.IsLocalOk)
                    {
                        LD.Logic.PlcHandle.Instance.WriteValue(LD.Common.PlcDevice.ArtTestCamLocalResult, 1); //告诉PLC定位结果OK
                        FileLib.Logger.Pop(" 告诉PLC补偿量已经发给PLC:", false, "运行日志");
                    }
                }
            }
        }
예제 #8
0
파일: DoProductProcess.cs 프로젝트: Gz1d/Gz
        public void DoFOFProject1(LD.Config.PlcDataItem PlcItem, Object Obj)
        {
            LD.Common.PlcDevice plcDevice = PlcItem.PlcDevice;
            if (plcDevice == LD.Common.PlcDevice.V_02_TriggerGrab)
            {
                FileLib.Logger.Pop("接受到PLC信号,偏移检测", false, "FOF运行日志");
                NowUpVisionProcess = new DoUpDnVisionProcess();
                NowUpLocalRlt      = new LocalResult();
                NowDnLocalRlt      = new LocalResult();
                //起始信号清零
                FileLib.Logger.Pop("启动信号清零", false, "FOF运行日志");
                LD.Logic.PlcHandle.Instance.WriteValue(LD.Common.PlcDevice.V_02_TriggerGrab, 0);
                System.Threading.Thread.Sleep(1);
                short  ClearValue = 1;
                object obj        = new object();

                FileLib.Logger.Pop("启动地址清零成功", false, "FOF运行日志");
                //读取机台编号 4 代表FOF左侧FOF偏移检测 ,5代表FOF右侧偏移检测
                int StageNum = (int)LD.Logic.PlcHandle.Instance.ReadValue(LD.Common.PlcDevice.ArtTestStageNumRead);
                FileLib.Logger.Pop("  读取机台编号:" + StageNum.ToString(), false, "FOF运行日志");
                System.Threading.Thread.Sleep(1);
                //获取视觉示教的定位参数
                NowProjectPara = ProjectParaManager.Instance.GetProjectPara(StageNum);
                //获取当前拍照点的视觉坐标
                double OffsetX = 0;
                double OffsetY = 0;
                try {
                    FileLib.Logger.Pop("开始FOF偏移检测上相机定位", false, "FOF运行日志");
                    NowVisionPara = NowProjectPara.GetVisionPara(0);
                    NowUpVisionProcess.SetVisionPara(NowVisionPara);
                    NowUpVisionProcess.Do();
                    NowUpLocalRlt = NowUpVisionProcess.MyLocalResult;
                    BlobLocalRlt FofRlt = (BlobLocalRlt)NowUpLocalRlt;
                    double       x      = FofRlt.ListWid[0] * NowVisionPara.localPara.Blobs.PixelSize;
                    double       y      = FofRlt.ListHei[1] * NowVisionPara.localPara.Blobs.PixelSize;
                    OffsetX = x + NowVisionPara.localPara.localSetting.Offset_x;
                    OffsetY = y + NowVisionPara.localPara.localSetting.Offset_y;
                    FileLib.Logger.Pop("偏移量: " + "OffsetX: " + OffsetX.ToString("f4") + "  " + "OffsetY: "
                                       + OffsetY.ToString("f4"), false, "FOF运行日志");
                }
                catch (Exception e0) {
                    Logger.PopError1(e0, false, "视觉错误日志");
                    OffsetX = 999999;
                    OffsetY = 999999;
                }
                ViewControl view1 = DisplaySystem.GetViewControl(CameraTest.UpCam2);
                view1.SetString(500, 500, "red", "OffsetX:  " + OffsetX.ToString("f4") + " mm");
                view1.SetString(500, 600, "red", "OffsetY:  " + OffsetY.ToString("f4") + " mm");

                if (Math.Abs(OffsetX) < NowVisionPara.localPara.localSetting.Offset_x_range && Math.Abs(OffsetY)
                    < NowVisionPara.localPara.localSetting.Offset_y_range)
                {
                    LD.Logic.PlcHandle.Instance.WriteValue(LD.Common.PlcDevice.FOF_inspect_result, 1); //检测结果Ok
                    FileLib.Logger.Pop("检测结果写给Plc(FOF_inspect_result):OK", false, "FOF运行日志");
                }
                else
                {
                    LD.Logic.PlcHandle.Instance.WriteValue(LD.Common.PlcDevice.FOF_inspect_result, 2); //检测结果NG
                    FileLib.Logger.Pop("检测结果写给Plc(FOF_inspect_result):NG", false, "FOF运行日志");
                }
                FileLib.Logger.Pop("循环读取启动地址,保证清零成功", false, "FOF运行日志");
                int ReadCount = 1;
                while (true)
                {
                    obj        = LD.Logic.PlcHandle.Instance.ReadValue(LD.Common.PlcDevice.V_02_TriggerGrab);
                    ClearValue = (short)obj;
                    if (ClearValue == 0)
                    {
                        break;
                    }
                    else
                    {
                        System.Threading.Thread.Sleep(10);
                        if (ReadCount % 10 == 0)
                        {
                            FileLib.Logger.Pop("重新执行一次清零", false, "FOF运行日志");
                            ReadCount = 1;
                            LD.Logic.PlcHandle.Instance.WriteValue(LD.Common.PlcDevice.V_02_TriggerGrab, 0);
                        }
                        if (ReadCount > 100)
                        {
                            FileLib.Logger.Pop("清零次数超过10,清零失败", false, "FOF运行日志");
                        }
                    }
                    ReadCount++;
                }
                FileLib.Logger.Pop("将偏移量写给PLC", false, "FOF运行日志");
                LD.Logic.PlcHandle.Instance.WriteValue(LD.Common.PlcDevice.FOF_offset_x, (int)(OffsetX * 1000));
                LD.Logic.PlcHandle.Instance.WriteValue(LD.Common.PlcDevice.FOF_offset_y, (int)(OffsetY * 1000));
                FileLib.Logger.Pop("偏移量写给PLC完成", false, "FOF运行日志");
                FileLib.Logger.Pop("。", false, "FOF运行日志");
                FileLib.Logger.Pop("。", false, "FOF运行日志");
                FileLib.Logger.Pop("。", false, "FOF运行日志");
            }
        }
예제 #9
0
        public override void Do()
        {
            //1.打开光源
            foreach (LightPara item in MyVisionPara.camLightPara.lightPara)
            {
                LightCtrlManager.Instance.SetLightValue(item);
            }
            //2.采图
            if (GrabImg != null)
            {
                GrabImg.Dispose();
            }
            CameraCtrl.Instance.SetExpos(MyVisionPara.camLightPara.CamName, MyVisionPara.camLightPara.Exposure);
            if (CameraCtrl.Instance.GrabImg(MyVisionPara.camLightPara.CamName, out GrabImg))
            {
                LD.Logic.PlcHandle.Instance.WriteValue(LD.Common.PlcDevice.FOF_Grabed_ok, 1); //拍照OK
            }
            else
            {
                LD.Logic.PlcHandle.Instance.WriteValue(LD.Common.PlcDevice.FOF_Grabed_ok, 2); //拍照NG
            }
            ViewControl view1 = DisplaySystem.GetViewControl(CameraTest.UpCam1);

            if (MyVisionPara.camLightPara.CamName == CameraEnum.Cam0)
            {
                view1 = DisplaySystem.GetViewControl(CameraTest.UpCam1);
            }
            if (MyVisionPara.camLightPara.CamName == CameraEnum.Cam1)
            {
                view1 = DisplaySystem.GetViewControl(CameraTest.UpCam2);
            }
            if (MyVisionPara.camLightPara.CamName == CameraEnum.Cam2)
            {
                view1 = DisplaySystem.GetViewControl(CameraTest.UpCam3);
            }
            view1.ResetView();
            view1.Refresh();
            view1.AddViewImage(GrabImg);
            view1.Repaint();
            MyVisionBase.SaveImg(GrabImg, "扎针对位图片");
            //3.关闭光源
            LightCtrlManager.Instance.SetAllLightTo0();
            //4.0设置定位模式
            MyLocal.SetLocalModel(MyVisionPara.localPara.localSetting.localModel);
            //5.0设置定位参数
            MyLocal.SetParam(GrabImg, MyVisionPara.localPara);
            //6.执行定位
            try
            {
                MyLocal.doLocal();
                LD.Logic.PlcHandle.Instance.WriteValue(LD.Common.PlcDevice.FOF_Grabed_result, 1); //告诉PLC定位结果OK
            }
            catch (Exception e0)
            {
                Logger.PopError1(e0, false, "视觉日志");
                LD.Logic.PlcHandle.Instance.WriteValue(LD.Common.PlcDevice.FOF_Grabed_result, 2); //告诉PLC定位结果OK
            }

            //7.告诉PLC定位结果完成

            MyLocalResult = MyLocal.GetResult();
            view1.AddViewObject(MyLocalResult.ShowContour);
            //结合标定坐标计算出产品的实际位置
            MyHomMat2D HomMat = new MyHomMat2D();

            HomMat = CaliParaManager.Instance.GetHomMAT(MyVisionPara.localPara.localSetting.CoordiCam); //获取示教的标定矩阵
            HalconDotNet.HTuple HHomMat = new HalconDotNet.HTuple();
            //标定矩阵的转换
            MyVisionBase.MyHomMatToHalcon(HomMat, out HHomMat);
            //图像坐标系的原点由左上角变到左下角
            MyVisionBase.AdjImgRow(GrabImg, ref MyLocalResult.row);
            St_VectorAngle PixelVector = new St_VectorAngle(MyLocalResult.row, MyLocalResult.col, MyLocalResult.angle);
            CaliValue      CaliPara    = CaliParaManager.Instance.GetCaliValue(MyVisionPara.localPara.localSetting.CoordiCam);

            //将像素坐标转换到标定坐标
            //MyLocalResult.AffineTransResult()
            HalconDotNet.HTuple HomMatCali = new HalconDotNet.HTuple();
            MyVisionBase.MyHomMatToHalcon(CaliPara.HomMat, out HomMatCali);

            MyVisionBase.AffineTransPt(MyLocalResult.col, MyLocalResult.row, HomMatCali, out MyLocalResult.x, out MyLocalResult.y);

            //MyVisionBase.AffineTransPt()

            //获取当前坐标



            //double X = 0, Y = 0, Z = 0, Theta = 0;
            //if (CaliParaManager.Instance.GetCaliMode(MyVisionPara.localPara.localSetting.TeachCoordi) == CaliModelEnum.HandEyeCali)
            //{
            //    MotionManager.Instance.SetCoordi(MyVisionPara.localPara.localSetting.TeachCoordi);
            //    MotionManager.Instance.GetCoordiPos(out X, out Y, out Z, out Theta);
            //}
            //VectorAngle GrabPos = new VectorAngle(X, Y, Theta);
            ////9 计算出当前产品距离旋转中心的坐标
            //EyeToHandPos.TransEyeToHandPos(PixelVector, CaliPara, GrabPos, out PosToRot);
            ////10计算出示教产品到旋转中心的坐标
            //St_VectorAngle TeachPixelPos = new St_VectorAngle(MyLocalResult.TeachRow, MyLocalResult.TeachCol, MyLocalResult.TeachAngle);
            //VectorAngle TeachGrabPos = new VectorAngle(MyLocalResult.TeachX, MyLocalResult.TeachY, MyLocalResult.TeachTheta);

            //MyVisionBase.AdjImgRow(GrabImg, ref TeachPixelPos.Row);
            //EyeToHandPos.TransEyeToHandPos(TeachPixelPos, CaliPara, TeachGrabPos, out TeachPosToRot);
            //view1.Repaint();
            //view1.SetString(100, 100, "red", "PosToRot: " + "   X: " + PosToRot.Col.ToString("f3") + "   Y: " +
            //    PosToRot.Row.ToString("f3") + "   Theta: " + PosToRot.Angle.ToString("f3"));
            //MyLocalResult.PosToRot = PosToRot;
            //MyLocalResult.TeachPosToRot = TeachPosToRot;
        }
예제 #10
0
파일: DoVisionProcess.cs 프로젝트: Gz1d/Gz
        public virtual void Do()
        {
            //1.打开光源
            FileLib.Logger.Pop("  打开光源:", false, "运行日志");
            foreach (LightPara item in MyVisionPara.camLightPara.lightPara)
            {
                LightCtrlManager.Instance.SetLightValue(item);
            }
            //2.采图
            if (GrabImg != null)
            {
                GrabImg.Dispose();
            }
            FileLib.Logger.Pop("  开始采图:", false, "运行日志");
            CameraCtrl.Instance.SetExpos(MyVisionPara.camLightPara.CamName, MyVisionPara.camLightPara.Exposure);
            //10.获取当前的机械坐标
            double X = 0, Y = 0, Z = 0, Theta = 0;

            if (CaliParaManager.Instance.GetCaliMode(MyVisionPara.localPara.localSetting.CoordiCam) == CaliModelEnum.HandEyeCali)
            {
                MotionManager.Instance.SetCoordi(MyVisionPara.localPara.localSetting.TeachCoordi);
                FileLib.Logger.Pop("当前的坐标系为:" + MyVisionPara.localPara.localSetting.TeachCoordi.ToString(), false, "运行日志");
                MotionManager.Instance.GetCoordiPos(out X, out Y, out Z, out Theta);
                FileLib.Logger.Pop("当前的机械坐标", false, "运行日志");
                FileLib.Logger.Pop("X:" + X.ToString("f4") + "  Y:" + Y.ToString("f4") +
                                   "  Z:" + Z.ToString("f4") + "  Theta:" + Theta.ToString("f4"), false, "运行日志");
            }

            if (CameraCtrl.Instance.GrabImg(MyVisionPara.camLightPara.CamName, out GrabImg))
            {
                LD.Logic.PlcHandle.Instance.WriteValue(LD.Common.PlcDevice.ArtTestCameraGrabed, 1); //拍照OK
                FileLib.Logger.Pop("  采图OK:", false, "运行日志");
            }
            else
            {
                LD.Logic.PlcHandle.Instance.WriteValue(LD.Common.PlcDevice.ArtTestCameraGrabed, 2); //拍照NG
                FileLib.Logger.Pop("  采图NG:", false, "运行日志");
            }
            ViewControl view1 = DisplaySystem.GetViewControl(CameraTest.UpCam1);

            if (MyVisionPara.camLightPara.CamName == CameraEnum.Cam0)
            {
                view1 = DisplaySystem.GetViewControl(CameraTest.UpCam1);
            }
            if (MyVisionPara.camLightPara.CamName == CameraEnum.Cam1)
            {
                view1 = DisplaySystem.GetViewControl(CameraTest.UpCam2);
            }
            if (MyVisionPara.camLightPara.CamName == CameraEnum.Cam2)
            {
                view1 = DisplaySystem.GetViewControl(CameraTest.UpCam3);
            }
            view1.ResetView();
            view1.Refresh();
            view1.AddViewImage(GrabImg);
            view1.Repaint();
            MyVisionBase.SaveImg(GrabImg, "扎针对位图片");
            //3.关闭光源
            LightCtrlManager.Instance.SetAllLightTo0();
            FileLib.Logger.Pop("  关闭光源:", false, "运行日志");
            //4.0设置定位模式
            MyLocal.SetLocalModel(MyVisionPara.localPara.localSetting.localModel);
            //5.0设置定位参数
            MyLocal.SetParam(GrabImg, MyVisionPara.localPara);
            //6.执行定位
            try
            {
                MyLocal.doLocal();
                //7.告诉PLC定位结果完成
                if (MyVisionPara.ProjectVisionItem == ProjectVisionEnum.ProjectVision1)
                {
                    FileLib.Logger.Pop(" 扎针右侧视觉定位完成,先不发给PLC信号,等计算出偏移量后,将信号发给PLC:", false, "运行日志");
                }
                else
                {
                    LD.Logic.PlcHandle.Instance.WriteValue(LD.Common.PlcDevice.ArtTestCamLocalResult, 1); //告诉PLC定位结果OK
                    FileLib.Logger.Pop("  告诉PLC拍照结果OK(告诉PLC定位结果OK):", false, "运行日志");
                }
            }
            catch (Exception e0)
            {
                Logger.PopError1(e0, false, "视觉错误日志");
                LD.Logic.PlcHandle.Instance.WriteValue(LD.Common.PlcDevice.ArtTestCamLocalResult, 2); //告诉PLC定位结果NG
                FileLib.Logger.Pop("  告诉PLC拍照结果OK(告诉PLC定位结果NG):", false, "运行日志");
                MyLocalResult.IsLocalOk = false;
            }


            MyLocalResult = MyLocal.GetResult();
            view1.AddViewObject(MyLocalResult.ShowContour);
            //结合标定坐标计算出产品的实际位置
            //8.获取标定矩阵
            MyHomMat2D HomMat = new MyHomMat2D();

            HomMat = CaliParaManager.Instance.GetHomMAT(MyVisionPara.localPara.localSetting.CoordiCam); //获取示教的标定矩阵
            FileLib.Logger.Pop("  获取示教的标定矩阵:" + MyVisionPara.localPara.localSetting.CoordiCam.ToString(), false, "运行日志");
            FileLib.Logger.Pop(HomMat.ToString(), false, "运行日志");
            HalconDotNet.HTuple HHomMat = new HalconDotNet.HTuple();
            //标定矩阵的转换
            MyVisionBase.MyHomMatToHalcon(HomMat, out HHomMat);
            //9.图像坐标系的原点由左上角变到左下角
            MyVisionBase.AdjImgRow(GrabImg, ref MyLocalResult.row);
            St_VectorAngle PixelVector = new St_VectorAngle(MyLocalResult.row, MyLocalResult.col, MyLocalResult.angle);

            FileLib.Logger.Pop("当前的像素坐标", false, "运行日志");
            FileLib.Logger.Pop("Col:" + MyLocalResult.col.ToString("f4") + "  Row:" + MyLocalResult.row.ToString("f4") +
                               "  Theta:" + MyLocalResult.angle.ToString("f4"), false, "运行日志");

            CaliValue CaliPara = CaliParaManager.Instance.GetCaliValue(MyVisionPara.localPara.localSetting.CoordiCam);

            VectorAngle GrabPos = new VectorAngle(X, Y, Theta);

            //9 计算出当前产品距离旋转中心的坐标
            EyeToHandPos.TransEyeToHandPos(PixelVector, CaliPara, GrabPos, out PosToRot);
            //10计算出示教产品到旋转中心的坐标
            St_VectorAngle TeachPixelPos = new St_VectorAngle(MyLocalResult.TeachRow, MyLocalResult.TeachCol, MyLocalResult.TeachAngle);
            VectorAngle    TeachGrabPos  = new VectorAngle(MyLocalResult.TeachX, MyLocalResult.TeachY, MyLocalResult.TeachTheta);

            MyVisionBase.AdjImgRow(GrabImg, ref TeachPixelPos.Row);
            EyeToHandPos.TransEyeToHandPos(TeachPixelPos, CaliPara, TeachGrabPos, out TeachPosToRot);
            view1.Repaint();
            view1.SetString(100, 100, "red", "PosToRot: " + "   X: " + PosToRot.Col.ToString("f3") + "   Y: " +
                            PosToRot.Row.ToString("f3") + "   Theta: " + PosToRot.Angle.ToString("f3"));
            MyLocalResult.PosToRot      = PosToRot;
            MyLocalResult.TeachPosToRot = TeachPosToRot;
            FileLib.Logger.Pop("示教的产品相对旋转中心的偏移量", false, "运行日志");

            FileLib.Logger.Pop("PosToRot: " + "   X: " + PosToRot.Col.ToString("f3") + "   Y: " +
                               PosToRot.Row.ToString("f3") + "   Theta: " + PosToRot.Angle.ToString("f3"), false, "运行日志");

            FileLib.Logger.Pop("当前的产品相对旋转中心的偏移量", false, "运行日志");
            FileLib.Logger.Pop("PosToRot: " + "   X: " + TeachPosToRot.Col.ToString("f3") + "   Y: " +
                               TeachPosToRot.Row.ToString("f3") + "   Theta: " + TeachPosToRot.Angle.ToString("f3"), false, "运行日志");
            //11.计算出X Y Theta的补偿量,

            ////图像坐标转到机械坐标系
            //MyVisionBase.AffineTransPt(MyLocalResult.col, MyLocalResult.row, HHomMat, out MyLocalResult.x, out MyLocalResult.y);
            ////
            //MyVisionBase.AffineTransPt(MyLocalResult.TeachCol, MyLocalResult.TeachRow, HHomMat, out MyLocalResult.TeachX, out MyLocalResult.TeachY);
        }
예제 #11
0
파일: FrmCaliUpDnCam.cs 프로젝트: Gz1d/Gz
 private void FrmUpDnCamCali_Load(object sender, EventArgs e)
 {
     view1 = DisplaySystem.GetViewControl("Cali");
     LocalModelCbx.SelectedIndex = (int)TeachCaliPara.localPara.localSetting.localModel;
 }
예제 #12
0
 private void FrmCamLightCtrl_Load(object sender, EventArgs e)
 {
     view1 = DisplaySystem.GetViewControl("Test");
     DisplaySystem.AddPanelForCCDView("Test", panel1);
     this.CamCbx.SelectedIndexChanged += new System.EventHandler(this.CamCbx_SelectedIndexChanged);
 }
예제 #13
0
        public override void Do()
        {
            //1.打开光源
            FileLib.Logger.Pop("  打开光源:", false, "FOF运行日志");
            foreach (LightPara item in MyVisionPara.camLightPara.lightPara)
            {
                LightCtrlManager.Instance.SetLightValue(item);
            }
            //2.采图
            FileLib.Logger.Pop("  开始采图:", false, "FOF运行日志");
            if (GrabImg != null)
            {
                GrabImg.Dispose();
            }
            if (FilterImg != null)
            {
                FilterImg.Dispose();
            }
            CameraCtrl.Instance.SetExpos(MyVisionPara.camLightPara.CamName, MyVisionPara.camLightPara.Exposure);
            if (CameraCtrl.Instance.GrabImg(MyVisionPara.camLightPara.CamName, out GrabImg))
            {
                if (MyVisionPara.camLightPara.CamName == CameraEnum.Cam2)
                {
                    LD.Logic.PlcHandle.Instance.WriteValue(LD.Common.PlcDevice.FOF_Grabed_ok, 1); //拍照OK
                }
                FileLib.Logger.Pop("  采图OK:", false, "FOF运行日志");
            }
            else
            {
                if (MyVisionPara.camLightPara.CamName == CameraEnum.Cam2)
                {
                    LD.Logic.PlcHandle.Instance.WriteValue(LD.Common.PlcDevice.FOF_Grabed_ok, 2); //拍照NG
                }
                FileLib.Logger.Pop("  采图NG:", false, "FOF运行日志");
            }
            ViewControl view1 = new ViewControl();

            view1 = DisplaySystem.GetViewControl(CameraTest.UpCam2);
            if (MyVisionPara.camLightPara.CamName == CameraEnum.Cam2)
            {
                view1 = DisplaySystem.GetViewControl(CameraTest.UpCam3);
            }
            view1.ResetView();
            view1.Refresh();

            //3.关闭光源
            //LightCtrlManager.Instance.SetAllLightTo0();
            //FileLib.Logger.Pop("  关闭光源:", false, "FOF运行日志");

            //4.0设置定位模式
            MyLocal.SetLocalModel(MyVisionPara.localPara.localSetting.localModel);
            //5.0设置定位参数
            FileLib.Logger.Pop("  开始偏移检测:", false, "FOF运行日志");
            MyVisionBase.SaveImg(GrabImg, "FOF偏移检测图片");


            if (MyVisionPara.camLightPara.IsFilter)
            {
                FileLib.Logger.Pop("  开始频域滤波,FilterC:" + MyVisionPara.camLightPara.FilterC.ToString(), false, "FOF运行日志");
                MyVisionBase.FilterImg(GrabImg, out FilterImg, MyVisionPara.camLightPara.FilterC);
                view1.AddViewImage(FilterImg);
                MyVisionBase.SaveImg(FilterImg, "FOF偏移检测图片");
                MyLocal.SetParam(FilterImg, MyVisionPara.localPara);
            }
            else
            {
                view1.AddViewImage(GrabImg);
                MyLocal.SetParam(GrabImg, MyVisionPara.localPara);
            }

            view1.Repaint();
            //6.执行定位
            try
            {
                FileLib.Logger.Pop("  开始定位:", false, "FOF运行日志");
                MyLocal.doLocal();
                if (MyVisionPara.camLightPara.CamName == CameraEnum.Cam2)
                {
                    LD.Logic.PlcHandle.Instance.WriteValue(LD.Common.PlcDevice.FOF_Grabed_result, 1);
                }
                FileLib.Logger.Pop("  告诉PLC拍照结果OK(告诉PLC定位结果OK):", false, "FOF运行日志");
            }
            catch (Exception e0)
            {
                if (MyVisionPara.camLightPara.CamName == CameraEnum.Cam2)
                {
                    LD.Logic.PlcHandle.Instance.WriteValue(LD.Common.PlcDevice.FOF_Grabed_result, 2);
                }
                Logger.PopError1(e0, false, "视觉错误日志");
                FileLib.Logger.Pop("  告诉PLC拍照结果OK(告诉PLC定位结果NG):", false, "FOF运行日志");
            }
            MyLocalResult = MyLocal.GetResult();
            view1.AddViewObject(MyLocalResult.ShowContour);
            view1.Repaint();
            //8.结合标定坐标计算出产品的实际位置
            MyHomMat2D HomMat = new MyHomMat2D();

            HomMat = CaliParaManager.Instance.GetHomMAT(MyVisionPara.localPara.localSetting.CoordiCam); //获取示教的标定矩阵
            FileLib.Logger.Pop("  获取标定矩阵(CoordiEnumItem):" + MyVisionPara.localPara.localSetting.CoordiCam.ToString()
                               , false, "FOF运行日志");
            FileLib.Logger.Pop(HomMat.ToString(), false, "FOF运行日志");
            HalconDotNet.HTuple HHomMat = new HalconDotNet.HTuple();
            //9.标定矩阵的转换
            MyVisionBase.MyHomMatToHalcon(HomMat, out HHomMat);
            //10.图像坐标系的原点由左上角变到左下角
            MyVisionBase.AdjImgRow(GrabImg, ref MyLocalResult.row);
            MyVisionBase.AffineTransPt(MyLocalResult.col, MyLocalResult.row, HHomMat, out MyLocalResult.x, out MyLocalResult.y);
            FileLib.Logger.Pop("col: " + MyLocalResult.col.ToString("f3") + " row: " + MyLocalResult.row.ToString("f3"), false, "FOF运行日志");
            FileLib.Logger.Pop("X: " + MyLocalResult.x.ToString("f3") + " Y:   " + MyLocalResult.y.ToString("f3"), false, "FOF运行日志");
            MyLocalResult.Theta = MyLocalResult.angle;
            if (FilterImg != null)
            {
                FilterImg.Dispose();
            }
            if (GrabImg != null)
            {
                GrabImg.Dispose();
            }
        }