|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading;
- using System.Threading.Tasks;
- using Lebai.SDK;
- using Lebai.SDK.Dtos;
- using Robotc;
-
- using BPA.Helper;
- using TaskStatus = Lebai.SDK.Dtos.TaskStatus;
- using BPASmartClient.Peripheral;
-
-
- using BPASmartClient.Model;
- using BPASmartClient.LebaiRobot;
- using BPASmartClient.Model.乐白机器人;
- using static BPA.Helper.EventBus;
-
- namespace BPASmartClient.Lebai
- {
- public class LebaiRobot : BasePeripheral
- {
-
- /// <summary>
- /// 抓手上传感器输入位索引
- /// </summary>
- public int HandSensor { get; set; }
- /// <summary>
- /// 输出信号量索引
- /// </summary>
- public int OutputSingalValue { get; set; }
-
- protected override void InitStatus()
- {
- status["Connected"] = false;
- status["HandSensor"] = 0;
- status["OutputSingalValue"] = 0;
- }
-
- public override void Start()
- {
- LebaiHelper.GetInstance().Connect(communicationPar.IPAddress);
- TaskManage.GetInstance.StartLong(() => { LebaiHelper.GetInstance().Reconnect(communicationPar.IPAddress); Thread.Sleep(5000); }, "机器人重连检测");
- TaskManage.GetInstance.StartLong(() =>
- {
- IsConnected = LebaiHelper.GetInstance().IsConnected;
- status["RobotIsConnected"] = LebaiHelper.GetInstance().IsConnected;
- status["RobotOK"] = LebaiHelper.GetInstance().GetValueAsync().Ok;
- status["RobotValue"] = LebaiHelper.GetInstance().GetValueAsync().Value;
- if (LebaiHelper.GetInstance().robotData != null) status["RobotMode"] = (ELebaiRModel)LebaiHelper.GetInstance().robotData.RobotMode.Mode;
- status["RobotValue1"] = LebaiHelper.GetInstance().GetValueAsync(1).Value;
- status["LeibaiGetTcpInput"] = LebaiHelper.GetInstance().GetTcpInput(0);
- status["LeibaiGetInput1"] = LebaiHelper.GetInstance().GetInput(0);
- status["LeibaiGetInput2"] = LebaiHelper.GetInstance().GetInput(1);
- status["LeibaiGetInput3"] = LebaiHelper.GetInstance().GetInput(2);
- status["LeibaiGetInput4"] = LebaiHelper.GetInstance().GetInput(3);
- if (LebaiHelper.GetInstance().robotData != null) status["RobotMode"] = LebaiHelper.GetInstance().robotData.RobotMode.Mode;
- LebaiHelper.GetInstance().GetRobotModeStatus();
- Thread.Sleep(10);
- }, "获取乐白机器人数据");
- }
-
- public override void Stop()
- {
-
- }
-
- public override void Init()
- {
- EventBus.GetInstance().Subscribe<Demo_MakeCoffeeEvent>(DeviceId, delegate (IEvent @event, EventCallBackHandle callBack)
- {
-
- });
- //获取机器人信号
- EventBus.GetInstance().Subscribe<LebaiRobot_GetInputEvent>(DeviceId, delegate (IEvent @event, EventCallBackHandle callBack)
- {
- if (@event == null) return;
- if (@event is LebaiRobot_GetInputEvent getInput)
- {
- callBack.Invoke(LebaiHelper.GetInstance().GetInput(getInput.Pin));
- }
- });
- //获取Tcp信号
- EventBus.GetInstance().Subscribe<LebaiRobot_GetTCPInputEvent>(DeviceId, delegate (IEvent @event, EventCallBackHandle callBack)
- {
- if (@event == null) return;
- if (@event is LebaiRobot_GetTCPInputEvent getTCPInput)
- {
- callBack?.Invoke(LebaiHelper.GetInstance().GetTcpInput(getTCPInput.Pin));
- }
- });
- //机器人输入信号
- EventBus.GetInstance().Subscribe<LebaiRobot_SetValueEvent>(DeviceId, delegate (IEvent @event, EventCallBackHandle callBack)
- {
- if (@event == null) return;
- if (@event is LebaiRobot_SetValueEvent SetValueEvent)
- {
- callBack?.Invoke(LebaiHelper.GetInstance().SetValue(SetValueEvent.RobotSetValue));
- }
- });
- //控制机器人
- EventBus.GetInstance().Subscribe<LebaiRobot_LebaiControlEvent>(DeviceId, delegate (IEvent @event, EventCallBackHandle callBack)
- {
- if (@event == null) return;
- if (@event is LebaiRobot_LebaiControlEvent lebaiControlEvent)
- {
- switch (lebaiControlEvent.LebaiControl)
- {
- case "启动":
- LebaiHelper.GetInstance().StartRobot();
- break;
- case "启动示教":
- LebaiHelper.GetInstance().StartTeachMode();
- break;
- case "停止示教":
- LebaiHelper.GetInstance().EndtTeachMode();
- break;
- case "急停":
- LebaiHelper.GetInstance().EStopRobot();
- break;
- case "暂停":
- LebaiHelper.GetInstance().pauseMode();
- break;
- case "恢复":
- LebaiHelper.GetInstance().resumeMode();
- break;
- default:
- break;
- }
-
- }
- });
- //选择机器人场景
- EventBus.GetInstance().Subscribe<LebaiRobot_LebaiSenceEvent>(DeviceId, delegate (IEvent @event, EventCallBackHandle callBack)
- {
- if (@event == null) return;
- if (@event is LebaiRobot_LebaiSenceEvent lebaiSenceEvent)
- {
- LebaiHelper.GetInstance().Scene(lebaiSenceEvent.LebaiSence);
- }
- });
-
- EventBus.GetInstance().Subscribe<LebaiRobot_SetOutPutEvent>(DeviceId, delegate (IEvent @event, EventCallBackHandle callBack)
- {
- if (@event == null) return;
- if (@event is LebaiRobot_SetOutPutEvent lebaiOutputEvent)
- {
- LebaiHelper.GetInstance().SetOutput(lebaiOutputEvent.Value, lebaiOutputEvent.Pin);
- }
- });
-
- InitStatus();
- Start();
- MessageLog.GetInstance.Show("乐白机器人初始化完成");
- }
-
- public override void WriteData(string address, object value)
- {
-
- }
-
- }
- }
|