MainMachine_OutCar.cs 12.1 KB
using CodeLibrary;
using OnlineStore;
using OnlineStore.Common;
using OnlineStore.LoadCSVLibrary;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace DeviceLibrary
{
    partial class MainMachine
    {

        bool OutHasCar { get => (IOValue(IO_Type.Unloading_Car_Check).Equals(IO_VALUE.HIGH) || IOValue(IO_Type.Unloading_Car1315_Check).Equals(IO_VALUE.HIGH)); }

        public CarTypeE OutCarType = CarTypeE.None;
        public int OutCurrentStringNum = 0;
        bool outnewreel = false;
        void OutCarProcess()
        {
            if (CheckWait(OutCarMoveInfo))
                return;
            
            switch (OutCarMoveInfo.MoveStep)
            {
                case MoveStep.Wait:
                    OutCarType = CarTypeE.None;
                    var hascar = OutHasCar;
                    if (hascar)
                        Unloading_NOCar_Led.LedState = LedState.blink;
                    else
                        Unloading_NOCar_Led.LedState = LedState.off;
                    if (hascar && IOValue(IO_Type.Unloading_CarLock_Btn).Equals(IO_VALUE.HIGH))
                    {
                        OutCarMoveInfo.NextMoveStep(MoveStep.OutCar_01);
                        OutCarMoveInfo.log("检测到小车到位");
                    }
                    else if (hascar && IOValue(IO_Type.Unloading_Car_Location_Up).Equals(IO_VALUE.HIGH))
                    {
                        OutCarMoveInfo.NextMoveStep(MoveStep.OutCar_02);
                        OutCarMoveInfo.log("小车已经到位");
                    }
                    break;
                case MoveStep.OutCar_01:
                    OutCarMoveInfo.NextMoveStep(MoveStep.OutCar_02);
                    OutCarMoveInfo.log($"提升定位气缸");
                    CylinderMove(OutCarMoveInfo, IO_Type.Unloading_Car_Location_Down, IO_Type.Unloading_Car_Location_Up, IO_VALUE.HIGH);
                    break;
                case MoveStep.OutCar_02:
                    var car7 = IOValue(IO_Type.Unloading_Car_Check).Equals(IO_VALUE.HIGH);
                    var car13 = IOValue(IO_Type.Unloading_Car1315_Check).Equals(IO_VALUE.HIGH);
                    if (car7 || car13)
                    {
                        if (car7)
                            OutCarType = CarTypeE.Car7;
                        else
                            OutCarType = CarTypeE.Car13;

                        OutCarMoveInfo.log($"检测到料车尺寸:{InCarType}");
                        OutCarMoveInfo.NextMoveStep(MoveStep.OutCar_03);
                        Unloading_NOCar_Led.LedState = LedState.on;
                    }
                    else {
                        OutCarMoveInfo.log($"小车丢失,重新检测");
                        CylinderMove(OutCarMoveInfo, IO_Type.Unloading_Car_Location_Down, IO_Type.Unloading_Car_Location_Up, IO_VALUE.LOW);
                        OutCarMoveInfo.NextMoveStep(MoveStep.Wait);
                    }
                    break;
                case MoveStep.OutCar_03:
                    OutCarMoveInfo.NextMoveStep(MoveStep.OutCar_04);
                    outnewreel = true;
                    OutCarMoveInfo.log($"新料串");
                    break;
                case MoveStep.OutCar_04:
                    OutCarMoveInfo.NextMoveStep(MoveStep.OutCar_05);
                    OutCarMoveInfo.log($"批量轴高速上升到顶部检测点");
                    BatchAxisToP2(OutCarMoveInfo, Unloading_Batch_Axis, OutGetLowReelCheckIOList(),IO_VALUE.HIGH, Config.Unloading_Batch_Axis_P2, Config.Unloading_Batch_Axis_P1_speed);
                    break;
                case MoveStep.OutCar_05:
                    var lowlist = OutGetLowReelCheckIOList();
                    if (Unloading_Batch_Axis.IsInPosition(Config.Unloading_Batch_Axis_P2)) {
                        OutCarMoveInfo.NextMoveStep(MoveStep.OutCar_06);
                        OutCarMoveInfo.log($"批量轴已到顶,可放料位置有:{string.Join(",", lowlist)}");
                    }
                    else if (lowlist.Count() > 0)
                    {
                        OutCarMoveInfo.NextMoveStep(MoveStep.OutCar_04);
                        OutCarMoveInfo.log($"lowlist={string.Join(",", lowlist)}");
                    }
                    else {
                        OutCarMoveInfo.NextMoveStep(MoveStep.OutCar_06);
                        OutCarMoveInfo.log($"批量轴已上升到最后一盘点亮位置");
                    }
                    break;
                case MoveStep.OutCar_06:
                    OutCarMoveInfo.NextMoveStep(MoveStep.OutCar_07);
                    OutCarMoveInfo.log($"批量轴高速下降到检测点灭");
                    BatchAxisToP2(OutCarMoveInfo, Unloading_Batch_Axis, OutGetReelCheckIOList(), IO_VALUE.LOW, Config.Unloading_Batch_Axis_P1, Config.Unloading_Batch_Axis_P1_speed);
                    break;
                case MoveStep.OutCar_07:
                    OutCarMoveInfo.NextMoveStep(MoveStep.OutCar_08);
                    OutCurrentStringNum = GetBottomStringNum(OutGetLowReelCheckIOList());
                    OutCarMoveInfo.log($"第一次检测到最低料串为:{OutCurrentStringNum}");
                    OutCarMoveInfo.log($"批量轴下降1mm再次检测");
                    Unloading_Batch_Axis.AbsMove(OutCarMoveInfo,Unloading_Batch_Axis.GetAclPosition()-Config.Unloading_UpDown_Axis_MMtoPOS, Config.Unloading_UpDown_Axis_P1_speed);
                    break;
                case MoveStep.OutCar_08:
                    var cur = GetBottomStringNum(OutGetLowReelCheckIOList());
                    OutCarMoveInfo.log($"当前low={cur},上次low={OutCurrentStringNum}");                    
                    if (cur != OutCurrentStringNum)
                    {
                        OutCarMoveInfo.NextMoveStep(MoveStep.OutCar_06);
                    }
                    else {
                        OutCarMoveInfo.NextMoveStep(MoveStep.OutCar_09);
                    }
                    break;
                case MoveStep.OutCar_09:
                    if (Unloading_Batch_Axis.IsInPosition(Config.Unloading_Batch_Axis_P1))
                    {
                        OutCarMoveInfo.NextMoveStep(MoveStep.OutCarOut_01);
                        OutCarMoveInfo.log($"出料料串已满");
                    }
                    else
                    {
                        OutCurrentStringNum = GetBottomStringNum(OutGetLowReelCheckIOList());
                        OutCarMoveInfo.log($"确认放料料串为:{OutCurrentStringNum}");
                        if (OutCurrentStringNum > 0)
                        {                            
                            OutCarMoveInfo.NextMoveStep(MoveStep.OutCarReadyPut);
                        }
                        else {
                            OutCarMoveInfo.NextMoveStep(MoveStep.OutCar_06);
                        }
                    }
                    break;
                case MoveStep.OutCarReadyPut:
                    Msg.add("出口料串放料准备就绪", MsgLevel.info);
                    break;
                case MoveStep.OutCarReelPut:
                    OutCarMoveInfo.NextMoveStep(MoveStep.OutCar_04);
                    OutCarMoveInfo.log($"料盘放入, 等待贴标");
                    break;
                case MoveStep.WaitForLabelling:
                    Msg.add("等待贴标", MsgLevel.info); 
                    break;
                case MoveStep.LabelFinish:
                    OutCarMoveInfo.log($"贴标完毕");
                    OutCarMoveInfo.NextMoveStep(MoveStep.OutCar_04);                    
                    break;
                case MoveStep.OutCarOut_01:
                    OutCarMoveInfo.NextMoveStep(MoveStep.OutCarOut_02);
                    OutCarMoveInfo.log($"料串下降到P1点");
                    Unloading_Batch_Axis.AbsMove(OutCarMoveInfo, Config.Unloading_Batch_Axis_P1, Config.Unloading_Batch_Axis_P1_speed);                    
                    OutCarMoveInfo.WaitList.Add(WaitResultInfo.WaitMsg("料串正在下降", MsgLevel.warning));
                    break;
                case MoveStep.OutCarOut_02:
                    OutCarMoveInfo.NextMoveStep(MoveStep.OutCarOut_Released);
                    OutCarMoveInfo.log($"顶升下降");
                    CylinderMove(OutCarMoveInfo, IO_Type.Unloading_Car_Location_Down, IO_Type.Unloading_Car_Location_Up, IO_VALUE.LOW);
                    break;
                case MoveStep.OutCarOut_Released:
                    OutCarMoveInfo.log($"料串已回到待机点");
                    OutCarMoveInfo.NewMove(MoveStep.Wait);                    
                    break;
                default:
                    OutCarMoveInfo.log($"未找到对应步骤:{OutCarMoveInfo.MoveStep}");
                    break;
            }
        }

        string OutCarProcessState() {
            string state = "";

            if (OutCarType == CarTypeE.Car13)
                state = "13/15寸盘小车";
            else if (OutCarType == CarTypeE.Car7)
            {                
                state = "7寸盘小车";
            }
            else if (InHasCar)
                state = "检测到小车,尚未锁定";

            if (OutCarMoveInfo.MoveStep == MoveStep.Wait)
            {
                return "空闲中";
            }
            else if (OutCarMoveInfo.MoveStep < MoveStep.OutCarReadyPut)
            {
                return state + "," + "准备中";
            }
            else if (OutCarMoveInfo.MoveStep == MoveStep.OutCarReadyPut)
            {
                return state + "," + "允许放料";
            }
            else if (OutCarMoveInfo.MoveStep >= MoveStep.OutCarOut_01)
            {
                return state + "," + "释放中";
            }
            else if (OutCarMoveInfo.MoveStep > MoveStep.OutCar_06)
            {
                return state;
            }

            return state;
        }
        string[] OutGetLowReelCheckIOList(int currentnum = 0) {
            if (currentnum > 0)
                return new string[] { "Unloading_Batch_ReelCheck_T" + currentnum.ToString() };
            List<string> iolist = new List<string>();
            if (OutCarType == CarTypeE.Car7)
            {
                if (IOValue(IO_Type.Unloading_Batch_ReelCheck_T1).Equals(IO_VALUE.LOW))
                    iolist.Add(IO_Type.Unloading_Batch_ReelCheck_T1);
                if (IOValue(IO_Type.Unloading_Batch_ReelCheck_T2).Equals(IO_VALUE.LOW))
                    iolist.Add(IO_Type.Unloading_Batch_ReelCheck_T2);
                if (IOValue(IO_Type.Unloading_Batch_ReelCheck_T4).Equals(IO_VALUE.LOW))
                    iolist.Add(IO_Type.Unloading_Batch_ReelCheck_T4);
                if (IOValue(IO_Type.Unloading_Batch_ReelCheck_T5).Equals(IO_VALUE.LOW))
                    iolist.Add(IO_Type.Unloading_Batch_ReelCheck_T5);
                return iolist.ToArray();
            }
            else
            {
                if (IOValue(IO_Type.Unloading_Batch_ReelCheck_T3).Equals(IO_VALUE.LOW))
                    iolist.Add(IO_Type.Unloading_Batch_ReelCheck_T3);
                return iolist.ToArray();
            }        
        }
        string[] OutGetReelCheckIOList(int currentnum = 0)
        {
            if (currentnum > 0)
                return new string[] { "Unloading_Batch_ReelCheck_T" + currentnum.ToString() };

            if (OutCarType == CarTypeE.Car7)
            {
                return new string[] { IO_Type.Unloading_Batch_ReelCheck_T1, IO_Type.Unloading_Batch_ReelCheck_T2, IO_Type.Unloading_Batch_ReelCheck_T4, IO_Type.Unloading_Batch_ReelCheck_T5 };
            }
            else
            {
                return new string[] { IO_Type.Unloading_Batch_ReelCheck_T3 };
            }
        }
        int GetBottomStringNum(string[] checkiolist)
        {
            foreach (var io in checkiolist)
            {
                if (IOValue(io).Equals(IO_VALUE.LOW))
                {
                    return int.Parse(io.Substring(io.Length - 1));
                }
            }
            return 0;
        }
    }
}