Commit cd57cc73 张东亮

将获取状态放入agv类里

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