| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383 |
- using Prism.Mvvm;
- using System;
- namespace SKMC.Api.Motion.Model
- {
- /// <summary>
- /// 电机模型
- /// </summary>
- public class MotionAxis : BindableBase
- {
- private long _id;
- public long Id
- {
- get { return _id; }
- set { _id = value; RaisePropertyChanged(); }
- }
- private string _type;
- /// <summary>
- /// 电机类型, Closed: 闭环, Open: 开环
- /// </summary>
- public string Type
- {
- get { return _type; }
- set { _type = value; }
- }
- private string _code;
- private short level;
- /// <summary>
- /// 安全等级, 0: 低压电机, 1: 高压电机
- /// </summary>
- public short Level
- {
- get { return level; }
- set { level = value; }
- }
- /// <summary>
- /// 电机码
- /// </summary>
- public string Code
- {
- get { return _code; }
- set { _code = value; RaisePropertyChanged(); }
- }
- private string catalog;
- /// <summary>
- /// 所属(模块)分类
- /// </summary>
- public string Catalog
- {
- get { return catalog; }
- set { catalog = value; RaisePropertyChanged(); }
- }
- private short _axisNo;
- /// <summary>
- /// 电机序号
- /// </summary>
- public short AxisNo
- {
- get { return _axisNo; }
- set { _axisNo = value; RaisePropertyChanged(); }
- }
- private char _axisDir;
- public char AxisDir
- {
- get { return _axisDir; }
- set { _axisDir = value; RaisePropertyChanged(); }
- }
- /// <summary>
- /// 默认的安全检查函数, 用于电机调试时
- /// </summary>
- public Func<bool> SafeChecker { get; set; }
- private MotionAxisStatus _axisSts;
- /// <summary>
- /// 电机状态
- /// </summary>
- public MotionAxisStatus AxisSts
- {
- get { return _axisSts; }
- set { _axisSts = value; RaisePropertyChanged(); }
- }
- /// <summary>
- /// 到位时允许的偏差 (mm)
- /// </summary>
- public double InRange { get; set; }
- /// <summary>
- /// 是否已停止
- /// </summary>
- public bool IsStopped => _axisSts.IsBusy == 0 && _axisSts.IsDone == 1;
- /// <summary>
- /// 是否上使能
- /// </summary>
- public bool IsEnabled => _axisSts.IsEnable == 1;
- /// <summary>
- /// <para>如果该轴出现异常, 是否会中断其他电机与IO控制</para>
- /// <para>如果需要对该轴出现异常后进行恢复处理, 为不影响到其他电机与IO控制, 这里需要设置为false</para>
- /// </summary>
- public bool CanInterruptAll { get; set; } = true;
- /// <summary>
- /// 是否已回零
- /// </summary>
- public bool IsHomed
- {
- get => _axisSts.IsHomed == 1;
- set => _axisSts.IsHomed = value ? (byte)1 : (byte)0;
- }
- private string _name;
- /// <summary>
- /// 名称/描述
- /// </summary>
- public string Name
- {
- get { return _name; }
- set { _name = value; RaisePropertyChanged(); }
- }
- private string _ptag;
- /// <summary>
- /// 正方向运动标签, 默认→
- /// </summary>
- public string PTag
- {
- get { return _ptag; }
- set { _ptag = value; }
- }
- private string _ntag;
- /// <summary>
- /// 负方向运动标签, 默认←
- /// </summary>
- public string NTag
- {
- get { return _ntag; }
- set { _ntag = value; }
- }
- private short _homeMod;
- /// <summary>
- /// 驱动器回零模式
- /// </summary>
- public short HomeMod
- {
- get { return _homeMod; }
- set { _homeMod = value; RaisePropertyChanged(); }
- }
- private short _homeDir;
- /// <summary>
- /// 回零方向
- /// </summary>
- public short HomeDir
- {
- get { return _homeDir; }
- set { _homeDir = value; RaisePropertyChanged(); }
- }
- private int _homeLowVel;
- /// <summary>
- /// 回零低速
- /// </summary>
- public int HomeLowVel
- {
- get { return _homeLowVel; }
- set { _homeLowVel = value; RaisePropertyChanged(); }
- }
- private int _homeHighVel;
- /// <summary>
- /// 回零高速
- /// </summary>
- public int HomeHighVel
- {
- get { return _homeHighVel; }
- set { _homeHighVel = value; RaisePropertyChanged(); }
- }
- public string SerialNo { get => $"[{AxisNo}]{AxisDir}: {Code}"; }
- public string SerialName { get => $"[{Code}]: {Name}"; }
- private int _gearScale;
- /// <summary>
- /// 电子齿轮比
- /// </summary>
- public int GearScale
- {
- get { return _gearScale; }
- set { _gearScale = value; }
- }
- private double _distanceR;
- /// <summary>
- /// 电机每旋转一圈机构的移动距离, 可以是螺距导程, 也可以是传动轮周长
- /// </summary>
- public double DistanceR
- {
- get { return _distanceR; }
- set { _distanceR = value; }
- }
- private short _unitType;
- // 单位类型, 0表示电机步距, 1表示实际距离
- public short UnitType
- {
- get { return _unitType; }
- set { _unitType = value; }
- }
- private string _unitName;
- // 单位名称用于显示, 例如mm, °等
- public string UnitName
- {
- get { return _unitName; }
- set { _unitName = value; }
- }
- private string _moveType;
- // 移动类型, L直线, R旋转
- public string MoveType
- {
- get { return _moveType; }
- set { _moveType = value; }
- }
- /// <summary>
- /// 距离(mm)对应的电机运动单位
- /// </summary>
- public double DistanceUnit
- {
- get => _gearScale / _distanceR;
- }
- /// <summary>
- /// 当前ENC值对应的实际距离mm
- /// </summary>
- public double Distance
- {
- get => _axisSts.ENC / DistanceUnit;
- }
- /// <summary>
- /// 离上一次记录的实际距离 mm
- /// </summary>
- public double WatchDistance => _axisSts.WatchPos / DistanceUnit;
- private double _prfUnit;
- /// <summary>
- /// 运动目标值, 实际单位mm或者角度等
- /// </summary>
- public double PrfUnit
- {
- get { return _prfUnit; }
- set
- {
- _prfUnit = value / DistanceUnit;
- AxisSts.PRF = value;
- RaisePropertyChanged();
- }
- }
- private double _encUnit;
- /// <summary>
- /// 运动反馈值, 实际单位mm或者角度等
- /// </summary>
- public double EncUnit
- {
- get { return _encUnit; }
- set
- {
- _encUnit = value / DistanceUnit;
- AxisSts.ENC = value;
- if (PercentOn) Percent = (_encUnit - NegativeUnit) / (PositiveUnit - NegativeUnit);
- RaisePropertyChanged();
- }
- }
- /// <summary>
- /// 是否使用位置百分比
- /// </summary>
- public bool PercentOn { get; set; }
- /// <summary>
- /// 负限位位置(mm)
- /// </summary>
- public double NegativeUnit { get; set; }
- /// <summary>
- /// 正限位位置(mm)
- /// </summary>
- public double PositiveUnit { get; set; }
- private double percent;
- /// <summary>
- /// 位置百分比, 负限位为0%, 正限位为100%
- /// </summary>
- public double Percent
- {
- get { return percent; }
- set { percent = value; RaisePropertyChanged(); }
- }
- /// <summary>
- /// 电机停止(中断)
- /// </summary>
- public bool IsInterrupt { get; set; }
- /// <summary>
- /// 被占用的handler
- /// </summary>
- public int? LockHandler { get; set; }
- /// <summary>
- /// 当前位置是否在偏移量之内
- /// </summary>
- /// <param name="targetVal"></param>
- /// <param name="offset"></param>
- /// <returns></returns>
- public bool IsEncInRange(double targetVal)
- {
- if (_encUnit == targetVal) return true;
- else if (_encUnit > targetVal) return _encUnit - targetVal <= InRange;
- else return targetVal - _encUnit <= InRange;
- }
- /// <summary>
- /// 当前位置是否在偏移量之内
- /// </summary>
- /// <param name="targetVal"></param>
- /// <param name="offset"></param>
- /// <returns></returns>
- public bool IsEncInRange(double targetVal, double offset)
- {
- if (_encUnit == targetVal) return true;
- else if (_encUnit > targetVal) return _encUnit - targetVal <= offset;
- else return targetVal - _encUnit <= offset;
- }
- }
- }
|