private void UpCamThread(Object Obj) { UpCamThreadSwitch = true; UpCamProcessEvent.Reset(); while (true) { if (UpCamProcessEvent.IsSet) { int UpCamStationNum = (int)LD.Logic.PlcHandle.Instance.ReadValue(UpCamVisionNumAddr); if (UpCamStationNum == 0) //上相机定位左上角 { //1.0开始采图 VisionStateBaseUpCamLeftUp.GrabingImg(); //2.0告诉PLC采图完成 LD.Logic.PlcHandle.Instance.WriteValue(UpCamGrabedAddr, 1); //3.0执行定位 VisionStateBaseUpCamLeftUp.DoLocal(); //4.0显示定位结果 VisionStateBaseUpCamLeftUp.ShowRlt(); //5.0获取定位结果 UpCamLeftUpLocalRlt = VisionStateBaseUpCamLeftUp.GetLocalRlt(); UpCamLeftUpLocalIsok = true; } else if (UpCamStationNum == 1)//上相机定位右上角 { VisionStateBaseUpCamRightUp.GrabingImg(); LD.Logic.PlcHandle.Instance.WriteValue(UpCamGrabedAddr, 1); VisionStateBaseUpCamRightUp.DoLocal(); VisionStateBaseUpCamRightUp.ShowRlt(); UpCamRightUpLocalRlt = VisionStateBaseUpCamLeftUp.GetLocalRlt(); UpCamRightUpLocalIsOk = true; } UpCamProcessEvent.Reset(); } else { Thread.Sleep(1); } if (UpCamLeftUpLocalIsok && UpCamRightUpLocalIsOk && LeftDnCamLeftLocalIsOk && LeftDnCamRightLocalIsOk) { //1.0计算胶带当前的定位坐标,相对于示教坐标的偏差; double LeftOffSetX = 0, LeftOffSetY = 0, RightOffSetX = 0, RightOffsetY = 0; LeftOffSetX = LeftDnCamLeftLocalResult.PosToRot.Col - LeftDnCamLeftLocalResult.TeachPosToRot.Col; LeftOffSetY = LeftDnCamLeftLocalResult.PosToRot.Row - LeftDnCamLeftLocalResult.TeachPosToRot.Row; RightOffSetX = LeftDnCamRightLocalResult.PosToRot.Col - LeftDnCamRightLocalResult.TeachPosToRot.Col; RightOffsetY = LeftDnCamRightLocalResult.PosToRot.Row - LeftDnCamRightLocalResult.TeachPosToRot.Row; //2.0 用当前的胶带坐标相对于示教的偏移量, 调整Ipad的示教坐标 Point2Db TeachIpadPosLeft = new Point2Db(UpCamLeftUpLocalRlt.TeachPosToRot.Col, UpCamLeftUpLocalRlt.TeachPosToRot.Row); Point2Db TeachIpadPosRight = new Point2Db(UpCamRightUpLocalRlt.TeachPosToRot.Col, UpCamRightUpLocalRlt.TeachPosToRot.Row); TeachIpadPosLeft.Col = TeachIpadPosLeft.Col + LeftOffSetX; TeachIpadPosLeft.Row = TeachIpadPosLeft.Row + LeftOffSetY; TeachIpadPosRight.Col = TeachIpadPosRight.Col + RightOffSetX; TeachIpadPosRight.Row = TeachIpadPosRight.Row + RightOffsetY; //3.0 利用调整后的Ipad示教坐标 和 当前的Ipad坐标 计算出 偏移补偿量 Point2Db NowIpadLeftPos = new Point2Db(UpCamLeftUpLocalRlt.PosToRot.Col, UpCamLeftUpLocalRlt.PosToRot.Row); Point2Db NowIpadRightPos = new Point2Db(UpCamRightUpLocalRlt.PosToRot.Col, UpCamRightUpLocalRlt.PosToRot.Row); //4.0计算出偏移量 double AddX = 0, AddY = 0, AddTheta = 0; MyVisionBase.CalculateThreeTapePos(NowIpadLeftPos, NowIpadRightPos, TeachIpadPosLeft, TeachIpadPosRight, out AddX, out AddY, out AddTheta); FileLib.Logger.Pop(" 计算出的偏移补偿量:" + AddX.ToString("f3") + " " + AddY.ToString("f3") + " " + AddTheta.ToString("f3"), false, "运行日志"); int SystemOffSetX = 0, SystemOffsetY = 0; SystemOffSetX = (int)(LeftDnCamLeftVisionPara.localPara.localSetting.Offset_x * 1000); //系统误差补偿 SystemOffsetY = (int)(LeftDnCamLeftVisionPara.localPara.localSetting.Offset_y * 1000); int NewAddX = (int)(AddX * 1000) + SystemOffSetX; int NewAddY = (int)(AddY * 1000) + SystemOffsetY; int NewAddTheta = (int)(AddTheta * 1000); LD.Logic.PlcHandle.Instance.WriteValue(LeftDnCamVisionFinishAddr, 1); LD.Logic.PlcHandle.Instance.WriteValue(LD.Common.PlcDevice.V_03_Offset_X, NewAddX); LD.Logic.PlcHandle.Instance.WriteValue(LD.Common.PlcDevice.V_03_Offset_Y, -NewAddY); //移动屏幕 LD.Logic.PlcHandle.Instance.WriteValue(LD.Common.PlcDevice.V_03_Offset_R, NewAddTheta); //5.0 清空此次定位的数据,进入下次定位 UpCamLeftUpLocalIsok = false; UpCamRightUpLocalIsOk = false; LeftDnCamLeftLocalIsOk = false; LeftDnCamRightLocalIsOk = false; } if (!UpCamThreadSwitch) { break; } } }
public void UpCamThread(Object Obj) { UpCamThreadSwitch = true; UpCamProcessEvent.Reset(); while (true) { if (UpCamProcessEvent.IsSet) { int UpCamStationNum = (int)LD.Logic.PlcHandle.Instance.ReadValue(UpCamVisionNumAddr); if (UpCamStationNum == 0) { VisionStateUpCamLeftDn.GrabingImg(); //1.0 开始采图 LD.Logic.PlcHandle.Instance.WriteValue(UpCamGrabedAddr, 1); //2.0 告诉Plc采图完成 VisionStateUpCamLeftDn.DoLocal(); //3.0 执行定位 VisionStateUpCamLeftDn.ShowRlt(); //4.0 显示定位结果 UpCamLeftDnLocalRlt = VisionStateUpCamLeftDn.GetLocalRlt(); //5.0 获取定位结果 UpCamLeftDnLocalIsOk = true; } else if (UpCamStationNum == 1) { VisionStateUpCamRightDn.GrabingImg(); LD.Logic.PlcHandle.Instance.WriteValue(UpCamGrabedAddr, 1); VisionStateUpCamRightDn.DoLocal(); VisionStateUpCamRightDn.ShowRlt(); UpCamRightDnLocalRlt = VisionStateUpCamRightDn.GetLocalRlt(); UpCamRightDnLocalIsOk = true; } UpCamProcessEvent.Reset(); } else { Thread.Sleep(1); } if (UpCamLeftDnLocalIsOk && UpCamRightDnLocalIsOk && RightDnLeftLocalIsOk && RightDnRightLocalIsOk) { //1.0计算胶带当前的定位坐标,相对于示教坐标的偏差; double LeftOffSetX = 0, LeftOffSetY = 0, RightOffSetX = 0, RightOffsetY = 0; LeftOffSetX = RightDnCamLeftLocalRlt.PosToRot.Col - RightDnCamLeftLocalRlt.TeachPosToRot.Col; LeftOffSetY = RightDnCamLeftLocalRlt.PosToRot.Row - RightDnCamLeftLocalRlt.TeachPosToRot.Row; RightOffSetX = RightDnCamRightLocalRlt.PosToRot.Col - RightDnCamRightLocalRlt.TeachPosToRot.Col; RightOffsetY = RightDnCamRightLocalRlt.PosToRot.Row - RightDnCamRightLocalRlt.TeachPosToRot.Row; //2.0 用当前的胶带坐标相对于示教的偏移量, 调整Ipad的示教坐标 Point2Db TeachIpadPosLeft = new Point2Db(UpCamLeftDnLocalRlt.TeachPosToRot.Col, UpCamLeftDnLocalRlt.TeachPosToRot.Row); Point2Db TeachIpadPosRight = new Point2Db(UpCamRightDnLocalRlt.TeachPosToRot.Col, UpCamRightDnLocalRlt.TeachPosToRot.Row); TeachIpadPosLeft.Col = TeachIpadPosLeft.Col + LeftOffSetX; TeachIpadPosLeft.Row = TeachIpadPosLeft.Row + LeftOffSetY; TeachIpadPosRight.Col = TeachIpadPosRight.Col + RightOffSetX; TeachIpadPosRight.Row = TeachIpadPosRight.Row + RightOffsetY; //3.0 利用调整后的Ipad示教坐标 和 当前的Ipad坐标 计算出 偏移补偿量 Point2Db NowIpadLeftPos = new Point2Db(UpCamLeftDnLocalRlt.PosToRot.Col, UpCamLeftDnLocalRlt.PosToRot.Row); Point2Db NowIpadRightPos = new Point2Db(UpCamRightDnLocalRlt.PosToRot.Col, UpCamRightDnLocalRlt.PosToRot.Row); //4.0计算出偏移量 double SystemOffsetX = RightDnLeftVisionPara.localPara.localSetting.Offset_x; double SystemOffsetY = RightDnLeftVisionPara.localPara.localSetting.Offset_y; double SystemOffsetTheta = RightDnLeftVisionPara.localPara.localSetting.Offset_theta; double AddX = 0, AddY = 0, AddTheta = 0; MyVisionBase.CalculateTwoPtPos(NowIpadLeftPos, NowIpadRightPos, TeachIpadPosLeft, TeachIpadPosRight, SystemOffsetX, SystemOffsetY, SystemOffsetTheta, out AddX, out AddY, out AddTheta); FileLib.Logger.Pop(" 计算出的偏移补偿量:" + AddX.ToString("f3") + " " + AddY.ToString("f3") + " " + AddTheta.ToString("f3"), false, "运行日志"); int NewAddX = (int)(AddX * 1000); int NewAddY = (int)(AddY * 1000); int NewAddTheta = (int)(AddTheta * 1000); LD.Logic.PlcHandle.Instance.WriteValue(RightDnCamVisionFinishAddr, 1); LD.Logic.PlcHandle.Instance.WriteValue(LD.Common.PlcDevice.V_05_Offset_X, -NewAddX); LD.Logic.PlcHandle.Instance.WriteValue(LD.Common.PlcDevice.V_05_Offset_Y, NewAddY); LD.Logic.PlcHandle.Instance.WriteValue(LD.Common.PlcDevice.V_05_Offset_R, NewAddTheta); } } }
private void IpadLcoalThread(object Obj) { FeederThreadSwitch = true; while (true) { if (FeerderCamTrigEvent.IsSet) { int StateNum = (int)LD.Logic.PlcHandle.Instance.ReadValue(FeederCamStateNumAddr); if (StateNum == 0) //Ipad左上角 { VisionStateLeftUp.GrabingImg(); LD.Logic.PlcHandle.Instance.WriteValue(FeederCamGrabedAddr, 1); VisionStateLeftUp.DoLocal(); VisionStateLeftUp.ShowRlt(); LeftUpLocalRlt = VisionStateLeftUp.GetLocalRlt(); LeftUpLocalIsOK = true; } else if (StateNum == 1) //Ipad右下角 { VisionStateRightDn.GrabingImg(); LD.Logic.PlcHandle.Instance.WriteValue(FeederCamGrabedAddr, 1); VisionStateRightDn.DoLocal(); VisionStateRightDn.ShowRlt(); RightDnLocalRlt = VisionStateRightDn.GetLocalRlt(); RightDnLocalIsOk = true; } } if (LeftUpLocalIsOK && RightDnLocalIsOk) { //1.0Ipad放置时的示教坐标 Point2Db IpadLeftUpTeachPos = new Point2Db(LeftUpLocalRlt.TeachPosToRot.Col, LeftUpLocalRlt.TeachPosToRot.Row); Point2Db IpadRightDnTeachPos = new Point2Db(RightDnLocalRlt.TeachPosToRot.Col, RightDnLocalRlt.TeachPosToRot.Row); //2.0Ipad的当前坐标 Point2Db IpadLeftUpNowPos = new Point2Db(LeftUpLocalRlt.PosToRot.Col, LeftUpLocalRlt.PosToRot.Row); Point2Db IpadRightDnNowPos = new Point2Db(RightDnLocalRlt.PosToRot.Col, RightDnLocalRlt.PosToRot.Row); //3.0计算出偏移量 double AddX = 0, AddY = 0, AddTheta = 0; MyVisionBase.CalculateThreeTapePos(IpadLeftUpNowPos, IpadRightDnNowPos, IpadLeftUpTeachPos, IpadRightDnTeachPos, out AddX, out AddY, out AddTheta); FileLib.Logger.Pop(" 计算出的偏移补偿量:" + AddX.ToString("f3") + " " + AddY.ToString("f3") + " " + AddTheta.ToString("f3"), false, "运行日志"); int SystemOffSetX = 0, SystemOffsetY = 0; SystemOffSetX = (int)(LeftUpVisionPara.localPara.localSetting.Offset_x * 1000); //系统误差补偿 SystemOffsetY = (int)(LeftUpVisionPara.localPara.localSetting.Offset_y * 1000); //系统误差补偿 int NewAddX = (int)(AddX * 1000) + SystemOffSetX; int NewAddY = (int)(AddY * 1000) + SystemOffsetY; int NewAddTheta = (int)(AddTheta * 1000); LD.Logic.PlcHandle.Instance.WriteValue(FeederCamVisionFinishAddr, 1); LD.Logic.PlcHandle.Instance.WriteValue(LD.Common.PlcDevice.V_01_Offset_X, NewAddX); LD.Logic.PlcHandle.Instance.WriteValue(LD.Common.PlcDevice.V_01_Offset_Y, NewAddY); //移动屏幕 LD.Logic.PlcHandle.Instance.WriteValue(LD.Common.PlcDevice.V_01_Offset_R, NewAddTheta); //4.0 清空此次定位的数据,进入下次定位 LeftUpLocalIsOK = false; RightDnLocalIsOk = false; } Thread.Sleep(1); if (!FeederThreadSwitch) { break; } } }