MainMachine _LeftProcess.cs 17.7 KB
using OnlineStore;
using CodeLibrary;
using OnlineStore.Common;
using OnlineStore.LoadCSVLibrary;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data;

namespace DeviceLibrary
{
    partial class MainMachine
    {
        bool LeftShelfNoTray = false;
        int LeftCount = 0;

        public bool SafeReleaseLeftShelf = false;
        //int Uppre = -1000;
        //int Uplast = -1000;
        //int step = 0;
        public int LastBatchAxisPosition = 0;
        public int PlwHight = 0;
        /// <summary>
        /// 料盘高度单位脉冲
        /// </summary>
        //public int PlwHight
        //{
        //    get
        //    {
        //        int hight = 0;
        //        //if (Uppre != -1000 && Uplast != -1000&&step==3)
        //        if (Uppre != -1000 && Uplast != -1000 && step == 2)
        //        {
        //            hight = Math.Abs(Uplast - Uppre) + 2000;
        //            RightMoveInfo.log($"料盘高度计算:hight:{hight},Uppre:{Uppre},Uplast:{Uplast}");
        //        }
        //        return hight;
        //    }
        //}
        void LeftProcess()
        {
            if (CheckWait(LeftMoveInfo))
                return;

            switch (LeftMoveInfo.MoveStep)
            {
                //阻挡上升,轴到p2
                case MoveStep.L01:
                    LeftCount = 0;
                    LeftShelfNoTray = false;
                    LeftMoveInfo.NextMoveStep(MoveStep.L03);
                    CylinderMove(null, IO_Type.LeftStopDown, IO_Type.LeftStopUP);
                    LeftBatchAxisToP2(Config.Left_Batch_P2, Config.Left_Batch_P1_speed, IO_VALUE.HIGH);
                    LeftMoveInfo.log($"批量轴上升到P2位置,第一次提升,LeftStartMovePosition={LeftStartMovePosition}");
                    break;
                //轴下降一点
                case MoveStep.L03:
                    LeftMoveInfo.NextMoveStep(MoveStep.L04);
                    int targetP1 = Left_Batch_Axis.GetAclPosition() - ConfigHelper.Config.Get("LeftAxisDownValue", 50) * Config.Left_Batch_ChangeValue;
                    if (PlwHight > 5000)
                    {
                        int currpoint = Left_Batch_Axis.GetAclPosition();
                        int countPleHight = PlwHight / Config.Right_Batch_ChangeValue * Config.Left_Batch_ChangeValue;
                        targetP1 = currpoint - countPleHight + 5000;
                        LeftMoveInfo.log($"出料提升机构,获取到料盘高度脉冲{PlwHight},当前位置{currpoint},计算盘高{countPleHight}");
                    }
                    int targetSpeed = Config.Left_Batch_P1_speed;
                    if (targetP1 <= 0)
                    {
                        LeftMoveInfo.log("出料提升机构,下降固定值小于0,设置回到0原点。");
                        targetP1 = 0;
                        LeftMoveInfo.NextMoveStep(MoveStep.L40_ShelfFull);
                        LeftMoveInfo.log($"批量轴已下降到底,料串已满,Left_Batch_P1={Config.Left_Batch_P1}");
                    }
                    LeftMoveInfo.log($"出料提升机构,下降固定值为{targetP1}脉冲!");
                    Left_Batch_Axis.AbsMove(LeftMoveInfo, targetP1, targetSpeed);
                    LeftMoveInfo.log($"批量轴下降固定值");
                    break;
                //根据轴位置判断去料串满步骤还是不满步骤
                case MoveStep.L04:
                    var currpos = Left_Batch_Axis.GetAclPosition();
                    if (currpos <= Config.Left_Batch_P1+2000)
                    {
                        LeftMoveInfo.NextMoveStep(MoveStep.L40_ShelfFull);
                        LeftMoveInfo.log($"批量轴已下降到底,料串已满,Left_Batch_P1={Config.Left_Batch_P1},needpos={currpos}");
                    }
                    else
                    {
                        LeftMoveInfo.NextMoveStep(MoveStep.L10_WaitReelPut);
                    }
                    break;
                //等中间步骤抓盘
                case MoveStep.L10_WaitReelPut:
                    Msg.add(crc.GetString("Res0095", "左侧空闲中"), MsgLevel.info);
                    break;
                //中间步骤给盘,下降一点,获取盘信息
                case MoveStep.L11_ReelPutted:
                    //if (RightMoveInfo.MoveStep== MoveStep.Wait)
                    {
                        LeftCount++;
                        LeftMoveInfo.NextMoveStep(MoveStep.L12);
                        LeftBatchAxisToP2(Config.Left_Batch_P1, Config.Left_Batch_P1_speed, IO_VALUE.LOW);
                        //LeftBatchAxisDown();
                        LabelMoveInfo.MoveParam = LeftMoveInfo.MoveParam.clone();
                        LeftMoveInfo.log($"左侧料盘已放入,批量轴下降固定值");
                    }
                    //else
                    //{
                    //    LeftMoveInfo.NextMoveStep(MoveStep.L11_ReelPutted);
                    //}
                    break;
                //防意外
                case MoveStep.L12:
                    LeftMoveInfo.NextMoveStep(MoveStep.L13);
                    //LeftBatchAxisToP2(false);
                    LeftAxisRiseMax();
                    LeftMoveInfo.log($"批量轴上升到P2位置,LeftStartMovePosition={LeftStartMovePosition}");
                    break;
                case MoveStep.L13:
                    LeftMoveInfo.NextMoveStep(MoveStep.L20_WaitLabel);

                    break;
                //等贴标,由贴标流程跳出
                case MoveStep.L20_WaitLabel:
                    break;
                //贴标完成,没有释放料串时进入判断料串满/不满流程
                case MoveStep.L30_LabelFinish:
                    if (SafeReleaseLeftShelf)
                    {
                        //LeftShelfNoTray = true;
                        SafeReleaseLeftShelf = false;
                        LeftMoveInfo.NextMoveStep(MoveStep.L40_ShelfFull);
                        LeftMoveInfo.log($"用户请求释放料架");
                    }
                    else
                    {
                        if (PlwHight >0)
                        {
                            LeftMoveInfo.NextMoveStep(MoveStep.L03);
                            LeftBatchAxisToP2(Config.Left_Batch_P1, Config.Left_Batch_P1_speed, IO_VALUE.LOW);
                            
                            LeftMoveInfo.log($"贴标完成,批量轴下降固定值");
                        }
                        else
                        {
                            LeftMoveInfo.NextMoveStep(MoveStep.L30_LabelFinish);
                        }
                    }
                    break;
                //满了下降到p1点,没有agv运输时挡停下降
                case MoveStep.L40_ShelfFull:
                    LeftShelfNoTray = true;
                    LeftMoveInfo.NextMoveStep(MoveStep.LEND);
                    Left_Batch_Axis.AbsMove(LeftMoveInfo, Config.Left_Batch_P1, Config.Left_Batch_P1_speed);
                    if (ConfigHelper.Config.Get("UseAGVTransferShelf", false))//是否用AGV运输料串
                    {
                        LeftMoveInfo.log($"料串已满,批量轴下降到P1位置");
                    }
                    else
                    {
                        CylinderMove(LeftMoveInfo, IO_Type.LeftStopUP, IO_Type.LeftStopDown);
                        LeftMoveInfo.log($"料串已满,批量轴下降到P1位置,阻挡下降");
                    }
                    break;
                case MoveStep.LEND:
                    LeftMoveInfo.EndMove();
                    LeftMoveInfo.log($"结束运动");
                    break;
                //}
                //料串出料流程,下降到p1,挡停下降,滚筒反转到后端检测低电平再转10秒,到前端检测低电平再转10秒,再等3秒,再等0.5秒后反转停止
                //switch (LeftMoveInfo.MoveStep)
                //{
                case MoveStep.L50_OutShelf:
                    LeftMoveInfo.NextMoveStep(MoveStep.L51);
                    Left_Batch_Axis.AbsMove(LeftMoveInfo, Config.Left_Batch_P1, Config.Left_Batch_P1_speed);
                    LeftMoveInfo.log($"批量轴下降到P1位置");
                    break;
                case MoveStep.L51:
                    LeftMoveInfo.NextMoveStep(MoveStep.L52);
                    CylinderMove(null, IO_Type.LeftStopUP, IO_Type.LeftStopDown);
                    LeftMoveInfo.log($"阻挡下降");
                    break;
                case MoveStep.L52:
                    LeftMoveInfo.NextMoveStep(MoveStep.L53);
                    IOMove(IO_Type.LeftMoto_Run, IO_VALUE.LOW);
                    IOMove(IO_Type.LeftMoto_Reverse, IO_VALUE.HIGH);
                    LeftMoveInfo.WaitList.Add(WaitResultInfo.WaitIO(IO_Type.LeftEnd_Check, IO_VALUE.LOW));
                    LeftMoveInfo.WaitList.Add(WaitResultInfo.WaitTime(10000));
                    LeftMoveInfo.log($"电滚筒向外滚动");
                    break;
                case MoveStep.L53:
                    LeftMoveInfo.NextMoveStep(MoveStep.L54);
                    LeftMoveInfo.WaitList.Add(WaitResultInfo.WaitIO(IO_Type.LeftFornt_Check, IO_VALUE.LOW));
                    LeftMoveInfo.WaitList.Add(WaitResultInfo.WaitTime(10000));
                    LeftMoveInfo.OneWaitCanEndStep = true;
                    LeftMoveInfo.log($"等待前置检测拉低");
                    break;
                case MoveStep.L54:
                    LeftMoveInfo.NextMoveStep(MoveStep.L55);
                    LeftMoveInfo.WaitList.Add(WaitResultInfo.WaitTime(3000));
                    break;
                case MoveStep.L55:
                    LeftMoveInfo.NextMoveStep(MoveStep.LEND);
                    IOMove(IO_Type.LeftMoto_Reverse, IO_VALUE.HIGH, false, 500);
                    LeftMoveInfo.log($"电滚停止");
                    break;
                //}
                //料串入料流程,轴下降到p1,挡停下降,滚筒正转到后端检测高电平后再转60秒,再转1秒,再转0.5秒停止,进入上料流程
                //switch (LeftMoveInfo.MoveStep)
                //{
                case MoveStep.L60_InShelf:
                    LeftMoveInfo.NextMoveStep(MoveStep.L61);
                    Left_Batch_Axis.AbsMove(LeftMoveInfo, Config.Left_Batch_P1, Config.Left_Batch_P1_speed);
                    LeftMoveInfo.log($"批量轴下降到P1位置");
                    break;
                case MoveStep.L61:
                    LeftMoveInfo.NextMoveStep(MoveStep.L62);
                    CylinderMove(null, IO_Type.LeftStopUP, IO_Type.LeftStopDown);
                    LeftMoveInfo.log($"阻挡下降");
                    break;
                case MoveStep.L62:
                    LeftMoveInfo.NextMoveStep(MoveStep.L63);
                    IOMove(IO_Type.LeftMoto_Reverse, IO_VALUE.LOW);
                    IOMove(IO_Type.LeftMoto_Run, IO_VALUE.HIGH);
                    LeftMoveInfo.WaitList.Add(WaitResultInfo.WaitIO(IO_Type.LeftEnd_Check, IO_VALUE.HIGH));
                    LeftMoveInfo.WaitList.Add(WaitResultInfo.WaitTime(60000));
                    LeftMoveInfo.TimeOutSeconds = 60;
                    LeftMoveInfo.OneWaitCanEndStep = true;
                    LeftMoveInfo.log($"等待料串到位");
                    break;
                case MoveStep.L63:
                    LeftMoveInfo.NextMoveStep(MoveStep.L64);
                    LeftMoveInfo.WaitList.Add(WaitResultInfo.WaitTime(1000));
                    break;
                case MoveStep.L64:
                    LeftMoveInfo.NextMoveStep(MoveStep.L65);
                    IOMove(IO_Type.LeftMoto_Run, IO_VALUE.HIGH, false, 500);
                    CylinderMove(null, IO_Type.LeftStopDown, IO_Type.LeftStopUP);
                    LeftMoveInfo.log($"电滚筒停止,阻挡上升");
                    break;
                case MoveStep.L65:
                    if (IOValue(IO_Type.LeftEnd_Check).Equals(IO_VALUE.HIGH))
                    {
                        LeftMoveInfo.NewMove(MoveStep.L01);
                        LeftMoveInfo.log($"料串进入开始上料");
                    }
                    else
                    {
                        LeftMoveInfo.NextMoveStep(MoveStep.LEND);
                        LeftMoveInfo.log($"料串进入失败");
                    }
                    break;
                default:
                    LeftMoveInfo.log($"未找到对应步骤:{LeftMoveInfo.MoveStep}");
                    break;
            }
        }
        string LeftState()
        {
            string state = "";
            if (IOValue(IO_Type.LeftEnd_Check).Equals(IO_VALUE.HIGH))
            {
                state += string.Format(crc.GetString("Res0069", "有料串,已放置{0}张料盘"), LeftCount);
                if (LeftShelfNoTray)
                    state += "," + crc.GetString("Res0043", "料串已满");
                else
                    state += ".";
                state += crc.GetString("Res0045", "当前ReelID:") + LeftMoveInfo.MoveParam.WareCode;
            }
            else
            {
                return crc.GetString("Res0046", "无料串");
            }

            return state;
        }

