添加 MX-PD-盘古 项目文件

将 MX-PD-盘古 - new 目录下的所有文件添加到主仓库
This commit is contained in:
Shi.Ji
2026-05-18 11:43:09 +08:00
parent 03632a379d
commit e31d3560bb
739 changed files with 99783 additions and 0 deletions

View File

@@ -0,0 +1,123 @@
using MwFramework.ManagerService;
using Stylet;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace MainShell.Recipe.Models
{
public class AxisFilteringParameter : PropertyChangedBase , IParameterItem
{
private int _axisIndex;
/// <summary>
/// 轴ID
/// </summary>
public int AxisIndex
{
get { return _axisIndex; }
set
{
if (SetAndNotify(ref _axisIndex, value))
{
NotifyOfPropertyChange(() => AxisDisplayName);
}
}
}
public string AxisDisplayName
{
get
{
string axisName = PidAxisCatalog.GetAxisName(AxisIndex);
return string.IsNullOrWhiteSpace(axisName) ? AxisIndex.ToString() : axisName;
}
}
private PIDLabel<bool> _isUseNotch = new PIDLabel<bool>() { Name = "PA_SLNothFilth", Value = false };
/// <summary>
/// 开启陷波滤波
/// </summary>
public PIDLabel<bool> IsUseNotch
{
get { return _isUseNotch; }
set { SetAndNotify(ref _isUseNotch, value); }
}
private PIDLabel<double> _notchFrequency = new PIDLabel<double>() { Name = "PA_SLVNFRQ", Value = 0 };
/// <summary>
/// 陷波滤波频率
/// </summary>
public PIDLabel<double> NotchFrequency
{
get { return _notchFrequency; }
set { SetAndNotify(ref _notchFrequency, value); }
}
private PIDLabel<double> _notchWidth = new PIDLabel<double>() { Name = "PA_SLVNWID", Value = 0 };
/// <summary>
/// 陷波滤波宽度
/// </summary>
public PIDLabel<double> NotchWidth
{
get { return _notchWidth; }
set { SetAndNotify(ref _notchWidth, value); }
}
private PIDLabel<double> _notchFalloff = new PIDLabel<double>() { Name = "PA_SLVNATT", Value = 0 };
/// <summary>
/// 陷波滤波衰减
/// </summary>
public PIDLabel<double> NotchFalloff
{
get { return _notchFalloff; }
set { SetAndNotify(ref _notchFalloff, value); }
}
private PIDLabel<bool> _isUseFiltering = new PIDLabel<bool>() { Name = "PA_SLLowPass", Value = false };
/// <summary>
/// 开启低通滤波
/// </summary>
public PIDLabel<bool> IsUseFiltering
{
get { return _isUseFiltering; }
set { SetAndNotify(ref _isUseFiltering, value); }
}
private PIDLabel<double> _filteringFrequency = new PIDLabel<double>() { Name = "PA_SLVSOF", Value = 0 };
/// <summary>
/// 低通滤波频率
/// </summary>
public PIDLabel<double> FilteringFrequency
{
get { return _filteringFrequency; }
set { SetAndNotify(ref _filteringFrequency, value); }
}
private PIDLabel<double> _filteringDamping = new PIDLabel<double>() { Name = "PA_SLVSOFD", Value = 0 };
/// <summary>
/// 低通滤波阻尼系数
/// </summary>
public PIDLabel<double> FilteringDamping
{
get { return _filteringDamping; }
set { SetAndNotify(ref _filteringDamping, value); }
}
public IParameterItem Clone()
{
return new AxisFilteringParameter
{
AxisIndex = this.AxisIndex,
IsUseNotch = this.IsUseNotch.Clone() as PIDLabel<bool>,
NotchFrequency = this.NotchFrequency.Clone() as PIDLabel<double>,
NotchWidth = this.NotchWidth.Clone() as PIDLabel<double>,
NotchFalloff = this.NotchFalloff.Clone() as PIDLabel<double>,
IsUseFiltering = this.IsUseFiltering.Clone() as PIDLabel<bool>,
FilteringFrequency = this.FilteringFrequency.Clone() as PIDLabel<double>,
FilteringDamping = this.FilteringDamping.Clone() as PIDLabel<double>
};
}
}
}

View File

