Commit 41b85e1f LN

agv对接功能。

1 个父辈 2c48ddc1
......@@ -42,6 +42,19 @@ namespace OnlineStore.Common
[MyConfigComment("二维码扫码超时毫秒")]
public static MyConfig<int> Device_RfidServer_Port = 30001;
[MyConfigComment("Agv服务器地址")]
public static MyConfig<string> Device_AgvServer = "127.0.0.1";
[MyConfigComment("AGV服务器端口号")]
public static MyConfig<int> Device_AgvPort = 12000;
[MyConfigComment("Agv节点ID列表")]
public static MyConfig<string[]> Device_AgvNodeId =new string[] { "1","2","3","4"};
[MyConfigComment("AGV节点名称")]
public static MyConfig<string[]> Device_AgvNodeName=new string[] { "A1", "A2", "A3", "A4" };
[MyConfigComment("管理员密码")]
public static MyConfig<string> User_AdminPassword = "123456";
[MyConfigComment("启用管理员密码")]
......
<?xml version="1.0" encoding="UTF-8"?>
<config ver="10">
<item key="App_Title" ver="10" value="SMD-BOX-XLC" />
<item key="App_Title" ver="10" value="出料机构" />
<item key="EnableBuzzer" ver="10" value="False" />
</config>
\ No newline at end of file
......@@ -32,6 +32,9 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="AGVLib">
<HintPath>..\SharedDLL\agv\AGVLib.dll</HintPath>
</Reference>
<Reference Include="Asa.Camera.VisionLib, Version=1.3.8479.24297, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\SharedDLL\Asa.Camera.VisionLib.dll</HintPath>
......@@ -79,6 +82,7 @@
</ItemGroup>
<ItemGroup>
<Compile Include="DeviceLibrary\AcSerialBean.cs" />
<Compile Include="DeviceLibrary\agv\AgvClient.cs" />
<Compile Include="DeviceLibrary\Camera.cs" />
<Compile Include="DeviceLibrary\CylinderManger.cs" />
<Compile Include="DeviceLibrary\HttpServer.cs" />
......@@ -89,7 +93,9 @@
<Compile Include="DeviceLibrary\ReelParam.cs" />
<Compile Include="DeviceLibrary\ServerCommunication.cs" />
<Compile Include="DeviceLibrary\AxisBean.cs" />
<Compile Include="DeviceLibrary\WaitUtil.cs" />
<Compile Include="theMachine\BaseBean.cs" />
<Compile Include="theMachine\OutShelfBean_AgvPro.cs" />
<Compile Include="theMachine\ReelTransport.cs" />
<Compile Include="theMachine\Common.cs" />
<Compile Include="theMachine\InReelBean.cs" />
......
......@@ -2,10 +2,7 @@
using OnlineStore.LoadCSVLibrary;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Timers;
namespace DeviceLibrary
......@@ -27,6 +24,10 @@ namespace DeviceLibrary
}
private static void T1_Elapsed(object sender, ElapsedEventArgs e)
{
if (RobotManage.mainMachine == null || (!RobotManage.mainMachine.LoadOk))
{
return;
}
foreach (var iOMonitorStrut in iOMonitorStruts)
{
var current_iovalue = IOManager.IOValue(iOMonitorStrut.ioType, iOMonitorStrut.Config);
......
......@@ -5,10 +5,7 @@ using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace DeviceLibrary
{
public class ServerCommunication
......
using OnlineStore.Common;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace DeviceLibrary.DeviceLibrary
{
public class WaitUtil
{
public delegate bool IsOk();
/// <summary>
/// 使用异步委托检测超时,防止isOk方法不返回结果导致卡死的问题
/// </summary>
/// <param name="waitName"></param>
/// <param name="timeout"></param>
/// <param name="isOk"></param>
public static bool Wait(int timeout, IsOk isOk, string waitName = "")
{
DateTime startTime = System.DateTime.Now;
TimeSpan timoutSpan = TimeSpan.FromMilliseconds(timeout);
TimeSpan waitSpan = TimeSpan.FromMilliseconds(0);
int sleepTime = 10;
while (true)
{
TimeSpan remainTimes = timoutSpan.Subtract(waitSpan);
if (remainTimes.TotalMilliseconds < 0)
{
//已经超时
throw new TimeoutException(waitName + "超时");
}
try
{
IAsyncResult re = isOk.BeginInvoke(null, null);
var waitResult = re.AsyncWaitHandle.WaitOne(remainTimes);
if (waitResult)
{
bool okResult = isOk.EndInvoke(re);
if (okResult)
{
return true;
}
}
}
catch (Exception ex)
{
LogUtil.error("同步等待出现异常:", ex);
}
Thread.Sleep(sleepTime);
waitSpan = System.DateTime.Now.Subtract(startTime);
}
}
}
}
using AGVLib;
using OnlineStore.Common;
using System;
using System.Collections.Generic;
namespace DeviceLibrary
{
public class AgvClient
{
public static bool DisAgv = false;
private static Client client;
/// <summary>
/// key=agvId
/// </summary>
public static Dictionary<int, AGVLib.NodeStatus> nodeStatusMap = new Dictionary<int, NodeStatus>();
private static bool isInit = false;
public static void Init()
{
LogUtil.info("开始 Init client");
if (!isInit)
{
isInit = true;
client = new Client();
client.ConnectedEvent += Client_ConnectedEvent;
client.ReceivedEvent += Client_ReceivedEvent;
client.IsAutoReconnect = true;
LogUtil.info($" 开始 client.Connect: {Setting_Init.Device_AgvServer},{Setting_Init.Device_AgvPort}");
client.Connect(Setting_Init.Device_AgvServer, Setting_Init.Device_AgvPort);
}
}
public static void setDisAgv(bool disAgv)
{
LogUtil.info("设置:DisAgv=" + disAgv);
DisAgv = disAgv;
}
private static string getNodeStr(Node node)
{
return $"nodeInfo: id={node.id},name={node.name},level={node.level},status={node.status} ,shelf_id={node.shelf_id}";
}
private static OutShelfBean GetShelfBean(string nodeName)
{
List<OutShelfBean> outShelfBeans = new List<OutShelfBean>(RobotManage.mainMachine.outShelfBeans.Values);
foreach (OutShelfBean bean in outShelfBeans)
{
if (bean.agvName.Equals(nodeName))
{
return bean;
}
}
return null;
}
private static void Client_ReceivedEvent(Node node)
{
LogUtil.info($"Client_ReceivedEvent : node={getNodeStr(node)}" );
OutShelfBean outShelfBean = GetShelfBean(node.name);
if (outShelfBean == null)
{
LogUtil.info($"Client_ReceivedEvent : node={getNodeStr(node)} ,未找到对应的OutShelfBean ");
return;
}
if (node.status.Equals(NodeStatus.Arrive))
{
outShelfBean.AgvArrive(node);
}else if (node.status.Equals(NodeStatus.RequestEnter))
{
outShelfBean.AgvRequestEnter(node);
}
else if (node.status.Equals(NodeStatus.RequestLeave))
{
outShelfBean.AgvRequestLeave(node);
}
}
private static void Client_ConnectedEvent(bool status)
{
LogUtil.info("Client_ConnectedEvent := " + status);
}
internal static bool ISConnected()
{
if (client == null)
{
return false;
}
return client.Connected;
}
public static void SetStatus(int agvId,string agvName, string shelfId = "", NodeStatus status = NodeStatus.None, NodeLevel level = NodeLevel.Low, bool isMust = false)
{
if (!isMust && level.Equals(NodeLevel.Low))
{
if (nodeStatusMap.ContainsKey(agvId))
{
NodeStatus currA = nodeStatusMap[agvId]; //相同状态就设置一次
if (currA.Equals(status))
{
return;
}
}
}
string mark = "";
if (shelfId != "")
{
int index = shelfId.IndexOf(',');
if (index > 0)
{
//紧急出料模块,料架离开时,mark=紧急料或者分配料,rfid=料架号
mark = shelfId.Substring(index + 1, shelfId.Length - index - 1);
shelfId = shelfId.Substring(0, index);
}
}
Node node = new Node(agvId, agvName);
node.SetState(status, level, shelfId);
client.SetStatus(node);
UpdateStatus(agvId, node);
}
public static bool SetToNone(int agvId, string agvName, string shelfId = "")
{
NodeStatus currA = GetCurrStatus(agvId);
if (currA.Equals(NodeStatus.None) || currA.Equals(NodeStatus.NeedLeave) || currA.Equals(NodeStatus.NeedEnter))
{
SetStatus(agvId,agvName, shelfId, NodeStatus.None);
return true;
}
return false;
}
public static bool NeedEnter(int agvId, string agvName, string shelfId = "", NodeLevel level = NodeLevel.Low)
{
NodeStatus currA = GetCurrStatus(agvId);
if (currA.Equals(NodeStatus.None) || currA.Equals(NodeStatus.NeedLeave) || currA.Equals(NodeStatus.NeedEnter))
{
SetStatus(agvId,agvName, shelfId, NodeStatus.NeedEnter, level);
return true;
}
return false;
}
public static bool NeedLeave(int agvId, string agvName, string shelfId = "", NodeLevel level = NodeLevel.Low)
{
NodeStatus currA = GetCurrStatus(agvId);
if (currA.Equals(NodeStatus.None) || currA.Equals(NodeStatus.NeedLeave) || currA.Equals(NodeStatus.NeedEnter))
{
SetStatus(agvId,agvName, shelfId, NodeStatus.NeedLeave, level);
return true;
}
return false;
}
public static NodeStatus GetCurrStatus(int agvId)
{
if (nodeStatusMap.ContainsKey(agvId))
{
return nodeStatusMap[agvId];
}
return NodeStatus.None;
}
public static void UpdateStatus(int agvId, Node node)
{
if (nodeStatusMap.ContainsKey(agvId))
{
nodeStatusMap[agvId] = node.status;
}
else
{
nodeStatusMap.Add(agvId, node.status);
}
}
public static void Dispose()
{
try
{
if (client != null)
{
client.Close();
}
}
catch (Exception ex)
{
LogUtil.error("释放 client " + Setting_Init.Device_AgvServer + " 出错:", ex);
}
}
}
}
......@@ -117,13 +117,40 @@ namespace DeviceLibrary
InReelBean inReel = new InReelBean("IN_"+i);
inReelBeans.Add(inReel);
}
List<string> rfidIp = new List<string> { Config.RFID_U1, Config.RFID_U2, Config.RFID_U3, Config.RFID_U4 };
for (int i = 1; i <= 4; i++)
{
string rfidip = rfidIp[i - 1];
string[] agvNodeIds = Setting_Init.Device_AgvNodeId;
string[] agvNodeNames = Setting_Init.Device_AgvNodeName;
if (agvNodeIds == null || agvNodeIds.Length <= 0)
{
agvNodeIds = new string[] { "1", "2", "3", "4" };
}
if (agvNodeNames == null || agvNodeNames.Length <= 0)
{
agvNodeNames = new string[] { "A1", "A2", "A3", "A4" };
}
int agvid = 0;
try
{
agvid = Convert.ToInt32(agvNodeIds[i - 1]);
}
catch (Exception ex)
{
LogUtil.error($"U{i}的agvID转为int失败,默认=0:" + ex.ToString());
}
string agvname = agvNodeNames[i - 1];
outShelfBeans.Add("U" + i, new OutShelfBean("U" + i, rfidip, agvid, agvname));
}
outShelfBeans.Add("U1", new OutShelfBean("U1", Config.RFID_U1));
outShelfBeans.Add("U2", new OutShelfBean("U2", Config.RFID_U2));
outShelfBeans.Add("U3", new OutShelfBean("U3", Config.RFID_U3));
outShelfBeans.Add("U4", new OutShelfBean("U4", Config.RFID_U4));
//outShelfBeans.Add("U1", new OutShelfBean("U1", Config.RFID_U1));
//outShelfBeans.Add("U2", new OutShelfBean("U2", Config.RFID_U2));
//outShelfBeans.Add("U3", new OutShelfBean("U3", Config.RFID_U3));
//outShelfBeans.Add("U4", new OutShelfBean("U4", Config.RFID_U4));
AgvClient.Init();
LedProcessInit();
LoadOk = true;
}
......
......@@ -156,18 +156,18 @@ namespace DeviceLibrary
S21_ShelfNeedLeave,
//呼叫agv拉料
S22_WaitAGV,
//agv到位
S23_AgvDetect,
//定位气缸下降
S24_LocationDown,
//电机反转
S25_LineRRun,
//等待前端料格检测 On变OFF
S26_ShelfBackHigh,
//等待前端料格检测 On变OFF
S27_ShelfBackLow,
//电机反转延时2秒OFF
S28_WaitTime,
////agv到位
//S23_AgvDetect,
////定位气缸下降
//S24_LocationDown,
////电机反转
//S25_LineRRun,
////等待前端料格检测 On变OFF
//S26_ShelfBackHigh,
////等待前端料格检测 On变OFF
//S27_ShelfBackLow,
////电机反转延时2秒OFF
//S28_WaitTime,
/// <summary>
......
......@@ -99,7 +99,7 @@ namespace DeviceLibrary
}
catch (Exception ex)
{
LoadFinishEvent?.Invoke(false, ex.Message);
LoadFinishEvent?.Invoke(false, ex.Message+":"+ex.ToString());
return;
}
LoadFinishEvent?.Invoke(IsConfigMode ? IsConfigMode : IsLoadOk, msg);
......
此文件类型无法预览
......@@ -227,8 +227,8 @@ namespace TheMachine
string name = moveInfo.Name;
OutShelfBean bean = RobotManage.mainMachine.getOutShelf(name);
if (bean != null && bean.CurrShelf != null)
{
stateinfo += "[" + bean.CurrShelf.ToStr() + "]";
{
stateinfo += "[" + bean.CurrShelf.ToStr() + "]["+bean.getAgvStatus()+"]";
}
else
{
......@@ -740,5 +740,16 @@ namespace TheMachine
LogUtil.info("[" + String.Join(",", camers) + "]扫码测试结果:\r\n" + lastCode);
MessageBox.Show("[" + String.Join(",", camers) + crc.GetString("Res0109", "]扫码测试结果:") + lastCode);
}
private void chbDIsAgv_CheckedChanged(object sender, EventArgs e)
{
if (chbDIsAgv.Checked.Equals(AgvClient.DisAgv))
{
return;
}
LogUtil.info("勾选:" + chbDIsAgv.Text + " =" +( chbDIsAgv.Checked ? "√" : "×"));
AgvClient.setDisAgv(chbDIsAgv.Checked);
}
}
}
\ No newline at end of file
using DeviceLibrary;
using log4net;
using OnlineStore;
using OnlineStore.Common;
using OnlineStore.DeviceLibrary;
using OnlineStore.LoadCSVLibrary;
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace TheMachine
......@@ -31,7 +22,7 @@ namespace TheMachine
if (value == null)
return;
_Config = value;
storePosControl1.Config = _Config;
storePosControl1.Config = _Config;
Init();
}
}
......
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!