        int LeftStartMovePosition = 0;
        void LeftBatchAxisToP2(int target, int Speed, IO_VALUE ioValue)
        {
            int targetP2 = target;
            int targetSpeed = Speed;

            int currPosition = Left_Batch_Axis.GetAclPosition();
            LeftMoveInfo.log("BatchAxisToP2 目标P2: " + targetP2 + "(" + currPosition + ")");

            LeftMoveInfo.TimeOutSeconds = 200;
            LeftMoveInfo.CanWhileCount = 0;
            //  需要增加定时器,获取验证信号并停止伺服
            LeftStartMovePosition = Left_Batch_Axis.GetAclPosition();
            LeftMoveInfo.WaitList.Add(WaitResultInfo.WaitBatchAxisMove(Config.Left_Batch_Axis, targetP2, targetSpeed));
            Config.Left_Batch_Axis.TargetPosition = targetP2;
            Left_Batch_Axis.AbsMove(null, targetP2, targetSpeed);
            //开始检测信号
            Left_Batch_Axis.BatchAxisStartCheck(IO_Type.LeftTop_Check, ioValue);
        }
        /// <summary>
        /// 左批量轴下降到X23对射信号灭
        /// </summary>
        void LeftBatchAxisToP1()
        {
            int targetP1 = Config.Left_Batch_P1;
            int targetSpeed = Config.Left_Batch_P2_speed;

            LeftMoveInfo.TimeOutSeconds = 200;
            LeftMoveInfo.CanWhileCount = 0;
            //  需要增加定时器,获取验证信号并停止伺服
            LeftStartMovePosition = Left_Batch_Axis.GetAclPosition();
            LeftMoveInfo.WaitList.Add(WaitResultInfo.WaitBatchAxisMove(Config.Left_Batch_Axis, targetP1, targetSpeed));
            Config.Left_Batch_Axis.TargetPosition = targetP1;
            Left_Batch_Axis.AbsMove(null, targetP1, targetSpeed);
            //开始检测信号
            Left_Batch_Axis.BatchAxisStartCheck(IO_Type.LeftTop_Check, IO_VALUE.LOW);
        }
        /// <summary>
        /// 下降固定值
        /// </summary>
        void LeftBatchAxisDown()
        {

            int targetP1 = Left_Batch_Axis.GetAclPosition() - ConfigHelper.Config.Get("LeftAxisDownValue", 50) * Config.Left_Batch_ChangeValue;
            if (PlwHight > 5000)
            {
                int currpoint = Left_Batch_Axis.GetAclPosition();
                int countPleHight = PlwHight / Config.Right_Batch_ChangeValue * Config.Left_Batch_ChangeValue;
                targetP1 = currpoint - countPleHight + 5000;
                LeftMoveInfo.log($"出料提升机构,获取到料盘高度脉冲{PlwHight},当前位置{currpoint},计算盘高{countPleHight}");
            }
            int targetSpeed = Config.Left_Batch_P1_speed;
            if (targetP1 <= 0)
            {
                LeftMoveInfo.log("出料提升机构,下降固定值小于0,设置回到0原点。");
                targetP1 = 0;
            }
            LeftMoveInfo.log($"出料提升机构,下降固定值为{targetP1}脉冲!");
            Left_Batch_Axis.AbsMove(LeftMoveInfo, targetP1, targetSpeed);
        }

