AC_BOX_Bean_Shelf.cs 13.0 KB
using OnlineStore.Common;
using OnlineStore.LoadCSVLibrary;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace OnlineStore.DeviceLibrary
{
    /// <summary>
    /// 料架新增的出入库逻辑
    /// </summary>
    partial class AC_BOX_Bean
    {

        /// <summary>
        /// 开始入库移动移动
        /// </summary> 
        public void StartShelfInStore()
        {

            if (storeRunStatus == StoreRunStatus.Runing)
            {
                if (IOValue(IO_Type.LineIn_Check).Equals(IO_VALUE.HIGH))
                {
                    LogInfo(" 空闲中,检测到入料口有信号,料架入库:入料口移门打开,");
                    storeRunStatus = StoreRunStatus.Busy;
                    storeStatus = StoreStatus.InStoreExecute;
                    MoveInfo.NewMove(StoreMoveType.InStore, new InOutParam());
                    MoveInfo.ShelfPositionList = new List<string>(ShelfPosList);
                    MoveInfo.NextMoveStep(StoreMoveStep.SI_S02_DoorOpen);
                    CylinderMove(MoveInfo, IO_Type.EntranceDoor_Close, IO_Type.EntranceDoor_Open);

                }
            }
        }
        private void ShelfInStoreProcess()
        {
            LineMoveP moveP = MoveInfo.MoveParam.MoveP;
            #region 料架移入料仓内部处理
            if (MoveInfo.MoveStep.Equals(StoreMoveStep.SI_S01_LineIn_Check))
            {
                MoveInfo.NextMoveStep(StoreMoveStep.SI_S02_DoorOpen);
                InOutStoreLog("料架入库:入料口移门打开");
                CylinderMove(MoveInfo, IO_Type.EntranceDoor_Close, IO_Type.EntranceDoor_Open);
            }
            else if (MoveInfo.MoveStep.Equals(StoreMoveStep.SI_S02_DoorOpen))
            {
                MoveInfo.NextMoveStep(StoreMoveStep.SI_S03_LineRun);
                InOutStoreLog("料架入库:线体正转,等待取料位检测到信号");
                IOMove(IO_Type.Line_BackRun, IO_VALUE.LOW);
                IOMove(IO_Type.Line_Run, IO_VALUE.HIGH);

                MoveInfo.WaitList.Add(WaitResultInfo.WaitIO(IO_Type.LineIn_Check, IO_VALUE.LOW));
                MoveInfo.WaitList.Add(WaitResultInfo.WaitIO(IO_Type.LineTake_Check, IO_VALUE.HIGH));
            }
            else if (MoveInfo.MoveStep.Equals(StoreMoveStep.SI_S03_LineRun))
            {
                MoveInfo.NextMoveStep(StoreMoveStep.SI_S04_LineStop);
                InOutStoreLog("料架入库:取料位检测到信号,停止线体正转");
                IOMove(IO_Type.Line_Run, IO_VALUE.LOW);

            }
            else if (MoveInfo.MoveStep.Equals(StoreMoveStep.SI_S04_LineStop))
            {
                MoveInfo.NextMoveStep(StoreMoveStep.SI_S05_DoorClose);
                InOutStoreLog("料架入库:入料口移门关闭");
                CylinderMove(MoveInfo, IO_Type.EntranceDoor_Open, IO_Type.EntranceDoor_Close);
            }
            else if (MoveInfo.MoveStep.Equals(StoreMoveStep.SI_S05_DoorClose))
            {
                MoveInfo.NextMoveStep(StoreMoveStep.SI_S06_LocationUp);
                InOutStoreLog("料架入库:定位装置上升");
                CylinderMove(MoveInfo, IO_Type.LocationCylinder_Down, IO_Type.LocationCylinder_Up);
            }
            else if (MoveInfo.MoveStep.Equals(StoreMoveStep.SI_S06_LocationUp))
            {
                MoveInfo.NextMoveStep(StoreMoveStep.SI_S07_TopCylinderUp);
                InOutStoreLog("料架入库:顶升装置上升");
                CylinderMove(MoveInfo, IO_Type.TopCylinder_Down, IO_Type.TopCylinder_Up);
            }
            else if (MoveInfo.MoveStep.Equals(StoreMoveStep.SI_S07_TopCylinderUp))
            {
                MoveInfo.NextMoveStep(StoreMoveStep.SI_S08_StartGetTray);
                InOutStoreLog("料架入库:开始循环从第一个空位逐个取料盘,扫码入库"); 
               
            }
            #endregion

            #region 料架取料盘扫码获取POSID
            else if (MoveInfo.MoveStep.Equals(StoreMoveStep.SI_S08_StartGetTray))
            {
                if (MoveInfo.NextShelfPos())
                {
                    //新的料架库位
                    MoveInfo.NextMoveStep(StoreMoveStep.SI_S11_InoutToP1);
                    InOutStoreLog("料架取料:叉子后退到待机点P1");
                    ACAxisMove(Config.InOut_Axis, Config.InOutAxis_P1_Position, Config.InOutAxis_P1_Speed);
                }
                else
                {
                    //所有料盘已取料完成
                }
            }else if (MoveInfo.MoveStep.Equals(StoreMoveStep.SI_S11_InoutToP1))
            {
                MoveInfo.NextMoveStep(StoreMoveStep.SI_S12_MoveToShelf);
                InOutStoreLog("料架取料:升降轴移动到PA1低点,旋转轴移动到PA1点,压紧轴到压紧前点");
                ACAxisMove(Config.UpDown_Axis, moveP.UpDown_LPA1, Config.UpDownAxis_PA1_Speed);
                ACAxisMove(Config.Middle_Axis, moveP.Middle_PA, Config.MiddleAxis_PA_Speed);
                ACAxisMove(Config.Comp_Axis, Config.CompAxis_P3_Speed, Config.CompAxis_P3_Speed);
            }
            else if (MoveInfo.MoveStep.Equals(StoreMoveStep.SI_S12_MoveToShelf))
            {
                MoveInfo.NextMoveStep(StoreMoveStep.SI_S13_InoutToPA);
                InOutStoreLog("料架取料:叉子前进到PA点");
            }
            else if (MoveInfo.MoveStep.Equals(StoreMoveStep.SI_S13_InoutToPA))
            {
                MoveInfo.NextMoveStep(StoreMoveStep.SI_S14_UpdownToPA2);
                InOutStoreLog("料架取料:升降轴上升到PA2点");
            }
            else if (MoveInfo.MoveStep.Equals(StoreMoveStep.SI_S14_UpdownToPA2))
            {
                MoveInfo.NextMoveStep(StoreMoveStep.SI_S15_StartCompress);
                InOutStoreLog("料架取料:压紧轴开始缓慢压紧");
            }
            else if (MoveInfo.MoveStep.Equals(StoreMoveStep.SI_S15_StartCompress))
            {
                MoveInfo.NextMoveStep(StoreMoveStep.SI_S16_ComAxisDownMove);
                InOutStoreLog("料架取料:检测到料叉压紧确认信号,再次向下压紧指定的值");
            }
            else if (MoveInfo.MoveStep.Equals(StoreMoveStep.SI_S16_ComAxisDownMove))
            {
                MoveInfo.NextMoveStep(StoreMoveStep.SI_S17_InoutBack);
                InOutStoreLog("料架取料:记录压紧高度,叉子后退到扫码点");
            }
            else if (MoveInfo.MoveStep.Equals(StoreMoveStep.SI_S17_InoutBack))
            {
                MoveInfo.NextMoveStep(StoreMoveStep.SI_S18_ScanCode);
                InOutStoreLog("料架取料:记录宽度,开始扫码");
            }
            else if (MoveInfo.MoveStep.Equals(StoreMoveStep.SI_S18_ScanCode))
            {
                MoveInfo.NextMoveStep(StoreMoveStep.SI_S19_GetPosId);
                InOutStoreLog("料架取料:扫码成功,从服务器获取库位号");

                StartSendTray();


            }
            else if (MoveInfo.MoveStep.Equals(StoreMoveStep.SI_S19_GetPosId))
            {
                MoveInfo.NextMoveStep(StoreMoveStep.SI_S20_CompressWare);
                InOutStoreLog("料架取料: 获取库位号完成,设置位置参数,开始入库");

                StartSendTray();
            }

            #endregion

            #region 入库逻辑
            else if (MoveInfo.MoveStep.Equals(StoreMoveStep.SI_S20_CompressWare))
            {
                MoveInfo.NextMoveStep(StoreMoveStep.SI_S21_MoveToBag);
                InOutStoreLog("入库:移动到库位点,轴1( 转盘) 至P2( 库位点)轴2(上下) 至P3(库位入库前点)");
            }
            else if (MoveInfo.MoveStep.Equals(StoreMoveStep.SI_S21_MoveToBag))
            {
                MoveInfo.NextMoveStep(StoreMoveStep.SI_S22_DeviceToBag);
                InOutStoreLog("入库:叉子进入库位中,轴3( 叉子) 至P3(库位取放料点)");
            }
            else if (MoveInfo.MoveStep.Equals(StoreMoveStep.SI_S22_DeviceToBag))
            {
                MoveInfo.NextMoveStep(StoreMoveStep.SI_S23_PutWareToBag);
                InOutStoreLog("入库:放下物品,轴2( 上下) 至P4( 库位入料缓冲点)轴4( 压紧) 至P3( 压紧前点)");
            }
            else if (MoveInfo.MoveStep.Equals(StoreMoveStep.SI_S23_PutWareToBag))
            {
                MoveInfo.NextMoveStep(StoreMoveStep.SI_S24_DeviceBackFromBag);
                InOutStoreLog("入库:叉子从库位中返回,轴3( 叉子) 动作至P1( 待机点)");
            }
            else if (MoveInfo.MoveStep.Equals(StoreMoveStep.SI_S24_DeviceBackFromBag))
            {
                MoveInfo.NextMoveStep(StoreMoveStep.SI_S25_GoBack);
                InOutStoreLog("入库:返回待机点,轴2/轴1/轴4动作至P1( 待机点))开始");
            }
            else if (MoveInfo.MoveStep.Equals(StoreMoveStep.SI_S25_GoBack))
            {
                MoveInfo.NextMoveStep(StoreMoveStep.SI_S08_StartGetTray);
                InOutStoreLog("料架入库:开始循环从第一个空位逐个取料盘,扫码入库");
            }
            #endregion

            #region 入库逻辑

            else if (MoveInfo.MoveStep.Equals(StoreMoveStep.SI_S31_ToNGDoor))
            {
                MoveInfo.NextMoveStep(StoreMoveStep.SI_S32_NGDoorUp);
                InOutStoreLog("送出料盘:NG料口升降门上升");
            }
            else if (MoveInfo.MoveStep.Equals(StoreMoveStep.SI_S32_NGDoorUp))
            {
                MoveInfo.NextMoveStep(StoreMoveStep.SI_S33_InoutToNGDoor);
                InOutStoreLog("送出料盘:进出轴前进到NG料门口位置");
            }
            else if (MoveInfo.MoveStep.Equals(StoreMoveStep.SI_S33_InoutToNGDoor))
            {
                MoveInfo.NextMoveStep(StoreMoveStep.SI_S34_UpdownDown);
                InOutStoreLog("送出料盘:升降轴缓慢下降,放下料盘");
            }
            else if (MoveInfo.MoveStep.Equals(StoreMoveStep.SI_S34_UpdownDown))
            {
                MoveInfo.NextMoveStep(StoreMoveStep.SI_S12_MoveToShelf);
                InOutStoreLog("料架取料:叉子后退到待机点P1");
            }
            else if (MoveInfo.MoveStep.Equals(StoreMoveStep.SI_S34_UpdownDown))
            {
                MoveInfo.NextMoveStep(StoreMoveStep.SI_S35_InoutToP1);
                InOutStoreLog("送出料盘:叉子后退到P1");
            }
            else if (MoveInfo.MoveStep.Equals(StoreMoveStep.SI_S35_InoutToP1))
            {
                MoveInfo.NextMoveStep(StoreMoveStep.SI_S36_NGDoorDown);
                InOutStoreLog("送出料盘:关门NG料门,送出料盘结束");
            }
            else if (MoveInfo.MoveStep.Equals(StoreMoveStep.SI_S36_NGDoorDown))
            { 
            } 
            #endregion
            else
            {

                LogInfo(" 入库,moveStatus=" + MoveInfo.MoveStep + ",没有对应的处理!");
            }

        }
        private void StartSendTray()
        { 
            MoveInfo.NextMoveStep(StoreMoveStep.SI_S31_ToNGDoor);
            InOutStoreLog("送出料盘:扫码或获取库位失败,升降轴移动到NG料门口上端,旋转轴移动到NG料门口");
        }

        #region 压紧轴压紧处理 
        private System.Timers.Timer axisCheckTimer = null;
        private string TargetIoType = IO_Type.Compress_Check;
        private IO_VALUE TargetIoValue = IO_VALUE.HIGH;
        private bool ComAxisStartCheck(string targetIo = "", IO_VALUE value = IO_VALUE.HIGH)
        {
            if (String.IsNullOrEmpty(targetIo))
            {
                targetIo = IO_Type.Compress_Check;
            }
            if (axisCheckTimer == null)
            {
                axisCheckTimer = new System.Timers.Timer();
                axisCheckTimer.AutoReset = true;
                axisCheckTimer.Interval += 30;
                axisCheckTimer.Elapsed += CheckTimer_Elapsed;
                axisCheckTimer.Enabled = false;
            }
            TargetIoValue = value;
            TargetIoType = targetIo;
            axisCheckTimer.Start();
            return true;
        }

        private bool ComAxisStopCheck()
        {
            if (!(axisCheckTimer == null))
            {
                axisCheckTimer.Stop();
            }
            return true;
        }
        private bool IsInProcess = false;
        private void CheckTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
        {
            if (IsInProcess) { return; }
            IsInProcess = true;
            if (IOValue(TargetIoType).Equals(TargetIoValue))
            {
                LogUtil.info(Name + "上料轴,检测到 " + TargetIoType + "=" + TargetIoValue + ",可以停止运动");
                ACServerManager.SuddenStop(Config.Comp_Axis.DeviceName, Config.Comp_Axis.GetAxisValue());
                ComAxisStopCheck();
            }
            IsInProcess = false;
        }
        #endregion
    }
}