ServoConfigViewModel.cs 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. using Avalonia.Collections;
  2. using IViewModel;
  3. using IViewModel.ViewModels;
  4. using MessagePack.Formatters;
  5. using Mono.Cecil;
  6. using Shaker.Models;
  7. using System;
  8. using System.Collections.Generic;
  9. using System.Linq;
  10. using System.Text;
  11. using System.Threading.Tasks;
  12. namespace Dynamicloadsimulationdevice.ViewModels
  13. {
  14. public sealed class ServoConfigViewModel : DisplayViewModelBase<ServoConfigModel>
  15. {
  16. private ServoConfigViewModel() : base()
  17. {
  18. Title = nameof(LanguageValueViewModel.MenuDeviceConfig);
  19. Content = typeof(Views.ServoConfigView);
  20. #if NO_DEVICE
  21. UpDateModel(new ServoConfigModel()
  22. {
  23. PI = [.. Enumerable.Range(0,ShakerConfigViewModel.Instance.VerticalCount).Select(x=>new PIModel()),..Enumerable.Range(0,ShakerConfigViewModel.Instance.VerticalCount).Select(x=>new PIModel())]
  24. });
  25. #endif
  26. }
  27. static ServoConfigViewModel()
  28. {
  29. }
  30. public override double Width => 780;
  31. public override double Height => 620;
  32. public override bool CanResize => false;
  33. public override string MenuKey => nameof(LanguageValueViewModel.MenuDeviceConfig);
  34. public override string MenuParentKey => nameof(LanguageValueViewModel.MenuDevice);
  35. public override string IconKey => nameof(IconResourceValueViewModel.DeviceConfigGeometry);
  36. public override bool ShowTop => true;
  37. public override void UpDateModel(ServoConfigModel model)
  38. {
  39. foreach (var item in PI)
  40. {
  41. item.Value.PropertyChanged -= (sender, args) => SetSaveClose(true);
  42. }
  43. PI.Clear();
  44. if(model.PI.Count>0)
  45. {
  46. for (int i = 0; i < model.PI.Count; i++)
  47. {
  48. PI.Add(new IndexValueItemViewModel<PIViewModel>(i + 1, new PIViewModel(model.PI[i])));
  49. PI[^1].Value.PropertyChanged += (sender, args) => SetSaveClose(true);
  50. }
  51. }
  52. base.UpDateModel(model);
  53. }
  54. protected override void Save()
  55. {
  56. base.Save();
  57. savecanclose = false;
  58. }
  59. public override string OKContent => nameof(LanguageValueViewModel.Apply);
  60. public static ServoConfigViewModel Instance { get; } = new ServoConfigViewModel();
  61. public AvaloniaList<IndexValueItemViewModel<PIViewModel>> PI { get; } = new AvaloniaList<IndexValueItemViewModel<PIViewModel>>();
  62. /// <summary>
  63. /// 水平阀死区电压(V)
  64. /// </summary>
  65. [PropertyAssociation(nameof(ServoConfigModel.HorizontalBarrierPotential))]
  66. public double HorizontalBarrierPotential { get => Model.HorizontalBarrierPotential; set => SetProperty(ref Model.HorizontalBarrierPotential, value); }
  67. /// <summary>
  68. /// 最大水平阀死区电压(V)
  69. /// </summary>
  70. [PropertyAssociation(nameof(ServoConfigModel.MaxHorizontalBarrierPotential))]
  71. public double MaxHorizontalBarrierPotential { get => Model.MaxHorizontalBarrierPotential; }
  72. /// <summary>
  73. /// 最小水平阀死区电压(V)
  74. /// </summary>
  75. [PropertyAssociation(nameof(ServoConfigModel.MinHorizontalBarrierPotential))]
  76. public double MinHorizontalBarrierPotential { get => Model.MinHorizontalBarrierPotential; }
  77. /// <summary>
  78. /// 竖直阀死区电压(V)
  79. /// </summary>
  80. [PropertyAssociation(nameof(ServoConfigModel.VerticalBarrierPotential))]
  81. public double VerticalBarrierPotential { get => Model.VerticalBarrierPotential; set => SetProperty(ref Model.VerticalBarrierPotential, value); }
  82. /// <summary>
  83. /// 最大竖直阀死区电压(V)
  84. /// </summary>
  85. [PropertyAssociation(nameof(ServoConfigModel.MaxVerticalBarrierPotential))]
  86. public double MaxVerticalBarrierPotential { get => Model.MaxVerticalBarrierPotential; }
  87. /// <summary>
  88. /// 最小竖直阀死区电压(V)
  89. /// </summary>
  90. [PropertyAssociation(nameof(ServoConfigModel.MinVerticalBarrierPotential))]
  91. public double MinVerticalBarrierPotential { get => Model.MinVerticalBarrierPotential; }
  92. /// <summary>
  93. /// 最大积分电压(V)
  94. /// </summary>
  95. [PropertyAssociation(nameof(ServoConfigModel.MaxIntegratedVoltage))]
  96. public double MaxIntegratedVoltage { get => Model.MaxIntegratedVoltage; set => SetProperty(ref Model.MaxIntegratedVoltage, value); }
  97. /// <summary>
  98. /// 最大最大积分电压(V)
  99. /// </summary>
  100. [PropertyAssociation(nameof(ServoConfigModel.MaxMaxIntegratedVoltage))]
  101. public double MaxMaxIntegratedVoltage { get => Model.MaxMaxIntegratedVoltage; }
  102. /// <summary>
  103. /// 最小最大积分电压(V)
  104. /// </summary>
  105. [PropertyAssociation(nameof(ServoConfigModel.MinMaxIntegratedVoltage))]
  106. public double MinMaxIntegratedVoltage { get => Model.MinMaxIntegratedVoltage; }
  107. /// <summary>
  108. /// 位移前馈增益
  109. /// </summary>
  110. [PropertyAssociation(nameof(ServoConfigModel.DisplacementFeedforwardGain))]
  111. public double DisplacementFeedforwardGain { get => Model.DisplacementFeedforwardGain; set => SetProperty(ref Model.DisplacementFeedforwardGain, value); }
  112. /// <summary>
  113. /// 最大位移前馈增益
  114. /// </summary>
  115. [PropertyAssociation(nameof(ServoConfigModel.MaxDisplacementFeedforwardGain))]
  116. public double MaxDisplacementFeedforwardGain { get => Model.MaxDisplacementFeedforwardGain; }
  117. /// <summary>
  118. /// 最小位移前馈增益
  119. /// </summary>
  120. [PropertyAssociation(nameof(ServoConfigModel.MinDisplacementFeedforwardGain))]
  121. public double MinDisplacementFeedforwardGain { get => Model.MinDisplacementFeedforwardGain; }
  122. /// <summary>
  123. /// 最大驱动电压(V)
  124. /// </summary>
  125. [PropertyAssociation(nameof(ServoConfigModel.MaxDriverVoltage))]
  126. public double MaxDriverVoltage { get => Model.MaxDriverVoltage; set => SetProperty(ref Model.MaxDriverVoltage, value); }
  127. /// <summary>
  128. /// 最大最大驱动电压(V)
  129. /// </summary>
  130. [PropertyAssociation(nameof(ServoConfigModel.MaxMaxDriverVoltage))]
  131. public double MaxMaxDriverVoltage { get => Model.MaxMaxDriverVoltage; }
  132. /// <summary>
  133. /// 最小最大驱动电压(V)
  134. /// </summary>
  135. [PropertyAssociation(nameof(ServoConfigModel.MinMaxDriverVoltage))]
  136. public double MinMaxDriverVoltage { get => Model.MinMaxDriverVoltage; }
  137. /// <summary>
  138. /// 驱动超限电压(V)
  139. /// </summary>
  140. [PropertyAssociation(nameof(ServoConfigModel.DriverOverLimitVoltage))]
  141. public double DriverOverLimitVoltage { get => Model.DriverOverLimitVoltage; set => SetProperty(ref Model.DriverOverLimitVoltage, value); }
  142. /// <summary>
  143. /// 最大驱动超限电压(V)
  144. /// </summary>
  145. [PropertyAssociation(nameof(ServoConfigModel.MaxDriverOverLimitVoltage))]
  146. public double MaxDriverOverLimitVoltage { get => Model.MaxDriverOverLimitVoltage; }
  147. /// <summary>
  148. /// 最小驱动超限电压(V)
  149. /// </summary>
  150. [PropertyAssociation(nameof(ServoConfigModel.MinDriverOverLimitVoltage))]
  151. public double MinDriverOverLimitVoltage { get => Model.MinDriverOverLimitVoltage; }
  152. /// <summary>
  153. /// 急停后驱动限幅值(V)
  154. /// </summary>
  155. [PropertyAssociation(nameof(ServoConfigModel.EmerhencyDriverLimitVoltage))]
  156. public double EmerhencyDriverLimitVoltage { get => Model.EmerhencyDriverLimitVoltage; set => SetProperty(ref Model.EmerhencyDriverLimitVoltage, value); }
  157. /// <summary>
  158. /// 最大急停后驱动限幅值(V)
  159. /// </summary>
  160. [PropertyAssociation(nameof(ServoConfigModel.MaxEmerhencyDriverLimitVoltage))]
  161. public double MaxEmerhencyDriverLimitVoltage { get => Model.MaxEmerhencyDriverLimitVoltage; }
  162. /// <summary>
  163. /// 最小急停后驱动限幅值(V)
  164. /// </summary>
  165. [PropertyAssociation(nameof(ServoConfigModel.MinEmerhencyDriverLimitVoltage))]
  166. public double MinEmerhencyDriverLimitVoltage { get => Model.MinEmerhencyDriverLimitVoltage; }
  167. }
  168. }