        /// <summary>
        /// 下降在上升以后,上升指定阈值,防止感应器失效
        /// </summary>
        void LeftAxisRiseMax()
        {
            //1.获取当前私服下降后的脉冲
            LeftStartMovePosition = Left_Batch_Axis.GetAclPosition();
            //2.获取下降的高度、冗余高度、一毫米的脉冲值
            int downvalue = ConfigHelper.Config.Get("LeftAxisDownValue", 50);
            int redundancy = ConfigHelper.Config.Get("LeftAxisRiseRedundancyValue", 10);
            int change = Config.Left_Batch_ChangeValue;
            int totalpulse = (downvalue + redundancy) * change;
            int targetP2 = LeftStartMovePosition + totalpulse;
            LeftMoveInfo.log($"下降固定值后提升,感应器亮或提升固定值:当前私服高度={LeftStartMovePosition},下降的固定高度={downvalue}," +
                $"上升最大高度={redundancy},每毫米脉冲={change},上升脉冲为{targetP2},P2={Config.Left_Batch_P2}");
            int targetSpeed = Config.Left_Batch_P2_speed;
            LeftMoveInfo.TimeOutSeconds = 200;
            LeftMoveInfo.CanWhileCount = 0;
            //  需要增加定时器,获取验证信号并停止伺服

            LeftMoveInfo.WaitList.Add(WaitResultInfo.WaitBatchAxisMove(Config.Left_Batch_Axis, targetP2, targetSpeed));
            Config.Left_Batch_Axis.TargetPosition = targetP2;
            Left_Batch_Axis.AbsMove(null, targetP2, targetSpeed);
            //开始检测信号
            Left_Batch_Axis.BatchAxisStartCheck(IO_Type.LeftTop_Check, IO_VALUE.HIGH);
        }
    }
}