From 72eae39c5b78d79d5e83143678b5d58073e6fef1 Mon Sep 17 00:00:00 2001 From: itachilee <3050155685@qq.com> Date: Sat, 9 Apr 2022 20:14:20 +0800 Subject: [PATCH] =?UTF-8?q?=E5=85=A5=E5=9C=BA=E4=BB=A3=E7=A0=81=E4=BF=AE?= =?UTF-8?q?=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- HBLConsole.Communication/LebaiHelper.cs | 38 ++++++++----- HBLConsole.MORKIC/Control_MORKIC.cs | 73 ++++++++++++++----------- 2 files changed, 65 insertions(+), 46 deletions(-) diff --git a/HBLConsole.Communication/LebaiHelper.cs b/HBLConsole.Communication/LebaiHelper.cs index d57f342..3dc8131 100644 --- a/HBLConsole.Communication/LebaiHelper.cs +++ b/HBLConsole.Communication/LebaiHelper.cs @@ -139,6 +139,18 @@ namespace HBLConsole.Communication return client.SetSignal(signalValue).Result; } + public bool GetInput(int pin=0) + { + if (client == null) return false; + var res = client.GetDIO(new IOPin() { Pin=pin}).Result; + if (res != null) + { + return res.Value == 1 ? true : false; + } + //int a = res.Value; + return false; + } + /// /// 运行指定的场景 /// @@ -146,23 +158,21 @@ namespace HBLConsole.Communication public void Scene(int id) { if (robotData == null || client == null) return; - var r= client?.RunScene(id).Result; - int t = r.Id; - TaskInfo res = client.GetTask(id).Result; - //var res1 = GetValueAsync(); - //while (res1.Value != id) - //{ - // client?.RunScene(id); - // Thread.Sleep(5); - //} - //LebaiHelper.GetInstance.SetValue(1000); - - //while (res.Status != Lebai.SDK.Dtos.TaskStatus.RunSuccess) + if (!client.GetIsCanRunTask().Result) return; + + client?.RunScene(id); + //var r = client.RunSceneUntilDone(id).Result; + + //var res = client.GetTask(id).Result; + //var res1 = GetValueAsync().Value; + //while (res1!=id) //{ // client?.RunScene(id); - // res = client.GetTask(id).Result; - // Thread.Sleep(1); + // Thread.Sleep(100); //} + //SetValue(1000); + + } } diff --git a/HBLConsole.MORKIC/Control_MORKIC.cs b/HBLConsole.MORKIC/Control_MORKIC.cs index f2ec811..b865404 100644 --- a/HBLConsole.MORKIC/Control_MORKIC.cs +++ b/HBLConsole.MORKIC/Control_MORKIC.cs @@ -317,7 +317,7 @@ namespace HBLConsole.MORKIC LebaiHelper.GetInstance.SetValue(100); Thread.Sleep(1500); //咖啡杯检测场景 - while (!ChipStatus.GetInstance().ArticleExits) + while (!LebaiHelper.GetInstance.GetInput()) { checkeNum++; if (checkeNum > 1) @@ -325,6 +325,8 @@ namespace HBLConsole.MORKIC LebaiHelper.GetInstance.Scene(LebaiHelper.SENCE_再次取杯); while (!(lebai.Ok && lebai.Value ==3)) { + + //LebaiHelper.GetInstance.Scene(LebaiHelper.SENCE_再次取杯); Thread.Sleep(5); } new TakeCupEvent() { Cup = IC_CUP.CUP_COFFEE }.Publish(); @@ -334,12 +336,12 @@ namespace HBLConsole.MORKIC //场景需要两次才能进去 Thread.Sleep(2000); if (lebai.Value != 2) - LebaiHelper.GetInstance.Scene(LebaiHelper.SENCE_咖啡杯检测); + LebaiHelper.GetInstance.Scene(LebaiHelper.SENCE_咖啡杯检测); while (!(lebai.Ok && lebai.Value == 2)) { Thread.Sleep(5); } - new ArticleExitsEvent() { }.Publish(); + Thread.Sleep(1000); } @@ -357,6 +359,7 @@ namespace HBLConsole.MORKIC //are.WaitOne(1 * 180); MessageLog.GetInstance.Show("咖啡机制作咖啡完成"); + SimpleFactory.GetInstance.OrderChanged(subOrderId, BPA.Message.Enum.ORDER_STATUS.COMPLETED_COOK); LebaiHelper.GetInstance.SetValue(101); Thread.Sleep(2000); //LebaiHelper.GetInstance.Scene(LebaiHelper.SENCE_送咖啡); @@ -372,39 +375,42 @@ namespace HBLConsole.MORKIC Thread.Sleep(5); } MessageLog.GetInstance.Show("机器人到达顾客取咖啡位置"); - SimpleFactory.GetInstance.OrderChanged(subOrderId, BPA.Message.Enum.ORDER_STATUS.COMPLETED_COOK); - LebaiHelper.GetInstance.Scene(LebaiHelper.SENCE_有无咖啡检测); - while (!(lebai.Ok && lebai.Value == 6)) - { - Thread.Sleep(5); - } - new ArticleExitsEvent() { }.Publish(); - Thread.Sleep(1000); - //有咖啡 - while (ChipStatus.GetInstance().ArticleExits) + + // LebaiHelper.GetInstance.Scene(LebaiHelper.SENCE_有无咖啡检测); + //while (!(lebai.Ok && lebai.Value == 6)) + //{ + // Thread.Sleep(5); + //} + //new ArticleExitsEvent() { }.Publish(); + //Thread.Sleep(1000); + ////有咖啡 + //while (ChipStatus.GetInstance().ArticleExits) + //{ + // LebaiHelper.GetInstance.Scene(LebaiHelper.SENCE_再送咖啡); + // while (!(lebai.Ok&&lebai.Value==7)) + // { + // Thread.Sleep(5); + // } + // LebaiHelper.GetInstance.Scene(LebaiHelper.SENCE_有无咖啡检测); + // while (!(lebai.Ok && lebai.Value == 6)) + // { + // Thread.Sleep(5); + // } + // new ArticleExitsEvent() { }.Publish(); + // Thread.Sleep(1000); + //} + //ChipStatus.GetInstance().ArticleExits = false; + //MessageLog.GetInstance.Show("顾客已经取走咖啡"); + if (!(morkOrderPushes.Count > 0)) { - LebaiHelper.GetInstance.Scene(LebaiHelper.SENCE_再送咖啡); - while (!(lebai.Ok&&lebai.Value==7)) - { - Thread.Sleep(5); - } - LebaiHelper.GetInstance.Scene(LebaiHelper.SENCE_有无咖啡检测); + LebaiHelper.GetInstance.Scene(LebaiHelper.SENCE_复位); while (!(lebai.Ok && lebai.Value == 6)) { - Thread.Sleep(5); + Thread.Sleep(8); } - new ArticleExitsEvent() { }.Publish(); - Thread.Sleep(1000); - } - ChipStatus.GetInstance().ArticleExits = false; - MessageLog.GetInstance.Show("顾客已经取走咖啡"); - //无咖啡 - LebaiHelper.GetInstance.Scene(LebaiHelper.SENCE_复位); - while (!(lebai.Ok && lebai.Value == 8)) - { - Thread.Sleep(8); + MessageLog.GetInstance.Show("机器人复位"); + } - MessageLog.GetInstance.Show("机器人复位"); //订单状态改变:完成 SimpleFactory.GetInstance.OrderChanged(subOrderId, BPA.Message.Enum.ORDER_STATUS.COMPLETED_TAKE); #endregion @@ -490,7 +496,10 @@ namespace HBLConsole.MORKIC ThreadManage.GetInstance.StartLong(new Action(() => { lebai = LebaiHelper.GetInstance.GetValueAsync(); - LebaiHelper.GetInstance.GetRobotModeStatus(); + LebaiHelper.GetInstance.GetRobotModeStatus(); + //LebaiHelper.GetInstance.GetInput(); + + Thread.Sleep(100); }), "乐百机器人数据读取"); }