AxisManager.cs 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. using Aitex.Core.RT.Log;
  2. using Aitex.Core.Util;
  3. using CyberX8_RT.Devices.AXIS.CANOpen;
  4. using CyberX8_RT.Devices.AXIS.Galil;
  5. using CyberX8_RT.Devices.AXIS.GalilLipsel;
  6. using CyberX8_RT.Devices.AXIS.Yaskawa;
  7. using System;
  8. using System.Collections.Generic;
  9. using System.Linq;
  10. using System.Reflection;
  11. using System.Text;
  12. using System.Threading.Tasks;
  13. namespace CyberX8_RT.Devices.AXIS
  14. {
  15. public class AxisManager : Singleton<AxisManager>
  16. {
  17. /// <summary>
  18. /// 模块电机字典
  19. /// </summary>
  20. private Dictionary<string, List<JetAxisBase>> _moduleAxisDictionary = new Dictionary<string, List<JetAxisBase>>();
  21. /// <summary>
  22. /// 获取Axis对象
  23. /// </summary>
  24. /// <param name="type"></param>
  25. /// <param name="module"></param>
  26. /// <param name="name"></param>
  27. /// <returns></returns>
  28. public JetAxisBase GetAxisInstance(string type,string module,string name)
  29. {
  30. switch(type)
  31. {
  32. case "Copley":
  33. return new CanOpenAxis(module, name);
  34. case "Yaskawa":
  35. return new YaskawaAxis(module, name);
  36. case "Maxon":
  37. return new MaxonAxis(module, name);
  38. case "Galil":
  39. return new GalilAxis(module, name);
  40. case "GalilLipsel":
  41. return new GalilLipselAxis(module, name);
  42. case "GalilRotation":
  43. return new GalilRotationAxis(module, name);
  44. default:
  45. return null;
  46. }
  47. }
  48. /// <summary>
  49. /// 将Axis增加至模块字典
  50. /// </summary>
  51. /// <param name="moduleName"></param>
  52. /// <param name="axis"></param>
  53. public void AddModuleAxis(string moduleName, JetAxisBase axis)
  54. {
  55. if (_moduleAxisDictionary.ContainsKey(moduleName))
  56. {
  57. List<JetAxisBase> lst=_moduleAxisDictionary[moduleName];
  58. if(lst.FindIndex(O=>O.Name==axis.Name&&O.Module==moduleName)==-1)
  59. {
  60. lst.Add(axis);
  61. }
  62. }
  63. else
  64. {
  65. List<JetAxisBase> lst = new List<JetAxisBase>();
  66. lst.Add(axis);
  67. _moduleAxisDictionary[moduleName] = lst;
  68. }
  69. }
  70. /// <summary>
  71. /// 获取模块电机集合
  72. /// </summary>
  73. /// <returns></returns>
  74. public List<JetAxisBase> GetModuleAxisList(string moduleName)
  75. {
  76. return _moduleAxisDictionary.ContainsKey(moduleName) ? _moduleAxisDictionary[moduleName]:null;
  77. }
  78. /// <summary>
  79. /// 检验模块电机是否均上电
  80. /// </summary>
  81. /// <returns></returns>
  82. public bool CheckModuleAxisSwitchOn(string module,string name)
  83. {
  84. List<JetAxisBase> axises = AxisManager.Instance.GetModuleAxisList(module);
  85. if (axises != null)
  86. {
  87. foreach (JetAxisBase axis in axises)
  88. {
  89. if (!axis.IsSwitchOn)
  90. {
  91. LOG.WriteLog(eEvent.ERROR_PUF_NOT_SWITCHON, $"{module}", $"{axis.Name} is switch off");
  92. return false;
  93. }
  94. }
  95. }
  96. return true;
  97. }
  98. }
  99. }