终端一体化运控平台
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

163 lines
6.5 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. case "暂停":
  112. LebaiHelper.GetInstance().pauseMode();
  113. break;
  114. case "恢复":
  115. LebaiHelper.GetInstance().resumeMode();
  116. break;
  117. default:
  118. break;
  119. }
  120. }
  121. });
  122. //选择机器人场景
  123. EventBus.EventBus.GetInstance().Subscribe<LebaiRobot_LebaiSenceEvent>(DeviceId, delegate (IEvent @event, EventCallBackHandle callBack)
  124. {
  125. if (@event == null) return;
  126. if (@event is LebaiRobot_LebaiSenceEvent lebaiSenceEvent)
  127. {
  128. LebaiHelper.GetInstance().Scene(lebaiSenceEvent.LebaiSence);
  129. }
  130. });
  131. EventBus.EventBus.GetInstance().Subscribe<LebaiRobot_SetOutPutEvent>(DeviceId, delegate (IEvent @event, EventCallBackHandle callBack)
  132. {
  133. if (@event == null) return;
  134. if (@event is LebaiRobot_SetOutPutEvent lebaiOutputEvent)
  135. {
  136. LebaiHelper.GetInstance().SetOutput(lebaiOutputEvent.Value,lebaiOutputEvent.Pin);
  137. }
  138. });
  139. InitStatus();
  140. Start();
  141. MessageLog.GetInstance.Show("乐白机器人初始化完成");
  142. }
  143. public override void WriteData(string address, object value)
  144. {
  145. }
  146. }
  147. }