Commit cd57cc73 张东亮

将获取状态放入agv类里

1 个父辈 1f11a863
......@@ -62,6 +62,7 @@ namespace DeviceLibrary.manager
iOInfo.IOID = item.InnerText;
agv_Info.IOStatus.Add(iOInfo);
}
agv_Info.StartTimer();
agv_Infos.Add(agv_Info);
}
xmlReader.Close();
......
......@@ -20,12 +20,8 @@ namespace DeviceLibrary
private System.Timers.Timer AgvCallTimer;
private System.Timers.Timer AgvStateTimer;
private System.Timers.Timer NodeStateTimer;
//public List<string> Marks;
private const int REG_STATUS = 20;
//private List<string> shelfLockedNodeNames;
public delegate void AgvChangedEvent(int agvIndex);
public event AgvChangedEvent AgvChanged;
public event AgvChangedEvent AgvOnline;
//public event AgvChangedEvent NodeChangedEvent;
public Control()
{
......@@ -121,52 +117,9 @@ namespace DeviceLibrary
//private eAGVState preAGVState = eAGVState.None;
private void AgvStateTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{
bool rtn;
if (AgvStateInProcess) return;
AgvStateInProcess = true;
HttpManager.AUOIsUsingD2(out MissionManager.AUOResult);
for (int i = 0; i < AGVManager.agvInfo.Count; i++)
{
AgvInfo agv = AGVManager.agvInfo[i];
try
{
agv.SetKanban();
if (!CheckOnline(i)) continue;
bool change = false;
if (!agv.TaskRunState.IsAllocatingTask && agv.Auto && agv.CurJob != null && agv.TaskRunState.TaskID.Equals(-1))
{
if (!MiR_API.Get_MissionByDescrp(agv))
{
agv.CurJob.ResendTask(agv);
log.Info($"{agv.Name}:Task=-1处理,Fleet无任务,重发任务:{agv.TaskRunState.Task.Name}");
}
else
{
log.Info($"{agv.Name}:Task=-1处理,Fleet有任务,自动赋值FleetTaskID={agv.TaskRunState.TaskID}");
}
}
//if ((agv.CurJob != null && !(agv.CurJob is ChargeJob || agv.CurJob is StandyJob))
// && (AGVManager.agvInfo[i].StateID.Equals(eAGVState.Executing)))
{
MiR_API.Get_Task_State(agv);
Thread.Sleep(50);
MiR_API.Get_IO_Status(agv);
}
//获取AGV状态
rtn = MiR_API.Get_State(agv, out eAGVState stateID, out string stateText, out int battery, out string mission_text, out AgvInfo.MirPosition position, out List<Mir_Error> errors);
Thread.Sleep(50);
if (rtn) change = agv.SetState(stateID, battery, mission_text, position, errors);
// if (change)
{
AgvChanged?.Invoke(i);
}
}
catch (Exception ex)
{
log.Error("AgvStateTimer_" + agv.Name + ex.Message + ex.StackTrace);
}
}
manager.UploadManager.UploadAgvState();
AgvStateInProcess = false;
}
......@@ -235,11 +188,16 @@ namespace DeviceLibrary
if (job != null)
{
agv.CurJob = job;
LogUtil.info($"{agv.Name} 收到任务 {job?.JobParam?.GetMissionInfo()?.missionId??""}");
}
}
else
{
agv.CurJob = agv.CurJob.Execute(agv);
if(agv.CurJob==null)
{
LogUtil.info($"{agv.Name} 任务完成");
}
}
}
catch (Exception ex)
......@@ -253,34 +211,33 @@ namespace DeviceLibrary
}
private bool CheckOnline(int idx)
public static bool CheckOnline(AgvInfo agv)
{
bool rtn = MiR_API.CheckIP(AGVManager.agvInfo[idx].IP);
bool rtn = MiR_API.CheckIP(agv.IP);
if (rtn)
{
if (AGVManager.agvInfo[idx].IsCon)
if (agv.IsCon)
{
//log.Debug(AGVManager.agvInfo[idx].Name + " Online");
}
else
{
AGVManager.agvInfo[idx].IsCon = true;
log.Info(AGVManager.agvInfo[idx].Name + " Online");
agv.IsCon = true;
log.Info(agv.Name + " Online");
}
}
else
{
if (AGVManager.agvInfo[idx].IsCon)
if (agv.IsCon)
{
AGVManager.agvInfo[idx].IsCon = false;
log.Info(AGVManager.agvInfo[idx].Name + " Offline");
agv.IsCon = false;
log.Info(agv.Name + " Offline");
}
else
{
//log.Debug(AGVManager.agvInfo[idx].Name + " Offline");
}
}
AgvOnline?.Invoke(idx);
return rtn;
}
......
......@@ -62,8 +62,12 @@ namespace DeviceLibrary
}
public bool CheckTaskFinished(string name = "")
{
//LogUtil.debug(name + " 检查任务是否结束: " + ToTaskState());
return TaskState.Equals(SettingString.Done);
if(TaskState.Equals(SettingString.Done))
{
LogUtil.info($"{Task?.Name??""},{TaskID},{SettingString.Done}");
return true;
}
return false;
}
public void EnWaitTaskQueue(AgvTask task)
{
......
......@@ -4,11 +4,13 @@ using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Xml;
using Common;
using DeviceLibrary.bean.agv;
using DeviceLibrary.manager;
using log4net.Util;
using Newtonsoft.Json;
namespace DeviceLibrary
......@@ -38,17 +40,21 @@ namespace DeviceLibrary
/// <summary>
/// 系统标识
/// </summary>
public string Client { get {
public string Client
{
get
{
if (Scope != null)
{
return $"{Common.AppConfigHelper.GetValue(SettingString.AppIdentity)}-{Scope.Workshop}";
}
else return Name;
} }
}
}
/// <summary>
/// 责任范围
/// </summary>
public Scope Scope{ get; set; }
public Scope Scope { get; set; }
/// <summary>
/// 是否在线
/// </summary>
......@@ -310,7 +316,7 @@ namespace DeviceLibrary
Place = new Node();
Msg = "";
Position = new MirPosition();
RunInfos = new List<string>() { "状态", "目的地", "车间", "负载", "运行模式", "任务信息", "AGV运行信息","错误消息"};
RunInfos = new List<string>() { "状态", "目的地", "车间", "负载", "运行模式", "任务信息", "AGV运行信息", "错误消息" };
StateKanban = new AGV_UI.Status(name, RunInfos);
}
public AgvInfo()
......@@ -323,13 +329,74 @@ namespace DeviceLibrary
IOStatus = new List<IOInfo>();
TaskRunState = new TaskRunState();
JobContext = new JobContext();
AgvTimer = new System.Timers.Timer
{
Interval = 3000,
AutoReset = true,
Enabled = false
};
AgvTimer.Elapsed += AgvTimer_Elapsed; ;
}
public void StartTimer()
{
AgvTimer.Enabled = true;
AgvTimer.Start();
}
public void StopTimer()
{
AgvTimer.Enabled = false;
}
private void AgvTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{
if (Monitor.TryEnter(AgvTimer))
{
try
{
SetKanban();
if (!Control.CheckOnline(this)) return;
if (!TaskRunState.IsAllocatingTask && Auto && CurJob != null && TaskRunState.TaskID.Equals(-1))
{
if (!MiR_API.Get_MissionByDescrp(this))
{
CurJob.ResendTask(this);
LogUtil.info($"{Name}:Task=-1处理,Fleet无任务,重发任务:{TaskRunState.Task.Name}");
}
else
{
LogUtil.info($"{Name}:Task=-1处理,Fleet有任务,自动赋值FleetTaskID={TaskRunState.TaskID}");
}
}
//if ((agv.CurJob != null && !(agv.CurJob is ChargeJob || agv.CurJob is StandyJob))
// && (AGVManager.agvInfo[i].StateID.Equals(eAGVState.Executing)))
{
MiR_API.Get_Task_State(this);
Thread.Sleep(50);
MiR_API.Get_IO_Status(this);
}
//获取AGV状态
MiR_API.Get_State(this, out eAGVState stateID, out string stateText, out int battery, out string mission_text, out AgvInfo.MirPosition position, out List<Mir_Error> errors);
Thread.Sleep(50);
SetState(stateID, battery, mission_text, position, errors);
}
catch (Exception ex)
{
LogUtil.error($"{Name ?? ""} 计时器出错:{ex.Message}", ex);
}
finally
{
Monitor.Exit(AgvTimer);
}
}
}
private System.Timers.Timer AgvTimer;
public List<string> RunInfos;
DateTime IoStartTime = DateTime.MaxValue;
int IoLastTime = 5000;
int StandLastTimeMinute = AppConfigHelper.GetIntValue(SettingString.StandTimeout);
public DateTime StandStartTime = DateTime.MaxValue;
public bool SetState(eAGVState stateID, int battery, string missionText, MirPosition position,List<Mir_Error> mir_Errors)
public bool SetState(eAGVState stateID, int battery, string missionText, MirPosition position, List<Mir_Error> mir_Errors)
{
bool isChange = false;
bool preShelfState = IsExistShelf;
......@@ -388,10 +455,10 @@ namespace DeviceLibrary
MissionText = missionText;
StateKanban.ShowInfo("AGV运行信息", missionText);
}
if(mir_Errors !=null && mir_Errors.Count > 0)
if (mir_Errors != null && mir_Errors.Count > 0)
{
Errors = mir_Errors;
StateKanban.ShowInfo("错误消息",string.Join(";",Errors));
StateKanban.ShowInfo("错误消息", string.Join(";", Errors));
}
CheckErrorState();
CheckOfflineTimeOut();
......@@ -403,24 +470,24 @@ namespace DeviceLibrary
{
StateKanban.ShowInfo("目的地", Place == null ? "" : Place.AliceName);
string runmode = "";
if(Auto)
if (Auto)
{
runmode=IsDebug ? "调试" : "自动";
runmode = IsDebug ? "调试" : "自动";
}
else
{
runmode = "手动";
}
StateKanban.ShowInfo("运行模式", runmode);
if (Scope!=null)
if (Scope != null)
StateKanban.ShowInfo("车间", Scope.Workshop);
if (this.CurJob != null)
{
Msg = this.CurJob.runInfo;
if(CurJob.JobParam.GetMissionInfo()==null)
StateKanban.ShowInfo("任务信息", this.CurJob.RunInfo);
if (CurJob.JobParam.GetMissionInfo() == null)
StateKanban.ShowInfo("任务信息", this.CurJob.RunInfo);
else
StateKanban.ShowInfo("任务信息", string.Format("[{0}]{1}",CurJob.JobParam.GetMissionInfo().missionId, this.CurJob.RunInfo));
StateKanban.ShowInfo("任务信息", string.Format("[{0}]{1}", CurJob.JobParam.GetMissionInfo().missionId, this.CurJob.RunInfo));
}
}
DateTime agvErrorStartTime = DateTime.MaxValue;
......@@ -570,7 +637,7 @@ namespace DeviceLibrary
if (!isAlarm && errorState)
{
isAlarm = true;
if(Errors!=null && Errors.Count > 0)
if (Errors != null && Errors.Count > 0)
{
SetErrorMsg($"状态:[{StateID.ToString()}][{string.Join(";", Errors)}]", (DateTime.Now - offlineStartTime).TotalMinutes.ToString("f2"));
}
......@@ -622,7 +689,7 @@ namespace DeviceLibrary
}
public void SetJobContext(JobContext jobContext)
{
if(!JobContext.Equals(jobContext))
if (!JobContext.Equals(jobContext))
{
JobContext = jobContext;
AGVManager.SaveJobContext(this);
......
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!