using Autofac;
|
using Bro.Common.Base;
|
using Bro.Common.Helper;
|
using Bro.Common.Interface;
|
using Bro.Common.Model;
|
using Bro.Device.AuboRobot;
|
using Bro.Device.SeerAGV;
|
using Newtonsoft.Json;
|
using System;
|
using System.Collections.Generic;
|
using System.Collections.ObjectModel;
|
using System.ComponentModel;
|
using System.Linq;
|
using System.Threading;
|
|
namespace A032.Process
|
{
|
public enum TaskState
|
{
|
/// <summary>
|
/// 新任务
|
/// </summary>
|
New = 0,
|
/// <summary>
|
/// 任务完成
|
/// </summary>
|
Done = 1,
|
/// <summary>
|
/// 任务失败
|
/// </summary>
|
Failed = 2,
|
/// <summary>
|
/// 任务已添加队列,等待执行
|
/// </summary>
|
Queueing = 3,
|
/// <summary>
|
/// 任务已指派
|
/// </summary>
|
Assigned = 4,
|
/// <summary>
|
/// 任务未指派,已取消
|
/// </summary>
|
Cancelled = 5,
|
}
|
|
public enum AGVState
|
{
|
/// <summary>
|
/// AGV状态不可知
|
/// </summary>
|
Unknown = 0,
|
/// <summary>
|
/// 空闲状态,可接收任务
|
/// </summary>
|
Idle = 1,
|
/// <summary>
|
/// 任务执行中
|
/// </summary>
|
Running = 2,
|
/// <summary>
|
/// 报警中,不可执行任务
|
/// </summary>
|
Warning = 3,
|
/// <summary>
|
/// 充电中,不可执行任务
|
/// </summary>
|
InCharge = 4,
|
/// <summary>
|
/// 空闲充电状态,可接收任务
|
/// </summary>
|
IdleCharge = 5,
|
}
|
|
//public class AGVTaskModel
|
//{
|
// public TaskAvailableLevel Level { get; set; } = TaskAvailableLevel.Robot;
|
|
// public string MethodName { get; set; }
|
|
// public IOperationConfig OpConfig { get; set; }
|
|
// public IDevice Device { get; set; }
|
|
// //public int Priority { get; set; } = 10;
|
|
// public AGVTaskModel() { }
|
|
// public AGVTaskModel(TaskAvailableLevel level, string methodName, IOperationConfig opConfig = null, IDevice device = null)
|
// {
|
// Level = level;
|
// MethodName = methodName;
|
// OpConfig = opConfig ?? new OperationConfigBase();
|
// Device = device;
|
// }
|
//}
|
|
public class AGVBindUnit : IComplexDisplay
|
{
|
#region 可编辑项目
|
[Category("设备绑定")]
|
[Description("绑定Id")]
|
[Browsable(false)]
|
public string Id { get; set; } = Guid.NewGuid().ToString();
|
|
[Category("设备绑定")]
|
[Description("绑定AGV")]
|
[TypeConverter(typeof(AGVDeviceConverter))]
|
public string AGVId { get; set; }
|
|
[Category("设备绑定")]
|
[Description("绑定Robot")]
|
[TypeConverter(typeof(RobotDeviceConverter))]
|
public string RobotId { get; set; }
|
|
[Category("设备绑定")]
|
[Description("绑定Camera")]
|
[TypeConverter(typeof(CameraDeviceConverter))]
|
public string CameraId { get; set; }
|
|
public string GetDisplayText()
|
{
|
using (var scope = GlobalVar.Container.BeginLifetimeScope())
|
{
|
ProcessConfig config = scope.Resolve<ProcessConfig>();
|
|
string agv = config.AGVConfigCollection.FirstOrDefault(u => u.ID == AGVId)?.Name ?? "未绑定AGV";
|
string robot = config.RobotConfigCollection.FirstOrDefault(u => u.ID == RobotId)?.Name ?? "未绑定机器人";
|
string camera = config.CameraConfigCollection.FirstOrDefault(u => u.ID == CameraId)?.Name ?? "未绑定相机";
|
|
return agv + "-" + robot + "-" + camera;
|
}
|
}
|
#endregion
|
|
#region 后台属性
|
#region 状态
|
private AGVState unitState = AGVState.Idle;
|
[Browsable(false)]
|
[JsonIgnore]
|
public AGVState UnitState
|
{
|
get => unitState;
|
set
|
{
|
if (value != unitState)
|
{
|
var preState = unitState;
|
unitState = value;
|
|
OnUnitStateChanged?.Invoke(this.Id, preState, unitState);
|
}
|
}
|
}
|
|
[Browsable(false)]
|
[JsonIgnore]
|
public string WarningMsg { get; set; } = "";
|
#endregion
|
|
#region 设备
|
[Browsable(false)]
|
[JsonIgnore]
|
public SeerAGVDriver AGV { get; set; } = null;
|
[Browsable(false)]
|
[JsonIgnore]
|
public AuboRobotDriver Robot { get; set; } = null;
|
[Browsable(false)]
|
[JsonIgnore]
|
public CameraBase Camera { get; set; } = null;
|
#endregion
|
|
#region 任务信息
|
[JsonIgnore]
|
[Browsable(false)]
|
public string CurrentTaskId { get; set; }
|
|
[JsonIgnore]
|
[Browsable(false)]
|
public bool IsTaskCancelled { get; set; } = false;
|
|
[JsonIgnore]
|
[Browsable(false)]
|
public bool IsTaskCancelling { get; set; } = false;
|
#endregion
|
|
#region 事件
|
[JsonIgnore]
|
[Browsable(false)]
|
public Action<string, AGVState, AGVState> OnUnitStateChanged { get; set; }
|
#endregion
|
|
#region 托盘信息
|
[JsonIgnore]
|
[Browsable(false)]
|
public int FullTrayNum { get; set; }
|
|
[JsonIgnore]
|
[Browsable(false)]
|
public int EmptyTrayNum { get; set; }
|
#endregion
|
#endregion
|
|
public AGVBindUnit()
|
{
|
}
|
}
|
|
public class AGVDeviceConverter : ComboBoxItemTypeConvert
|
{
|
public override void GetConvertHash()
|
{
|
using (var scope = GlobalVar.Container.BeginLifetimeScope())
|
{
|
ProcessConfig config = scope.Resolve<ProcessConfig>();
|
|
config.AGVConfigCollection.ForEach(plc =>
|
{
|
_hash[plc.ID] = plc.Name;
|
});
|
}
|
}
|
}
|
|
public class RobotDeviceConverter : ComboBoxItemTypeConvert
|
{
|
public override void GetConvertHash()
|
{
|
using (var scope = GlobalVar.Container.BeginLifetimeScope())
|
{
|
ProcessConfig config = scope.Resolve<ProcessConfig>();
|
|
config.RobotConfigCollection.ForEach(robot =>
|
{
|
_hash[robot.ID] = robot.Name;
|
});
|
}
|
}
|
}
|
|
public class CameraDeviceConverter : ComboBoxItemTypeConvert
|
{
|
public override void GetConvertHash()
|
{
|
using (var scope = GlobalVar.Container.BeginLifetimeScope())
|
{
|
ProcessConfig config = scope.Resolve<ProcessConfig>();
|
|
config.CameraConfigCollection.ForEach(camera =>
|
{
|
_hash[camera.ID] = camera.Name;
|
});
|
}
|
}
|
}
|
|
public class PLCDeviceConverter : ComboBoxItemTypeConvert
|
{
|
public override void GetConvertHash()
|
{
|
using (var scope = GlobalVar.Container.BeginLifetimeScope())
|
{
|
_hash[""] = "未指定";
|
|
ProcessConfig config = scope.Resolve<ProcessConfig>();
|
|
config.PLCConfigCollection.ForEach(plc =>
|
{
|
_hash[plc.ID] = plc.Name;
|
});
|
}
|
}
|
}
|
|
public class AllDeviceIdConverter : ComboBoxItemTypeConvert
|
{
|
public override void GetConvertHash()
|
{
|
using (var scope = GlobalVar.Container.BeginLifetimeScope())
|
{
|
_hash[""] = "未指定";
|
|
List<IDevice> deviceList = scope.Resolve<List<IDevice>>();
|
|
deviceList.ForEach(d =>
|
{
|
_hash[d.Id] = d.Name;
|
});
|
}
|
}
|
}
|
|
public class AllDeviceNameConverter : ComboBoxItemTypeConvert
|
{
|
public override void GetConvertHash()
|
{
|
using (var scope = GlobalVar.Container.BeginLifetimeScope())
|
{
|
_hash[""] = "未指定";
|
|
List<IDevice> deviceList = scope.Resolve<List<IDevice>>();
|
|
deviceList.ForEach(d =>
|
{
|
_hash[d.Name] = d.Name;
|
});
|
}
|
}
|
}
|
}
|