EmptyAGVBackJob.cs 5.8 KB

using AGVControl;
using System;
using System.Collections.Generic;
using System.Linq;
using System.ServiceModel.PeerResolvers;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace AGVControl
{
    /// <summary>
    /// 空车返回待机位任务
    /// </summary>
    public class EmptyAGVBackJob : Job
    {
        /// <summary>
        /// 出完满料后-空车返回任务
        /// </summary>
        /// <param name="agvPlae">小车当前位置,空表示在待机位</param>
        /// <param name="palce">空料架位置点</param>
        public EmptyAGVBackJob(string agvPlae)
        {
            this.agvPlace = agvPlae;
        }


        /// <summary>
        /// 接收任务时,agv的位置
        /// </summary>
        private string agvPlace { get; set; }

        /// <summary>
        /// 到达待机位
        /// </summary>
        public override bool IsEnd { get { return EmptyAGVBackStep.IsStep(EMPTY_AGV_BACK_STEP.END); } }

        private JobStep<EMPTY_AGV_BACK_STEP> EmptyAGVBackStep = new JobStep<EMPTY_AGV_BACK_STEP>(EMPTY_AGV_BACK_STEP.NONE);

        /// <summary>
        /// 空车返回执行
        /// </summary>
        /// <param name="agv"></param>
        public override Job Execute(Agv_Info agv)
        {
            string msg = agv.Name+" ";
            bool rtn = false;
            agv.Msg = EmptyAGVBackStep.Msg;
            if (EmptyAGVBackStep.IsStep(EMPTY_AGV_BACK_STEP.NONE))
            {
                if (Common.FindEmptyShelfNode(agv, out string nodeName,true))
                {
                    //EmptyAGVBackStep.ToNextStep(EMPTY_AGV_BACK_STEP.END);
                    msg = "小车在产线 " + agvPlace + " 准备返回时检测到 " + nodeName + " 有空料架";
                    EmptyAGVBackStep.Msg = msg;
                    return new GoEmptyShelfLineJob(agvPlace, nodeName);
                }
                else
                {
                    if (agvPlace.StartsWith("G"))
                    {
                        EmptyAGVBackStep.ToNextStep(EMPTY_AGV_BACK_STEP.WAIT_AGV_REACH_4D_DOOR);
                        msg = "从产线" + agvPlace + "回待机位,先到4D门";
                        EmptyAGVBackStep.Msg = msg;
                        Common.DoorMission(agv, SettingString.DoorCToD);
                    }
                    else
                    {
                        EmptyAGVBackStep.ToNextStep(EMPTY_AGV_BACK_STEP.WAIT_REACH_STANDBY);
                        msg = "从产线" + agvPlace + "回待机位";
                        EmptyAGVBackStep.Msg = msg;
                        Common.MoveToNode(agv, SettingString.Standby);
                    }
                }
            }
            else if (EmptyAGVBackStep.IsStep(EMPTY_AGV_BACK_STEP.WAIT_REACH_STANDBY))
            {
                if (Common.CheckTaskFinished(agv, SettingString.Standby, agv.CurTaskGUID))
                {
                    Job job = Common.control.GetJob(agv);
                    if (job == null && agv.Battery < Common.chargeStatus.chargeMax)
                    {
                        msg = "到达待机位,电量[" + agv.Battery + "]小于最大电量[" + Common.chargeStatus.chargeMax + "],暂无任务,去充电";
                        EmptyAGVBackStep.Msg = msg;
                        return new ChargeJob("");
                    }
                    else
                    {
                        msg = "到达待机位,检测到新任务,执行任务";
                        EmptyAGVBackStep.Msg = msg;
                        return job;
                    }

                }
                else
                {
                    if (Common.FindFullShelfTask(agv))
                    {
                        msg = "从产线" + agvPlace + "回待机位过程中,检测到A6出满料,去A6";
                        EmptyAGVBackStep.Msg = msg;
                        return new GoFullShelfStationJob(SettingString.Standby);
                    }
                    //else
                    //{
                    //    msg = "从产线" + agvPlace + "到达4D门,暂无任务,去充电位";
                    //    EmptyAGVBackStep.Msg = msg;
                    //    return new ChargeJob(SettingString.D4_DOOR_Name);
                    //}
                }

            }
            else if (EmptyAGVBackStep.IsStep(EMPTY_AGV_BACK_STEP.WAIT_AGV_REACH_4D_DOOR))
            {
                if (Common.CheckTaskFinished(agv, SettingString.DoorCToD, agv.CurTaskGUID))
                {
                    if (Common.FindFullShelfTask(agv))
                    {
                        msg = "从产线" + agvPlace + "到达4D门,检测到A6出满料,去A6";
                        EmptyAGVBackStep.Msg = msg;
                        return new GoFullShelfStationJob(SettingString.D4_DOOR_Name);
                    }
                    else
                    {
                        msg = "从产线" + agvPlace + "到达4D门,暂无任务,去充电位";
                        EmptyAGVBackStep.Msg = msg;
                        return new ChargeJob(SettingString.D4_DOOR_Name);
                    }
                }
            }
            return this;
        }


        /// <summary>
        /// AGV回收空料架流程
        /// </summary>
        private enum EMPTY_AGV_BACK_STEP
        {
            /// <summary>
            /// 查询任务
            /// </summary>
            NONE,

            /// <summary>
            /// 等待到达4D门
            /// </summary>
            WAIT_AGV_REACH_4D_DOOR,
            /// <summary>
            /// 等待AGV到达待机位
            /// </summary>
            WAIT_REACH_STANDBY,

            /// <summary>
            /// 
            /// </summary>
            END
        }
    }

}