Esempio n. 1
0
        /// <summary>
        /// 根据示教Mark点的坐标找到对应的文件中的Mark点坐标
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        public DataBase GetData(DataBase data)
        {
            try
            {
                if (data is DataAmphnol)
                {
                    DataAmphnol dataAmphnol        = data as DataAmphnol;
                    double      anglePatternMark1  = 0;
                    double      lengthPatternMark1 = 0;

                    this.findPointRelWorkPiece(this.workPieceMark1, this.workPieceMark1, dataAmphnol.MarkInMachine, out anglePatternMark1, out lengthPatternMark1);

                    foreach (ResultAmphnol item in this.patternMarksTransed)
                    {
                        double angleTmp  = 0;
                        double lengthTmp = 0;
                        this.findPointRelWorkPiece(this.workpieceMark1Transed.position, this.workpieceMark2Transed.position, item.position, out angleTmp, out lengthTmp);
                        if (Math.Abs(anglePatternMark1 - angleTmp) < this.toleranceAngle && Math.Abs(lengthPatternMark1 - lengthTmp) < this.tolerancePos)
                        {
                            data.IsOk         = true;
                            data.MarkFromFile = item.position;
                            return(data);
                        }
                    }
                    // 没匹配上可能是跳过的穴位
                    data.IsOk         = true;
                    data.MarkFromFile = new PointD(10000, 10000);
                }
            }
            catch (Exception e)
            {
                data.IsOk = false;
                Log.Print(e.Message);
            }
            return(data);
        }
Esempio n. 2
0
        public override Result Execute()
        {
            if (Machine.Instance.Robot.IsSimulation)
            {
                return(Result.OK);
            }
            Log.Dprint("begin to execute Mark");
            Log.Dprint("move to position : " + this.Position);
            Result ret = Result.OK;

            if (this.IsFromFile)
            {
                this.ModelFindPrm.PosInMachine = new PointD(this.Position.X, this.Position.Y);

                //从指定的位置获取当前mark
                Custom.DataCentor.DataBase data = new DataAmphnol();

                data.MarkInMachine = new PointD(this.Position.X, this.Position.Y);

                data = Executor.Instance.GetCustom().GetData(data);
                if (!data.IsOk)
                {
                    ret = Result.FAILED;
                }
                this.ModelFindPrm.TargetInMachine = data.MarkFromFile;
            }
            else
            {
                // 移动到拍照位置
                ret = Machine.Instance.Robot.MoveSafeZAndReply();
                if (!ret.IsOk)
                {
                    return(ret);
                }
                ret = Machine.Instance.Robot.MovePosXYAndReply(this.Position,
                                                               this.Program.MotionSettings.VelXYMark,
                                                               this.Program.MotionSettings.AccXY);
                if (!ret.IsOk)
                {
                    return(ret);
                }
                Log.Dprint("capture mark");
                // 拍照并获取mark点位置
                this.ModelFindPrm.PosInMachine = new PointD(this.Position.X, this.Position.Y);
                Bitmap bmp;
                ret = Machine.Instance.CaptureMark(this.ModelFindPrm, out bmp);
                if (ret.IsOk)
                {
                    Log.Dprint("mark real position : " + this.ModelFindPrm.TargetInMachine);
                }
                if (this.Program.RuntimeSettings.SaveMarkImages)
                {
                    bmp?.SaveMarkImage(this.Program.Name, "Marks", "mark");
                    //if (bmp != null)
                    //{
                    //    string filePath = RecordPathDef.Program_Marks_Date(this.Program.Name, "Marks")
                    //        + "\\mark_" + DateTime.Now.ToString("yyyyMMddHHmmssfff") + ".jpg";
                    //    DataServer.Instance.Fire(() =>
                    //    {
                    //        try
                    //        {
                    //            bmp.Save(filePath, ImageFormat.Jpeg);
                    //        }
                    //        catch (Exception e)
                    //        {
                    //            Log.Dprint("Mark Image Save error :" + e.Message);
                    //        }
                    //    });
                    //}
                }
            }

            return(ret);
        }