From f9a42afa8fa433fd033f11ff4811428186ec6366 Mon Sep 17 00:00:00 2001 From: yahaha Date: Mon, 12 Dec 2022 13:11:10 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B0=8F=E7=82=92=E6=B5=B7=E7=A7=91=E6=B5=8B?= =?UTF-8?q?=E8=AF=95=E6=9C=80=E7=BB=88=E7=89=88=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- BPASmartClient.MORKSM.BK.PLC/PLCMachine.cs | 2 +- BPASmartClient.Modbus/ModbusTcp.cs | 4 +- BPASmartClient.MorkF/Control_MorkF.cs | 193 +++++++++--------- .../ViewModel/MaterialCalibrationViewModel.cs | 2 +- 4 files changed, 105 insertions(+), 96 deletions(-) diff --git a/BPASmartClient.MORKSM.BK.PLC/PLCMachine.cs b/BPASmartClient.MORKSM.BK.PLC/PLCMachine.cs index 657783a2..53bbb097 100644 --- a/BPASmartClient.MORKSM.BK.PLC/PLCMachine.cs +++ b/BPASmartClient.MORKSM.BK.PLC/PLCMachine.cs @@ -40,7 +40,7 @@ namespace BPASmartClient.PLC } } } - Thread.Sleep(500); + Thread.Sleep(100); } Thread.Sleep(1000); }), $"设备[{DeviceId}][{modbusTcp.IPAdress}]PLC读取线程", true); diff --git a/BPASmartClient.Modbus/ModbusTcp.cs b/BPASmartClient.Modbus/ModbusTcp.cs index a1efd533..711c303c 100644 --- a/BPASmartClient.Modbus/ModbusTcp.cs +++ b/BPASmartClient.Modbus/ModbusTcp.cs @@ -59,8 +59,8 @@ namespace BPASmartClient.Modbus Connect(); if (Connected) { - master.Transport.ReadTimeout = 2000;//读取超时时间 - master.Transport.WriteTimeout = 2000;//写入超时时间 + master.Transport.ReadTimeout = 3000;//读取超时时间 + master.Transport.WriteTimeout = 3000;//写入超时时间 master.Transport.Retries = 10;//重试次数 ConnectOk?.Invoke(); Show?.Invoke($"设备【{ip}:{port}】连接成功"); diff --git a/BPASmartClient.MorkF/Control_MorkF.cs b/BPASmartClient.MorkF/Control_MorkF.cs index 6106123a..ad4e78eb 100644 --- a/BPASmartClient.MorkF/Control_MorkF.cs +++ b/BPASmartClient.MorkF/Control_MorkF.cs @@ -34,7 +34,7 @@ namespace BPASmartClient.MorkF /// /// 菜品库while循环最大sleep次数 /// - private const int materialSleepCount = 600; + private const int materialSleepCount = 900; /// /// 菜品库while循环每次sleep时间 @@ -1281,12 +1281,6 @@ namespace BPASmartClient.MorkF MessageLog.GetInstance.Show($"传感器的距离{laserHigh}"); - //if (laserHigh > 29) - //{ - // MessageLog.GetInstance.Show("错误:传感器获取数据大于隔板与传感器之间的距离"); - // return false; - //} - int moveX = 0; if (LaserDistance2Coordinate(laserHigh, x, out moveX) != Laser2CoordinateState.MaterialNormal) { @@ -1310,14 +1304,12 @@ namespace BPASmartClient.MorkF Electromagnetism(new List { true }); Thread.Sleep(500); -#if true //爪子去1号位抓菜 if (!PawToPoint1()) { return false; } -#endif //伸出爪子 PawExtend(); @@ -1325,8 +1317,6 @@ namespace BPASmartClient.MorkF Electromagnetism(new List { false }); Thread.Sleep(500); - - int heightDifferent = 0; //根据x轴所在坐标系,计算高度差。 if( (x > 0 && x <= MaterialCoordinate.GetInstance().dicNoMaterialCoordinate["1"].X)&& (MaterialCoordinate.GetInstance().MaterialOneX > 0 && MaterialCoordinate.GetInstance().MaterialOneX < x)) @@ -1361,13 +1351,12 @@ namespace BPASmartClient.MorkF return false; } -#if true //爪子去2号位放菜 if (!PawToPoint2()) { return false; } -#endif + //收缩爪子 PawShrink(); @@ -1399,28 +1388,34 @@ namespace BPASmartClient.MorkF y = MaterialCoordinate.GetInstance().frying2.Y; } - //设置到炒锅1出菜处 - if (!SetArmPosition(x, y)) + //先设置到炒锅i出菜处上10000点 + if (!SetArmPosition(x - materialToFryDistance, y)) { return false; } -#if true //爪子去3号位放菜 if (!PawToPoint3()) { return false; } -#endif - - //伸出爪子 - PawExtend(); //开启磁吸 MagnetOn(fryNum); Thread.Sleep(200); + //设置到炒锅1出菜处 + if (!SetArmPosition(x, y)) + { + return false; + } + + //伸出爪子 + PawExtend(); + + Thread.Sleep(300); + //关闭电磁阀 Electromagnetism(new List { true }); Thread.Sleep(300); @@ -1434,13 +1429,11 @@ namespace BPASmartClient.MorkF return false; } -#if true //爪子回到2号位 if (!PawToPoint2()) { return false; } -#endif //开启电磁阀 Electromagnetism(new List { false }); @@ -1472,9 +1465,43 @@ namespace BPASmartClient.MorkF return false; } + //关闭电磁阀 + Electromagnetism(new List { true }); + + //爪子收回 + PawShrink(); + + //爪子去2号点位 + if(!PawToPoint2()) + { + return false; + } + + //开启电磁阀 + Electromagnetism(new List { false }); + //遍历坐标系与位置,并根据位置更新菜品余量 - foreach(var item in MaterialCoordinate.GetInstance().dicNoMaterialCoordinate) + foreach (var item in MaterialCoordinate.GetInstance().dicNoMaterialCoordinate) { + bool ret = true; + switch (item.Key) + { + //遇到1 9 10 18 19 27号位置跳过不检测,因为这6个位置不放菜品 + case "1": + case "9": + case "10": + case "18": + case "19": + case "27": + ret = false; + break; + } + + if (!ret) + { + continue; + } + //设置到抓菜处 if (!SetArmPosition(item.Value.X, item.Value.Y)) { @@ -1499,7 +1526,7 @@ namespace BPASmartClient.MorkF int surplus = 0; //根据距离算出菜品余量 Laser2CoordinateState state = LaserDistance2MaterialCount(laserHigh, item.Value.X, out surplus); - if (state != Laser2CoordinateState.MaterialNormal || state != Laser2CoordinateState.MaterialEmpty) + if (state != Laser2CoordinateState.MaterialNormal && state != Laser2CoordinateState.MaterialEmpty) { return false; } @@ -1507,7 +1534,7 @@ namespace BPASmartClient.MorkF //更新菜品余量 if (!MaterialSurplusOperation.GetInstance().UpdateSurplus(item.Key, surplus)) { - return false; + //return false; } } @@ -1528,40 +1555,9 @@ namespace BPASmartClient.MorkF public Laser2CoordinateState LaserDistance2Coordinate(int distance, int x, out int x_high) { x_high = 0; - //int heightDifferent = 0; int boxCount = 0; - ////传感器高度小于6,无法移出,菜品库满 - //if (distance < 60) - //{ - // MessageLog.GetInstance.ShowEx("错误:传感器距离不满足出菜高度"); - // return Laser2CoordinateState.MaterialOverdo; - //} try { - ////根据x轴所在坐标系,计算高度差。 - //if (x > 0 && x <= MaterialCoordinate.GetInstance().dicNoMaterialCoordinate["1"].X) - //{ - // heightDifferent = MaterialCoordinate.GetInstance().distance_1 - distance; - //} - //else if (x <= MaterialCoordinate.GetInstance().dicNoMaterialCoordinate["10"].X && x > MaterialCoordinate.GetInstance().dicNoMaterialCoordinate["1"].X) - //{ - // heightDifferent = MaterialCoordinate.GetInstance().distance_2 - distance; - //} - //else if (x > MaterialCoordinate.GetInstance().dicNoMaterialCoordinate["10"].X && x <= MaterialCoordinate.GetInstance().dicNoMaterialCoordinate["20"].X) - //{ - // heightDifferent = MaterialCoordinate.GetInstance().distance_3 - distance; - //} - //else - //{ - // return Laser2CoordinateState.MaterialOverdo; - //} - ////盒子高度为45,但是需要考虑到误差,因此除以50 - //boxCount = heightDifferent / 50; - //if (heightDifferent <= 20) - //{ - // MessageLog.GetInstance.ShowEx("错误:菜品量为空"); - // return Laser2CoordinateState.MaterialEmpty; - //} Laser2CoordinateState laser2CoordinateState = LaserDistance2MaterialCount(distance, x, out boxCount); if (laser2CoordinateState == Laser2CoordinateState.MaterialNormal) { @@ -1613,6 +1609,12 @@ namespace BPASmartClient.MorkF { return Laser2CoordinateState.MaterialOverdo; } + + if(heightDifferent < 0) + { + MessageLog.GetInstance.ShowEx($"菜品库检测{x}处的菜品量时,传感器获取的高度差为负数,请校准该层高度"); + } + //盒子高度为45,但是需要考虑到误差,不足35,则认为为空 int boxCount = heightDifferent / 35; count = boxCount; @@ -1623,7 +1625,7 @@ namespace BPASmartClient.MorkF } else if(count > 6) { - MessageLog.GetInstance.Show("菜品库数量超量"); + MessageLog.GetInstance.ShowEx("菜品库数量超量"); return Laser2CoordinateState.MaterialOverdo; } else @@ -2342,7 +2344,7 @@ namespace BPASmartClient.MorkF //遍历炒锅,找到合适、空闲的炒锅 for(int i = 0;i