robotMatrix
This commit is contained in:
parent
5e804f7c3c
commit
5fe374eeff
@ -105,6 +105,10 @@ namespace PLCSharp.Models
|
||||
/// </summary>
|
||||
public DbSet<RobotPoint> RobotPoints { get; set; }
|
||||
/// <summary>
|
||||
/// 机器人矩阵
|
||||
/// </summary>
|
||||
public DbSet<RobotMatrix> RobotMatrices { get; set; }
|
||||
/// <summary>
|
||||
/// 错误Logs
|
||||
/// </summary>
|
||||
public DbSet<ErrorLog> ErrorLogs { get; set; }
|
||||
|
||||
@ -11,7 +11,6 @@ using PLCSharp.VVMs.MotionController;
|
||||
using PLCSharp.VVMs.Recipe;
|
||||
using PLCSharp.VVMs.Robots;
|
||||
using PLCSharp.VVMs.Vision;
|
||||
using PLCSharp.VVMs.Vision.Camera;
|
||||
using PLCSharp.VVMs.Workflows;
|
||||
using Prism.Commands;
|
||||
using Prism.Dialogs;
|
||||
@ -160,6 +159,7 @@ namespace PLCSharp.Models
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 硬件
|
||||
/// <summary>
|
||||
/// 连接模型
|
||||
@ -190,7 +190,7 @@ namespace PLCSharp.Models
|
||||
{
|
||||
var connect = Connects.Connects.FirstOrDefault(c => c.Name == name)
|
||||
?? throw new Exception("网络未配置!");
|
||||
|
||||
|
||||
return connect;
|
||||
}
|
||||
/// <summary>
|
||||
@ -202,7 +202,7 @@ namespace PLCSharp.Models
|
||||
{
|
||||
var robot = RobotModel.Robots.FirstOrDefault(c => c.Name == name)
|
||||
?? throw new Exception("Robot未配置!");
|
||||
|
||||
|
||||
return robot;
|
||||
}
|
||||
/// <summary>
|
||||
@ -230,6 +230,7 @@ namespace PLCSharp.Models
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
#region 任务
|
||||
/// <summary>
|
||||
/// Workflows模型
|
||||
@ -250,6 +251,7 @@ namespace PLCSharp.Models
|
||||
return WorkflowsModel.Workflows.FirstOrDefault(t => t.Name == name);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region 日志
|
||||
private ObservableCollection<ErrorLog> _ErrorLogs = [];
|
||||
|
||||
@ -362,6 +364,7 @@ namespace PLCSharp.Models
|
||||
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region 模式与状态
|
||||
private ModeState _ModeState = new();
|
||||
/// <summary>
|
||||
@ -403,6 +406,7 @@ namespace PLCSharp.Models
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region 配方
|
||||
|
||||
|
||||
@ -1086,116 +1090,18 @@ namespace PLCSharp.Models
|
||||
{
|
||||
Target = "UIReLoad"
|
||||
});
|
||||
//加载当前配方的用户变量列表
|
||||
VariablesModel.Variables.Clear();
|
||||
var variables = _DatasContext.Variables.Where(c => c.RecipeID == CurrentRecipe.ID);
|
||||
foreach (var item in variables)
|
||||
{
|
||||
if (item.RetainPersistent)
|
||||
{
|
||||
|
||||
item.Value = Variable.DynamicValue(item.ValueStr, item.Type);
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
item.Value = Variable.DynamicValue(item.DefaultValueStr, item.Type);
|
||||
item.DefaultValue = item.Value;
|
||||
|
||||
}
|
||||
VariablesModel.Variables.Add(item);
|
||||
}
|
||||
//加载当前配方的系统变量列表
|
||||
VariablesModel.SystemVariables.Clear();
|
||||
var systemVariables = _DatasContext.SystemVariables.Where(c => c.RecipeID == CurrentRecipe.ID);
|
||||
foreach (var item in systemVariables)
|
||||
{
|
||||
if (item.RetainPersistent)
|
||||
{
|
||||
|
||||
item.Value = Variable.DynamicValue(item.ValueStr, item.Type);
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
item.Value = Variable.DynamicValue(item.DefaultValueStr, item.Type);
|
||||
item.DefaultValue = item.Value;
|
||||
|
||||
}
|
||||
VariablesModel.SystemVariables.Add(item);
|
||||
}
|
||||
//加载当前配方的图像数据列表
|
||||
VisionsModel.ImageDatas.Clear();
|
||||
var currRecipeImageDatas = _DatasContext.ImageDatas.Where(c => c.RecipeID == CurrentRecipe.ID);
|
||||
foreach (var item in currRecipeImageDatas)
|
||||
{
|
||||
var itemcopy = item.DeepCopy();
|
||||
itemcopy.Prompt = "";
|
||||
VisionsModel.ImageDatas.Add(itemcopy);
|
||||
}
|
||||
|
||||
//加载当前配方的全局变量列表
|
||||
VariablesModel.LoadRecipe(CurrentRecipe.ID);
|
||||
|
||||
//加载当前配方的视觉功能列表
|
||||
VisionsModel.VisionFunctions.Clear();
|
||||
var currRecipeVisionFunctions = _DatasContext.VisionFunctions.Where(c => c.RecipeID == CurrentRecipe.ID);
|
||||
foreach (var item in currRecipeVisionFunctions)
|
||||
{
|
||||
var itemcopy = item.DeepCopy();
|
||||
itemcopy.Prompt = "";
|
||||
itemcopy.VisionsModel = VisionsModel;
|
||||
itemcopy.ImageDatas = VisionsModel.ImageDatas;
|
||||
itemcopy.GlobalModel = this;
|
||||
VisionsModel.VisionFunctions.Add(itemcopy);
|
||||
}
|
||||
VisionsModel.LoadRecipe(CurrentRecipe.ID);
|
||||
|
||||
//加载当前配方的点位列表
|
||||
ControllersModel.Stop();
|
||||
ControllersModel.AxisPoints.Clear();
|
||||
var currRecipeAxisPoints = _DatasContext.AxisPoints.Where(c => c.RecipeID == CurrentRecipe.ID);
|
||||
foreach (var item in currRecipeAxisPoints)
|
||||
{
|
||||
var axisPoint = item.DeepCopy();
|
||||
ControllersModel.AxisPoints.Add(axisPoint);
|
||||
var axisX = ControllersModel.Axes.Where(a => a.Name == axisPoint.AxisXName).FirstOrDefault();
|
||||
if (axisX != null)
|
||||
axisPoint.AxisX = axisX;
|
||||
var axisY = ControllersModel.Axes.Where(a => a.Name == axisPoint.AxisYName).FirstOrDefault();
|
||||
if (axisY != null)
|
||||
axisPoint.AxisY = axisY;
|
||||
var axisZ = ControllersModel.Axes.Where(a => a.Name == axisPoint.AxisZName).FirstOrDefault();
|
||||
if (axisZ != null)
|
||||
axisPoint.AxisZ = axisZ;
|
||||
var axisU = ControllersModel.Axes.Where(a => a.Name == axisPoint.AxisUName).FirstOrDefault();
|
||||
if (axisU != null)
|
||||
axisPoint.AxisU = axisU;
|
||||
}
|
||||
//加载当前西方的矩阵列表
|
||||
ControllersModel.Matrices.Clear();
|
||||
var currRecipeMatrices = _DatasContext.Matrices.Where(c => c.RecipeID == CurrentRecipe.ID);
|
||||
foreach (var item in currRecipeMatrices)
|
||||
{
|
||||
var matrix = item.DeepCopy();
|
||||
ControllersModel.Matrices.Add(matrix);
|
||||
ControllersModel.LoadRecipe(CurrentRecipe.ID);
|
||||
|
||||
ControllersModel.Create(matrix);
|
||||
|
||||
|
||||
}
|
||||
|
||||
//加载当前配方的插补列表
|
||||
|
||||
ControllersModel.InterpolationGroups.Clear();
|
||||
var currRecipeInterpolationGroups = _DatasContext.InterpolationGroups.Where(c => c.RecipeID == CurrentRecipe.ID);
|
||||
foreach (var item in currRecipeInterpolationGroups)
|
||||
{
|
||||
var itemcopy = item.DeepCopy();
|
||||
ControllersModel.InterpolationGroups.Add(itemcopy);
|
||||
var axisX = ControllersModel.Axes.Where(a => a.Name == itemcopy.AxisXName).FirstOrDefault();
|
||||
if (axisX != null)
|
||||
itemcopy.AxisX = axisX;
|
||||
var axisY = ControllersModel.Axes.Where(a => a.Name == itemcopy.AxisYName).FirstOrDefault();
|
||||
if (axisY != null)
|
||||
itemcopy.AxisY = axisY;
|
||||
}
|
||||
ControllersModel.Start();
|
||||
//加载当前配方的机器人点位和矩阵列表
|
||||
RobotModel.LoadRecipe(CurrentRecipe.ID);
|
||||
|
||||
//加载当前配方的任务列表
|
||||
WorkflowsModel.Workflows.Clear();
|
||||
@ -1324,6 +1230,7 @@ namespace PLCSharp.Models
|
||||
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region 主页面
|
||||
private ObservableCollection<CustomControl> _CustomControls = [];
|
||||
/// <summary>
|
||||
|
||||
@ -45,9 +45,47 @@ namespace PLCSharp.VVMs.GlobalVariables
|
||||
item._DatasContext = _DatasContext;
|
||||
}
|
||||
}
|
||||
internal void LoadRecipe(Guid CurrentRecipeID)
|
||||
{
|
||||
Variables.Clear();
|
||||
var variables = _DatasContext.Variables.Where(c => c.RecipeID == CurrentRecipeID);
|
||||
foreach (var item in variables)
|
||||
{
|
||||
if (item.RetainPersistent)
|
||||
{
|
||||
|
||||
item.Value = Variable.DynamicValue(item.ValueStr, item.Type);
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
item.Value = Variable.DynamicValue(item.DefaultValueStr, item.Type);
|
||||
item.DefaultValue = item.Value;
|
||||
|
||||
}
|
||||
Variables.Add(item);
|
||||
}
|
||||
|
||||
//加载当前配方的系统变量列表
|
||||
SystemVariables.Clear();
|
||||
var systemVariables = _DatasContext.SystemVariables.Where(c => c.RecipeID == CurrentRecipeID);
|
||||
foreach (var item in systemVariables)
|
||||
{
|
||||
if (item.RetainPersistent)
|
||||
{
|
||||
|
||||
item.Value = Variable.DynamicValue(item.ValueStr, item.Type);
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
item.Value = Variable.DynamicValue(item.DefaultValueStr, item.Type);
|
||||
item.DefaultValue = item.Value;
|
||||
|
||||
}
|
||||
SystemVariables.Add(item);
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 局部变量集合
|
||||
/// </summary>
|
||||
|
||||
@ -101,7 +101,7 @@ namespace PLCSharp.VVMs.MotionController
|
||||
|
||||
|
||||
}
|
||||
e.Cancel = true; // 标记任务已被取消
|
||||
|
||||
|
||||
}
|
||||
#endregion
|
||||
@ -186,6 +186,15 @@ namespace PLCSharp.VVMs.MotionController
|
||||
|
||||
}
|
||||
|
||||
private double _Rate = 100;
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public double Rate
|
||||
{
|
||||
get { return _Rate; }
|
||||
set { SetProperty(ref _Rate, value); }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// DI
|
||||
@ -1651,6 +1660,61 @@ namespace PLCSharp.VVMs.MotionController
|
||||
|
||||
}
|
||||
|
||||
internal void LoadRecipe(Guid CurrentRecipeID)
|
||||
{
|
||||
|
||||
|
||||
Stop();
|
||||
AxisPoints.Clear();
|
||||
var currRecipeAxisPoints = _DatasContext.AxisPoints.Where(c => c.RecipeID == CurrentRecipeID);
|
||||
foreach (var item in currRecipeAxisPoints)
|
||||
{
|
||||
var axisPoint = item.DeepCopy();
|
||||
AxisPoints.Add(axisPoint);
|
||||
var axisX = Axes.Where(a => a.Name == axisPoint.AxisXName).FirstOrDefault();
|
||||
if (axisX != null)
|
||||
axisPoint.AxisX = axisX;
|
||||
var axisY = Axes.Where(a => a.Name == axisPoint.AxisYName).FirstOrDefault();
|
||||
if (axisY != null)
|
||||
axisPoint.AxisY = axisY;
|
||||
var axisZ = Axes.Where(a => a.Name == axisPoint.AxisZName).FirstOrDefault();
|
||||
if (axisZ != null)
|
||||
axisPoint.AxisZ = axisZ;
|
||||
var axisU = Axes.Where(a => a.Name == axisPoint.AxisUName).FirstOrDefault();
|
||||
if (axisU != null)
|
||||
axisPoint.AxisU = axisU;
|
||||
}
|
||||
//加载当前配方的矩阵列表
|
||||
Matrices.Clear();
|
||||
var currRecipeMatrices = _DatasContext.Matrices.Where(c => c.RecipeID == CurrentRecipeID);
|
||||
foreach (var item in currRecipeMatrices)
|
||||
{
|
||||
var matrix = item.DeepCopy();
|
||||
Matrices.Add(matrix);
|
||||
|
||||
Create(matrix);
|
||||
|
||||
|
||||
}
|
||||
|
||||
//加载当前配方的插补列表
|
||||
InterpolationGroups.Clear();
|
||||
var currRecipeInterpolationGroups = _DatasContext.InterpolationGroups.Where(c => c.RecipeID == CurrentRecipeID);
|
||||
foreach (var item in currRecipeInterpolationGroups)
|
||||
{
|
||||
var itemcopy = item.DeepCopy();
|
||||
InterpolationGroups.Add(itemcopy);
|
||||
var axisX = Axes.Where(a => a.Name == itemcopy.AxisXName).FirstOrDefault();
|
||||
if (axisX != null)
|
||||
itemcopy.AxisX = axisX;
|
||||
var axisY = Axes.Where(a => a.Name == itemcopy.AxisYName).FirstOrDefault();
|
||||
if (axisY != null)
|
||||
itemcopy.AxisY = axisY;
|
||||
}
|
||||
Start();
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
@ -119,7 +119,7 @@ public class EpsonRobot : Robot
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
System.Diagnostics.Debug.WriteLine($"Epson状态轮询异常: {ex.Message}");
|
||||
Model.SendErr($"Epson状态轮询异常: {ex.Message}");
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -185,7 +185,7 @@ public class EpsonRobot : Robot
|
||||
|
||||
catch (Exception ex)
|
||||
{
|
||||
System.Diagnostics.Debug.WriteLine($"Epson状态解析异常: {ex.Message}");
|
||||
Model.SendErr($"Epson状态解析异常: {ex.Message}");
|
||||
Thread.Sleep(1000);
|
||||
break;
|
||||
}
|
||||
@ -193,7 +193,7 @@ public class EpsonRobot : Robot
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
System.Diagnostics.Debug.WriteLine($"Epson状态轮询外异常: {ex.Message}");
|
||||
Model.SendErr($"Epson状态轮询外异常: {ex.Message}");
|
||||
Thread.Sleep(1000);
|
||||
}
|
||||
}
|
||||
@ -319,7 +319,7 @@ public class EpsonRobot : Robot
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 点动
|
||||
/// 点动
|
||||
/// </summary>
|
||||
/// <param name="pointBase"></param>
|
||||
/// <param name="cmd"></param>
|
||||
@ -329,7 +329,7 @@ public class EpsonRobot : Robot
|
||||
public override void Jog(string pointName, string cmd, double dist, double rate = 0)
|
||||
{
|
||||
PointDone = false;
|
||||
|
||||
|
||||
var point = Points.FirstOrDefault(p => p.Name == pointName) ?? throw new Exception($"机器人点位{pointName}不存在");
|
||||
|
||||
PointCommand = CurrPoint.DeepCopy();
|
||||
@ -413,6 +413,17 @@ public class EpsonRobot : Robot
|
||||
|
||||
}
|
||||
|
||||
|
||||
public override void RunMatrixPoint(RobotMatrix matrix, int xTarget, int yTarget)
|
||||
{
|
||||
|
||||
var point = matrix.GetPoint(xTarget, yTarget) ?? throw new Exception($"机器人矩阵点位{xTarget} , {yTarget}不存在");
|
||||
point.Command = "RunPoint";
|
||||
PointCommand = point.DeepCopy();
|
||||
SendCommand(PointCommand);
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Power
|
||||
/// </summary>
|
||||
|
||||
@ -14,6 +14,11 @@ namespace PLCSharp.VVMs.Robots
|
||||
/// </summary>
|
||||
public class Robot : BindableBase
|
||||
{
|
||||
[NotMapped]
|
||||
|
||||
public RobotModel Model { get; set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 唯一标识
|
||||
/// </summary>
|
||||
@ -414,10 +419,9 @@ namespace PLCSharp.VVMs.Robots
|
||||
/// 运行点位
|
||||
/// </summary>
|
||||
/// <param name="robotPoint">机器人点位</param>
|
||||
/// <returns>返回布尔值</returns>
|
||||
public virtual void RunPoint(string pointName)
|
||||
{
|
||||
|
||||
|
||||
|
||||
}
|
||||
/// <summary>
|
||||
@ -428,16 +432,16 @@ namespace PLCSharp.VVMs.Robots
|
||||
/// <param name="dist">dist</param>
|
||||
/// <param name="rate">rate</param>
|
||||
/// <returns>返回布尔值</returns>
|
||||
public virtual void Jog(string pointName, string cmd, double dist, double rate = 0)
|
||||
public virtual void Jog(string pointName, string cmd, double dist, double rate = 0)
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 点位运行完成
|
||||
/// </summary>
|
||||
[NotMapped]
|
||||
|
||||
|
||||
public bool PointDone { get; set; }
|
||||
|
||||
private DelegateCommand _HomeCmd;
|
||||
@ -486,5 +490,103 @@ namespace PLCSharp.VVMs.Robots
|
||||
}
|
||||
|
||||
|
||||
#region RobotMatrix
|
||||
|
||||
private ObservableCollection<RobotMatrix> _RobotMatrices = [];
|
||||
/// <summary>
|
||||
/// 机器人矩阵列表
|
||||
/// </summary>
|
||||
[NotMapped]
|
||||
public ObservableCollection<RobotMatrix> RobotMatrices
|
||||
{
|
||||
get { return _RobotMatrices; }
|
||||
set { SetProperty(ref _RobotMatrices, value); }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 根据矩阵配置生成点位网格(平行四边形插值)
|
||||
/// </summary>
|
||||
/// <param name="matrix">矩阵配置</param>
|
||||
internal void Create(RobotMatrix matrix)
|
||||
{
|
||||
matrix.Points.Clear();
|
||||
|
||||
|
||||
|
||||
int xCount = matrix.XCount > 0 ? matrix.XCount : 1;
|
||||
int yCount = matrix.YCount > 0 ? matrix.YCount : 1;
|
||||
int total = xCount * yCount;
|
||||
|
||||
// 从机器人的点位列表中查找三个角点
|
||||
var startPoint = Points.FirstOrDefault(p => p.Name == matrix.StartName);
|
||||
var xEndPoint = Points.FirstOrDefault(p => p.Name == matrix.XEndName);
|
||||
var yEndPoint = Points.FirstOrDefault(p => p.Name == matrix.YEndName);
|
||||
|
||||
if (startPoint == null || xEndPoint == null || yEndPoint == null)
|
||||
{
|
||||
Model.SendInfoDialog("基准点位名称错误,创建失败!");
|
||||
return;
|
||||
}
|
||||
|
||||
// 计算 X/Y/Z 方向基向量(平行四边形插值)
|
||||
double xBasisX = xCount > 1 ? (xEndPoint.X - startPoint.X) / (xCount - 1) : 0;
|
||||
double xBasisY = xCount > 1 ? (xEndPoint.Y - startPoint.Y) / (xCount - 1) : 0;
|
||||
double xBasisZ = xCount > 1 ? (xEndPoint.Z - startPoint.Z) / (xCount - 1) : 0;
|
||||
double yBasisX = yCount > 1 ? (yEndPoint.X - startPoint.X) / (yCount - 1) : 0;
|
||||
double yBasisY = yCount > 1 ? (yEndPoint.Y - startPoint.Y) / (yCount - 1) : 0;
|
||||
double yBasisZ = yCount > 1 ? (yEndPoint.Z - startPoint.Z) / (yCount - 1) : 0;
|
||||
|
||||
double originX = startPoint.X;
|
||||
double originY = startPoint.Y;
|
||||
double originZ = startPoint.Z;
|
||||
|
||||
// 按 MatrixType 确定遍历顺序
|
||||
for (int i = 0; i < total; i++)
|
||||
{
|
||||
int x, y;
|
||||
if (matrix.MatrixType == 0)
|
||||
{
|
||||
x = i % xCount;
|
||||
y = i / xCount;
|
||||
}
|
||||
else
|
||||
{
|
||||
y = i % yCount;
|
||||
x = i / yCount;
|
||||
}
|
||||
|
||||
// 平行四边形插值坐标(X/Y/Z 线性插值,U/V/W 取自起始点)
|
||||
double px = originX + x * xBasisX + y * yBasisX;
|
||||
double py = originY + x * xBasisY + y * yBasisY;
|
||||
double pz = originZ + x * xBasisZ + y * yBasisZ;
|
||||
|
||||
var point = new RobotPoint
|
||||
{
|
||||
RobotID = matrix.RobotID,
|
||||
XIndex = x,
|
||||
YIndex = y,
|
||||
X = px,
|
||||
Y = py,
|
||||
Z = pz,
|
||||
U = startPoint.U,
|
||||
V = startPoint.V,
|
||||
W = startPoint.W,
|
||||
Rate = startPoint.Rate,
|
||||
Hand = startPoint.Hand,
|
||||
ToolNum = startPoint.ToolNum,
|
||||
};
|
||||
|
||||
matrix.Points.Add(point);
|
||||
}
|
||||
}
|
||||
|
||||
public virtual void RunMatrixPoint(RobotMatrix matrix, int xTarget, int yTarget)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
132
PLCSharpWpf/VVMs/Robots/RobotMatrix.cs
Normal file
132
PLCSharpWpf/VVMs/Robots/RobotMatrix.cs
Normal file
@ -0,0 +1,132 @@
|
||||
using Prism.Mvvm;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
|
||||
namespace PLCSharp.VVMs.Robots
|
||||
{
|
||||
/// <summary>
|
||||
/// 机器人矩阵(平行四边形插值生成点位网格)
|
||||
/// </summary>
|
||||
public class RobotMatrix : BindableBase
|
||||
{
|
||||
/// <summary>
|
||||
/// 唯一标识
|
||||
/// </summary>
|
||||
[Key]
|
||||
public Guid ID { get; set; } = Guid.NewGuid();
|
||||
/// <summary>
|
||||
/// 配方标识
|
||||
/// </summary>
|
||||
public Guid RecipeID { get; set; }
|
||||
/// <summary>
|
||||
/// 所属机器人ID
|
||||
/// </summary>
|
||||
public Guid RobotID { get; set; }
|
||||
|
||||
private string _Name;
|
||||
/// <summary>
|
||||
/// 名称
|
||||
/// </summary>
|
||||
public string Name
|
||||
{
|
||||
get { return _Name; }
|
||||
set { SetProperty(ref _Name, value); }
|
||||
}
|
||||
|
||||
private string _StartName;
|
||||
/// <summary>
|
||||
/// 首点名(原点 (0,0))
|
||||
/// </summary>
|
||||
public string StartName
|
||||
{
|
||||
get { return _StartName; }
|
||||
set { SetProperty(ref _StartName, value); }
|
||||
}
|
||||
|
||||
private string _XEndName;
|
||||
/// <summary>
|
||||
/// X方向尾点名((XCount-1, 0))
|
||||
/// </summary>
|
||||
public string XEndName
|
||||
{
|
||||
get { return _XEndName; }
|
||||
set { SetProperty(ref _XEndName, value); }
|
||||
}
|
||||
|
||||
private string _YEndName;
|
||||
/// <summary>
|
||||
/// Y方向尾点名((0, YCount-1))
|
||||
/// </summary>
|
||||
public string YEndName
|
||||
{
|
||||
get { return _YEndName; }
|
||||
set { SetProperty(ref _YEndName, value); }
|
||||
}
|
||||
|
||||
private int _XCount;
|
||||
/// <summary>
|
||||
/// X方向点数
|
||||
/// </summary>
|
||||
public int XCount
|
||||
{
|
||||
get { return _XCount; }
|
||||
set { SetProperty(ref _XCount, value); }
|
||||
}
|
||||
|
||||
private int _YCount;
|
||||
/// <summary>
|
||||
/// Y方向点数
|
||||
/// </summary>
|
||||
public int YCount
|
||||
{
|
||||
get { return _YCount; }
|
||||
set { SetProperty(ref _YCount, value); }
|
||||
}
|
||||
|
||||
private int _MatrixType;
|
||||
/// <summary>
|
||||
/// 矩阵元素顺序 0先X后Y, 1先Y后X
|
||||
/// </summary>
|
||||
public int MatrixType
|
||||
{
|
||||
get { return _MatrixType; }
|
||||
set { SetProperty(ref _MatrixType, value); }
|
||||
}
|
||||
|
||||
private int _XTarget;
|
||||
/// <summary>
|
||||
/// 手动运行时输入的X目标
|
||||
/// </summary>
|
||||
[NotMapped]
|
||||
public int XTarget
|
||||
{
|
||||
get { return _XTarget; }
|
||||
set { SetProperty(ref _XTarget, value); }
|
||||
}
|
||||
|
||||
private int _YTarget;
|
||||
/// <summary>
|
||||
/// 手动运行时输入的Y目标
|
||||
/// </summary>
|
||||
[NotMapped]
|
||||
public int YTarget
|
||||
{
|
||||
get { return _YTarget; }
|
||||
set { SetProperty(ref _YTarget, value); }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 生成的点位列表
|
||||
/// </summary>
|
||||
[NotMapped]
|
||||
public List<RobotPoint> Points { get; set; } = [];
|
||||
|
||||
/// <summary>
|
||||
/// 按索引查找点位
|
||||
/// </summary>
|
||||
public RobotPoint? GetPoint(int x, int y)
|
||||
{
|
||||
return Points.FirstOrDefault(p => p.XIndex == x && p.YIndex == y);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,4 +1,4 @@
|
||||
using PLCSharp.Core.Prism;
|
||||
using PLCSharp.Core.Prism;
|
||||
using PLCSharp.Core.Tools;
|
||||
using PLCSharp.Models;
|
||||
using PLCSharp.VVMs.Robots.Epson;
|
||||
@ -66,13 +66,14 @@ namespace PLCSharp.VVMs.Robots
|
||||
GlobalModel = globalModel;
|
||||
foreach (var item in _DatasContext.Robots)
|
||||
{
|
||||
|
||||
|
||||
switch (item.Type)
|
||||
{
|
||||
case RobotType.Undefined:
|
||||
break;
|
||||
case RobotType.Epson:
|
||||
var epsonRobot = EpsonRobot.Create(item);
|
||||
epsonRobot.Model = this;
|
||||
Robots.Add(epsonRobot);
|
||||
break;
|
||||
default:
|
||||
@ -82,15 +83,48 @@ namespace PLCSharp.VVMs.Robots
|
||||
|
||||
|
||||
}
|
||||
foreach (var item in _DatasContext.RobotPoints)
|
||||
{
|
||||
var point = item.DeepCopy();
|
||||
var robot = Robots.FirstOrDefault(r => r.ID == point.RobotID);
|
||||
robot?.Points.Add(point);
|
||||
}
|
||||
|
||||
}
|
||||
#endregion
|
||||
|
||||
public void LoadRecipe(Guid CurrentRecipeID)
|
||||
{
|
||||
|
||||
|
||||
foreach (var robot in Robots)
|
||||
{
|
||||
robot.Points.Clear();
|
||||
|
||||
foreach (var item in _DatasContext.RobotPoints)
|
||||
{
|
||||
if (item.RobotID == robot.ID && item.RecipeID == CurrentRecipeID)
|
||||
{
|
||||
|
||||
var point = item.DeepCopy();
|
||||
|
||||
robot.Points.Add(point);
|
||||
}
|
||||
}
|
||||
|
||||
robot.RobotMatrices.Clear();
|
||||
foreach (var item in _DatasContext.RobotMatrices)
|
||||
{
|
||||
|
||||
|
||||
if (item.RobotID == robot.ID && item.RecipeID == CurrentRecipeID)
|
||||
{
|
||||
|
||||
var matrix = item.DeepCopy();
|
||||
robot.Create(matrix);
|
||||
robot.RobotMatrices.Add(matrix);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -219,6 +219,17 @@ namespace PLCSharp.VVMs.Robots
|
||||
[NotMapped]
|
||||
public string Command { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 在矩阵中的X索引
|
||||
/// </summary>
|
||||
[NotMapped]
|
||||
public int XIndex { get; internal set; }
|
||||
/// <summary>
|
||||
/// 在矩阵中的Y索引
|
||||
/// </summary>
|
||||
[NotMapped]
|
||||
public int YIndex { get; internal set; }
|
||||
|
||||
/// <summary>
|
||||
/// 点位Params
|
||||
/// </summary>
|
||||
|
||||
@ -30,6 +30,7 @@
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="160" />
|
||||
<RowDefinition Height="2*" />
|
||||
<RowDefinition Height="*" />
|
||||
<RowDefinition Height="200" />
|
||||
</Grid.RowDefinitions>
|
||||
@ -167,8 +168,11 @@
|
||||
|
||||
|
||||
<!-- 状态显示 -->
|
||||
<GroupBox Grid.Row="1" Header="点位配置">
|
||||
<Grid Grid.ColumnSpan="4" Tag="表">
|
||||
<GroupBox Grid.Row="1" Header="点位表">
|
||||
|
||||
|
||||
|
||||
<Grid Margin="3">
|
||||
<DataGrid Width="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Grid}, AncestorLevel=1}, Path=ActualWidth}"
|
||||
Height="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Grid}, AncestorLevel=1}, Path=ActualHeight}"
|
||||
HorizontalAlignment="Center" VerticalAlignment="Center"
|
||||
@ -200,8 +204,46 @@
|
||||
</DataGrid.Columns>
|
||||
</DataGrid>
|
||||
</Grid>
|
||||
|
||||
|
||||
</GroupBox>
|
||||
<GroupBox Grid.Row="2" Header="点位配置">
|
||||
<GroupBox Grid.Row="2" Header="矩阵表">
|
||||
<Grid Margin="3">
|
||||
|
||||
<DataGrid Width="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Grid}, AncestorLevel=1}, Path=ActualWidth}"
|
||||
Height="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Grid}, AncestorLevel=1}, Path=ActualHeight}"
|
||||
HorizontalAlignment="Center" VerticalAlignment="Center"
|
||||
AutoGenerateColumns="False" CanUserAddRows="False"
|
||||
CanUserDeleteRows="False" CanUserSortColumns="False"
|
||||
ItemsSource="{Binding SelectedRobot.RobotMatrices}"
|
||||
ScrollViewer.VerticalScrollBarVisibility="Auto"
|
||||
SelectedItem="{Binding SelectedRobotMatrix}"
|
||||
Unloaded="DataGrid_Unloaded">
|
||||
<DataGrid.ContextMenu>
|
||||
<ContextMenu IsEnabled="True" StaysOpen="False">
|
||||
<MenuItem Command="{Binding RobotMatrixManage}" CommandParameter="New" Header="新增" />
|
||||
<MenuItem Command="{Binding RobotMatrixManage}" CommandParameter="Create" Header="计算矩阵" />
|
||||
<MenuItem Command="{Binding RobotMatrixManage}" CommandParameter="Save" Header="保存" />
|
||||
<MenuItem Command="{Binding RobotMatrixManage}" CommandParameter="Remove" Header="删除" />
|
||||
<MenuItem Command="{Binding RobotMatrixManage}" CommandParameter="RunPoint" Header="运行到" />
|
||||
|
||||
</ContextMenu>
|
||||
</DataGrid.ContextMenu>
|
||||
<DataGrid.Columns>
|
||||
<DataGridTextColumn MinWidth="80" Binding="{Binding Name, UpdateSourceTrigger=LostFocus}" Header="名称" />
|
||||
<DataGridTextColumn MinWidth="80" Binding="{Binding StartName, UpdateSourceTrigger=LostFocus}" Header="首点" />
|
||||
<DataGridTextColumn MinWidth="80" Binding="{Binding XEndName, UpdateSourceTrigger=LostFocus}" Header="X尾点" />
|
||||
<DataGridTextColumn MinWidth="80" Binding="{Binding YEndName, UpdateSourceTrigger=LostFocus}" Header="Y尾点" />
|
||||
<DataGridTextColumn MinWidth="50" Binding="{Binding XCount, UpdateSourceTrigger=LostFocus}" Header="X点数" />
|
||||
<DataGridTextColumn MinWidth="50" Binding="{Binding YCount, UpdateSourceTrigger=LostFocus}" Header="Y点数" />
|
||||
<DataGridTextColumn MinWidth="50" Binding="{Binding XTarget, UpdateSourceTrigger=LostFocus}" Header="目标X" />
|
||||
<DataGridTextColumn MinWidth="50" Binding="{Binding YTarget, UpdateSourceTrigger=LostFocus}" Header="目标Y" />
|
||||
</DataGrid.Columns>
|
||||
</DataGrid>
|
||||
</Grid>
|
||||
|
||||
</GroupBox>
|
||||
<GroupBox Grid.Row="3" Header="点位配置">
|
||||
<ContentControl Content="{Binding RobotPointsConfig}" />
|
||||
</GroupBox>
|
||||
|
||||
|
||||
@ -170,6 +170,133 @@ namespace PLCSharp.VVMs.Robots
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region RobotMatrix CRUD
|
||||
|
||||
private RobotMatrix _SelectedRobotMatrix;
|
||||
/// <summary>
|
||||
/// Selected机器人矩阵
|
||||
/// </summary>
|
||||
public RobotMatrix SelectedRobotMatrix
|
||||
{
|
||||
get { return _SelectedRobotMatrix; }
|
||||
set { SetProperty(ref _SelectedRobotMatrix, value); }
|
||||
}
|
||||
|
||||
private DelegateCommand<object> _RobotMatrixManage;
|
||||
/// <summary>
|
||||
/// 机器人矩阵管理
|
||||
/// </summary>
|
||||
public DelegateCommand<object> RobotMatrixManage =>
|
||||
_RobotMatrixManage ??= new DelegateCommand<object>(ExecuteRobotMatrixManage);
|
||||
|
||||
void ExecuteRobotMatrixManage(object param)
|
||||
{
|
||||
|
||||
if (SelectedRobot == null)
|
||||
{
|
||||
SendInfoDialog("请先选择机器人");
|
||||
return;
|
||||
}
|
||||
var cmd = param as string;
|
||||
|
||||
|
||||
switch (cmd)
|
||||
{
|
||||
case "New":
|
||||
|
||||
var newMatrix = new RobotMatrix
|
||||
{
|
||||
RobotID = SelectedRobot.ID,
|
||||
RecipeID = RobotModel.GlobalModel.CurrentRecipe.ID ,
|
||||
Name = "新矩阵",
|
||||
XCount = 2,
|
||||
YCount = 2,
|
||||
};
|
||||
SelectedRobot.RobotMatrices.Add(newMatrix);
|
||||
SelectedRobotMatrix = newMatrix;
|
||||
break;
|
||||
|
||||
case "Create":
|
||||
|
||||
if (SelectedRobotMatrix == null)
|
||||
{
|
||||
SendInfoDialog("请先选择矩阵");
|
||||
return;
|
||||
}
|
||||
SelectedRobot.Create(SelectedRobotMatrix);
|
||||
SendInfoDialog("矩阵计算完成");
|
||||
break;
|
||||
|
||||
case "Save":
|
||||
|
||||
var names = new List<string>();
|
||||
foreach (var item in SelectedRobot.RobotMatrices)
|
||||
{
|
||||
if (string.IsNullOrEmpty(item.Name))
|
||||
{
|
||||
SendInfoDialog($"保存失败,矩阵名称不能为空");
|
||||
return;
|
||||
}
|
||||
if (names.Contains(item.Name))
|
||||
{
|
||||
SendInfoDialog($"保存失败,重复名称:{item.Name}");
|
||||
return;
|
||||
}
|
||||
names.Add(item.Name);
|
||||
|
||||
if (!RobotModel._DatasContext.RobotMatrices.Any(h => h.ID == item.ID))
|
||||
{
|
||||
RobotModel._DatasContext.RobotMatrices.Add(item);
|
||||
}
|
||||
else
|
||||
{
|
||||
var exist = RobotModel._DatasContext.RobotMatrices.FirstOrDefault(m => m.ID == item.ID);
|
||||
if (exist != null)
|
||||
{
|
||||
exist.Name = item.Name;
|
||||
exist.StartName = item.StartName;
|
||||
exist.XEndName = item.XEndName;
|
||||
exist.YEndName = item.YEndName;
|
||||
exist.XCount = item.XCount;
|
||||
exist.YCount = item.YCount;
|
||||
exist.MatrixType = item.MatrixType;
|
||||
}
|
||||
}
|
||||
}
|
||||
RobotModel._DatasContext.Save();
|
||||
SendInfoDialog("矩阵保存成功");
|
||||
break;
|
||||
|
||||
case "Remove":
|
||||
|
||||
if (SelectedRobotMatrix != null)
|
||||
{
|
||||
if (RobotModel._DatasContext.RobotMatrices.Any(h => h.ID == SelectedRobotMatrix.ID))
|
||||
{
|
||||
var remove = RobotModel._DatasContext.RobotMatrices.FirstOrDefault(m => m.ID == SelectedRobotMatrix.ID);
|
||||
if (remove != null)
|
||||
RobotModel._DatasContext.RobotMatrices.Remove(remove);
|
||||
}
|
||||
SelectedRobot.RobotMatrices.Remove(SelectedRobotMatrix);
|
||||
RobotModel._DatasContext.Save();
|
||||
SelectedRobotMatrix = null;
|
||||
}
|
||||
break;
|
||||
|
||||
case "RunPoint":
|
||||
|
||||
if (SelectedRobotMatrix != null) {
|
||||
|
||||
SelectedRobot.RunMatrixPoint(SelectedRobotMatrix,SelectedRobotMatrix.XTarget, SelectedRobotMatrix.YTarget);
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Robot CRUD
|
||||
|
||||
|
||||
|
||||
@ -60,6 +60,8 @@ namespace PLCSharp.VVMs.Vision
|
||||
/// </summary>
|
||||
public GlobalModel GlobalModel { get; set; }
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 初始化
|
||||
/// </summary>
|
||||
@ -70,6 +72,35 @@ namespace PLCSharp.VVMs.Vision
|
||||
Connects = GlobalModel.Connects;
|
||||
}
|
||||
|
||||
public void LoadRecipe(Guid CurrentRecipeID)
|
||||
{
|
||||
|
||||
//加载当前配方的图像数据列表
|
||||
ImageDatas.Clear();
|
||||
var currRecipeImageDatas = _DatasContext.ImageDatas.Where(c => c.RecipeID == CurrentRecipeID);
|
||||
foreach (var item in currRecipeImageDatas)
|
||||
{
|
||||
var itemcopy = item.DeepCopy();
|
||||
itemcopy.Prompt = "";
|
||||
ImageDatas.Add(itemcopy);
|
||||
}
|
||||
|
||||
|
||||
VisionFunctions.Clear();
|
||||
var currRecipeVisionFunctions = _DatasContext.VisionFunctions.Where(c => c.RecipeID == CurrentRecipeID);
|
||||
foreach (var item in currRecipeVisionFunctions)
|
||||
{
|
||||
var itemcopy = item.DeepCopy();
|
||||
itemcopy.Prompt = "";
|
||||
itemcopy.VisionsModel = this;
|
||||
itemcopy.ImageDatas = ImageDatas;
|
||||
itemcopy.GlobalModel = GlobalModel;
|
||||
VisionFunctions.Add(itemcopy);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// SearchCameras
|
||||
/// </summary>
|
||||
@ -417,7 +448,7 @@ namespace PLCSharp.VVMs.Vision
|
||||
{
|
||||
if (string.IsNullOrEmpty(item.Name))
|
||||
{
|
||||
SendInfoDialog($"保存失败,名称{item.Name}不合适!" );
|
||||
SendInfoDialog($"保存失败,名称{item.Name}不合适!");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@ -284,6 +284,10 @@ namespace PLCSharp.VVMs.Workflows
|
||||
if (_BackgroundWorker != null && _BackgroundWorker.IsBusy)
|
||||
{
|
||||
_BackgroundWorker.CancelAsync();
|
||||
}
|
||||
while (_BackgroundWorker.IsBusy)
|
||||
{
|
||||
|
||||
}
|
||||
IsRuning = false;
|
||||
}
|
||||
@ -308,6 +312,7 @@ namespace PLCSharp.VVMs.Workflows
|
||||
sw.Stop();
|
||||
CycleTime = sw.Elapsed.TotalSeconds;
|
||||
}
|
||||
|
||||
}
|
||||
GlobalModel GlobalModel;
|
||||
private FlowModel _Flow = new();
|
||||
|
||||
Loading…
Reference in New Issue
Block a user