Axis.cs 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Linq;
  5. using System.Runtime.CompilerServices;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. using System.Web;
  9. namespace TeamAAS_VP.Core.Robots
  10. {
  11. /// <summary>
  12. /// Represents command node names for an axis.
  13. /// </summary>
  14. public class AxisCommand
  15. {
  16. /// <summary>
  17. /// 使能,Bool类型
  18. /// </summary>
  19. public string PowerNode { get; set; }
  20. /// <summary>
  21. /// 停止,Bool类型
  22. /// </summary>
  23. public string StopNode { get; set; }
  24. /// <summary>
  25. /// 手动回原,Bool类型
  26. /// </summary>
  27. public string ManuToHomeNode { get; set; }
  28. /// <summary>
  29. /// 自动回原,Bool类型
  30. /// </summary>
  31. public string AutoToHomeNode { get; set; }
  32. /// <summary>
  33. /// 手动J0G+,Bool类型
  34. /// </summary>
  35. public string ManuJogFowardNode { get; set; }
  36. /// <summary>
  37. /// 手动J0G-,Bool类型
  38. /// </summary>
  39. public string ManuJogBackwardNode { get; set; }
  40. /// <summary>
  41. /// 速度模式控制,Bool类型
  42. /// </summary>
  43. public string VelocityControlNode { get; set; }
  44. /// <summary>
  45. /// 速度模式变速,Bool类型
  46. /// </summary>
  47. public string VelocityChangeNode { get; set; }
  48. /// <summary>
  49. /// 自动相对运动,Int类型
  50. /// </summary>
  51. public string AutoINCNode { get; set; }
  52. /// <summary>
  53. /// 自动绝对运动,Int类型
  54. /// </summary>
  55. public string AutoABSNode { get; set; }
  56. /// <summary>
  57. /// 转矩控制运动,Int类型
  58. /// </summary>
  59. public string TorqueNode { get; set; }
  60. /// <summary>
  61. /// 点位选择,Int类型
  62. /// </summary>
  63. public string PointSelectNode { get; set; }
  64. /// <summary>
  65. /// 示教使能,Bool类型
  66. /// </summary>
  67. public string TeachOnNode { get; set; }
  68. /// <summary>
  69. /// 示教位置,Bool类型
  70. /// </summary>
  71. public string TeachNode { get; set; }
  72. /// <summary>
  73. /// 手动绝对运动点位,Bool类型
  74. /// </summary>
  75. public string ManuPointNode { get; set; }
  76. /// <summary>
  77. /// 手动绝对运动指定位置,Bool类型
  78. /// </summary>
  79. public string ManuPositionNode { get; set; }
  80. }
  81. /// <summary>
  82. /// Represents parameter node names for an axis.
  83. /// </summary>
  84. public class AxisParameter
  85. {
  86. /// <summary>
  87. /// 手动定位点位,Real类型
  88. /// </summary>
  89. public string ManuPositionNode { get; set; }
  90. /// <summary>
  91. /// 手动定位速度,Real类型
  92. /// </summary>
  93. public string ManuVelocityNode { get; set; }
  94. /// <summary>
  95. /// 速度模式定位速度,Real类型
  96. /// </summary>
  97. public string VelModeVelocityNode { get; set; }
  98. /// <summary>
  99. /// 轴名称,String类型
  100. /// </summary>
  101. public string CommentNode { get; set; }
  102. }
  103. /// <summary>
  104. /// Represents state node names for an axis.
  105. /// </summary>
  106. public class AxisState
  107. {
  108. /// <summary>
  109. /// 轴已使能,Bool类型
  110. /// </summary>
  111. public string PowerOnNode { get; set; }
  112. /// <summary>
  113. /// 运转中,Bool类型
  114. /// </summary>
  115. public string BusyNode { get; set; }
  116. /// <summary>
  117. /// 定位完成,Bool类型
  118. /// </summary>
  119. public string PosOKNode { get; set; }
  120. /// <summary>
  121. /// 回原完成,Bool类型
  122. /// </summary>
  123. public string InitialedNode { get; set; }
  124. /// <summary>
  125. /// 轴暂停中,Bool类型
  126. /// </summary>
  127. public string PausedNode { get; set; }
  128. /// <summary>
  129. /// 轴正转中,Bool类型
  130. /// </summary>
  131. public string PosiNode { get; set; }
  132. /// <summary>
  133. /// 轴反转中,Bool类型
  134. /// </summary>
  135. public string NegaNode { get; set; }
  136. /// <summary>
  137. /// 错误,Bool类型
  138. /// </summary>
  139. public string ErrorNode { get; set; }
  140. /// <summary>
  141. /// 错误代码,Int类型
  142. /// </summary>
  143. public string ErrorIdNode { get; set; }
  144. /// <summary>
  145. /// 实际位置,Real类型
  146. /// </summary>
  147. public string ActPositionNode { get; set; }
  148. /// <summary>
  149. /// 实际速度,Real类型
  150. /// </summary>
  151. public string ActVelocityNode { get; set; }
  152. /// <summary>
  153. /// 实际扭矩,Real类型
  154. /// </summary>
  155. public string ActTorqueNode { get; set; }
  156. /// <summary>
  157. /// 停止位置,Real类型
  158. /// </summary>
  159. public string StopPositionNode { get; set; }
  160. /// <summary>
  161. /// 绝对位置点位,Real类型
  162. /// </summary>
  163. public string HmiPositionNode { get; set; }
  164. /// <summary>
  165. /// 运动时间,Int类型
  166. /// </summary>
  167. public string SpTimeNode { get; set; }
  168. /// <summary>
  169. /// 轴状态,Int类型
  170. /// </summary>
  171. public string StateNode { get; set; }
  172. }
  173. /// <summary>
  174. /// Axis model that groups command, parameter and state node names.
  175. /// </summary>
  176. public class Axis
  177. {
  178. public Axis()
  179. {
  180. Command = new AxisCommand();
  181. Parameter = new AxisParameter();
  182. State = new AxisState();
  183. }
  184. public Axis(string name, int index) : this()
  185. {
  186. Name = name;
  187. Index = index;
  188. }
  189. /// <summary>
  190. /// Logical name of the axis, e.g. "X","Y","Z","U" or "A1".
  191. /// </summary>
  192. public string Name { get; set; }
  193. /// <summary>
  194. /// Axis index (1-based) when applicable.
  195. /// </summary>
  196. public int Index { get; set; }
  197. public AxisCommand Command { get; set; }
  198. public AxisParameter Parameter { get; set; }
  199. public AxisState State { get; set; }
  200. }
  201. public class AxisExtended : Axis, INotifyPropertyChanged
  202. {
  203. //当前坐标
  204. private double _CurrentPosition;
  205. public double CurrentPosition
  206. {
  207. get { return _CurrentPosition; }
  208. set { SetProperty(ref _CurrentPosition, value); }
  209. }
  210. #region 属性通知
  211. /// <summary>
  212. /// Occurs when a property value changes.
  213. /// </summary>
  214. public event PropertyChangedEventHandler PropertyChanged;
  215. /// <summary>
  216. /// Checks if a property already matches a desired value. Sets the property and
  217. /// notifies listeners only when necessary.
  218. /// </summary>
  219. /// <typeparam name="T">Type of the property.</typeparam>
  220. /// <param name="storage">Reference to a property with both getter and setter.</param>
  221. /// <param name="value">Desired value for the property.</param>
  222. /// <param name="propertyName">Name of the property used to notify listeners. This
  223. /// value is optional and can be provided automatically when invoked from compilers that
  224. /// support CallerMemberName.</param>
  225. /// <returns>True if the value was changed, false if the existing value matched the
  226. /// desired value.</returns>
  227. protected virtual bool SetProperty<T>(ref T storage, T value, [CallerMemberName] string propertyName = null)
  228. {
  229. if (EqualityComparer<T>.Default.Equals(storage, value)) return false;
  230. storage = value;
  231. RaisePropertyChanged(propertyName);
  232. return true;
  233. }
  234. /// <summary>
  235. /// Checks if a property already matches a desired value. Sets the property and
  236. /// notifies listeners only when necessary.
  237. /// </summary>
  238. /// <typeparam name="T">Type of the property.</typeparam>
  239. /// <param name="storage">Reference to a property with both getter and setter.</param>
  240. /// <param name="value">Desired value for the property.</param>
  241. /// <param name="propertyName">Name of the property used to notify listeners. This
  242. /// value is optional and can be provided automatically when invoked from compilers that
  243. /// support CallerMemberName.</param>
  244. /// <param name="onChanged">Action that is called after the property value has been changed.</param>
  245. /// <returns>True if the value was changed, false if the existing value matched the
  246. /// desired value.</returns>
  247. protected virtual bool SetProperty<T>(ref T storage, T value, Action onChanged, [CallerMemberName] string propertyName = null)
  248. {
  249. if (EqualityComparer<T>.Default.Equals(storage, value)) return false;
  250. storage = value;
  251. onChanged?.Invoke();
  252. RaisePropertyChanged(propertyName);
  253. return true;
  254. }
  255. /// <summary>
  256. /// Raises this object's PropertyChanged event.
  257. /// </summary>
  258. /// <param name="propertyName">Name of the property used to notify listeners. This
  259. /// value is optional and can be provided automatically when invoked from compilers
  260. /// that support <see cref="CallerMemberNameAttribute"/>.</param>
  261. protected void RaisePropertyChanged([CallerMemberName] string propertyName = null)
  262. {
  263. OnPropertyChanged(new PropertyChangedEventArgs(propertyName));
  264. }
  265. /// <summary>
  266. /// Raises this object's PropertyChanged event.
  267. /// </summary>
  268. /// <param name="args">The PropertyChangedEventArgs</param>
  269. protected virtual void OnPropertyChanged(PropertyChangedEventArgs args)
  270. {
  271. PropertyChanged?.Invoke(this, args);
  272. }
  273. #endregion
  274. }
  275. }