Commit a1f4eb60 张东亮

出库逻辑优化初版

1 个父辈 a9a602b9
此文件类型无法预览
此文件类型无法预览
......@@ -76,6 +76,7 @@
<Compile Include="deviceLibrary\IO\NJSDot\NanjingSDotIO.cs" />
<Compile Include="ESS\ESS_CancelBody.cs" />
<Compile Include="ESS\ESS_CreateTaskBody.cs" />
<Compile Include="ESS\ResultData.cs" />
<Compile Include="ESS\TaskStateInfo.cs" />
<Compile Include="lineManager\ALineManager.cs" />
<Compile Include="clientLine\StationEquip_InStore.cs" />
......
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace OnlineStore.DeviceLibrary
{
public class ResultData
{
public int code { get; set; }
public string msg { get; set; }
public RobotStates data { get; set; }
}
public class RobotStates
{
public List<RobotState> robots { get; set; }
}
public class RobotState
{
/// <summary>
/// 编码
/// </summary>
public string robotCode { get; set; }
/// <summary>
/// 型号
/// </summary>
public string robotTypeCode { get; set; }
/// <summary>
/// 节点编码
/// 机器人当前所处节点
/// </summary>
public string pointCode { get; set; }
/// <summary>
/// 坐标X,单位mm
/// </summary>
public long positionX { get; set; }
/// <summary>
/// 坐标Y,单位mm
/// </summary>
public long positionY { get; set; }
/// <summary>
/// 电量
/// </summary>
public int energyLevel { get; set; }
/// <summary>
/// 机器人角度
/// </summary>
public int theta { get; set; }
/// <summary>
/// 货叉高度
/// </summary>
public long forkHeight { get; set; }
/// <summary>
/// 货叉长度
/// </summary>
public long forkLength { get; set; }
/// <summary>
/// 货叉相对机器人角度
/// </summary>
public int forkTheta { get; set; }
/// <summary>
/// 工作站编码
/// </summary>
public string stationCode { get; set; }
/// <summary>
/// 工作位编码
/// </summary>
public string locationCode { get; set; }
/// <summary>
/// 机器人状态
/// UNAVAILABLE = 杀机器人后,在场外的状态
///UNKNOWN = 未知, 待初始化
///ERROR = 错误(机器人状态更新超时)
///IDLE = 空闲
///EXECUTING = 执行任务中
///AWAITING = 原地等待
/// </summary>
public string state { get; set; }
/// <summary>
/// 机器人硬件状态
/// ROBOT_READY_TO_INIT = 机器人启动以后的初始状态,等待初始化指令
///ROBOT_IDLE = 空闲状态,等待任务指令(MOVE、BIN_OP)
///ROBOT_RUNNING = 运行状态(正在执行任务)
///ROBOT_ABNORMAL = 异常状态(内部故障,或者执行任务过程中发生异常需要处理)
///ROBOT_RECOVERY = 恢复状态
///ROBOT_PAUSED = 暂停状态
/// </summary>
public string hardwareState { get; set; }
/// <summary>
/// 背篓描述
/// </summary>
public List<tray> trays { get; set; }
}
public class tray
{
/// <summary>
/// 背篓序号
/// 货叉标识64
/// </summary>
public int trayLevel { get; set; }
/// <summary>
/// 容器编码
/// 若背篓为空则为空
/// </summary>
public string containerCode { get; set; }
/// <summary>
/// 业务任务
/// 容器对应的业务任务编码
/// </summary>
public List<string> taskCodes { get; set; }
/// <summary>
/// 位置编码
/// 格式为机器人id#背篓序号
/// </summary>
public string positionCode { get; set; }
}
}
......@@ -582,7 +582,7 @@ namespace OnlineStore.DeviceLibrary
object timerLockobj = new object();
protected override void mainTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{
if(Monitor.TryEnter(timerLockobj))
if (Monitor.TryEnter(timerLockobj))
{
try
{
......@@ -845,7 +845,7 @@ namespace OnlineStore.DeviceLibrary
{
map.Add($"s{equip.DeviceID}", data.StrData);
//自动上传出库料箱被其他工位拿走的状态
if(ContainerManager.GetOutStoreBox(data.ToContainerId()))
if (ContainerManager.GetOutStoreBox(data.ToContainerId()))
{
ContainerManager.UpdateTaskStatus(data.ToContainerId(), TaskStatus.FINISHED, $"s{equip.DeviceID}");
LogUtil.info($"出库容器被拿上工位s{equip.DeviceID},自动完成:{data.ToContainerId()}");
......@@ -858,23 +858,28 @@ namespace OnlineStore.DeviceLibrary
}
}
List<string> inTask = SServerManager.UploadStationInfo(Name, map);
List<OutTaskData> outTask = SServerManager.GetOutTask(Name);
if (inTask != null && inTask.Count > 0)
{
foreach (var item in inTask)
{
if (map.ContainsKey(item))
{
ContainerManager.AddOrUpdateContainerInfo(item,map[item]);
ContainerManager.AddOrUpdateContainerInfo(item, map[item]);
}
}
}
List<OutTaskData> outTask = SServerManager.GetOutTask(Name);
if (outTask != null && outTask.Count > 0)
{
foreach (var item in outTask)
RobotStates states = SServerManager.GetRobotState();
if (LineManager.RobotIsIdle(states) || LineManager.CheckRobotTrayIsInstore(states))
{
ContainerManager.AddOrUpdateContainerInfo(item.barcode);
foreach (var item in outTask)
{
ContainerManager.AddOrUpdateContainerInfo(item.barcode);
}
}
}
//发送呼叫任务
ContainerManager.HandlePendingTask();
......
......@@ -8,6 +8,7 @@ using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Web.Management;
using System.Windows.Forms;
namespace OnlineStore.DeviceLibrary
......@@ -184,5 +185,75 @@ namespace OnlineStore.DeviceLibrary
{
return Line?.AllEquipMap[101]?.BoxCheck() ?? false;
}
#region 机器人
/// <summary>
/// 是否有机器人空闲:背篓为空且空闲
/// </summary>
/// <param name="robotStates"></param>
/// <returns>true:空闲</returns>
public static bool RobotIsIdle(RobotStates robotStates)
{
try
{
if(robotStates !=null && robotStates.robots!=null)
{
foreach (var item in robotStates.robots)
{
if (!item.state.Equals("IDLE")) continue;
var fullTray = item.trays.FindAll(s => s.containerCode != null);
if (fullTray == null) return true;
}
}
}
catch(Exception ex)
{
LogUtil.error("RobotTrayIsEmpty", ex);
}
return false;
}
/// <summary>
/// 检查机器人背篓是否是入库容器
/// </summary>
/// <param name="robotStates"></param>
/// <returns>true:是入库容器</returns>
public static bool CheckRobotTrayIsInstore(RobotStates robotStates)
{
try
{
if (robotStates != null && robotStates.robots != null)
{
foreach (var item in robotStates.robots)
{
var fullTray = item.trays.FindAll(s => s.containerCode != null);
if (fullTray != null)
{
foreach (var tray in fullTray)
{
var instore = ContainerManager.GetTrayInfo(tray.containerCode);
if (instore != null && instore.InOrOutStore.Equals(ContainerType.InStore))
return true;
}
}
}
}
}
catch (Exception ex)
{
LogUtil.error("CheckRobotTrayIsInstore", ex);
}
return false;
}
/// <summary>
/// 检查容器任务数是否超限
/// </summary>
/// <returns></returns>
public static bool CheckTaskCntIsInLimit()
{
return ContainerManager.getTrayList().Count <= 30;
}
#endregion
}
}
......@@ -102,7 +102,10 @@ namespace OnlineStore.DeviceLibrary
}
public static ContainerInfo GetTrayInfo(string trayNum)
{
if (trayNum.EndsWith("A") || trayNum.EndsWith("B"))
{
trayNum = trayNum.Substring(0, trayNum.Length - 1);
}
if (containerInfoMap.ContainsKey(trayNum))
{
return containerInfoMap[trayNum];
......
......@@ -118,8 +118,8 @@ namespace OnlineStore.DeviceLibrary
string path = ess_server + Addr_createTask;
if (HttpHelper.Post(path, param, out bool isTimueOut, out string outMsg))
{
ServerData1 server= JsonHelper.DeserializeJsonToObject<ServerData1>(outMsg);
if(server != null)
ServerData1 server = JsonHelper.DeserializeJsonToObject<ServerData1>(outMsg);
if (server != null)
{
foreach (var item in containerInfos)
{
......@@ -323,6 +323,8 @@ namespace OnlineStore.DeviceLibrary
public static List<OutTaskData> GetOutTask(string deviceName)
{
List<OutTaskData> list = new List<OutTaskData>();
//判断任务数》-30 不获取出库任务
if (!LineManager.CheckTaskCntIsInLimit()) return list;
try
{
string msg = "";
......@@ -477,9 +479,37 @@ namespace OnlineStore.DeviceLibrary
#region ESS 接口
public static bool CreateTask()
static string Addr_GetRobotState = "/robot/query";
/// <summary>
/// 获取机器人状态
/// </summary>
/// <returns></returns>
public static RobotStates GetRobotState()
{
return false;
try
{
string path = ess_server + Addr_GetRobotState;
if (HttpHelper.Post(path, "", out bool isTimueOut, out string outMsg))
{
ResultData resultData = JsonHelper.DeserializeJsonToObject<ResultData>(outMsg);
if (resultData != null)
{
if (resultData.code.Equals(0))
return resultData.data;
}
else
return null;
}
else
{
return null;
}
}
catch (Exception ex)
{
LogUtil.error($"GetRobotState ", ex);
}
return null;
}
#endregion
#region 未使用接口
......
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!