终端一体化运控平台
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

LebaiRobot.cs 6.7 KiB

2 år sedan
2 år sedan
2 år sedan
2 år sedan
2 år sedan
2 år sedan
2 år sedan
2 år sedan
2 år sedan
2 år sedan
2 år sedan
2 år sedan
2 år sedan
2 år sedan
2 år sedan
2 år sedan
2 år sedan
2 år sedan
2 år sedan
2 år sedan
2 år sedan
2 år sedan
2 år sedan
2 år sedan
2 år sedan
2 år sedan
2 år sedan
2 år sedan
2 år sedan
2 år sedan
2 år sedan
2 år sedan
2 år sedan
2 år sedan
2 år sedan
2 år sedan
2 år sedan
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  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["LeibaiGetTcpInput"] = LebaiHelper.GetInstance().GetTcpInput();
  50. status["LeibaiGetInput1"] = LebaiHelper.GetInstance().GetInput(1);
  51. status["LeibaiGetInput2"] = LebaiHelper.GetInstance().GetInput(2);
  52. status["LeibaiGetInput3"] = LebaiHelper.GetInstance().GetInput(3);
  53. status["LeibaiGetInput4"] = LebaiHelper.GetInstance().GetInput(4);
  54. if (LebaiHelper.GetInstance().robotData != null) status["RobotMode"] = LebaiHelper.GetInstance().robotData.RobotMode.Mode;
  55. LebaiHelper.GetInstance().GetRobotModeStatus();
  56. Thread.Sleep(10);
  57. }, "获取乐白机器人数据");
  58. }
  59. public override void Stop()
  60. {
  61. }
  62. public override void Init()
  63. {
  64. EventBus.EventBus.GetInstance().Subscribe<Demo_MakeCoffeeEvent>(DeviceId, delegate (IEvent @event, EventCallBackHandle callBack)
  65. {
  66. });
  67. //获取机器人信号
  68. EventBus.EventBus.GetInstance().Subscribe<LebaiRobot_GetInputEvent>(DeviceId, delegate (IEvent @event, EventCallBackHandle callBack)
  69. {
  70. if (@event == null) return;
  71. if (@event is LebaiRobot_GetInputEvent getInput)
  72. {
  73. callBack.Invoke(LebaiHelper.GetInstance().GetInput(getInput.Pin));
  74. }
  75. });
  76. //获取Tcp信号
  77. EventBus.EventBus.GetInstance().Subscribe<LebaiRobot_GetTCPInputEvent>(DeviceId, delegate (IEvent @event, EventCallBackHandle callBack)
  78. {
  79. if (@event == null) return;
  80. if (@event is LebaiRobot_GetTCPInputEvent getTCPInput)
  81. {
  82. callBack?.Invoke(LebaiHelper.GetInstance().GetTcpInput(getTCPInput.Pin));
  83. }
  84. });
  85. //机器人输入信号
  86. EventBus.EventBus.GetInstance().Subscribe<LebaiRobot_SetValueEvent>(DeviceId, delegate (IEvent @event, EventCallBackHandle callBack)
  87. {
  88. if (@event == null) return;
  89. if (@event is LebaiRobot_SetValueEvent SetValueEvent)
  90. {
  91. callBack?.Invoke(LebaiHelper.GetInstance().SetValue(SetValueEvent.RobotSetValue));
  92. }
  93. });
  94. //控制机器人
  95. EventBus.EventBus.GetInstance().Subscribe<LebaiRobot_LebaiControlEvent>(DeviceId, delegate (IEvent @event, EventCallBackHandle callBack)
  96. {
  97. if (@event == null) return;
  98. if (@event is LebaiRobot_LebaiControlEvent lebaiControlEvent)
  99. {
  100. switch (lebaiControlEvent.LebaiControl)
  101. {
  102. case "启动":
  103. LebaiHelper.GetInstance().StartRobot();
  104. break;
  105. case "启动示教":
  106. LebaiHelper.GetInstance().StartTeachMode();
  107. break;
  108. case "停止示教":
  109. LebaiHelper.GetInstance().EndtTeachMode();
  110. break;
  111. case "急停":
  112. LebaiHelper.GetInstance().EStopRobot();
  113. break;
  114. case "暂停":
  115. LebaiHelper.GetInstance().pauseMode();
  116. break;
  117. case "恢复":
  118. LebaiHelper.GetInstance().resumeMode();
  119. break;
  120. default:
  121. break;
  122. }
  123. }
  124. });
  125. //选择机器人场景
  126. EventBus.EventBus.GetInstance().Subscribe<LebaiRobot_LebaiSenceEvent>(DeviceId, delegate (IEvent @event, EventCallBackHandle callBack)
  127. {
  128. if (@event == null) return;
  129. if (@event is LebaiRobot_LebaiSenceEvent lebaiSenceEvent)
  130. {
  131. LebaiHelper.GetInstance().Scene(lebaiSenceEvent.LebaiSence);
  132. }
  133. });
  134. EventBus.EventBus.GetInstance().Subscribe<LebaiRobot_SetOutPutEvent>(DeviceId, delegate (IEvent @event, EventCallBackHandle callBack)
  135. {
  136. if (@event == null) return;
  137. if (@event is LebaiRobot_SetOutPutEvent lebaiOutputEvent)
  138. {
  139. LebaiHelper.GetInstance().SetOutput(lebaiOutputEvent.Value,lebaiOutputEvent.Pin);
  140. }
  141. });
  142. InitStatus();
  143. Start();
  144. MessageLog.GetInstance.Show("乐白机器人初始化完成");
  145. }
  146. public override void WriteData(string address, object value)
  147. {
  148. }
  149. }
  150. }