diff --git a/BPASmartClient.MorkF/Control_MorkF.cs b/BPASmartClient.MorkF/Control_MorkF.cs index 49d6486b..6106123a 100644 --- a/BPASmartClient.MorkF/Control_MorkF.cs +++ b/BPASmartClient.MorkF/Control_MorkF.cs @@ -175,6 +175,9 @@ namespace BPASmartClient.MorkF MaterialCoordinate.GetInstance().frying1 = materialCoordinate.frying1; MaterialCoordinate.GetInstance().frying2 = materialCoordinate.frying2; MaterialCoordinate.GetInstance().materialHeight = materialCoordinate.materialHeight; + MaterialCoordinate.GetInstance().MaterialOneX = materialCoordinate.MaterialOneX; + MaterialCoordinate.GetInstance().MaterialTwoX = materialCoordinate.MaterialTwoX; + MaterialCoordinate.GetInstance().MaterialThreeX = materialCoordinate.MaterialThreeX; } ////菜品库编号与坐标系对象存储 //SaveMaterialCoordinate(); @@ -1291,7 +1294,7 @@ namespace BPASmartClient.MorkF return false; } - if(x < moveX) + if (x < moveX) { MessageLog.GetInstance.ShowEx("错误:传感器距离转坐标值大于当前x轴坐标"); return false; @@ -1315,7 +1318,6 @@ namespace BPASmartClient.MorkF } #endif - //伸出爪子 PawExtend(); @@ -1323,13 +1325,42 @@ namespace BPASmartClient.MorkF Electromagnetism(new List { false }); Thread.Sleep(500); - //菜品盒子出菜品库,往上移动一个盒子的距离 - if (!SetArmPosition(x - moveX - materialBoxHeight, y)) + + int heightDifferent = 0; + //根据x轴所在坐标系,计算高度差。 + if( (x > 0 && x <= MaterialCoordinate.GetInstance().dicNoMaterialCoordinate["1"].X)&& + (MaterialCoordinate.GetInstance().MaterialOneX > 0 && MaterialCoordinate.GetInstance().MaterialOneX < x)) + { + //菜品盒子出菜品库,往上移动一个盒子的距离 + if (!SetArmPosition(MaterialCoordinate.GetInstance().MaterialOneX, y)) + { + return false; + } + } + else if( (x <= MaterialCoordinate.GetInstance().dicNoMaterialCoordinate["10"].X && x > MaterialCoordinate.GetInstance().dicNoMaterialCoordinate["1"].X)&& + (MaterialCoordinate.GetInstance().MaterialTwoX > 0 && MaterialCoordinate.GetInstance().MaterialTwoX < x)) + { + //菜品盒子出菜品库,往上移动一个盒子的距离 + if (!SetArmPosition(MaterialCoordinate.GetInstance().MaterialTwoX, y)) + { + return false; + } + } + else if ((x > MaterialCoordinate.GetInstance().dicNoMaterialCoordinate["10"].X && x <= MaterialCoordinate.GetInstance().dicNoMaterialCoordinate["20"].X) && + (MaterialCoordinate.GetInstance().MaterialThreeX > 0 && MaterialCoordinate.GetInstance().MaterialThreeX < x)) + { + //菜品盒子出菜品库,往上移动一个盒子的距离 + if (!SetArmPosition(MaterialCoordinate.GetInstance().MaterialThreeX, y)) + { + return false; + } + } + else { + MessageLog.GetInstance.ShowEx("错误:未设置当前菜品库出菜位置"); return false; } - #if true //爪子去2号位放菜 if (!PawToPoint2()) @@ -1337,16 +1368,19 @@ namespace BPASmartClient.MorkF return false; } #endif - ////判断炒锅是否可以放盒 - //for (int i = 0; materialSleepCount > i && !morkFs[fryIndex].FryPot1_HOBTPut; i++) - //{ - // Thread.Sleep(materialSleepTime); - // if (i >= materialSleepCount - 1) - // { - // MessageLog.GetInstance.Show("等待炒锅允许放盒超时"); - // return; - // } - //} + //收缩爪子 + PawShrink(); + + //判断炒锅是否可以放盒 + for (int i = 0; materialSleepCount > i && !morkFs[fryIndex].FryPot1_HOBTPut; i++) + { + Thread.Sleep(materialSleepTime); + if (i >= materialSleepCount - 1) + { + MessageLog.GetInstance.Show("等待炒锅允许放盒超时"); + return false; + } + } //关闭启磁吸 MagnetOff(fryNum); @@ -1379,6 +1413,9 @@ namespace BPASmartClient.MorkF } #endif + //伸出爪子 + PawExtend(); + //开启磁吸 MagnetOn(fryNum); @@ -1388,15 +1425,15 @@ namespace BPASmartClient.MorkF Electromagnetism(new List { true }); Thread.Sleep(300); + //收缩爪子 + PawShrink(); + //设置到炒锅i出菜处 if (!SetArmPosition(x + materialToFryDistance, y)) { return false; } - //收缩爪子 - PawShrink(); - #if true //爪子回到2号位 if (!PawToPoint2()) @@ -1404,6 +1441,9 @@ namespace BPASmartClient.MorkF return false; } #endif + + //开启电磁阀 + Electromagnetism(new List { false }); if (morkFs.ContainsKey(fryNum)) { morkFs[fryNum].GetMaterialComplete = true; @@ -1458,7 +1498,7 @@ namespace BPASmartClient.MorkF int surplus = 0; //根据距离算出菜品余量 - Laser2CoordinateState state = LaserDistance2MaterialCount(laserHigh, out surplus); + Laser2CoordinateState state = LaserDistance2MaterialCount(laserHigh, item.Value.X, out surplus); if (state != Laser2CoordinateState.MaterialNormal || state != Laser2CoordinateState.MaterialEmpty) { return false; @@ -1488,136 +1528,47 @@ namespace BPASmartClient.MorkF public Laser2CoordinateState LaserDistance2Coordinate(int distance, int x, out int x_high) { x_high = 0; - int heightDifferent = 0; + //int heightDifferent = 0; int boxCount = 0; - //传感器高度小于6,无法移出,菜品库满 - if (distance < 60) - { - MessageLog.GetInstance.ShowEx("错误:传感器距离不满足出菜高度"); - return Laser2CoordinateState.MaterialOverdo; - } + ////传感器高度小于6,无法移出,菜品库满 + //if (distance < 60) + //{ + // MessageLog.GetInstance.ShowEx("错误:传感器距离不满足出菜高度"); + // return Laser2CoordinateState.MaterialOverdo; + //} try { - if (x > 0 && x <= MaterialCoordinate.GetInstance().dicNoMaterialCoordinate["1"].X) - { - heightDifferent = MaterialCoordinate.GetInstance().distance_1 - distance; - ////菜盒放多了 - //if (heightDifferent < 10) - //{ - // return Laser2CoordinateState.MaterialOverdo; - //} - //else if (distance >= 10 && distance < 15) - //{ - // x_high = 11441; - // return Laser2CoordinateState.MaterialNormal; - //} - //else if (distance >= 15 && distance < 19) - //{ - // x_high = 5720; - // return Laser2CoordinateState.MaterialNormal; - //} - //else if (distance >= 19 && distance < 23) - //{ - // x_high = 0; - // return Laser2CoordinateState.MaterialNormal; - //} - //else - //{ - // return Laser2CoordinateState.MaterialEmpty; - //} - } - else if (x <= MaterialCoordinate.GetInstance().dicNoMaterialCoordinate["10"].X && x > MaterialCoordinate.GetInstance().dicNoMaterialCoordinate["1"].X) - { - heightDifferent = MaterialCoordinate.GetInstance().distance_2 - distance; - ////菜盒放多了 - //if (distance < 6) - //{ - // return Laser2CoordinateState.MaterialOverdo; - //} - //else if (distance >= 6 && distance < 10) - //{ - // x_high = 24882; - // return Laser2CoordinateState.MaterialNormal; - //} - //else if (distance >= 10 && distance < 15) - //{ - // x_high = 18661; - // return Laser2CoordinateState.MaterialNormal; - //} - //else if (distance >= 15 && distance < 19) - //{ - // x_high = 12441; - // return Laser2CoordinateState.MaterialNormal; - //} - //else if (distance >= 19 && distance < 23) - //{ - // x_high = 6220; - // return Laser2CoordinateState.MaterialNormal; - //} - //else if (distance >= 23 && distance < 28) - //{ - // x_high = 0; - // return Laser2CoordinateState.MaterialNormal; - //} - //else - //{ - // return Laser2CoordinateState.MaterialEmpty; - //} - } - else if (x > MaterialCoordinate.GetInstance().dicNoMaterialCoordinate["10"].X && x <= MaterialCoordinate.GetInstance().dicNoMaterialCoordinate["20"].X) - { - heightDifferent = MaterialCoordinate.GetInstance().distance_3 - distance; - ////菜盒放多了 - //if (distance < 7) - //{ - // return Laser2CoordinateState.MaterialOverdo; - //} - //else if (distance >= 7 && distance < 12) - //{ - // x_high = 24882; - // return Laser2CoordinateState.MaterialNormal; - //} - //else if (distance >= 12 && distance < 17) - //{ - // x_high = 18661; - // return Laser2CoordinateState.MaterialNormal; - //} - //else if (distance >= 17 && distance < 21) - //{ - // x_high = 12441; - // return Laser2CoordinateState.MaterialNormal; - //} - //else if (distance >= 21 && distance < 26) - //{ - // x_high = 6220; - // return Laser2CoordinateState.MaterialNormal; - //} - //else if (distance >= 26 && distance < 30) - //{ - // x_high = 0; - // return Laser2CoordinateState.MaterialNormal; - //} - //else - //{ - // return Laser2CoordinateState.MaterialEmpty; - //} - } - else - { - - return Laser2CoordinateState.MaterialOverdo; - } - //盒子高度为45,但是需要考虑到误差,因此除以50 - boxCount = heightDifferent / 50; - if (heightDifferent <= 20) + ////根据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) { - MessageLog.GetInstance.ShowEx("错误:菜品量为空"); - return Laser2CoordinateState.MaterialEmpty; + //盒子高度计算除去起始位置的那个盒子 + x_high = (boxCount - 1) * materialBoxHeight; } - - //盒子高度计算除去起始位置的那个盒子 - x_high = boxCount * materialBoxHeight; - return Laser2CoordinateState.MaterialNormal; + return laser2CoordinateState; } catch(Exception ex) @@ -1632,46 +1583,94 @@ namespace BPASmartClient.MorkF /// /// /// - public Laser2CoordinateState LaserDistance2MaterialCount(int distance, out int count) + public Laser2CoordinateState LaserDistance2MaterialCount(int distance, int x, out int count) { count = 0; try { - //菜盒放多了 - if (distance < 6) + //传感器高度小于80mm,无法移出,菜品库满 + if (distance < 80) { + MessageLog.GetInstance.ShowEx("错误:传感器距离不满足出菜高度"); return Laser2CoordinateState.MaterialOverdo; } - else if (distance >= 6 && distance < 10) + + int heightDifferent = 0; + //根据x轴所在坐标系,计算高度差。 + if (x > 0 && x <= MaterialCoordinate.GetInstance().dicNoMaterialCoordinate["1"].X) { - count = 5; - return Laser2CoordinateState.MaterialNormal; + heightDifferent = MaterialCoordinate.GetInstance().distance_1 - distance; } - else if (distance >= 10 && distance < 14) + else if (x <= MaterialCoordinate.GetInstance().dicNoMaterialCoordinate["10"].X && x > MaterialCoordinate.GetInstance().dicNoMaterialCoordinate["1"].X) { - count = 4; - return Laser2CoordinateState.MaterialNormal; + heightDifferent = MaterialCoordinate.GetInstance().distance_2 - distance; } - else if (distance >= 14 && distance < 19) + else if (x > MaterialCoordinate.GetInstance().dicNoMaterialCoordinate["10"].X && x <= MaterialCoordinate.GetInstance().dicNoMaterialCoordinate["20"].X) { - count = 3; - return Laser2CoordinateState.MaterialNormal; + heightDifferent = MaterialCoordinate.GetInstance().distance_3 - distance; + } + else + { + return Laser2CoordinateState.MaterialOverdo; } - else if (distance >= 19 && distance < 23) + //盒子高度为45,但是需要考虑到误差,不足35,则认为为空 + int boxCount = heightDifferent / 35; + count = boxCount; + if (count == 0) { - count = 2; - return Laser2CoordinateState.MaterialNormal; + MessageLog.GetInstance.Show("菜品库为空"); + return Laser2CoordinateState.MaterialEmpty; } - else if (distance >= 23 && distance < 28) + else if(count > 6) { - count = 1; - return Laser2CoordinateState.MaterialNormal; + MessageLog.GetInstance.Show("菜品库数量超量"); + return Laser2CoordinateState.MaterialOverdo; } else { - count = 0; - return Laser2CoordinateState.MaterialEmpty; + return Laser2CoordinateState.MaterialNormal; } + //if (heightDifferent <= 20) + //{ + // MessageLog.GetInstance.ShowEx("错误:菜品量为空"); + // return Laser2CoordinateState.MaterialEmpty; + //} + + ////菜盒放多了 + //if (distance < 6) + //{ + // return Laser2CoordinateState.MaterialOverdo; + //} + //else if (distance >= 6 && distance < 10) + //{ + // count = 5; + // return Laser2CoordinateState.MaterialNormal; + //} + //else if (distance >= 10 && distance < 14) + //{ + // count = 4; + // return Laser2CoordinateState.MaterialNormal; + //} + //else if (distance >= 14 && distance < 19) + //{ + // count = 3; + // return Laser2CoordinateState.MaterialNormal; + //} + //else if (distance >= 19 && distance < 23) + //{ + // count = 2; + // return Laser2CoordinateState.MaterialNormal; + //} + //else if (distance >= 23 && distance < 28) + //{ + // count = 1; + // return Laser2CoordinateState.MaterialNormal; + //} + //else + //{ + // count = 0; + // return Laser2CoordinateState.MaterialEmpty; + //} } catch (Exception ex) { @@ -1884,7 +1883,9 @@ namespace BPASmartClient.MorkF } int i = 0; - if(isMaterial) + MessageLog.GetInstance.Show("倒菜启动开始"); + + if (isMaterial) { //判断是否完成取菜 for (i = 0; i < materialSleepCount && !morkFs[num].GetMaterialComplete; i++) @@ -2341,7 +2342,7 @@ namespace BPASmartClient.MorkF //遍历炒锅,找到合适、空闲的炒锅 for(int i = 0;i - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/BPASmartClient.MorkF/ViewModel/MaterialCalibrationViewModel.cs b/BPASmartClient.MorkF/ViewModel/MaterialCalibrationViewModel.cs index c64ce452..eaec03ca 100644 --- a/BPASmartClient.MorkF/ViewModel/MaterialCalibrationViewModel.cs +++ b/BPASmartClient.MorkF/ViewModel/MaterialCalibrationViewModel.cs @@ -255,6 +255,24 @@ namespace BPASmartClient.MorkF.ViewModel public int Frying2Y { get { return _Frying2Y; } set { _Frying2Y = value; OnPropertyChanged(); } } private int _Frying2Y; #endregion + #region 第一层菜品库出菜位置 + public bool PositionMaterialOne { get { return _PositionMaterialOne; } set { _PositionMaterialOne = value; OnPropertyChanged(); } } + private bool _PositionMaterialOne; + public int MaterialOneX { get { return _MaterialOneX; } set { _MaterialOneX = value; OnPropertyChanged(); } } + private int _MaterialOneX; + #endregion + #region 第二层菜品库出菜位置 + public bool PositionMaterialTwo { get { return _PositionMaterialTwo; } set { _PositionMaterialTwo = value; OnPropertyChanged(); } } + private bool _PositionMaterialTwo; + public int MaterialTwoX { get { return _MaterialTwoX; } set { _MaterialTwoX = value; OnPropertyChanged(); } } + private int _MaterialTwoX; + #endregion + #region 第三层菜品库出菜位置 + public bool PositionMaterialThree { get { return _PositionMaterialThree; } set { _PositionMaterialThree = value; OnPropertyChanged(); } } + private bool _PositionMaterialThree; + public int MaterialThreeX { get { return _MaterialThreeX; } set { _MaterialThreeX = value; OnPropertyChanged(); } } + private int _MaterialThreeX; + #endregion #region 菜品库各传感器高度临时值 public int Distance_1 { get { return _Distance_1; } set { _Distance_1 = value; OnPropertyChanged(); } } private int _Distance_1; @@ -478,6 +496,9 @@ namespace BPASmartClient.MorkF.ViewModel materialCoordinate.distance_1 = Distance_1; materialCoordinate.distance_2 = Distance_2; materialCoordinate.distance_3 = Distance_3; + materialCoordinate.MaterialOneX = MaterialOneX; + materialCoordinate.MaterialTwoX = MaterialTwoX; + materialCoordinate.MaterialThreeX = MaterialThreeX; Json.Data = materialCoordinate; Json.Save(); @@ -486,6 +507,9 @@ namespace BPASmartClient.MorkF.ViewModel MaterialCoordinate.GetInstance().frying2 = materialCoordinate.frying2; MaterialCoordinate.GetInstance().materialHeight = materialCoordinate.materialHeight; MaterialCoordinate.GetInstance().dicNoMaterialCoordinate = materialCoordinate.dicNoMaterialCoordinate; + MaterialCoordinate.GetInstance().MaterialOneX = materialCoordinate.MaterialOneX; + MaterialCoordinate.GetInstance().MaterialTwoX = materialCoordinate.MaterialTwoX; + MaterialCoordinate.GetInstance().MaterialThreeX = materialCoordinate.MaterialThreeX; } /// @@ -650,6 +674,9 @@ namespace BPASmartClient.MorkF.ViewModel } } + MaterialOneX = materialCoordinate.MaterialOneX; + MaterialTwoX = materialCoordinate.MaterialTwoX; + MaterialThreeX = materialCoordinate.MaterialThreeX; MaterialHeightX = materialCoordinate.materialHeight.X; MaterialHeightY = materialCoordinate.materialHeight.Y; Frying1X = materialCoordinate.frying1.X; @@ -786,9 +813,18 @@ namespace BPASmartClient.MorkF.ViewModel Frying1Y = Frying1Y + OperationY; break; case "Frying2": - Frying2X = Frying1X + OperationX; + Frying2X = Frying2X + OperationX; Frying2Y = Frying2Y + OperationY; break; + case "MaterialOne": + MaterialOneX = MaterialOneX + OperationX; + break; + case "MaterialTwo": + MaterialTwoX = MaterialTwoX + OperationX; + break; + case "MaterialThree": + MaterialThreeX = MaterialThreeX + OperationX; + break; default: break; } @@ -802,7 +838,7 @@ namespace BPASmartClient.MorkF.ViewModel if (!PositionOne && !PositionTwo && !PositionThree && !PositionFour && !PositionFive && !PositionSix && !PositionSeven && !PositionEight && !PositionNine && !PositionTen && !PositionEleven && !PositionTwelve && !PositionThirteen && !PositionFourteen && !PositionFifteen && !PositionSixteen && !PositionSeventeen && !PositionEighteen && !PositionNineteen && !PositionTwenty && !PositionTwentyOne && !PositionTwentyTwo && !PositionTwentyThree && !PositionTwentyFour && !PositionTwentyFive && !PositionTwentySix && !PositionTwentySeven - && !PositionMaterialHeight && !PositionFrying1 && !PositionFrying2) + && !PositionMaterialHeight && !PositionFrying1 && !PositionFrying2 && !PositionMaterialOne && !PositionMaterialThree &&!PositionMaterialTwo) { MessageBox.Show("未选择点位"); return; @@ -928,6 +964,18 @@ namespace BPASmartClient.MorkF.ViewModel { ActionManage.GetInstance.Send("CalibrationCoordination", new List { "Frying2", Frying2X + OperationX, Frying2Y + OperationY });//设定机械臂当前位置 } + if(PositionMaterialOne) + { + ActionManage.GetInstance.Send("CalibrationCoordination", new List { "MaterialOne", MaterialOneX + OperationX, 0 });//设定机械臂当前位置 + } + if (PositionMaterialTwo) + { + ActionManage.GetInstance.Send("CalibrationCoordination", new List { "MaterialTwo", MaterialTwoX + OperationX, 0 });//设定机械臂当前位置 + } + if (PositionMaterialThree) + { + ActionManage.GetInstance.Send("CalibrationCoordination", new List { "MaterialThree", MaterialThreeX + OperationX, 0 });//设定机械臂当前位置 + } } public MaterialCalibrationViewModel()