From 1e8d0aee3dc476bdee863019726d41ae15bc69de Mon Sep 17 00:00:00 2001 From: NXX <447201003@qq> Date: Wed, 11 Jan 2023 09:35:02 +0800 Subject: [PATCH 01/96] =?UTF-8?q?=E5=B0=8F=E7=82=92?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- BPASmartClient.MorkF/Control_MorkF.cs | 138 ++++++++++++++---- BPASmartClient.MorkF/ML_MorkF.cs | 9 ++ BPASmartClient.MorkF/View/LocalMenu.xaml | 76 +++++----- .../View/MaterialCalibration.xaml | 103 +++++++++---- .../ViewModel/MaterialCalibrationViewModel.cs | 91 ++++++++---- BPASmartClient/MainWindow.xaml.cs | 1 + 6 files changed, 300 insertions(+), 118 deletions(-) diff --git a/BPASmartClient.MorkF/Control_MorkF.cs b/BPASmartClient.MorkF/Control_MorkF.cs index 2d687cdf..cf742f12 100644 --- a/BPASmartClient.MorkF/Control_MorkF.cs +++ b/BPASmartClient.MorkF/Control_MorkF.cs @@ -35,7 +35,7 @@ namespace BPASmartClient.MorkF /// /// 菜品库while循环最大sleep次数 /// - private const int materialSleepCount = 900; + private const int materialSleepCount = 600; /// /// 菜品库while循环每次sleep时间 @@ -61,7 +61,7 @@ namespace BPASmartClient.MorkF /// /// 菜品盒坐标系高度 /// - private const int materialBoxHeight = 9500; + private const int materialBoxHeight = 9700; //传感器1到菜品库的高度(厘米) private const int materialLaserHighCM_1 = 22; @@ -346,7 +346,15 @@ namespace BPASmartClient.MorkF ml_morkf.PawArrivePortThree = bools[2]; } }), 2); - + //获取爪子伸出退回到位 + GetStatus("M10.6", new Action((objects) => + { + if (objects is bool[] bools && bools.Length == 2) + { + ml_morkf.PawOutComplete = bools[0]; + ml_morkf.PawInComplete = bools[1]; + } + }), 2); //获取总初始化完成 GetStatus("M10.2", new Action((objects) => { @@ -478,8 +486,21 @@ namespace BPASmartClient.MorkF GetDistance_3(); }), "GetDistance_3"); }), "GetDistance_3"); - ActionManage.GetInstance.Register(PawExtend, "PawTurnFront"); - ActionManage.GetInstance.Register(PawShrink, "PawTurnBack"); + ActionManage.GetInstance.Register(new Action(() => + { + ThreadManage.GetInstance().Start(new Action(() => + { + PawExtend(); + }), "PawTurnFront"); + }), "PawTurnFront"); + + ActionManage.GetInstance.Register(new Action(() => + { + ThreadManage.GetInstance().Start(new Action(() => + { + PawShrink(); + }), "PawTurnBack"); + }), "PawTurnBack"); ActionManage.GetInstance.Register(new Action((list) => { ThreadManage.GetInstance().Start(new Action(() => @@ -968,33 +989,54 @@ namespace BPASmartClient.MorkF /// 爪子伸出 /// /// 电磁阀启停:true:启动。false:停止。 - public void PawExtend() + public bool PawExtend() { if (!ml_morkf.InitialComplete) { MessageLog.GetInstance.ShowEx("爪子伸出错误,菜品库未初始化"); - return; + return false; } - + Thread.Sleep(500); MaterailLibrary_Write("M0.6", true); - //等待爪子伸出延时4s - Thread.Sleep(6000); + for (int i = 0; i < materialSleepCount && !ml_morkf.PawOutComplete; i++)//潘华小炒没有夹爪到位功能 + { + Thread.Sleep(materialSleepTime); + if (i >= materialSleepCount - 1) + { + MessageLog.GetInstance.ShowEx("爪子伸出超时"); + return false; + } + } + return true; + ////等待爪子伸出延时4s + //Thread.Sleep(6000); } /// /// 爪子收缩 /// /// 电磁阀启停:true:启动。false:停止。 - public void PawShrink() + public bool PawShrink() { if (!ml_morkf.InitialComplete) { MessageLog.GetInstance.ShowEx("爪子伸出错误,菜品库未初始化"); - return; + return false; } MaterailLibrary_Write("M0.7", true); + Thread.Sleep(500); + for (int i = 0; i < materialSleepCount && !ml_morkf.PawInComplete; i++)//潘华小炒没有夹爪到位功能 + { + Thread.Sleep(materialSleepTime); + if (i >= materialSleepCount - 1) + { + MessageLog.GetInstance.ShowEx("爪子伸出超时"); + return false; + } + } + return true; //等待爪子收缩延时4s - Thread.Sleep(6000); + //Thread.Sleep(6000); } /// /// 电磁阀启停 @@ -1033,6 +1075,10 @@ namespace BPASmartClient.MorkF Thread.Sleep(materialSleepTime); if (i >= materialSleepCount - 1) { + if (i == 10) + { + MaterailLibrary_Write("M1.0", true); + } MessageLog.GetInstance.ShowEx("爪子去到1号位超时"); return false; } @@ -1063,6 +1109,10 @@ namespace BPASmartClient.MorkF Thread.Sleep(materialSleepTime); if (i >= materialSleepCount - 1) { + if (i == 10) + { + MaterailLibrary_Write("M1.1", true); + } MessageLog.GetInstance.ShowEx("爪子去到2号位超时"); return false; } @@ -1090,10 +1140,14 @@ namespace BPASmartClient.MorkF for (int i = 0; i < materialSleepCount && !ml_morkf.PawArrivePortThree; i++) { Thread.Sleep(materialSleepTime); + if(i == 30) + { + MaterailLibrary_Write("M1.2", true); + } if (i >= materialSleepCount - 1) { MessageLog.GetInstance.ShowEx("爪子去到3号位超时"); - return false; + } } if (!ml_morkf.PawPositon_3) @@ -1243,6 +1297,12 @@ namespace BPASmartClient.MorkF return false; } + if (x>212000|| y >240000) + { + MessageLog.GetInstance.ShowEx("机械臂移动超出范围"); + return false; + } + //取反 x = 0 - Math.Abs(x); y = 0 - Math.Abs(y); @@ -1374,9 +1434,9 @@ namespace BPASmartClient.MorkF Thread.Sleep(1000); //获取传感器的距离,转换成坐标系的点 - //int laserHigh = ml_morkf.LaserDistance; + int laserHigh = ml_morkf.LaserDistance; - int laserHigh = 400; + //秦工要求读取后置0 WriteDistance(0); @@ -1396,7 +1456,7 @@ namespace BPASmartClient.MorkF } //设置到传感器感应的距离处 - if (!SetArmPosition(x, y)) + if (!SetArmPosition(x - moveX, y)) { return false; } @@ -1414,7 +1474,11 @@ namespace BPASmartClient.MorkF } //伸出爪子 - PawExtend(); + if (!PawExtend()) + { + return false; + } + //移动前开启电磁阀 Electromagnetism(new List { false }); @@ -1467,10 +1531,12 @@ namespace BPASmartClient.MorkF // //收缩爪子 // PawShrink(); //}), "GetMaterialPawShrink"); - PawShrink(); + + //收缩爪子 + if (!PawShrink()) return false; //判断炒锅是否可以放盒 - for (int i = 0; materialSleepCount > i && !morkFs[fryIndex].FryPot1_HOBTPut; i++) + for (int i = 0; materialSleepCount > i && !morkFs[fryNum].FryPot1_HOBTPut; i++) { Thread.Sleep(materialSleepTime); if (i >= materialSleepCount - 1) @@ -1520,8 +1586,12 @@ namespace BPASmartClient.MorkF return false; } + //伸出爪子 - PawExtend(); + if (!PawExtend()) + { + return false; + } Thread.Sleep(300); @@ -1530,7 +1600,7 @@ namespace BPASmartClient.MorkF Thread.Sleep(300); //收缩爪子 - PawShrink(); + if (!PawShrink()) return false; //设置到炒锅i出菜处 if (!SetArmPosition(x + materialToFryDistance, y)) @@ -1578,10 +1648,13 @@ namespace BPASmartClient.MorkF Electromagnetism(new List { true }); //爪子收回 - PawShrink(); + if (!PawShrink()) + { + return false; + } //爪子去2号点位 - if(!PawToPoint2()) + if (!PawToPoint2()) { return false; } @@ -1670,8 +1743,10 @@ namespace BPASmartClient.MorkF Laser2CoordinateState laser2CoordinateState = LaserDistance2MaterialCount(distance, x, out boxCount); if (laser2CoordinateState == Laser2CoordinateState.MaterialNormal) { + int compensateHeight = boxCount > 1 ? 500 : 0;//补偿高度,超过1层盒子增加补偿 + //盒子高度计算除去起始位置的那个盒子 - x_high = (boxCount - 1) * materialBoxHeight; + x_high = (boxCount - 1) * materialBoxHeight + compensateHeight; } return laser2CoordinateState; @@ -1722,6 +1797,7 @@ namespace BPASmartClient.MorkF if(heightDifferent < 0) { MessageLog.GetInstance.ShowEx($"菜品库检测{x}处的菜品量时,传感器获取的高度差为负数,请校准该层高度"); + return Laser2CoordinateState.MaterialEmpty; ; } //盒子高度为45,但是需要考虑到误差,不足35,则认为为空 @@ -2542,7 +2618,7 @@ namespace BPASmartClient.MorkF //更新 morkFs[i].UpdateProcess(potActions); - + switch (potActions.Actions) { case nameof(StirFryPotActionEnum.加热开启): @@ -2608,6 +2684,16 @@ namespace BPASmartClient.MorkF MessageLog.GetInstance.Show(potActions.Actions); break; case nameof(StirFryPotActionEnum.取原料): + if(potActions.SeasoningLists[0].Loc == 1 || + potActions.SeasoningLists[0].Loc == 9 || + potActions.SeasoningLists[0].Loc == 10 || + potActions.SeasoningLists[0].Loc == 18 || + potActions.SeasoningLists[0].Loc == 19 || + potActions.SeasoningLists[0].Loc == 27 ) + { + MessageLog.GetInstance.ShowEx("该取料位置禁止使用"); + return; + } //炒锅取菜状态置为未取到 morkFs[i].GetMaterialComplete = false; diff --git a/BPASmartClient.MorkF/ML_MorkF.cs b/BPASmartClient.MorkF/ML_MorkF.cs index 993de6c1..4ce879a3 100644 --- a/BPASmartClient.MorkF/ML_MorkF.cs +++ b/BPASmartClient.MorkF/ML_MorkF.cs @@ -35,6 +35,15 @@ namespace BPASmartClient.MorkF /// public bool InitialComplete { get; set; } + /// + /// 爪子伸出到位 + /// + public bool PawOutComplete { get; set; } + /// + /// 爪子缩回到位 + /// + public bool PawInComplete { get; set; } + private bool _ArriveComplete = false; /// /// 定位到达,上升沿捕获需要特殊处理 diff --git a/BPASmartClient.MorkF/View/LocalMenu.xaml b/BPASmartClient.MorkF/View/LocalMenu.xaml index a950c91c..b217bd3d 100644 --- a/BPASmartClient.MorkF/View/LocalMenu.xaml +++ b/BPASmartClient.MorkF/View/LocalMenu.xaml @@ -7,50 +7,61 @@ xmlns:local="clr-namespace:BPASmartClient.MorkF.View" xmlns:vm="clr-namespace:BPASmartClient.MorkF.ViewModel" mc:Ignorable="d" - Title="LocalMenu" Height="800" Width="800" WindowStartupLocation="CenterScreen" WindowStyle="None" AllowsTransparency="True" MouseLeftButtonDown="Window_MouseLeftButtonDown"> + Title="LocalMenu" Height="800" Width="800" WindowStartupLocation="CenterScreen" WindowStyle="None" AllowsTransparency="True" MouseLeftButtonDown="Window_MouseLeftButtonDown" Background="Gray" + > - + + + + + + + + + - + + + + - + - - + +