Agv.cs 10 KB
using XingYe_ACS.Business;
using PropertyChanged;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace XingYe_ACS.BaseStruct
{
    [ImplementPropertyChanged]
    public class Agv : IComparable
    {
        /// <summary>
        /// 电量排序
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public int CompareTo(object obj)
        {
            Agv agv = obj as Agv;
            if (agv == null) throw new NotImplementedException();
            return currentCharge.CompareTo(agv.currentCharge);
        }

        /// <summary>
        /// 小车编号
        /// </summary>
        public string strAgvNo { get; set; }

        /// <summary>
        /// 小车当前所在区域
        /// </summary>
        public string agvAreaType { get; set; }

        /// <summary>
        /// 小车当前码值
        /// </summary>
        public string strBarcode { get; set; }

        /// <summary>
        /// 小车状态
        /// </summary>
        public EnumMsg.State agvState { get; set; }

        /// <summary>
        /// 小车顶升状态
        /// </summary>
        public EnumMsg.HeightState heightState { get; set; }

        /// <summary>
        /// 小车车头方向
        /// </summary>
        public EnumMsg.OriType agvOri { get; set; }

        /// <summary>
        /// 小车转盘方向
        /// </summary>
        public EnumMsg.OriType dialOri { get; set; }

        /// <summary>
        /// 小车当前的电量
        /// </summary>
        public float currentCharge { get; set; }

        /// <summary>
        /// 小车充电时间的时间
        /// </summary>
        public DateTime chargeTime { get; set; }

        /// <summary>
        /// 小车充电时间的时间
        /// </summary>
        public DateTime taskTime { get; set; }

        /// <summary>
        /// 小车匹配的充电桩
        /// </summary>
        public string strChooseStation { get; set; }

        /// <summary>
        /// 小车当前是否可用
        /// </summary>
        public bool isEnable { get; set; }

        /// <summary>
        /// 小车当前是否在线
        /// </summary>
        public bool isOnline { get; set; }

        /// <summary>
        /// 计算小车多久未发送心跳
        /// </summary>
        public void HeartStop()
        {
            float Sec = 0;
            TimeSpan tsHeart = new TimeSpan(agvHeart.Ticks);
            TimeSpan tsNow = new TimeSpan(DateTime.Now.Ticks);
            TimeSpan tsDurat = tsNow.Subtract(tsHeart).Duration();
            float S = tsDurat.Seconds;
            Sec = tsDurat.Hours * 3600 + tsDurat.Minutes * 60 + S;
            if (Sec > 30)//大于10S,判定离线
            {
                isOnline = false;
                if (App.offAgvNo.Contains(strAgvNo))
                {
                    App.offAgvNo.Remove(strAgvNo);
                }
                if (isEnable)
                {
                    agvBground = EnumMsg.AgvBground.Gray;//小车未报心跳
                    if (agvState != EnumMsg.State.离线)
                    {
                        string errState = "AGV离线";
                        App.ExFile.MessageBusinessErr("BusinessAgvState", strAgvNo + "= =" + errState + "= =" + agvState);
                        agvState = EnumMsg.State.离线;
                        Agv agv = App.AgvList.Find(a => a.strAgvNo == strAgvNo);
                        UpdateManage.UpdateAgvMsg(agv);
                        UpdateManage.InsertAgvState(agv, 15);
                    }
                }
                else
                {
                    return;
                }
                Config_ClientControl clientControl = App.ClientWork.Find(a => a.strAgvNo == strAgvNo);
                if (clientControl == null) return;
                if (clientControl.isDoing)
                {
                    clientControl.isDoing = false;
                    App.ExFile.MessageError("ClientIp", "==" + clientControl.strAgvNo + "==" + "线程没正确释放此小车IP控制");
                }
            }
            else
            {
                if (!Enum.IsDefined(typeof(EnumMsg.State), (int)agvState) || agvState == EnumMsg.State.离线)
                {
                    string errState = "AGV上报自身状态";
                    App.ExFile.MessageBusinessErr("BusinessAgvState", strAgvNo + "= =" + errState + "= =" + agvState);
                }
                isOnline = true;
            }
        }

        /// <summary>
        /// 小车是否载货
        /// </summary>
        public bool isCarry { get; set; }

        /// <summary>
        /// 输送线标识
        /// </summary>
        public int flag;
        
        /// <summary>
        /// 小车发送最新心跳的时间
        /// </summary>
        public DateTime agvHeart { get; set; }

        /// <summary>
        /// 小车当前的执行的任务
        /// </summary>
        public FTask agvTask { get; set; }

        /// <summary>
        /// 小车当前的界面显示的背景色
        /// </summary>
        public EnumMsg.AgvBground agvBground { get; set; }

        /// <summary>
        /// 小车停止原因
        /// </summary>
        public string strStopReason { get; set; }

        /// <summary>
        /// 小车异常信息
        /// </summary>
        public string strAgvError { get; set; }

        /// <summary>
        /// agv里程
        /// </summary>
        public int agvMilage { get; set; }

        /// <summary>
        /// AGV群组
        /// </summary>
        public string agvGroup { get; set; }

        /// <summary>
        /// AGV所在地图
        /// </summary>
        public string agvMap { get; set; }

        /// <summary>
        /// AGV开始充电电量
        /// </summary>
        public float startCharges { get; set; }

        /// <summary>
        /// 增删改
        /// </summary>
        public string type { get; set; }

        /// <summary>
        /// 等待时间
        /// </summary>
        public string waitTime { get; set; }

        public int intRunDistance { get; set; }

        /// <summary>
        /// 下个路径点
        /// </summary>
        public string nextPoint { get; set; }

        /// <summary>
        /// 上一路径点
        /// </summary>
        public string beforePoint { get; set; }

        /// <summary>
        /// 两点之间的距离
        /// </summary>
        public int pointLength { get; set; }

        /// <summary>
        /// agvIP地址
        /// </summary>
        public string agvIP { get; set; }

        /// <summary>
        /// agv异常编码
        /// </summary>
        public int agvErrorCode { get; set; }

        /// <summary>
        /// 记录充电日志时间
        /// </summary>
        public DateTime logTime { get; set; }

        /// <summary>
        /// 车速[mm/min]
        /// </summary>
        public float rSpeed { get; set; }
        /// <summary>
        /// 电压
        /// </summary>
        public float rBatVoltage { get; set; }
      

        /// <summary>
        /// 电流
        /// </summary>
        public float rBatCurrent { get; set; }
        /// <summary>
        /// 电池健康状态
        /// </summary>
        public short iBatPowerSupplyHealth { get; set; }
    }

    /// <summary>
    /// 关机AGV
    /// </summary>
    public class offAgv
    {
        /// <summary>
        /// 关机类型1:整体关机;2:指定AGV关机
        /// </summary>
        public int offType { get; set; }

        /// <summary>
        /// 关机AGV编号 整体关机不做判断
        /// </summary>
        public string agvNo { get; set; }
    }

    /// <summary>
    /// 单步控制AGV
    /// </summary>
    public class LinkAgv
    {
        #region 单步控制agv
        /// <summary>
        /// 控制AGV编号
        /// </summary>
        public string agvNo { get; set; }

        /// <summary>
        /// 控制AGV动作
        /// </summary>
        public int action { get; set; }

        /// <summary>
        /// 连接状态 true开启连接,false关闭连接
        /// </summary>
        public bool link { get; set; }
        #endregion
    }

    public class s7AGV 
    {
        /// <summary>
        /// 状态
        /// </summary>
        public short iStatus { get; set; }
        /// <summary>
        /// 错误
        /// </summary>
        public short iAlarm { get; set; }
        /// <summary>
        /// 错误信息
        /// </summary>
        public short iAlarmMsg { get; set; }
        /// <summary>
        /// 当前坐标
        /// </summary>
        public short iCurrentPose { get; set; }
        /// <summary>
        /// 前一坐标
        /// </summary>
        public short iBeforePose { get; set; }
        /// <summary>
        /// 后一坐标
        /// </summary>
        public short iAfterPose { get; set; }
        /// <summary>
        /// 状态[0:空闲1:有任务2:充电]
        /// </summary>
        public short iTaskStatus { get; set; }
        /// <summary>
        /// 车速[mm/min]
        /// </summary>
        public float rSpeed { get; set; }
        /// <summary>
        /// 电压
        /// </summary>
        public float rBatVoltage { get; set; }
        /// <summary>
        /// 电流
        /// </summary>
        public float rBatCurrent { get; set; }
        /// <summary>
        /// 电池电量
        /// </summary>
        public short iBatteryCapacity { get; set; }
        /// <summary>
        /// 供能状态[0:功能状态未知1:充电中2:前往充电点3:没在充电4:电池满电量]
        /// </summary>
        public short iBatPowerSupplyStatus { get; set; }
        /// <summary>
        /// 电池健康状态
        /// </summary>
        public short iBatPowerSupplyHealth { get; set; }
        /// <summary>
        /// 当前小车托盘状态[0:无托盘1:下料托盘2:上料托盘]
        /// </summary>
        public short iActProductState { get; set; }
    }
}