终端一体化运控平台
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.
 
 
 

140 lines
5.3 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"] = LebaiHelper.GetInstance().robotData.RobotMode.Mode;
  48. LebaiHelper.GetInstance().GetRobotModeStatus();
  49. Thread.Sleep(10);
  50. },"获取乐白机器人数据");
  51. }
  52. public override void Stop()
  53. {
  54. }
  55. public override void Init()
  56. {
  57. EventBus.EventBus.GetInstance().Subscribe<Demo_MakeCoffeeEvent>(DeviceId, delegate (IEvent @event, EventCallBackHandle callBack )
  58. {
  59. });
  60. //获取机器人信号
  61. EventBus.EventBus.GetInstance().Subscribe<LebaiRobot_GetInputEvent>(DeviceId, delegate (IEvent @event, EventCallBackHandle callBack)
  62. {
  63. if (@event == null) return;
  64. if (@event is LebaiRobot_GetInputEvent getInput)
  65. {
  66. callBack.Invoke(LebaiHelper.GetInstance().GetInput(getInput.Pin));
  67. }
  68. });
  69. //获取Tcp信号
  70. EventBus.EventBus.GetInstance().Subscribe<LebaiRobot_GetTCPInputEvent>(DeviceId, delegate (IEvent @event, EventCallBackHandle callBack)
  71. {
  72. if (@event == null) return;
  73. if (@event is LebaiRobot_GetTCPInputEvent getTCPInput)
  74. {
  75. callBack?.Invoke(LebaiHelper.GetInstance().GetTcpInput(getTCPInput.Pin));
  76. }
  77. });
  78. //机器人输入信号
  79. EventBus.EventBus.GetInstance().Subscribe<LebaiRobot_SetValueEvent>(DeviceId, delegate (IEvent @event, EventCallBackHandle callBack)
  80. {
  81. if (@event == null) return;
  82. if (@event is LebaiRobot_SetValueEvent SetValueEvent)
  83. {
  84. LebaiHelper.GetInstance().SetValue(SetValueEvent.RobotSetValue);
  85. }
  86. });
  87. //控制机器人
  88. EventBus.EventBus.GetInstance().Subscribe<LebaiRobot_LebaiControlEvent>(DeviceId, delegate (IEvent @event, EventCallBackHandle callBack)
  89. {
  90. if (@event == null) return;
  91. if (@event is LebaiRobot_LebaiControlEvent lebaiControlEvent)
  92. {
  93. switch (lebaiControlEvent.LebaiControl)
  94. {
  95. case "机器人启动":
  96. LebaiHelper.GetInstance().StartRobot();
  97. break;
  98. case "启动示教":
  99. LebaiHelper.GetInstance().StartTeachMode();
  100. break;
  101. case "停止示教":
  102. LebaiHelper.GetInstance().EndtTeachMode();
  103. break;
  104. case "机器人急停":
  105. LebaiHelper.GetInstance().EStopRobot();
  106. break;
  107. default:
  108. break;
  109. }
  110. }
  111. });
  112. //选择机器人场景
  113. EventBus.EventBus.GetInstance().Subscribe<LebaiRobot_LebaiSenceEvent>(DeviceId, delegate (IEvent @event, EventCallBackHandle callBack)
  114. {
  115. if (@event == null) return;
  116. if (@event is LebaiRobot_LebaiSenceEvent lebaiSenceEvent)
  117. {
  118. LebaiHelper.GetInstance().Scene(lebaiSenceEvent.LebaiSence);
  119. }
  120. });
  121. InitStatus();
  122. Start();
  123. MessageLog.GetInstance.Show("乐白机器人初始化完成");
  124. }
  125. }
  126. }