终端一体化运控平台
Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.
 
 
 

155 Zeilen
6.2 KiB

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading;
  6. using System.Threading.Tasks;
  7. using Lebai.SDK;
  8. using Lebai.SDK.Dtos;
  9. using Robotc;
  10. using BPASmartClient.Message;
  11. using BPASmartClient.Helper;
  12. using TaskStatus = Lebai.SDK.Dtos.TaskStatus;
  13. using BPASmartClient.Peripheral;
  14. using BPASmartClient.EventBus;
  15. using static BPASmartClient.EventBus.EventBus;
  16. using BPASmartClient.Model;
  17. using BPASmartClient.LebaiRobot;
  18. using BPASmartClient.Model.乐白机器人;
  19. namespace BPASmartClient.Lebai
  20. {
  21. public class LebaiRobot : BasePeripheral
  22. {
  23. /// <summary>
  24. /// 抓手上传感器输入位索引
  25. /// </summary>
  26. public int HandSensor { get; set; }
  27. /// <summary>
  28. /// 输出信号量索引
  29. /// </summary>
  30. public int OutputSingalValue { get; set; }
  31. protected override void InitStatus()
  32. {
  33. status["Connected"] = false;
  34. status["HandSensor"] = 0;
  35. status["OutputSingalValue"] = 0;
  36. }
  37. public override void Start()
  38. {
  39. LebaiHelper.GetInstance().Connect(communicationPar.IPAddress);
  40. ThreadManage.GetInstance().StartLong(() => { LebaiHelper.GetInstance().Reconnect(communicationPar.IPAddress); Thread.Sleep(5000); }, "机器人重连检测");
  41. ThreadManage.GetInstance().StartLong(() =>
  42. {
  43. IsConnected = LebaiHelper.GetInstance().IsConnected;
  44. status["RobotIsConnected"] = LebaiHelper.GetInstance().IsConnected;
  45. status["RobotOK"] = LebaiHelper.GetInstance().GetValueAsync().Ok;
  46. status["RobotValue"] = LebaiHelper.GetInstance().GetValueAsync().Value;
  47. if (LebaiHelper.GetInstance().robotData != null) status["RobotMode"] =(ELebaiRModel)LebaiHelper.GetInstance().robotData.RobotMode.Mode;
  48. status["RobotValue1"] = LebaiHelper.GetInstance().GetValueAsync(1).Value;
  49. status["GetInput"] = LebaiHelper.GetInstance().GetInput();
  50. status["GetInput2"] = LebaiHelper.GetInstance().GetInput(2);
  51. if (LebaiHelper.GetInstance().robotData != null) status["RobotMode"] = LebaiHelper.GetInstance().robotData.RobotMode.Mode;
  52. LebaiHelper.GetInstance().GetRobotModeStatus();
  53. Thread.Sleep(10);
  54. }, "获取乐白机器人数据");
  55. }
  56. public override void Stop()
  57. {
  58. }
  59. public override void Init()
  60. {
  61. EventBus.EventBus.GetInstance().Subscribe<Demo_MakeCoffeeEvent>(DeviceId, delegate (IEvent @event, EventCallBackHandle callBack)
  62. {
  63. });
  64. //获取机器人信号
  65. EventBus.EventBus.GetInstance().Subscribe<LebaiRobot_GetInputEvent>(DeviceId, delegate (IEvent @event, EventCallBackHandle callBack)
  66. {
  67. if (@event == null) return;
  68. if (@event is LebaiRobot_GetInputEvent getInput)
  69. {
  70. callBack.Invoke(LebaiHelper.GetInstance().GetInput(getInput.Pin));
  71. }
  72. });
  73. //获取Tcp信号
  74. EventBus.EventBus.GetInstance().Subscribe<LebaiRobot_GetTCPInputEvent>(DeviceId, delegate (IEvent @event, EventCallBackHandle callBack)
  75. {
  76. if (@event == null) return;
  77. if (@event is LebaiRobot_GetTCPInputEvent getTCPInput)
  78. {
  79. callBack?.Invoke(LebaiHelper.GetInstance().GetTcpInput(getTCPInput.Pin));
  80. }
  81. });
  82. //机器人输入信号
  83. EventBus.EventBus.GetInstance().Subscribe<LebaiRobot_SetValueEvent>(DeviceId, delegate (IEvent @event, EventCallBackHandle callBack)
  84. {
  85. if (@event == null) return;
  86. if (@event is LebaiRobot_SetValueEvent SetValueEvent)
  87. {
  88. callBack?.Invoke(LebaiHelper.GetInstance().SetValue(SetValueEvent.RobotSetValue));
  89. }
  90. });
  91. //控制机器人
  92. EventBus.EventBus.GetInstance().Subscribe<LebaiRobot_LebaiControlEvent>(DeviceId, delegate (IEvent @event, EventCallBackHandle callBack)
  93. {
  94. if (@event == null) return;
  95. if (@event is LebaiRobot_LebaiControlEvent lebaiControlEvent)
  96. {
  97. switch (lebaiControlEvent.LebaiControl)
  98. {
  99. case "机器人启动":
  100. LebaiHelper.GetInstance().StartRobot();
  101. break;
  102. case "启动示教":
  103. LebaiHelper.GetInstance().StartTeachMode();
  104. break;
  105. case "停止示教":
  106. LebaiHelper.GetInstance().EndtTeachMode();
  107. break;
  108. case "机器人急停":
  109. LebaiHelper.GetInstance().EStopRobot();
  110. break;
  111. default:
  112. break;
  113. }
  114. }
  115. });
  116. //选择机器人场景
  117. EventBus.EventBus.GetInstance().Subscribe<LebaiRobot_LebaiSenceEvent>(DeviceId, delegate (IEvent @event, EventCallBackHandle callBack)
  118. {
  119. if (@event == null) return;
  120. if (@event is LebaiRobot_LebaiSenceEvent lebaiSenceEvent)
  121. {
  122. LebaiHelper.GetInstance().Scene(lebaiSenceEvent.LebaiSence);
  123. }
  124. });
  125. EventBus.EventBus.GetInstance().Subscribe<LebaiRobot_SetOutPutEvent>(DeviceId, delegate (IEvent @event, EventCallBackHandle callBack)
  126. {
  127. if (@event == null) return;
  128. if (@event is LebaiRobot_SetOutPutEvent SetOutEvent)
  129. {
  130. LebaiHelper.GetInstance().SetOutput(SetOutEvent.bDO, SetOutEvent.pin);
  131. }
  132. });
  133. InitStatus();
  134. Start();
  135. MessageLog.GetInstance.Show("乐白机器人初始化完成");
  136. }
  137. public override void WriteData(string address, object value)
  138. {
  139. }
  140. }
  141. }