@@ -0,0 +1,284 @@
using MwFramework.ManagerService;
using Stylet;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace MainShell.Recipe.Models
{
public class PidAxisOption
{
public string AxisName { get; set; }
public int AxisIndex { get; set; }
}
public static class PidAxisCatalog
{
private static readonly Dictionary<int, string> _axisNameByIndex = new Dictionary<int, string>();
private static readonly Dictionary<string, int> _axisIndexByName = new Dictionary<string, int>(StringComparer.OrdinalIgnoreCase);
public static void SetAxisOptions(IEnumerable<PidAxisOption> axisOptions)
{
_axisNameByIndex.Clear();
_axisIndexByName.Clear();
if (axisOptions == null)
{
return;
}
foreach (PidAxisOption axisOption in axisOptions)
{
if (axisOption == null || string.IsNullOrWhiteSpace(axisOption.AxisName))
{
continue;
}
_axisNameByIndex[axisOption.AxisIndex] = axisOption.AxisName;
_axisIndexByName[axisOption.AxisName] = axisOption.AxisIndex;
}
}
public static string GetAxisName(int axisIndex)
{
string axisName;
return _axisNameByIndex.TryGetValue(axisIndex, out axisName) ? axisName : string.Empty;
}
public static bool TryGetAxisIndex(string axisName, out int axisIndex)
{
if (string.IsNullOrWhiteSpace(axisName))
{
axisIndex = -1;
return false;
}
return _axisIndexByName.TryGetValue(axisName, out axisIndex);
}
}
public class AxisPIDParameter : PropertyChangedBase, IParameterItem
{
private bool _isSynchronizingAxis;
private string _moduleName;
public string ModuleName
{
get { return _moduleName; }
set
{
if (SetAndNotify(ref _moduleName, value))
{
SyncAxisIndexFromModuleName();
}
}
}
private int _axisIndex;
public int AxisIndex
{
get { return _axisIndex; }
set
{
if (SetAndNotify(ref _axisIndex, value))
{
SyncModuleNameFromAxisIndex();
}
}
}
private PIDLabel<double> _pA_SLVKP = new PIDLabel<double>() { Name = "PA_SLVKP_", Value = 0 };
/// <summary>
/// 速度环KP
/// </summary>
public PIDLabel<double> PA_SLVKP
{
get { return _pA_SLVKP; }
set { SetAndNotify(ref _pA_SLVKP, value); }
}
private PIDLabel<double> _pA_SLVKI = new PIDLabel<double>() { Name = "PA_SLVKI_", Value = 0 };
/// <summary>
/// 速度环KI
/// </summary>
public PIDLabel<double> PA_SLVKI
{
get { return _pA_SLVKI; }
set { SetAndNotify(ref _pA_SLVKI, value); }
}
private PIDLabel<double> _pA_SLVKPSF = new PIDLabel<double>() { Name = "PA_SLVKPSF_", Value = 0 };
/// <summary>
/// 速度环KP Settle因子
/// </summary>
public PIDLabel<double> PA_SLVKPSF
{
get { return _pA_SLVKPSF; }
set { SetAndNotify(ref _pA_SLVKPSF, value); }
}
private PIDLabel<double> _pA_SLVKPIF = new PIDLabel<double>() { Name = "PA_SLVKPIF_", Value = 0 };
/// <summary>
/// 速度环KP Iddle因子
/// </summary>
public PIDLabel<double> PA_SLVKPIF
{
get { return _pA_SLVKPIF; }
set { SetAndNotify(ref _pA_SLVKPIF, value); }
}
private PIDLabel<double> _pA_SLVKISF = new PIDLabel<double>() { Name = "PA_SLVKISF_", Value = 0 };
/// <summary>
/// 速度环KI Settle因子
/// </summary>
public PIDLabel<double> PA_SLVKISF
{
get { return _pA_SLVKISF; }
set { SetAndNotify(ref _pA_SLVKISF, value); }
}
private PIDLabel<double> _pA_SLVKIIF = new PIDLabel<double>() { Name = "PA_SLVKIIF_", Value = 0 };
/// <summary>
/// 速度环KI Iddle因子
/// </summary>
public PIDLabel<double> PA_SLVKIIF
{
get { return _pA_SLVKIIF; }
set { SetAndNotify(ref _pA_SLVKIIF, value); }
}
private PIDLabel<double> _pA_SLPKP = new PIDLabel<double>() { Name = "PA_SLPKP_", Value = 0 };
/// <summary>
/// 位置环的KP
/// </summary>
public PIDLabel<double> PA_SLPKP
{
get { return _pA_SLPKP; }
set { SetAndNotify(ref _pA_SLPKP, value); }
}
private PIDLabel<double> _pA_SLPKPIF = new PIDLabel<double>() { Name = "PA_SLPKPIF_", Value = 0 };
/// <summary>
/// 位置环的KP的Idel因子
/// </summary>
public PIDLabel<double> PA_SLPKPIF
{
get { return _pA_SLPKPIF; }
set { SetAndNotify(ref _pA_SLPKPIF, value); }
}
private PIDLabel<double> _pA_SLPKPSF = new PIDLabel<double>() { Name = "PA_SLPKPSF_", Value = 0 };
/// <summary>
/// 位置环的KP的Settle因子
/// </summary>
public PIDLabel<double> PA_SLPKPSF
{
get { return _pA_SLPKPSF; }
set { SetAndNotify(ref _pA_SLPKPSF, value); }
}
private PIDLabel<double> _pA_SLAFF = new PIDLabel<double>() { Name = "PA_SLAFF_", Value = 0 };
/// <summary>
/// 加速度前馈
/// </summary>
public PIDLabel<double> PA_SLAFF
{
get { return _pA_SLAFF; }
set { SetAndNotify(ref _pA_SLAFF, value); }
}
private PIDLabel<double> _pA_SLJFF = new PIDLabel<double>() { Name = "PA_SLJFF_", Value = 0 };
/// <summary>
/// 加加速度前馈
/// </summary>
public PIDLabel<double> PA_SLJFF
{
get { return _pA_SLJFF; }
set { SetAndNotify(ref _pA_SLJFF, value); }
}
public AxisPIDParameter()
{
}
public AxisPIDParameter(string moduleName)
{
ModuleName = moduleName;
}
public IParameterItem Clone()
{
AxisPIDParameter copy = new AxisPIDParameter
{
ModuleName = this.ModuleName,
AxisIndex = this.AxisIndex,
PA_SLVKP = this.PA_SLVKP != null ? (PIDLabel<double>)this.PA_SLVKP.Clone() : new PIDLabel<double>(),
PA_SLVKI = this.PA_SLVKI != null ? (PIDLabel<double>)this.PA_SLVKI.Clone() : new PIDLabel<double>(),
PA_SLVKPSF = this.PA_SLVKPSF != null ? (PIDLabel<double>)this.PA_SLVKPSF.Clone() : new PIDLabel<double>(),
PA_SLVKPIF = this.PA_SLVKPIF != null ? (PIDLabel<double>)this.PA_SLVKPIF.Clone() : new PIDLabel<double>(),
PA_SLVKISF = this.PA_SLVKISF != null ? (PIDLabel<double>)this.PA_SLVKISF.Clone() : new PIDLabel<double>(),
PA_SLVKIIF = this.PA_SLVKIIF != null ? (PIDLabel<double>)this.PA_SLVKIIF.Clone() : new PIDLabel<double>(),
PA_SLPKP = this.PA_SLPKP != null ? (PIDLabel<double>)this.PA_SLPKP.Clone() : new PIDLabel<double>(),
PA_SLPKPIF = this.PA_SLPKPIF != null ? (PIDLabel<double>)this.PA_SLPKPIF.Clone() : new PIDLabel<double>(),
PA_SLPKPSF = this.PA_SLPKPSF != null ? (PIDLabel<double>)this.PA_SLPKPSF.Clone() : new PIDLabel<double>(),
PA_SLAFF = this.PA_SLAFF != null ? (PIDLabel<double>)this.PA_SLAFF.Clone() : new PIDLabel<double>(),
PA_SLJFF = this.PA_SLJFF != null ? (PIDLabel<double>)this.PA_SLJFF.Clone() : new PIDLabel<double>()
};
return copy;
}
private void SyncAxisIndexFromModuleName()
{
if (_isSynchronizingAxis)
{
return;
}
int axisIndex;
if (!PidAxisCatalog.TryGetAxisIndex(ModuleName, out axisIndex))
{
return;
}
_isSynchronizingAxis = true;
try
{
SetAndNotify(ref _axisIndex, axisIndex);
}
finally
{
_isSynchronizingAxis = false;
}
}
private void SyncModuleNameFromAxisIndex()
{
if (_isSynchronizingAxis)
{
return;
}
string axisName = PidAxisCatalog.GetAxisName(AxisIndex);
if (string.IsNullOrWhiteSpace(axisName))
{
return;
}
_isSynchronizingAxis = true;
try
{
SetAndNotify(ref _moduleName, axisName);
}
finally
{
_isSynchronizingAxis = false;
}
}
}
}

