WeldStepBean.cs 6.3 KB

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using URSoldering.Common;

namespace URSoldering.DeviceLibrary
{
    /// <summary>
    /// 焊接步骤信息
    /// </summary>
    public class WeldStepBean
    {
        public WeldStepBean()
        {
            weldPointList = new List<WeldPointInfo>();
            currBoard = null;
            CurrPointIndex = 0;
            CurrPoint = null;
            moveType = MoveType.None;
            this.moveStep = MoveStep.Wait;
            IsInWait = false;
            PointTime = null;
            OneWaitOk = false;
        }
        public void PositionOffSet(double x, double y)
        {
            for (int i = 0; i < weldPointList.Count; i++)
            {
                if (weldPointList[i].pointType.Equals(3))
                {
                    LogUtil.info(weldPointList[i].pointName + "是拍照点,不需要坐标偏移");
                }
                else if (weldPointList[i].pointType.Equals(1))
                {
                    LogUtil.info(weldPointList[i].pointName + "是中间点,不需要坐标偏移");
                }
                else
                {
                    string oldPosition = weldPointList[i].GetURPoint().ToShowStr();
                    weldPointList[i].RobotX += x;
                    weldPointList[i].RobotY += y;
                    LogUtil.info(weldPointList[i].pointName + "坐标偏移:偏移前【" + oldPosition + "】偏移后【" + weldPointList[i].GetURPoint().ToShowStr() + "】");
                }
            }
        }
        /// <summary>
        /// 焊接的板子信息
        /// </summary>
        public BoardInfo currBoard;
        public List<WeldPointInfo> weldPointList = new List<WeldPointInfo>();
        public int CurrPointIndex = 0;
   
        /// <summary>
        /// 当前焊点信息
        /// </summary>
        public WeldPointInfo CurrPoint;
        /// <summary>
        /// 焊点时间记录
        /// </summary>
        public PointWeldTime PointTime;
        /// <summary>
        /// 最后一个步骤操作时间
        /// </summary>
        public DateTime LastSetpTime;
        /// <summary>
        /// 操作类型
        /// </summary>
        public MoveType moveType = MoveType.None;
        /// <summary>
        /// 当前执行到的步骤
        /// </summary>
        public MoveStep moveStep;
        /// <summary>
        /// 是否再当前步骤等待中
        /// </summary>
        public bool IsInWait;
        public DateTime WeldStartTime = DateTime.Now;
        public bool OneWaitOk = false;
        /// <summary>
        /// 开始焊接时第一个焊点的索引
        /// </summary>
        public int StartPointIndex = 0;
        /// <summary>
        /// 已经复位的次数
        /// </summary>
        public int ResetCount = 0;
        /// <summary>
        /// 是否已经慢速送丝
        /// </summary>
        public bool IsSlowSendWire = false;
        /// <summary>
        /// 当前步骤执行完成
        /// </summary>
        public void EndStepWait()
        {
            OneWaitOk = false;
            IsInWait = false;
            WaitList = new List<WaitResultInfo>();
        }
        public void NewWeld(MoveType type)
        {
            IsSlowSendWire = false;
            OneWaitOk = false;
            moveStep = MoveStep.Wait;
            this.moveType = type;
            LastSetpTime = DateTime.Now;
            WeldStartTime = DateTime.Now;
            WaitList = new List<WaitResultInfo>();
            CurrPointIndex = 0;
            ResetCount = 0; 
        }
        /// <summary>
        /// 开始焊接
        /// </summary> 
        /// <param name="pointType">焊点类型,0=所有 </param>
        public bool NewWeld(MoveType type, BoardInfo board)
        {
            IsSlowSendWire = false;
            StartPointIndex = 0;
            OneWaitOk = false;
            NewWeld(type);
            this.currBoard = board;
            CurrPointIndex = 0;

            //安装配置顺序加入
            weldPointList = new List<WeldPointInfo>();
            foreach (WeldPointInfo p in board.pointList)
            {
                if (!URRobotControl.PointIsValid(p.GetURPoint()))
                {
                    LogUtil.error("【" + board.boardName + "】的焊点【" + p.pointName + "】坐标无效,无法开始焊接");
                    return false;
                }
                WeldPointInfo newP =  p.Clone();
                weldPointList.Add(newP);
            }
            if (weldPointList.Count <= 0)
            {
                return false;
            }

            CurrPoint = weldPointList[CurrPointIndex];
            PointTime = new PointWeldTime();
            ResetCount = 0;
            return true;
        }

        public void NextMoveStep(MoveStep step)
        {
            OneWaitOk = false;
            moveStep = step;
            LastSetpTime = DateTime.Now;
            IsInWait = true;
            WaitList = new List<WaitResultInfo>();
        }
        public bool NextPoint()
        {
            IsSlowSendWire = false;
            ResetCount = 0;
            OneWaitOk = false;
            CurrPointIndex++;
            if (weldPointList.Count <= CurrPointIndex)
            {
                return false;
            }
            else
            {
                CurrPoint = weldPointList[CurrPointIndex];
                PointTime = new PointWeldTime();
                return true;
            }
        }
        public void EndMove()
        {
            IsSlowSendWire = false;
            OneWaitOk = false;
            this.moveType = MoveType.None;
            this.currBoard = null;
            moveStep = MoveStep.Wait;
            LastSetpTime = DateTime.Now;
            IsInWait = false;
            WaitList = new List<WaitResultInfo>();
        }

        public List<WaitResultInfo> WaitList = new List<WaitResultInfo>();

        public bool IsFirstPoint()
        {
            if (CurrPointIndex.Equals(0))
            {
                return true;
            }
            return false;
        }
        public bool IsLastPoint()
        {
            if (weldPointList.Count <= CurrPointIndex + 1)
            {
                return true;
            }
            return false;
        }
    }
}