public override Result Execute() { if (Machine.Instance.Robot.IsSimulation) { return(Result.OK); } Log.Dprint("begin to execute Bad Mark"); Log.Dprint("move to position : " + Position); // 移动到拍照位置 Result ret = Machine.Instance.Robot.MoveSafeZAndReply(); if (!ret.IsOk) { return(ret); } ret = Machine.Instance.Robot.MovePosXYAndReply(Position, this.Program.MotionSettings.VelXYMark, this.Program.MotionSettings.AccXY); if (!ret.IsOk) { return(ret); } Log.Dprint("capture Bad mark"); VisionFindPrmBase visionFindPrm = null; switch (this.FindType) { case BadMarkType.ModelFind: visionFindPrm = this.ModelFindPrm; break; case BadMarkType.GrayScale: visionFindPrm = this.GrayCheckPrm; break; } visionFindPrm.PosInMachine = new PointD(Position.X, Position.Y); //Machine.Instance.Light.SetLight(visionFindPrm.LightType); Machine.Instance.Light.SetLight(visionFindPrm.ExecutePrm); Machine.Instance.Camera.SetExposure(visionFindPrm.ExposureTime); Machine.Instance.Camera.SetGain(visionFindPrm.Gain); Thread.Sleep(visionFindPrm.SettlingTime); byte[] bytes = Machine.Instance.Camera.TriggerAndGetBytes(TimeSpan.FromSeconds(1)).DeepClone(); if (bytes == null) { return(Result.FAILED); } Result result = Result.OK; //移动到拍照高度 if (Machine.Instance.Setting.MachineSelect == MachineSelection.RTV) { Machine.Instance.Robot.MoveToMarkZAndReply(); } if (this.FindType == BadMarkType.ModelFind) { ModelFindPrm.ImgData = bytes; ModelFindPrm.ImgWidth = Machine.Instance.Camera.Executor.ImageWidth; ModelFindPrm.ImgHeight = Machine.Instance.Camera.Executor.ImageHeight; if (!ModelFindPrm.Execute()) { result = Result.FAILED; } } else if (this.FindType == BadMarkType.GrayScale) { GrayCheckPrm.CheckData = GrayCheckPrm.GetROI(bytes, Machine.Instance.Camera.Executor.ImageWidth, Machine.Instance.Camera.Executor.ImageHeight); GrayCheckPrm.CheckWidth = GrayCheckPrm.ModelWidth; GrayCheckPrm.CheckHeight = GrayCheckPrm.ModelHeight; if (!GrayCheckPrm.Execute()) { result = Result.FAILED; } } Log.Dprint(string.Format("bad mark result : {0}", result.IsOk)); // save mark image if (this.Program.RuntimeSettings.SaveBadMarkImages) { bytes?.SaveMarkImage( Machine.Instance.Camera.Executor.ImageWidth, Machine.Instance.Camera.Executor.ImageHeight, this.Program.Name, "BadMarks", "badmark"); } ////如果OK跳过则结果取反 //if (this.IsOkSkip) //{ // result = result.IsOk ? Result.FAILED : Result.OK; //} return(result); }
private Result doCheck() { Log.Dprint("capture Bad mark"); VisionFindPrmBase visionFindPrm = null; switch (this.CheckThm) { case CheckThm.GrayScale: visionFindPrm = this.GrayCheckPrm; break; case CheckThm.ModelFind: visionFindPrm = this.ModelFindPrm; break; } //设置拍照参数 visionFindPrm.PosInMachine = new PointD(Position.X, Position.Y); //Machine.Instance.Light.SetLight(visionFindPrm.LightType); Machine.Instance.Light.SetLight(visionFindPrm.ExecutePrm); Machine.Instance.Camera.SetExposure(visionFindPrm.ExposureTime); Machine.Instance.Camera.SetGain(visionFindPrm.Gain); //采集图像 Thread.Sleep(visionFindPrm.SettlingTime); byte[] bytes = Machine.Instance.Camera.TriggerAndGetBytes(TimeSpan.FromSeconds(1)).DeepClone(); if (bytes == null) { return(Result.FAILED); } //执行检测算法 Result result = Result.OK; //移动到拍照高度 if (Machine.Instance.Setting.MachineSelect == MachineSelection.RTV) { Machine.Instance.Robot.MoveToMarkZAndReply(); } if (this.CheckThm == CheckThm.GrayScale) { GrayCheckPrm.CheckData = GrayCheckPrm.GetROI(bytes, Machine.Instance.Camera.Executor.ImageWidth, Machine.Instance.Camera.Executor.ImageHeight); GrayCheckPrm.CheckWidth = GrayCheckPrm.ModelWidth; GrayCheckPrm.CheckHeight = GrayCheckPrm.ModelHeight; if (!GrayCheckPrm.Execute()) { result = Result.FAILED; } } else if (this.CheckThm == CheckThm.ModelFind) { ModelFindPrm.ImgData = bytes; ModelFindPrm.ImgWidth = Machine.Instance.Camera.Executor.ImageWidth; ModelFindPrm.ImgHeight = Machine.Instance.Camera.Executor.ImageHeight; if (!ModelFindPrm.Execute()) { result = Result.FAILED; } } Log.Dprint(string.Format("bad mark result : {0}", result.IsOk)); //如果OK跳过则结果取反 if (this.IsOkAlarm) { result = result.IsOk ? Result.FAILED : Result.OK; } return(result); }