View File

@@ -0,0 +1,34 @@
using MwFramework.ManagerService;
using Stylet;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace MainShell.Recipe.Models
{
public class PIDLabel<T> : PropertyChangedBase , IParameterItem
{
private string _name;
public string Name
{
get { return _name; }
set { SetAndNotify(ref _name, value); }
}
private T _value;
public T Value
{
get { return _value; }
set { SetAndNotify(ref _value, value); }
}
public IParameterItem Clone()
{
return this.MemberwiseClone() as IParameterItem;
}
}
}

View File

@@ -0,0 +1,108 @@
using MwFramework.Device;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
namespace MainShell.Recipe.Models
{
public class PIDOperater
{
public void SendPIDParameters(AxisPIDParameter axisPIDParameter)
{
var controller = GetControler();
foreach (var property in axisPIDParameter.GetType().GetProperties())
{
var value = property.GetValue(axisPIDParameter);
if (value is PIDLabel<double> pIDLabel)
{
controller.WriteVariableBuffer(-1, axisPIDParameter.ModuleName + pIDLabel.Name, pIDLabel.Value);
}
}
}
public AxisPIDParameter ReadPIDParametersFromDevice(string moduleName)
{
var controller = GetControler();
AxisPIDParameter axisPIDParameter = new AxisPIDParameter(moduleName);
var props = axisPIDParameter.GetType()
.GetProperties(BindingFlags.Public | BindingFlags.Instance)
.Where(p => p.CanRead && p.CanWrite);
foreach (var property in props)
{
var value = property.GetValue(axisPIDParameter);
if (value is PIDLabel<double> pIDLabel)
{
controller.ReadVariableBuffer(-1, axisPIDParameter.ModuleName + pIDLabel.Name, out var val);
if (val == null)
{
continue;
}
pIDLabel.Value = Convert.ToDouble(val);
}
}
return axisPIDParameter;
}
private IMotionController GetControler()
{
var hw = IoC.Get<Hardware.HardwareManager>();
if (hw?.AcsCard?.Controller == null)
throw new InvalidOperationException("硬件控制器未初始化 (HardwareManager.AcsCard.Controller is null).");
return hw.AcsCard.Controller;
}
public void SendPIDFilteringParameters(AxisFilteringParameter pidFilteringParameter)
{
var controller = GetControler();
foreach (var property in pidFilteringParameter.GetType().GetProperties())
{
var value = property.GetValue(pidFilteringParameter);
if (value is PIDLabel<double> pIDLabel)
{
controller.WriteVariableBuffer(-1, pIDLabel.Name, pIDLabel.Value);
}
else if (value is PIDLabel<bool> pIDLabelBool)
{
var val= pIDLabelBool.Value== true ? 1 : 0;
controller.WriteVariableBuffer(-1, pIDLabelBool.Name, val);
}
}
}
public AxisFilteringParameter ReadPIDFilteringParametersFromDevice()
{
var controller = GetControler();
var axisFilteringParameter = new AxisFilteringParameter();
var props = axisFilteringParameter.GetType()
.GetProperties(BindingFlags.Public | BindingFlags.Instance)
.Where(p => p.CanRead && p.CanWrite);
foreach (var property in props)
{
var value = property.GetValue(axisFilteringParameter);
if (value is PIDLabel<double> pIDLabel)
{
controller.ReadVariableBuffer(-1, pIDLabel.Name, out var val);
if (val == null)
{
continue;
}
pIDLabel.Value = Convert.ToDouble(val);
}
else if (value is PIDLabel<bool> pIDLabelBool)
{
controller.ReadVariableBuffer(-1, pIDLabelBool.Name, out var val);
if (val == null)
{
continue;
}
pIDLabelBool.Value = Convert.ToInt32(val) != 0;
}
}
return axisFilteringParameter;
}
}
}

