diff --git a/BPASmartClient.MorkF/Control_MorkF.cs b/BPASmartClient.MorkF/Control_MorkF.cs index c28b9688..b26b53fc 100644 --- a/BPASmartClient.MorkF/Control_MorkF.cs +++ b/BPASmartClient.MorkF/Control_MorkF.cs @@ -13,6 +13,7 @@ using BPASmartClient.MorkF.Model; using System.Text; using System.Collections.Concurrent; using System.Windows.Documents; +using BPASmartClient.Business; namespace BPASmartClient.MorkF { @@ -28,21 +29,65 @@ namespace BPASmartClient.MorkF /// private const int sleepTime = 500; + /// + /// 菜品库while循环最大sleep次数 + /// + private const int materialSleepCount = 400; + + /// + /// 菜品库while循环每次sleep时间 + /// + private const int materialSleepTime = 100; + /// /// 初始化炒锅数量 /// private int count = 2; - // - private const int materialHigh = 40000; + /// + /// 菜品盒下移高度,相对于坐标系 + /// + private const int materialBoxHigh = 4080; + + //菜品库一层的高度 + private const int materialHigh = 34500; + + /// + /// + /// + private const int materialOne = 34500; + + /// + /// + /// + private const int materialTwo = 34500; + + /// + /// + /// + private const int materialThree = 34500; + + //传感器到菜品库的高度(坐标系) + private const int materialLaserHigh = 34500; + + //传感器到菜品库的高度(厘米) + private const int materialLaserHighCM = 29; + + /// + /// 传感器到隔板的距离(坐标系) + /// + private const int clapboardLaserHigh = 10000; //炒锅1倒菜的xy坐标 - private const int materialPutPositionXFry1 = -30000; - private const int materialPutPositionYFry1 = -20000; + private const int materialPutPositionXFry1 = 70000; + private const int materialPutPositionYFry1 = 40000; //炒锅2倒菜的xy坐标 - private const int materialPutPositionXFry2 = -30000; - private const int materialPutPositionYFry2 = -20000; + private const int materialPutPositionXFry2 = 70000; + private const int materialPutPositionYFry2 = 40000; + + //菜品库机械爪放置菜品距离 + private const int materialToFryDistance = 10000; //当前炒锅,默认为1号炒锅 private int fryIndex = 0; @@ -54,7 +99,7 @@ namespace BPASmartClient.MorkF /// /// 炒锅编号与炒锅实例 /// - Dictionary morkFs = new Dictionary();//全局对象声明 + Dictionary morkFs = new Dictionary();//全局对象声明 /// /// 菜品库对象 @@ -79,7 +124,7 @@ namespace BPASmartClient.MorkF /// /// 当前炒制菜品 /// - private OrderLocInfo nowStirFryGood = null; + private OrderLocInfo[] nowStirFryGood = new OrderLocInfo[2]; /// /// 待取菜队列 @@ -94,12 +139,8 @@ namespace BPASmartClient.MorkF public override void DoMain() { IsHealth = true; - //WriteControl("VD836", 0); - //WriteControl("VD840", 0); - //Thread.Sleep(400); - //WriteControl("M0.0", true); - for (int i = 0;i< count;i++) + for (int i = 0; i < count; i++) { morkFs.Add(i, new GVL_MorkF()); } @@ -109,7 +150,8 @@ namespace BPASmartClient.MorkF ServerInit(); DeviceProcessLogShow("MORKF 设备初始化完成"); ///初始化菜品库 - FoodLibInit(); + //FoodLibInit(); + Task2ReadMaterialData(); } /// @@ -117,11 +159,121 @@ namespace BPASmartClient.MorkF /// public override void MainTask() { + //炒锅炒制线程 MainProcessExcute(); + //菜品库操作线程 + MainProcessMaterial(); //MinorProcessExcute(); //SingleProcess(); } + private void Task2ReadMaterialData() + { + ThreadManage.GetInstance().StartLong(new Action(() => { + + //获取定位到达状态 + GetStatus("M10.0", new Action((objects) => + { + if (objects is bool[] bools) + { + + //ml_morkf.ArriveComplete = bools[i]; + //小炒定点到达上升沿信号捕获 + if (RTrig.GetInstance("SmartArriveComplete").Start(bools[0])) + { + if (isInitialArrive == false) + { + MessageLog.GetInstance.Show("到达上升沿为true,isInitialArrive is false"); + isInitialArrive = true; + } + else + { + MessageLog.GetInstance.Show("到达上升沿为true"); + ml_morkf.ArriveComplete = true; + isInitialArrive = true; + } + } + } + + }), 2); + }), "ReadMaterialSmartArriveCompleteData", true); + + ThreadManage.GetInstance().StartLong(new Action(() => { + ReadMaterialData(); + + Thread.Sleep(10); + }), "ReadMaterialData", true); + } + + private void ReadMaterialData() + { + //获取激光距离 + GetStatus("VW270", new Action((objects) => + { + if (objects is ushort[] bools) + { + for (int i = 0; i < 1; i++) + { + ml_morkf.LaserDistance = bools[i]; + } + } + }), 2); + + //获取坐标X + GetStatus("VD828", new Action((objects) => + { + if (objects is int bools) + { + ml_morkf.ArmPositionX = bools; + } + }), 2); + + //获取坐标Y + GetStatus("VD832", new Action((objects) => + { + if (objects is int bools) + { + ml_morkf.ArmPositionY = bools; + } + }), 2); + + //获取爪子到达位置 + GetStatus("M11.0", new Action((objects) => + { + if (objects is bool[] bools && bools.Length > 3) + { + ml_morkf.PawArrivePortOne = bools[0]; + ml_morkf.PawArrivePortTwo = bools[1]; + ml_morkf.PawArrivePortThree = bools[2]; + } + }), 2); + + //获取总初始化完成 + GetStatus("M10.2", new Action((objects) => + { + if (objects is bool[] bools) + { + for (int i = 0; i < 1; i++) + { + ml_morkf.InitialComplete = bools[i]; + } + } + }), 2); + + //抓手初始化完成 + GetStatus("M10.3", new Action((objects) => + { + if (objects is bool[] bools) + { + for (int i = 0; i < 1; i++) + { + ml_morkf.PawInitialComplete = bools[i]; + } + } + }), 2); + + } + public override void Stop() { IsHealth = false; @@ -154,6 +306,27 @@ namespace BPASmartClient.MorkF }), "Electromagnetism"); }), "Electromagnetism"); ActionManage.GetInstance.Register(new Action(() => + { + ThreadManage.GetInstance().Start(new Action(() => + { + PawToPoint1(); + }), "PawToPoint1"); + }), "PawToPoint1"); + ActionManage.GetInstance.Register(new Action(() => + { + ThreadManage.GetInstance().Start(new Action(() => + { + PawToPoint2(); + }), "PawToPoint2"); + }), "PawToPoint2"); + ActionManage.GetInstance.Register(new Action(() => + { + ThreadManage.GetInstance().Start(new Action(() => + { + PawToPoint3(); + }), "PawToPoint3"); + }), "PawToPoint3"); + ActionManage.GetInstance.Register(new Action(() => { ThreadManage.GetInstance().Start(new Action(() => { @@ -180,7 +353,7 @@ namespace BPASmartClient.MorkF { ThreadManage.GetInstance().Start(new Action(() => { - if(list is List list_int) + if (list is List list_int) { if (list_int.Count == 2) { @@ -250,7 +423,7 @@ namespace BPASmartClient.MorkF { Plc1Reset(fryIndex); }), "Plc1Reset"); - }) , "Plc1Reset"); + }), "Plc1Reset"); ActionManage.GetInstance.Register(new Action(() => { @@ -336,7 +509,7 @@ namespace BPASmartClient.MorkF { ThreadManage.GetInstance().Start(new Action(() => { - SetFire(o,fryIndex); + SetFire(o, fryIndex); }), "SetFire"); }), "SetFire"); @@ -352,7 +525,7 @@ namespace BPASmartClient.MorkF { ThreadManage.GetInstance().Start(new Action(() => { - SetStir(o,fryIndex); + SetStir(o, fryIndex); }), "SetStir"); }), "SetStir"); #endregion @@ -365,8 +538,8 @@ namespace BPASmartClient.MorkF /// private void StartOrder(object o) { - if(o==null) return; - if(o is int goodId) + if (o == null) return; + if (o is int goodId) { var res = LocalstirFryGoods?.FirstOrDefault(p => p.GoodsKey == goodId);//匹配订单对应制作流程 if (res != null) @@ -411,12 +584,12 @@ namespace BPASmartClient.MorkF private void StartLocalOrder() { if (StirFryGoodsQuenes.Count > 0) return;//只能一个一个做 - if (Json.Data.LocalstirFryGoods.StirPotActions.Count>0) + if (Json.Data.LocalstirFryGoods.StirPotActions.Count > 0) { StirFryGoodsQuenes.Enqueue(new OrderLocInfo() { SuborderId = Guid.NewGuid().ToString(), - StirPotActions = Json.Data.LocalstirFryGoods.StirPotActions, + StirPotActions = Json.Data.LocalstirFryGoods.StirPotActions, GoodName = "本地菜品" }); MessageLog.GetInstance.Show($"添加本地模拟的订单{Json.Data.LocalstirFryGoods.GoodsKey}"); @@ -435,12 +608,12 @@ namespace BPASmartClient.MorkF if (!morkFs.ContainsKey(num)) { //根据调试界面的当前炒锅编号停止炒制线程 - ThreadManage.GetInstance().StopTask(String.Format(striConst, fryIndex.ToString(), nowStirFryGood.GoodName), new Action(() => { Plc1Reset(fryIndex); })); + ThreadManage.GetInstance().StopTask(String.Format(striConst, fryIndex.ToString(), nowStirFryGood[fryIndex].GoodName), new Action(() => { Plc1Reset(fryIndex); })); } else { //根据炒锅编号停止炒制线程 - ThreadManage.GetInstance().StopTask(String.Format(striConst, fryIndex.ToString(), nowStirFryGood.GoodName), new Action(() => { Plc1Reset(num); })); + ThreadManage.GetInstance().StopTask(String.Format(striConst, fryIndex.ToString(), nowStirFryGood[num].GoodName), new Action(() => { Plc1Reset(num); })); } } @@ -548,130 +721,6 @@ namespace BPASmartClient.MorkF }), i); } - //获取激光距离 - GetStatus("VW270", new Action((objects) => - { - if (objects is int[] bools) - { - for (int i = 0; i < 1; i++) - { - ml_morkf.LaserDistance = bools[i]; - } - } - }), 2); - - //获取坐标X - GetStatus("VD828", new Action((objects) => - { - if (objects is int[] bools) - { - for (int i = 0; i < 1; i++) - { - ml_morkf.ArmPositionX = bools[i]; - } - } - }), 2); - - //获取坐标Y - GetStatus("VD832", new Action((objects) => - { - if (objects is int[] bools) - { - for (int i = 0; i < 1; i++) - { - ml_morkf.ArmPositionY = bools[i]; - } - } - }), 2); - - //获取爪子到达位置 - GetStatus("M11.0", new Action((objects) => - { - if (objects is bool[] bools && bools.Length > 3) - { - - //ml_morkf.PawArrivePortOne = bools[0]; - //ml_morkf.PawArrivePortTwo = bools[1]; - //ml_morkf.PawArrivePortThree = bools[2]; - - if (isInitialPaw == false) - { - isInitialArrive = true; - } - else - { - //小炒爪子到达1号位上升沿信号捕获 - if (RTrig.GetInstance("SmartGitdistance1Complete").Start(bools[0])) - { - ml_morkf.PawArrivePortOne = true; - } - //小炒爪子到达3号位上升沿信号捕获 - if (RTrig.GetInstance("SmartGitdistance2Complete").Start(bools[1])) - { - ml_morkf.PawArrivePortTwo = true; - } - //小炒爪子到达3号位上升沿信号捕获 - if (RTrig.GetInstance("SmartGitdistance3Complete").Start(bools[2])) - { - ml_morkf.PawArrivePortThree = true; - } - isInitialArrive = true; - } - } - }), 2); - - //获取定位到达状态 - GetStatus("M10.0", new Action((objects) => - { - if (objects is bool[] bools) - { - for (int i = 0; i < 1; i++) - { - //ml_morkf.ArriveComplete = bools[i]; - //小炒定点到达上升沿信号捕获 - if (RTrig.GetInstance("SmartArriveComplete").Start(bools[i])) - { - if (isInitialArrive == false) - { - MessageLog.GetInstance.Show("到达上升沿为true,isInitialArrive is false"); - isInitialArrive = true; - } - else - { - MessageLog.GetInstance.Show("到达上升沿为true"); - ml_morkf.ArriveComplete = true; - isInitialArrive = true; - } - } - } - } - - }), 2); - - //获取总初始化完成 - GetStatus("M10.2", new Action((objects) => - { - if (objects is bool[] bools) - { - for (int i = 0; i < 1; i++) - { - ml_morkf.InitialComplete = bools[i]; - } - } - }), 2); - - //抓手初始化完成 - GetStatus("M10.3", new Action((objects) => - { - if (objects is bool[] bools) - { - for (int i = 0; i < 1; i++) - { - ml_morkf.PawInitialComplete = bools[i]; - } - } - }), 2); - } #endregion @@ -682,7 +731,7 @@ namespace BPASmartClient.MorkF /// /// /// - private void MaterailLibrary_Write(string address, object value,int num = 2) + private void MaterailLibrary_Write(string address, object value, int num = 2) { WriteControlExact(address, value, num); } @@ -693,10 +742,12 @@ namespace BPASmartClient.MorkF { MaterailLibrary_Write("M0.2", true); - for (int i = 0; i < sleepCount && !ml_morkf.InitialComplete; i++) + Thread.Sleep(500); + + for (int i = 0; i < materialSleepCount && !ml_morkf.InitialComplete; i++) { - Thread.Sleep(sleepTime); - if (i >= sleepCount - 1) + Thread.Sleep(materialSleepTime); + if (i >= materialSleepCount - 1) { MessageLog.GetInstance.Show("菜品库初始化超时"); return false; @@ -722,7 +773,8 @@ namespace BPASmartClient.MorkF MaterailLibrary_Write("M1.3", bs[0]); } } - public bool GetDistance_1() + + public bool PawToPoint1() { if (!ml_morkf.InitialComplete) { @@ -731,10 +783,10 @@ namespace BPASmartClient.MorkF MessageLog.GetInstance.Show("爪子去到1号位"); MaterailLibrary_Write("M1.0", true); - for (int i = 0; i < sleepCount && !ml_morkf.PawArrivePortOne; i++) + for (int i = 0; i < materialSleepCount && !ml_morkf.PawArrivePortOne; i++) { - Thread.Sleep(sleepTime); - if (i >= sleepCount - 1) + Thread.Sleep(materialSleepTime); + if (i >= materialSleepCount - 1) { MessageLog.GetInstance.Show("爪子去到1号位超时"); return false; @@ -746,7 +798,8 @@ namespace BPASmartClient.MorkF MessageLog.GetInstance.Show("爪子去到1号位完成"); return true; } - public bool GetDistance_2() + + public bool PawToPoint2() { if (!ml_morkf.InitialComplete) { @@ -755,10 +808,10 @@ namespace BPASmartClient.MorkF MessageLog.GetInstance.Show("爪子去到2号位"); MaterailLibrary_Write("M1.1", true); - for (int i = 0; i < sleepCount && !ml_morkf.PawArrivePortTwo; i++) + for (int i = 0; i < materialSleepCount && !ml_morkf.PawArrivePortTwo; i++) { - Thread.Sleep(sleepTime); - if (i >= sleepCount - 1) + Thread.Sleep(materialSleepTime); + if (i >= materialSleepCount - 1) { MessageLog.GetInstance.Show("爪子去到2号位超时"); return false; @@ -770,7 +823,8 @@ namespace BPASmartClient.MorkF MessageLog.GetInstance.Show("爪子去到2号位完成"); return true; } - public bool GetDistance_3() + + public bool PawToPoint3() { if (!ml_morkf.InitialComplete) { @@ -779,10 +833,10 @@ namespace BPASmartClient.MorkF MessageLog.GetInstance.Show("爪子去到3号位"); MaterailLibrary_Write("M1.2", true); - for (int i = 0; i < sleepCount && !ml_morkf.PawArrivePortThree; i++) + for (int i = 0; i < materialSleepCount && !ml_morkf.PawArrivePortThree; i++) { - Thread.Sleep(sleepTime); - if (i >= sleepCount - 1) + Thread.Sleep(materialSleepTime); + if (i >= materialSleepCount - 1) { MessageLog.GetInstance.Show("爪子去到3号位超时"); return false; @@ -794,6 +848,78 @@ namespace BPASmartClient.MorkF MessageLog.GetInstance.Show("爪子去到3号位完成"); return true; } + + public bool GetDistance_1() + { + if (!ml_morkf.InitialComplete) + { + return false; + } + + MaterailLibrary_Write("M0.3", true); + MaterailLibrary_Write("M0.3", false); + Thread.Sleep(300); + + MessageLog.GetInstance.Show("1号测距开启完成"); + return true; + } + public bool GetDistance_2() + { + if (!ml_morkf.InitialComplete) + { + return false; + } + + MaterailLibrary_Write("M0.4", true); + MaterailLibrary_Write("M0.4", false); + Thread.Sleep(300); + + MessageLog.GetInstance.Show("2号测距开启完成"); + return true; + } + public bool GetDistance_3() + { + if (!ml_morkf.InitialComplete) + { + return false; + } + + MaterailLibrary_Write("M0.5", true); + MaterailLibrary_Write("M0.5", false); + Thread.Sleep(300); + + MessageLog.GetInstance.Show("3号测距开启完成"); + return true; + } + + /// + /// 根据x坐标获取传感器距离 + /// + /// + /// + public bool GetDistance(int x) + { + //是否在第一层菜品库 + if (x > 0 && x <= materialLaserHigh) + { + //获取传感器1的距离 + return GetDistance_1(); + } + //是否在第二层菜品库 + else if (x > materialLaserHigh && x <= (2 * materialLaserHigh + clapboardLaserHigh)) + { + //获取传感器1的距离 + return GetDistance_2(); + } + //是否在第三层菜品库 + else if (x > (2 * materialLaserHigh + clapboardLaserHigh) && x <= (3 * materialLaserHigh + 2 * clapboardLaserHigh)) + { + //获取传感器1的距离 + return GetDistance_3(); + } + return false; + } + public void PawTurnFront() { MaterailLibrary_Write("", true); @@ -810,7 +936,7 @@ namespace BPASmartClient.MorkF /// public bool SetArmPosition(int x, int y) { - if(!ml_morkf.InitialComplete) + if (!ml_morkf.InitialComplete) { return false; } @@ -818,6 +944,11 @@ namespace BPASmartClient.MorkF //取反 x -= 2 * x; y -= 2 * y; + if (x > 0 || y > 0) + { + MessageLog.GetInstance.Show($"机械臂移动到[{x},{y}]非法"); + return false; + } MaterailLibrary_Write("VD836", x); Thread.Sleep(100); MaterailLibrary_Write("VD840", y); @@ -825,16 +956,28 @@ namespace BPASmartClient.MorkF Thread.Sleep(200); MessageLog.GetInstance.Show($"机械臂移动到[{x},{y}]"); + + //到达置为false + ml_morkf.ArriveComplete = false; + //定位启动 MaterailLibrary_Write("M0.0", true); - for (int i = 0; i < sleepCount && !ml_morkf.ArriveComplete; i++) + Thread.Sleep(400); + + for (int i = 0; i < materialSleepCount && (!ml_morkf.ArriveComplete); i++) { - Thread.Sleep(sleepTime); - if (i >= sleepCount - 1) + Thread.Sleep(materialSleepTime); + //若是目标点与当前坐标一致,跳出循环 + if((ml_morkf.ArmPositionX == x && ml_morkf.ArmPositionY == y)) + { + MessageLog.GetInstance.Show($"机械臂已移动到[{ml_morkf.ArmPositionX},{ml_morkf.ArmPositionY}]"); + break; + } + if (i >= materialSleepCount - 1) { MessageLog.GetInstance.Show("机械臂移动操作超时"); - return false; + return false; } } @@ -910,20 +1053,57 @@ namespace BPASmartClient.MorkF /// /// 取菜x轴坐标 /// 取菜y轴坐标 - /// - public void GetMaterail(int x,int y,int fryNum = 0) + /// 炒锅编号 + public void GetMaterail(int x, int y, int fryNum = 0) { //设置到抓菜处 - if(!SetArmPosition(x, y)) + if (!SetArmPosition(x, y)) + { + return; + } + + if (!GetDistance(x)) + { + MessageLog.GetInstance.Show("错误:获取传感器数据出错"); + return; + } + + Thread.Sleep(200); + + if (!GetDistance(x)) { + MessageLog.GetInstance.Show("错误:获取传感器数据出错"); return; } - //获取传感器的距离 + Thread.Sleep(1000); + + //获取传感器的距离,转换成坐标系的点 int laserHigh = ml_morkf.LaserDistance; + MessageLog.GetInstance.Show($"传感器的距离{laserHigh}"); + + if (laserHigh > 29) + { + MessageLog.GetInstance.Show("错误:传感器获取数据大于隔板与传感器之间的距离"); + return; + } + + int moveX = 0; + if (LaserDistance2Coordinate(laserHigh, out moveX) != Laser2CoordinateState.MaterialNormal) + { + MessageLog.GetInstance.Show("错误:传感器距离转坐标值失败"); + return; + } + + if(x < moveX) + { + MessageLog.GetInstance.Show("错误:传感器距离转坐标值大于当前x轴坐标"); + return; + } + //设置到传感器感应的距离处 - if(!SetArmPosition(x+ laserHigh, y )) + if (!SetArmPosition(x - moveX, y)) { return; } @@ -932,14 +1112,16 @@ namespace BPASmartClient.MorkF //Electromagnetism(new List { true }); //Thread.Sleep(500); +#if true //爪子去1号位抓菜 - if (!GetDistance_1()) + if (!PawToPoint1()) { return; } +#endif //设置到该层菜品库最高处 - if (!SetArmPosition(x + materialHigh, y)) + if (!SetArmPosition(x - materialHigh, y)) { return; } @@ -948,85 +1130,159 @@ namespace BPASmartClient.MorkF //Electromagnetism(new List { false }); //Thread.Sleep(500); +#if true //爪子去2号位放菜 - if (!GetDistance_2()) + if (!PawToPoint2()) { return; } +#endif + ////判断炒锅是否可以放盒 + //for(int i = 0;materialSleepCount > i && !morkFs[fryIndex].FryPot1_HOBTPut;i++) + //{ + // Thread.Sleep(materialSleepTime); + // if (i >= materialSleepCount - 1) + // { + // MessageLog.GetInstance.Show("等待炒锅允许放盒超时"); + // return; + // } + //} + + //关闭启磁吸 + MagnetOff(fryNum); + + Thread.Sleep(200); //根据炒锅不同设置不同的出菜处 - if (fryNum == 0) + if (fryNum % 2 == 0) { - //设置到炒锅1出菜处 - if (!SetArmPosition(materialPutPositionXFry1, materialPutPositionYFry1)) - { - return; - } + x = materialPutPositionXFry1; + y = materialPutPositionYFry1; } else { - //设置到炒锅2出菜处 - if (!SetArmPosition(materialPutPositionXFry1, materialPutPositionYFry1)) - { - return; - } + x = materialPutPositionXFry2; + y = materialPutPositionYFry2; + } + + //设置到炒锅1出菜处 + if (!SetArmPosition(x, y)) + { + return; } +#if true //爪子去3号位放菜 - if (!GetDistance_3()) + if (!PawToPoint3()) { return; } +#endif + + //开启磁吸 + MagnetOn(fryNum); + + Thread.Sleep(200); + //设置到炒锅1出菜处 + if (!SetArmPosition(x + materialToFryDistance, y)) + { + return; + } + +#if true + //爪子回到2号位 + if (!PawToPoint2()) + { + return; + } +#endif ////关闭电磁阀 //Electromagnetism(new List { false }); //Thread.Sleep(300); - if(morkFs.ContainsKey(fryNum)) + if (morkFs.ContainsKey(fryNum)) { morkFs[fryNum].GetMaterialComplete = true; } } /// - /// 获取菜品测试 + /// 传感器距离转为x轴坐标系 /// - /// - private void GetMaterailTest(int getNum) + /// + /// + /// + public Laser2CoordinateState LaserDistance2Coordinate(int distance,out int x) { - ThreadManage.GetInstance().Start(new Action(()=>{ - int x1 = 0, x2 = 0, y= 0; - - for (int i = 0; i < sleepCount * 2 && ml_morkf.MaterailIsWorking; i++) + x = 0; + try + { + //菜盒放多了 + if (distance<6) { - Thread.Sleep(sleepTime); - if (i >= sleepCount * 2 - 1) - { - MessageLog.GetInstance.Show("菜品库正在工作中....."); - return; - } + return Laser2CoordinateState.MaterialOverdo; } - - //if (!ml_morkf.InitialComplete) - //{ - // MessageLog.GetInstance.Show("菜品库未初始化"); - // return; - //} - if (getNum == 0) + else if (distance >= 6 && distance < 10) { - x2 = -20000; - y = 40000; - + x = 24882; + return Laser2CoordinateState.MaterialNormal; + } + else if(distance>=10 && distance < 14) + { + x = 18661; + return Laser2CoordinateState.MaterialNormal; + } + else if(distance >= 14 && distance < 19) + { + x = 12441; + return Laser2CoordinateState.MaterialNormal; + } + else if (distance >= 19 && distance < 23) + { + x = 6220; + return Laser2CoordinateState.MaterialNormal; } - else if (getNum == 1) + else if (distance >= 23 && distance < 28) { - x2 = -15000; - y = -52500; + x = 0; + return Laser2CoordinateState.MaterialNormal; } else { - MessageLog.GetInstance.Show("菜品库无效操作"); - return; + return Laser2CoordinateState.MaterialEmpty; } + } + catch(Exception ex) + { + return Laser2CoordinateState.MaterialUnkown; + } + } + + /// + /// 获取菜品测试 + /// + /// + private void GetMaterailTest(Coordinate coordinate) + { + ThreadManage.GetInstance().Start(new Action(() => { + //int x1 = 0, x2 = 0, y = 0; + + //if (getNum % 2 == 0) + //{ + // x2 = 35000; + // y = 82000; + + //} + //else if (getNum % 2 == 1) + //{ + // x2 = 35000; + // y = 9000; + //} + //else + //{ + // MessageLog.GetInstance.Show("菜品库无效操作"); + // return; + //} try { lock (lock_Materail) @@ -1034,14 +1290,14 @@ namespace BPASmartClient.MorkF ml_morkf.MaterailIsWorking = true; } //取菜操作 - GetMaterail(x2,y); + GetMaterail(coordinate.X, coordinate.Y); - //机械臂回原点 - if (!SetArmPosition(0, 0)) - { - MessageLog.GetInstance.Show("菜品库[机械臂操作失败]"); - return; - } + ////机械臂回原点 + //if (!SetArmPosition(0, 0)) + //{ + // MessageLog.GetInstance.Show("菜品库[机械臂操作失败]"); + // return; + //} } catch (Exception ex) { @@ -1055,7 +1311,7 @@ namespace BPASmartClient.MorkF } } - }),$"菜品库操作{getNum}"); + }), $"菜品库操作"); } #endregion @@ -1220,9 +1476,9 @@ namespace BPASmartClient.MorkF } int i = 0; //判断是否完成取菜 - for (i = 0; i < sleepCount*2 && !morkFs[num].GetMaterialComplete; i++) + for (i = 0; i < sleepCount * 2 && !morkFs[num].GetMaterialComplete; i++) { - if(i == 3) + if (i == 3) { //停止搅拌 StopStir(num); @@ -1283,16 +1539,9 @@ namespace BPASmartClient.MorkF } } - //while (!morkFs[num].ArmOnOrigin) - //{ - // Thread.Sleep(200); - //} FirePot_Write("LB5", false, num); Thread.Sleep(200); MessageLog.GetInstance.Show("搅拌臂到达原点位"); - - - } //搅拌臂去炒制位 @@ -1384,7 +1633,18 @@ namespace BPASmartClient.MorkF } } - #endregion + public void MagnetOn(int num) + { + FirePot_Write("LB8", false, num); + Thread.Sleep(200); + } + + public void MagnetOff(int num) + { + FirePot_Write("LB8", true, num); + Thread.Sleep(200); + } +#endregion bool isInitialArrive = false; @@ -1632,7 +1892,6 @@ namespace BPASmartClient.MorkF } #endregion - private object lock_MainProcessExcute = new object(); /// @@ -1646,7 +1905,7 @@ namespace BPASmartClient.MorkF //遍历炒锅,找到合适、空闲的炒锅 for(int i = 0;i { try { + MessageLog.GetInstance.Show($"炒锅{i}开始炒制菜品{res.GoodName}"); + + Coordinate myCoordinate = new Coordinate(); int getMaterailNum = 0; foreach (var potActions in res.StirPotActions) { - if (ThreadManage.GetInstance().IsCanncel(String.Format(striConst, i.ToString(), nowStirFryGood.GoodName))) + if (ThreadManage.GetInstance().IsCanncel(String.Format(striConst, i.ToString(), nowStirFryGood[i].GoodName))) { return; } @@ -1744,8 +2004,22 @@ namespace BPASmartClient.MorkF case nameof(StirFryPotActionEnum.取原料): //炒锅取菜状态置为未取到 morkFs[i].GetMaterialComplete = false; - materialOperationQuenes.Enqueue(new MaterialOperation() { fryNum = i, x = 0, y = 0 }); - getMaterailNum++; + if(getMaterailNum == 0) + { + if (NoMaterial2Coordinate("A2", out myCoordinate)) + { + materialOperationQuenes.Enqueue(new MaterialOperation() { fryNum = i, coordinate = myCoordinate }); + getMaterailNum++; + } + } + else if(getMaterailNum == 1) + { + if (NoMaterial2Coordinate("B2", out myCoordinate)) + { + materialOperationQuenes.Enqueue(new MaterialOperation() { fryNum = i, coordinate = myCoordinate }); + getMaterailNum++; + } + } MessageLog.GetInstance.Show(potActions.Actions); break; case nameof(StirFryPotActionEnum.开启搅拌): @@ -1794,18 +2068,11 @@ namespace BPASmartClient.MorkF } } - Plc1Reset(i);//复位 Thread.Sleep(3000); //回原点位 StirArmGoOrigin(i); - //while (!morkFs[i].ArmOnOrigin) - //{ - // Thread.Sleep(100); - //} - //出餐 - //OutMeal(i); MessageLog.GetInstance.Show($"菜品{res.GoodName}完成"); @@ -1817,12 +2084,12 @@ namespace BPASmartClient.MorkF } finally { - nowStirFryGood = null; + nowStirFryGood[i] = null; //炒完后出队列 morkFs[i].StirFryGoodsQuenes.TryDequeue(out var orderQueue); morkFs[i].FryWorking = false; } - }), String.Format(striConst, i.ToString(), nowStirFryGood.GoodName)/*$"炒锅{i}炒制{res.GoodName}线程"*/); + }), String.Format(striConst, i.ToString(), nowStirFryGood[i].GoodName)/*$"炒锅{i}炒制{res.GoodName}线程"*/); } } break; @@ -1831,6 +2098,8 @@ namespace BPASmartClient.MorkF } } + private int testNum = 0; + /// /// 菜品库主流程 /// @@ -1849,7 +2118,8 @@ namespace BPASmartClient.MorkF //ThreadManage.GetInstance().Start(new Action(()=>{ // GetMaterail(res.x, res.y, res.fryNum); //}),"菜品库操作"); - GetMaterailTest(res.fryNum); + GetMaterailTest(res.coordinate); + testNum++; } } } @@ -1861,121 +2131,131 @@ namespace BPASmartClient.MorkF private void SingleProcess() { - //if (!morkF.AutoMode) - //{ - // if (morkF.IsAuto) - // { - // Plc1Reset(); - // morkF.IsAuto = false; - // } - //} - //else morkF.IsAuto = true; + } + private void ScreenDataServer() + { + LocalMqtt.GetInstance.Init(ScreenDeviceType.大炒); + ThreadManage.GetInstance().StartLong(new Action(() => + { + List statsModels = new List(); + statsModels.Add(new StatsModel() { Name = "帝王蟹", Count = 666 }); + ScreenModelMinWok maxWok = new ScreenModelMinWok + { + IsRun = new Random().Next(0, 2) == 0 ? IsRun.运行 : IsRun.停止, //设备是否运行 + WorkStatus_1 = (WorkStatus)new Random().Next(0, 3), //设备运行状态 + WorkStatus_2 = (WorkStatus)new Random().Next(0, 3), //设备运行状态 + RobotStatu = (WorkStatus)new Random().Next(0, 3), //机器人状态 待机 1 正常 + Alarm = new List(), //告警集合 + FailuresCount = 0, //故障数 + StatsCount = statsModels, //统计菜品数量 + MinWok_Dishes_1 = "满汉全席",//当前炒制菜品名 + MinWok_Dishes_2 = "海鲜大餐", + MinWok_Task_1 = "炒制菜品",//当前任务 + MinWok_Task_2 = "热油", //当前任务 + MinWok_Process_1 = new List(), //炒锅当前任务流程 + MinWok_Process_2 = new List(), //炒锅当前任务流程 + MinWok_HeatGear_1 = new Random().Next(0, 5).ToString(), //炒锅加热档位 + MinWok_HeatGear_2 = new Random().Next(0, 5).ToString(), //炒锅加热档位 + MinWok_StirGear_1 = new Random().Next(0, 5).ToString(), //炒锅搅拌档位 + MinWok_StirGear_2 = new Random().Next(0, 5).ToString(), //炒锅搅拌档位 + MinWok_OrderCount_1 = 2, //订单数量 + MinWok_OrderCount_2 = 2, //订单数量 + MinWok_ErrorOrderCount_1 = 0, //异常订单数量 + MinWok_ErrorOrderCount_2 = 0, //异常订单数量 + + }; + LocalMqtt.GetInstance.Publish(maxWok); + Thread.Sleep(1000); + + }), "大屏数据上报"); } public override void SimOrder() { - ActionManage.GetInstance.Register(morkSim, "模拟小炒锅1订单"); + } - private void morkSim(object o) + /// + /// 菜品编号转换为坐标 + /// + /// + /// + /// + public bool NoMaterial2Coordinate(string no,out Coordinate coordinate) { - //if (o == null) return; - //if(o is List ins) - //{ - // ThreadManage.GetInstance().Start(new Action(() => - // { - // if (morkF.FryPot1_InitialComplete && morkF.AutoMode)//初始化完成&&自动模式&& 锅在原点位置 - // { - // if (!morkF.ArmOnWorking)//搅拌臂是否在工作位 - // { - // StirArmGoWork(); - - // while (!morkF.ArmOnWorking) - // { - // Thread.Sleep(500); - // } - // OutSeasoning(new List { 1, 100 });//加油500g - // while (!morkF.PassWay1_1Compelete) - // { - // Thread.Sleep(1000); - // } - // WriteControlExact(morkF.StartPassWay[ 1], false);//开启通道关闭 - // Thread.Sleep(500); - // SetFire(new List { ins[1] });//加热三档 - - // StartFire();//开始加热 - // Thread.Sleep(500); - // SetStir(new List { ins[2] });//搅拌二挡 - // Thread.Sleep(500); - // StartStir();//开始搅拌 - // Thread.Sleep(ins[0]*1000);//加热10s - - // OutSeasoning(new List { 11, 30 });//加调料1 50g - // Thread.Sleep(400); - // OutSeasoning(new List { 12, 30 });//加调料2 30g - // while (!morkF.PassWay1_11Compelete&& !morkF.PassWay1_12Compelete) - // { - // Thread.Sleep(1000); - // } - - - - - // WriteControlExact(morkF.StartPassWay[11], false);//开启通道关闭 - // Thread.Sleep(500); - // WriteControlExact(morkF.StartPassWay[12], false);//开启通道信号关闭 - - - - // Thread.Sleep(500); - - // OutFood();//倒菜品1 - // while (!morkF.FryPot1_MaterialIntoPot)//菜品1倒菜完成 - // { - // Thread.Sleep(500); - // } - // WriteControlExact("LB53", false); - // Thread.Sleep(500); - // SetFire(new List { ins[4] });//菜品1加热档 - // Thread.Sleep(500); - // SetStir(new List() { ins[5] });//菜品1搅拌挡 - // Thread.Sleep(ins[3]*1000);//菜品1炒制时间 - - // OutSeasoning(new List {3, 8 });//加调料3 20g - // while (!morkF.PassWay1_3Compelete) - // { - // Thread.Sleep(1000); - // } - // WriteControlExact(morkF.StartPassWay[3], false);//开启通道信号关闭 - // Thread.Sleep(500); - // OutFood();//倒菜菜品2 - // while (!morkF.FryPot1_MaterialIntoPot)//菜品2倒菜完成 - // { - // Thread.Sleep(500); - // } - // WriteControlExact("LB53", false); - // Thread.Sleep(500); - // SetFire(new List { ins[7] });//菜品2加热档 - // Thread.Sleep(500); - // SetStir(new List() { ins[8] });//菜品2搅拌挡 - // Thread.Sleep(ins[6] * 1000);//菜品2炒制时间 - - - - // StopStir();//停止搅拌 - // Thread.Sleep(500); - // StopFire();//停止加热 - // Thread.Sleep(2000); - // StirArmGoOrigin();//搅拌臂回原点位 - // } - // } - // }), "模拟炒锅1订单"); - //} - - + //默认返回0,0 + coordinate = new Coordinate(); + coordinate.X = 0; + coordinate.Y = 0; + + try + { + if(dicNoMaterialCoordinate.ContainsKey(no)) + { + coordinate = dicNoMaterialCoordinate[no]; + return true; + } + else + { + return false; + } + } + catch (Exception ex) + { + return false; + } + finally + { + + } + } + + /// + /// 每个取菜点的编号与坐标字典 + /// + private static Dictionary dicNoMaterialCoordinate { get; set; } = new Dictionary() + { + {"A1",new Coordinate(){ X = 34500,Y=0} }, + {"A2",new Coordinate(){ X = 34500,Y=9000} }, + {"A3",new Coordinate(){ X = 34500,Y=0} }, + {"B1",new Coordinate(){ X = 34500,Y=0} }, + {"B2",new Coordinate(){ X = 34500,Y=83000} }, + {"B3",new Coordinate(){ X = 34500,Y=0} }, + {"C1",new Coordinate(){ X = 34500,Y=0} }, + {"C2",new Coordinate(){ X = 34500,Y=0} }, + {"C3",new Coordinate(){ X = 34500,Y=0} }, + {"D1",new Coordinate(){ X = 0,Y=0} }, + {"D2",new Coordinate(){ X = 0,Y=0} }, + {"D3",new Coordinate(){ X = 0,Y=0} }, + {"E1",new Coordinate(){ X = 0,Y=0} }, + {"E2",new Coordinate(){ X = 0,Y=0} }, + {"E3",new Coordinate(){ X = 0,Y=0} }, + {"F1",new Coordinate(){ X = 0,Y=0} }, + {"F2",new Coordinate(){ X = 0,Y=0} }, + {"F3",new Coordinate(){ X = 0,Y=0} }, + {"G1",new Coordinate(){ X = 0,Y=0} }, + {"G2",new Coordinate(){ X = 0,Y=0} }, + {"G3",new Coordinate(){ X = 0,Y=0} }, + {"H1",new Coordinate(){ X = 0,Y=0} }, + {"H2",new Coordinate(){ X = 0,Y=0} }, + {"H3",new Coordinate(){ X = 0,Y=0} }, + {"I1",new Coordinate(){ X = 0,Y=0} }, + {"I2",new Coordinate(){ X = 0,Y=0} }, + {"I3",new Coordinate(){ X = 0,Y=0} }, + {"J1",new Coordinate(){ X = 0,Y=0} }, + {"J2",new Coordinate(){ X = 0,Y=0} }, + {"J3",new Coordinate(){ X = 0,Y=0} }, + }; + + public enum Laser2CoordinateState + { + MaterialOverdo = 0,//菜品过量 + MaterialNormal = 1,//菜品正常 + MaterialEmpty = 2,//菜品为空 + MaterialUnkown = 999,//菜品未知错误 } } } \ No newline at end of file diff --git a/BPASmartClient.MorkF/ML_MorkF.cs b/BPASmartClient.MorkF/ML_MorkF.cs index 74a66a0a..b7a6b624 100644 --- a/BPASmartClient.MorkF/ML_MorkF.cs +++ b/BPASmartClient.MorkF/ML_MorkF.cs @@ -43,17 +43,7 @@ namespace BPASmartClient.MorkF { get { - var ret = _ArriveComplete; - _ArriveComplete = false; - if(ret) - { - MessageLog.GetInstance.Show("到达上升沿为true"); - } - else - { - MessageLog.GetInstance.Show("到达上升沿为false"); - } - return ret; + return _ArriveComplete; } set { diff --git a/BPASmartClient.MorkF/MaterialOperation.cs b/BPASmartClient.MorkF/MaterialOperation.cs index 83b1a6d9..130546bd 100644 --- a/BPASmartClient.MorkF/MaterialOperation.cs +++ b/BPASmartClient.MorkF/MaterialOperation.cs @@ -6,19 +6,20 @@ using System.Threading.Tasks; namespace BPASmartClient.MorkF { + public class Coordinate + { + public int X { get; set; } = 0; + + public int Y { get; set; } = 0; + } + /// /// 菜品库操作类 /// internal class MaterialOperation { - /// - /// x轴坐标 - /// - public int x; - /// - /// y轴坐标 - /// - public int y; + public Coordinate coordinate { get; set; } = new Coordinate(); + /// /// 炒锅编号 /// diff --git a/BPASmartClient.MorkF/View/DebugView.xaml b/BPASmartClient.MorkF/View/DebugView.xaml index 63ad05c5..9b3ad9a5 100644 --- a/BPASmartClient.MorkF/View/DebugView.xaml +++ b/BPASmartClient.MorkF/View/DebugView.xaml @@ -89,7 +89,7 @@ diff --git a/BPASmartClient.MorkF/ViewModel/DebugViewModel.cs b/BPASmartClient.MorkF/ViewModel/DebugViewModel.cs index 091de4ac..575d8167 100644 --- a/BPASmartClient.MorkF/ViewModel/DebugViewModel.cs +++ b/BPASmartClient.MorkF/ViewModel/DebugViewModel.cs @@ -96,6 +96,9 @@ namespace BPASmartClient.MorkF.ViewModel public RelayCommand PawTurnBack { get; set; }//夹爪反转 public RelayCommand SetArmPosition { get; set; }//机器臂位置设定 public RelayCommand ArmRun { get; set; }//机械臂运动 + public RelayCommand PawToPoint1 { get; set; }//感应测距1 + public RelayCommand PawToPoint2 { get; set; }//感应测距2 + public RelayCommand PawToPoint3 { get; set; }//感应测距3 #endregion @@ -207,8 +210,11 @@ namespace BPASmartClient.MorkF.ViewModel StopElectromagnetism = new RelayCommand(() => { ActionManage.GetInstance.Send("Electromagnetism", new List { true });});//电磁阀关闭 SetSpeed = new RelayCommand(() => { - ActionManage.GetInstance.Send("SetSpeed", new List { MoveSpeed }); + ActionManage.GetInstance.Send("SetSpeed", new List { MoveSpeed }); });//设定速度 + PawToPoint1 = new RelayCommand(() => { ActionManage.GetInstance.Send("PawToPoint1"); });//爪子去1号位 + PawToPoint2 = new RelayCommand(() => { ActionManage.GetInstance.Send("PawToPoint2"); });//爪子去2号位 + PawToPoint3 = new RelayCommand(() => { ActionManage.GetInstance.Send("PawToPoint3"); });//爪子去3号位 GetDistance_1 = new RelayCommand(() => { ActionManage.GetInstance.Send("GetDistance_1"); });//感应距离1 GetDistance_2 = new RelayCommand(() => { ActionManage.GetInstance.Send("GetDistance_2"); });//感应距离2 GetDistance_3 = new RelayCommand(() => { ActionManage.GetInstance.Send("GetDistance_3"); });//感应距离3