MotorBase.cs 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using Aitex.Core.Common.DeviceData;
  7. using Aitex.Core.RT.DataCenter;
  8. using Aitex.Core.RT.Device;
  9. using Aitex.Core.RT.OperationCenter;
  10. namespace MECF.Framework.Common.Device.Bases
  11. {
  12. public abstract class MotorBase : BaseDevice, IDevice
  13. {
  14. public virtual bool IsServoOn { get; set; }
  15. public virtual bool IsError { get; set; }
  16. public virtual bool IsHomed { get; set; }
  17. public virtual bool IsMoving { get; set; }
  18. public virtual bool IsInTargetPosition { get; set; }
  19. public virtual float CurrentPosition { get; set; }
  20. public virtual float Target { get; set; }
  21. public virtual AITServoMotorData DeviceData { get; set; }
  22. protected MotorBase() : base()
  23. {
  24. }
  25. protected MotorBase(string module, string name) : base(module, name, name, name)
  26. {
  27. }
  28. public virtual bool Initialize()
  29. {
  30. DATA.Subscribe($"{Module}.{Name}.DeviceData", () => DeviceData);
  31. DATA.Subscribe($"{Module}.{Name}.IsServoOn", () => IsServoOn);
  32. DATA.Subscribe($"{Module}.{Name}.IsError", () => IsError);
  33. DATA.Subscribe($"{Module}.{Name}.IsHomed", () => IsHomed);
  34. DATA.Subscribe($"{Module}.{Name}.IsMoving", () => IsMoving);
  35. DATA.Subscribe($"{Module}.{Name}.IsInTargetPosition", () => IsInTargetPosition);
  36. DATA.Subscribe($"{Module}.{Name}.CurrentPosition", () => CurrentPosition);
  37. OP.Subscribe($"{Module}.{Name}.Home", (function, args) =>
  38. {
  39. Home();
  40. return true;
  41. });
  42. OP.Subscribe($"{Module}.{Name}.ServoOn", (function, args) =>
  43. {
  44. ServoOn();
  45. return true;
  46. });
  47. OP.Subscribe($"{Module}.{Name}.SetSpeed", (function, args) =>
  48. {
  49. SetSpeed((float)args[0]);
  50. return true;
  51. });
  52. OP.Subscribe($"{Module}.{Name}.SetPosition", (function, args) =>
  53. {
  54. SetPosition((float)args[0]);
  55. return true;
  56. });
  57. OP.Subscribe($"{Module}.{Name}.StopMotion", (function, args) =>
  58. {
  59. StopMotion( );
  60. return true;
  61. });
  62. OP.Subscribe($"{Module}.{Name}.ResetError", (function, args) =>
  63. {
  64. ResetError( );
  65. return true;
  66. });
  67. return true;
  68. }
  69. public virtual void Home()
  70. {
  71. }
  72. public virtual void ServoOn()
  73. {
  74. }
  75. public virtual void SetSpeed(float speed)
  76. {
  77. }
  78. public virtual void SetPosition(float position)
  79. {
  80. }
  81. public virtual void StopMotion()
  82. {
  83. }
  84. public virtual void ResetError()
  85. {
  86. }
  87. public virtual void Terminate()
  88. {
  89. }
  90. public virtual void Monitor()
  91. {
  92. }
  93. public virtual void Reset()
  94. {
  95. }
  96. }
  97. }