View File

@@ -0,0 +1,63 @@
using Stylet;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace MainShell.Recipe.Models.PID
{
public class PIDProfile : PropertyChangedBase
{
private string _name;
public string Name
{
get { return _name; }
set { SetAndNotify(ref _name, value); }
}
private string _description;
public string Description
{
get { return _description; }
set { SetAndNotify(ref _description, value); }
}
// 每个 profile 下的轴参数集合
public ObservableCollection<AxisPIDParameter> Axes { get; set; }
private ObservableCollection<AxisFilteringParameter> _filteringParameters;
public ObservableCollection<AxisFilteringParameter> FilteringParameters
{
get { return _filteringParameters; }
set { SetAndNotify(ref _filteringParameters, value); }
}
public PIDProfile()
{
Axes = new ObservableCollection<AxisPIDParameter>();
FilteringParameters = new ObservableCollection<AxisFilteringParameter>();
}
public PIDProfile(string name)
: this()
{
Name = name;
}
public void EnsureAxes()
{
if (Axes == null)
{
Axes = new ObservableCollection<AxisPIDParameter>();
NotifyOfPropertyChange(() => Axes);
}
if (FilteringParameters == null)
{
FilteringParameters = new ObservableCollection<AxisFilteringParameter>();
}
}
}
}