终端一体化运控平台
Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.

LebaiRobot.cs 5.7 KiB

2 anni fa
2 anni fa
2 anni fa
2 anni fa
2 anni fa
2 anni fa
2 anni fa
2 anni fa
2 anni fa
2 anni fa
2 anni fa
2 anni fa
2 anni fa
2 anni fa
2 anni fa
2 anni fa
2 anni fa
2 anni fa
2 anni fa
2 anni fa
2 anni fa
2 anni fa
2 anni fa
2 anni fa
2 anni fa
2 anni fa
2 anni fa
2 anni fa
2 anni fa
2 anni fa
2 anni fa
2 anni fa
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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. 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. InitStatus();
  126. Start();
  127. MessageLog.GetInstance.Show("乐白机器人初始化完成");
  128. }
  129. public override void WriteData(string address, object value)
  130. {
  131. }
  132. }
  133. }