motorTest/Model/MotionControl/MotionPointModel.cs
2026-10-17 11:39:30 +08:00

660 lines
19 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using Community;
using System;
using System.Collections.ObjectModel;
using System.Linq;
using System.Reflection;
namespace Model.MotionControl
{
/// <summary>
/// 运行点位
/// </summary>
public class MotionPointModel : NotificationObject
{
public int ID { get; set; }
private int pointNumber;
/// <summary>
/// 序号
/// </summary>
public int PointNumber
{
get { return pointNumber; }
set
{
pointNumber = value;
this.RaisePropertyChanged("Number");
}
}
/// <summary>
/// 机种ID
/// </summary>
public int MachineID { get; set; }
private string pointName;
/// <summary>
/// 点名称
/// </summary>
public string PointName
{
get { return pointName; }
set
{
pointName = value;
this.RaisePropertyChanged("PointName");
}
}
private int pointClass;
/// <summary>
/// 点位分类 1:点位分类1 2:点位分类2
/// </summary>
public int PointClass
{
get { return pointClass; }
set
{
pointClass = value;
this.RaisePropertyChanged("PointClass");
}
}
private int pointType;
/// <summary>
/// 点位类型 1:取料点 2:作用点 3:视觉点 4:待机点
/// </summary>
public int PointType
{
get { return pointType; }
set
{
pointType = value;
this.RaisePropertyChanged("PointType");
}
}
private double shaftPoint_X;
/// <summary>
/// X轴坐标点
/// </summary>
public double ShaftPoint_X
{
get { return shaftPoint_X; }
set
{
shaftPoint_X = value;
this.RaisePropertyChanged("ShaftPoint_X");
}
}
private double shaftPoint_Y;
/// <summary>
/// Y轴坐标点
/// </summary>
public double ShaftPoint_Y
{
get { return shaftPoint_Y; }
set
{
shaftPoint_Y = value;
this.RaisePropertyChanged("ShaftPoint_Y");
}
}
private double shaftPoint_Z;
/// <summary>
/// Z轴坐标点
/// </summary>
public double ShaftPoint_Z
{
get { return shaftPoint_Z; }
set
{
shaftPoint_Z = value;
this.RaisePropertyChanged("ShaftPoint_Z");
}
}
private double shaftPoint_U;
/// <summary>
/// U轴坐标点(旋转)
/// </summary>
public double ShaftPoint_U
{
get { return shaftPoint_U; }
set
{
shaftPoint_U = value;
this.RaisePropertyChanged("ShaftPoint_U");
}
}
private double speed_X;
/// <summary>
/// X轴移动速度
/// </summary>
public double Speed_X
{
get { return speed_X; }
set
{
speed_X = value;
this.RaisePropertyChanged("Speed_X");
}
}
private double speed_Y;
/// <summary>
/// Y轴移动速度
/// </summary>
public double Speed_Y
{
get { return speed_Y; }
set
{
speed_Y = value;
this.RaisePropertyChanged("Speed_Y");
}
}
private double speed_Z;
/// <summary>
/// Z轴移动速度
/// </summary>
public double Speed_Z
{
get { return speed_Z; }
set
{
speed_Z = value;
this.RaisePropertyChanged("Speed_Z");
}
}
private double speed_U;
/// <summary>
/// U轴移动速度
/// </summary>
public double Speed_U
{
get { return speed_U; }
set
{
speed_U = value;
this.RaisePropertyChanged("Speed_U");
}
}
private double speed_Gear;
/// <summary>
/// 速度档位(自动挡)
/// </summary>
public double Speed_Gear
{
get { return speed_Gear; }
set
{
speed_Gear = value;
this.RaisePropertyChanged("Speed_Gear");
}
}
private int shaftID_X;
/// <summary>
/// X轴ID
/// </summary>
public int ShaftID_X
{
get { return shaftID_X; }
set
{
shaftID_X = value;
this.RaisePropertyChanged("ShaftID_X");
}
}
private int shaftID_Y;
/// <summary>
/// Y轴ID
/// </summary>
public int ShaftID_Y
{
get { return shaftID_Y; }
set
{
shaftID_Y = value;
this.RaisePropertyChanged("ShaftID_Y");
}
}
private int shaftID_Z;
/// <summary>
/// Z轴ID
/// </summary>
public int ShaftID_Z
{
get { return shaftID_Z; }
set
{
shaftID_Z = value;
this.RaisePropertyChanged("ShaftID_Z");
}
}
private int shaftID_U;
/// <summary>
/// U轴ID
/// </summary>
public int ShaftID_U
{
get { return shaftID_U; }
set
{
shaftID_U = value;
this.RaisePropertyChanged("ShaftID_U");
}
}
/// <summary>
/// 点位进行中
/// </summary>
public bool DispensingRuning { get; set; }
#region 轴对象
/// <summary>
/// X轴
/// </summary>
public FeiYuShaft Shaft_X { get; set; }
/// <summary>
/// Y轴
/// </summary>
public FeiYuShaft Shaft_Y { get; set; }
/// <summary>
/// Z轴
/// </summary>
public FeiYuShaft Shaft_Z { get; set; }
/// <summary>
/// U轴
/// </summary>
public FeiYuShaft Shaft_U { get; set; }
#endregion
/// <summary>
/// Z轴抬升高度
/// </summary>
double HeightZ { get; set; }
/// <summary>
/// 点位运行步骤
/// </summary>
public GengralProcessEnum PointRunStep { get; set; }
#region 实例化点位参数(包含插补参数)
/// <summary>
/// 是否先移动Y轴
/// </summary>
bool moveY { get; set; }
/// <summary>
/// 此点位的轴是否在同一控制器
/// </summary>
public bool SameController { get; set; }
/// <summary>
/// 实例化点位参数(包含插补参数)
/// </summary>
/// <param name="AllShaftList">所有轴集合</param>
/// <param name="multiple">降速倍数</param>
public void GetInterpolationPer(ObservableCollection<FeiYuShaft> AllShaftList, int multiple = 1)
{
Shaft_X = AllShaftList.Where(s => s.ID == this.ShaftID_X && this.ShaftID_X > 0).FirstOrDefault();
Shaft_Y = AllShaftList.Where(s => s.ID == this.ShaftID_Y && this.ShaftID_Y > 0).FirstOrDefault();
Shaft_Z = AllShaftList.Where(s => s.ID == this.ShaftID_Z && this.ShaftID_Z > 0).FirstOrDefault();
Shaft_U = AllShaftList.Where(s => s.ID == this.ShaftID_U && this.ShaftID_U > 0).FirstOrDefault();
this.Speed_X = Shaft_X != null ? this.Speed_Gear : 0;
this.Speed_Y = Shaft_Y != null ? this.Speed_Gear : 0;
this.Speed_Z = Shaft_Z != null ? this.Speed_Gear : 0;
this.Speed_U = Shaft_U != null ? this.Speed_Gear : 0;
if (PointClass == 1 || PointClass == 2)
{
//if (this.Speed_Y >= 800)
//{
// this.Speed_Y = 800;
//}
//this.Speed_X = this.Speed_X * 0.625;
//this.Speed_Z = this.Speed_Z * 0.625;
}
//轴对应的卡号一致
if (Shaft_X != null && Shaft_Y != null && (Shaft_X.MyCard.ID == Shaft_Y.MyCard.ID))
{
SameController = true;
}
else
{
SameController = false;
}
if (Shaft_X != null)
{
Shaft_X.GengrelMp = Coper(Shaft_X.MyMotionPar);
Shaft_X.GengrelMp.ActualDir = Math.Round(this.ShaftPoint_X, 2);
Shaft_X.GengrelMp.StartSpeed = Math.Round(Shaft_X.GengrelMp.StartSpeed / multiple, 2);
Shaft_X.GengrelMp.RunSpeed = Math.Round(this.Speed_X / multiple, 2);
}
if (Shaft_Y != null)
{
Shaft_Y.GengrelMp = Coper(Shaft_Y.MyMotionPar);
Shaft_Y.GengrelMp.ActualDir = Math.Round(this.ShaftPoint_Y, 2);
Shaft_Y.GengrelMp.StartSpeed = Math.Round(Shaft_Y.GengrelMp.StartSpeed / multiple, 2);
Shaft_Y.GengrelMp.RunSpeed = Math.Round(this.Speed_Y / multiple, 2);
}
if (Shaft_Z != null)
{
Shaft_Z.GengrelMp = Coper(Shaft_Z.MyMotionPar);
Shaft_Z.GengrelMp.ActualDir = Math.Round(this.ShaftPoint_Z, 2);
Shaft_Z.GengrelMp.StartSpeed = Math.Round(Shaft_Z.GengrelMp.StartSpeed / multiple, 2);
Shaft_Z.GengrelMp.RunSpeed = Math.Round(this.Speed_Z / multiple, 2);
}
if (Shaft_U != null)
{
Shaft_U.GengrelMp = Coper(Shaft_U.MyMotionPar);
Shaft_U.GengrelMp.ActualDir = Math.Round(this.ShaftPoint_U, 2);
Shaft_U.GengrelMp.StartSpeed = Math.Round(Shaft_U.GengrelMp.StartSpeed / multiple, 2);
Shaft_U.GengrelMp.RunSpeed = Math.Round(this.Speed_U / multiple, 2);
}
// moveY = (Shaft_Y != null && Shaft_Y.ActualDir - Shaft_Y.GengrelMp.ActualDir < -300) ? true : false;
if (Shaft_Z != null)
{
if ((Shaft_X == null || Math.Abs(Shaft_X.ActualDir - Shaft_X.GengrelMp.ActualDir) < 150)
&& (Shaft_Y == null || Math.Abs(Shaft_Y.ActualDir - Shaft_Y.GengrelMp.ActualDir) < 150)
)
{
if (Shaft_Z.ActualDir < Shaft_Z.GengrelMp.ActualDir)
{
HeightZ = Shaft_Z.ActualDir;
}
else
{
HeightZ = Shaft_Z.GengrelMp.ActualDir;
}
}
else
{
if (Shaft_Z.ActualDir < 0)
{
HeightZ = Shaft_Z.ActualDir;
}
else if (Shaft_Z.GengrelMp.ActualDir < 0)
{
HeightZ = Shaft_Z.GengrelMp.ActualDir;
}
else
{
HeightZ = 0;
}
}
}
}
#endregion
#region 多轴同时运行
/// <summary>
/// 多轴同时运行
/// </summary>
private void MoreShaftRun()
{
//Shaft_X?.DZDC(Shaft_X.GengrelMp);
//Shaft_Y?.DZDC(Shaft_Y.GengrelMp);
//Shaft_U?.DZDC(Shaft_U.GengrelMp);
}
#endregion
#region 多轴同时运行完成
/// <summary>
/// 多轴同时运行是否完成
/// </summary>
private bool MoreShaftRrunOK()
{
bool bl = true;
if (moveY)
{
if (Shaft_Y != null)
{
if (Shaft_Y.ActualDir != Math.Round(Shaft_Y.GengrelMp.ActualDir, 2))
{
Shaft_Y?.DZDC(Shaft_Y.GengrelMp);
bl = false;
}
else
{
if (Shaft_X != null)
{
if (Shaft_X.ActualDir != Math.Round(Shaft_X.GengrelMp.ActualDir, 2))
{
Shaft_X?.DZDC(Shaft_X.GengrelMp);
bl = false;
}
}
}
}
}
else
{
if (Shaft_X != null)
{
if (Shaft_X.ActualDir != Math.Round(Shaft_X.GengrelMp.ActualDir, 2))
{
Shaft_X?.DZDC(Shaft_X.GengrelMp);
bl = false;
}
}
if (Shaft_Y != null)
{
if (Shaft_Y.ActualDir != Math.Round(Shaft_Y.GengrelMp.ActualDir, 2))
{
Shaft_Y?.DZDC(Shaft_Y.GengrelMp);
bl = false;
}
}
}
if (Shaft_U != null)
{
//因为 360°除不尽 存在误差 故用此方式
if (Math.Abs(Shaft_U.ActualDir - Math.Round(Shaft_U.GengrelMp.ActualDir, 2)) >= 0.01)
{
Shaft_U?.DZDC(Shaft_U.GengrelMp);
bl = false;
}
}
return bl;
}
#endregion
#region 运行点位
/// <summary>
/// 运行点位 List<InputSignal> InputList,
/// </summary>
/// <param name="AllShaftList">所有轴集合</param>
/// <param name="multiple">降速倍数</param>
/// <returns></returns>
public bool PointRun(ObservableCollection<FeiYuShaft> AllShaftList, int multiple = 1)
{
bool bl = false;
try
{
switch (PointRunStep)
{
case GengralProcessEnum.Start:
GetInterpolationPer(AllShaftList, multiple);
if (Shaft_Z != null)
{
Shaft_Z.GengrelMp.ActualDir = HeightZ;
Shaft_Z.GengrelMp.RunSpeed = this.Speed_Z;
Shaft_Z.DZDC(Shaft_Z.GengrelMp);
PointRunStep++;
}
else
{
PointRunStep = GengralProcessEnum.Step2;
}
break;
case GengralProcessEnum.Step1:
if (Shaft_Z.ActualDir == HeightZ)// && Shaft_Z.ss.org == 1
{
Shaft_Z.GengrelMp = Coper(Shaft_Z.MyMotionPar);
Shaft_Z.GengrelMp.ActualDir = Math.Round(this.ShaftPoint_Z, 2);
Shaft_Z.GengrelMp.StartSpeed = Math.Round(Shaft_Z.GengrelMp.StartSpeed / multiple, 2);
Shaft_Z.GengrelMp.RunSpeed = Math.Round(this.Speed_Z / multiple, 2);
PointRunStep++;
}
break;
case GengralProcessEnum.Step2:
if (MoreShaftRrunOK())
{
if (Shaft_Z != null)
{
Shaft_Z.DZDC(Shaft_Z.GengrelMp);
PointRunStep++;
}
else
{
PointRunStep = GengralProcessEnum.Start;
bl = true;
}
}
else
{
if (Shaft_Z == null || Shaft_Z.ActualDir == HeightZ) // && Shaft_Z.ss.org == 1
{
MoreShaftRun();
}
else
{
PointRunStep = GengralProcessEnum.Start;
}
}
break;
case GengralProcessEnum.Step3:
if (Shaft_Z == null || (Shaft_Z.ActualDir == Shaft_Z.GengrelMp.ActualDir && Shaft_Z.ShaftState.StatusBackground == ColorStr.Red))
{
PointRunStep = GengralProcessEnum.Start;
bl = true;
}
break;
}
}
catch (Exception)
{
//string str = PointRunStep.ToString();
}
return bl;
}
#endregion
#region 停止点位运行
/// <summary>
/// 停止点位运行
/// </summary>
public void PointStop()
{
Shaft_X?.ShaftStop();
Shaft_Y?.ShaftStop();
Shaft_Z?.ShaftStop();
Shaft_U?.ShaftStop();
PointRunStep = GengralProcessEnum.Start;
}
#endregion
#region 利用反射进行对象复制
/// <summary>
/// 利用反射进行对象复制
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="Coperobj"></param>
/// <returns></returns>
public T Coper<T>(T Coperobj)
{
T a = System.Activator.CreateInstance<T>();
try
{
var Types = Coperobj.GetType();//获得类型
var Typed = a.GetType();
foreach (PropertyInfo sp in Types.GetProperties())//获得类型的属性字段
{
foreach (PropertyInfo dp in Typed.GetProperties())
{
if (dp.Name == sp.Name)//判断属性名是否相同
{
dp.SetValue(a, sp.GetValue(Coperobj, null), null);//获得s对象属性的值复制给d对象的属性
}
}
}
}
catch (Exception ex)
{
throw ex;
}
return a;
}
#endregion
}
}