diff --git a/BPASmartClient.MorkF/Control_MorkF.cs b/BPASmartClient.MorkF/Control_MorkF.cs index 36e22b15..42b1c2ea 100644 --- a/BPASmartClient.MorkF/Control_MorkF.cs +++ b/BPASmartClient.MorkF/Control_MorkF.cs @@ -15,9 +15,11 @@ namespace BPASmartClient.MorkF public class Control_MorkF : BaseDevice { public override DeviceClientType DeviceType => DeviceClientType.MORKSF; - + public AutoResetEvent minorReset = new AutoResetEvent(false); + public AutoResetEvent mainReset = new AutoResetEvent(false); GVL_MorkF morkF = new GVL_MorkF();//全局对象声明 public StirFryBom stirFryBom = new StirFryBom();//创建获取流程的对象 + List resultorder = new List();//调试变量 public static readonly object taskLock = new object(); /// @@ -63,17 +65,17 @@ namespace BPASmartClient.MorkF //流程 stirFryBom.AddAction(new StirFryAction() { Time = StirFryTime.T1, RobotActions = new List() { StirFryRobotAction.清洗槽取锅 } }); stirFryBom.AddAction(new StirFryAction() { Time = StirFryTime.T2, PotActions = new List() { StirFryPotAction.大火持续 }, During = 5 }); - stirFryBom.AddAction(new StirFryAction() { Time = StirFryTime.T3, RobotActions = new List() { StirFryRobotAction.加入A料 }, PotActions = new List() { StirFryPotAction.加油,StirFryPotAction.搅拌臂下位, StirFryPotAction.低速旋转 }, During = 6 }); + stirFryBom.AddAction(new StirFryAction() { Time = StirFryTime.T3, RobotActions = new List() { StirFryRobotAction.加入A料 }, PotActions = new List() { StirFryPotAction.加油, StirFryPotAction.搅拌臂下位, StirFryPotAction.低速旋转 }, During = 6 }); stirFryBom.AddAction(new StirFryAction() { Time = StirFryTime.T4, PotActions = new List() { StirFryPotAction.停止旋转, StirFryPotAction.停止火力, StirFryPotAction.搅拌臂上位 } });//加A料 stirFryBom.AddAction(new StirFryAction() { Time = StirFryTime.T5, RobotActions = new List() { StirFryRobotAction.加入B料 }, PotActions = new List() { StirFryPotAction.中火持续, StirFryPotAction.搅拌臂下位, StirFryPotAction.快速旋转 }, During = 6 }); - stirFryBom.AddAction(new StirFryAction() { Time = StirFryTime.T6, PotActions = new List() {StirFryPotAction.停止火力, StirFryPotAction.停止旋转, StirFryPotAction.搅拌臂上位 } });//加B料 + stirFryBom.AddAction(new StirFryAction() { Time = StirFryTime.T6, PotActions = new List() { StirFryPotAction.停止火力, StirFryPotAction.停止旋转, StirFryPotAction.搅拌臂上位 } });//加B料 - stirFryBom.AddAction(new StirFryAction() { Time = StirFryTime.T7, RobotActions = new List() { StirFryRobotAction.加入C料 }, PotActions = new List() {StirFryPotAction.中火持续, StirFryPotAction.搅拌臂下位, StirFryPotAction.快速旋转 }, During = 9 }); + stirFryBom.AddAction(new StirFryAction() { Time = StirFryTime.T7, RobotActions = new List() { StirFryRobotAction.加入C料 }, PotActions = new List() { StirFryPotAction.中火持续, StirFryPotAction.搅拌臂下位, StirFryPotAction.快速旋转 }, During = 9 }); stirFryBom.AddAction(new StirFryAction() { Time = StirFryTime.T8, PotActions = new List() { StirFryPotAction.停止火力, StirFryPotAction.停止旋转, StirFryPotAction.搅拌臂上位 } });//加C料 - stirFryBom.AddAction(new StirFryAction() { Time = StirFryTime.T9, PotActions = new List() {StirFryPotAction.中火持续,StirFryPotAction.搅拌臂下位, StirFryPotAction.快速旋转 }, During = 30 }); - stirFryBom.AddAction(new StirFryAction() { Time = StirFryTime.T10, PotActions = new List() { StirFryPotAction.停止火力, StirFryPotAction.停止旋转, StirFryPotAction.搅拌臂上位 }}); + stirFryBom.AddAction(new StirFryAction() { Time = StirFryTime.T9, PotActions = new List() { StirFryPotAction.中火持续, StirFryPotAction.搅拌臂下位, StirFryPotAction.快速旋转 }, During = 30 }); + stirFryBom.AddAction(new StirFryAction() { Time = StirFryTime.T10, PotActions = new List() { StirFryPotAction.停止火力, StirFryPotAction.停止旋转, StirFryPotAction.搅拌臂上位 } }); stirFryBom.AddAction(new StirFryAction() { Time = StirFryTime.T11, RobotActions = new List() { StirFryRobotAction.灶取锅 } }); } /// @@ -118,14 +120,14 @@ namespace BPASmartClient.MorkF stirFryBom.AddAction(new StirFryAction() { Time = StirFryTime.T2, RobotActions = new List() { StirFryRobotAction.加入A料 }, PotActions = new List() { StirFryPotAction.中火持续, StirFryPotAction.搅拌臂下位, StirFryPotAction.低速旋转 }, During = 5 }); stirFryBom.AddAction(new StirFryAction() { Time = StirFryTime.T3, PotActions = new List() { StirFryPotAction.加油 }, During = 12 }); stirFryBom.AddAction(new StirFryAction() { Time = StirFryTime.T4, PotActions = new List() { StirFryPotAction.停止旋转, StirFryPotAction.搅拌臂上位 } });//加A料 - stirFryBom.AddAction(new StirFryAction() { Time = StirFryTime.T6,RobotActions = new List() { StirFryRobotAction.加入B料 }, PotActions = new List() { StirFryPotAction.搅拌臂下位, StirFryPotAction.快速旋转 }, During = 25 }); + stirFryBom.AddAction(new StirFryAction() { Time = StirFryTime.T6, RobotActions = new List() { StirFryRobotAction.加入B料 }, PotActions = new List() { StirFryPotAction.搅拌臂下位, StirFryPotAction.快速旋转 }, During = 25 }); stirFryBom.AddAction(new StirFryAction() { Time = StirFryTime.T7, PotActions = new List() { StirFryPotAction.停止旋转, StirFryPotAction.搅拌臂上位 } });//加B料 - + stirFryBom.AddAction(new StirFryAction() { Time = StirFryTime.T9, RobotActions = new List() { StirFryRobotAction.加入C料 }, PotActions = new List() { StirFryPotAction.搅拌臂下位, StirFryPotAction.快速旋转 }, During = 30 }); stirFryBom.AddAction(new StirFryAction() { Time = StirFryTime.T10, PotActions = new List() { StirFryPotAction.停止火力, StirFryPotAction.停止旋转, StirFryPotAction.搅拌臂上位 } });//加C料 - stirFryBom.AddAction(new StirFryAction() { Time = StirFryTime.T6,PotActions = new List() { StirFryPotAction.搅拌臂下位, StirFryPotAction.快速旋转 }, During = 55 }); + stirFryBom.AddAction(new StirFryAction() { Time = StirFryTime.T6, PotActions = new List() { StirFryPotAction.搅拌臂下位, StirFryPotAction.快速旋转 }, During = 55 }); stirFryBom.AddAction(new StirFryAction() { Time = StirFryTime.T11, RobotActions = new List() { StirFryRobotAction.灶取锅 } }); } public void TakePot() @@ -369,7 +371,7 @@ namespace BPASmartClient.MorkF } } - //根据ID 查找对应制作流程 + //根据ID 查找对应制作流程, } }); @@ -382,20 +384,144 @@ namespace BPASmartClient.MorkF { TakePlatelTask(); TurntableControl(); - ProcessExecute(); + MainProcessExecute(); + MinorProcessExcute(); SingleProcess(); } - //机器人,锅灶流程执行 - public void ProcessExecute() + //辅流程执行 + private void MinorProcessExcute() { - if (!morkF.ProcessExcuteLock) + if (!morkF.MinorProcessExcuteLock) { - morkF.ProcessExcuteLock = true; + morkF.MinorProcessExcuteLock = true; + Task.Run(() => + { + if (morkF.MinorProcessFlag && !morkF.RoobotIdle && morkF.TakeMaterialQueue.Count > 0) + { + morkF.MinorProessStatus = true; + morkF.MainProcessStatus = false; + StirFryBom bom = morkF.listStirBom.ElementAt(0); + morkF.listStirBom.RemoveAt(0); + foreach (var res in bom.StirFryActions) + { + MessageLog.GetInstance.Show($"执行流程{res.Time}"); + //机器人线程 + Task taskRobot = Task.Run(new Action(() => + { + foreach (var temp in res.RobotActions) + { + switch (temp) + { + case StirFryRobotAction.清洗槽取锅: + TakePotTask();//执行取锅操作 + break; + case StirFryRobotAction.加入A料: + TakeBurdenATask();//执行取A料操作 + break; + case StirFryRobotAction.加入B料: + TakeBurdenATask();//执行取B料操作 + break; + case StirFryRobotAction.加入C料: + TakeBurdenCTask();//执行取C料操作 + break; + case StirFryRobotAction.灶取锅: + OutDishTask();//执行出餐操作 + CleanPotTask();//洗锅操作 + break; + } + + } + + })); + //炒锅线程操作 + Task taskPot = Task.Run(new Action(() => + { + foreach (var temp in res.PotActions) + { + switch (temp) + { + case StirFryPotAction.NONE: + break; + case StirFryPotAction.大火t1s: + KitchenAdjustGears(3); + Task.Delay(1000).Wait(); //大火加热1s//执行大火锅干操作 + break; + case StirFryPotAction.加油: + AddOil();//注油//执行加油操作 + break; + case StirFryPotAction.中火t2s: + KitchenAdjustGears(2); + Task.Delay(2000).Wait();//执行操作 + break; + case StirFryPotAction.小火持续: + KitchenAdjustGears(1); + break; + case StirFryPotAction.中火持续: + KitchenAdjustGears(5); + break; + case StirFryPotAction.大火持续: + KitchenAdjustGears(7); + break; + case StirFryPotAction.停止火力: + KitchenAdjustGears(0);//关闭灶加热 + break; + case StirFryPotAction.搅拌臂上位: + TurnUpStatusDetect();//执行搅拌臂上位操作 + break; + case StirFryPotAction.搅拌臂下位: + TurnDownStatusDetect();//执行搅拌臂下位操作 + break; + case StirFryPotAction.低速旋转: + TurnMachineGearsControl(1);//执行搅拌臂速度1挡操作 + break; + case StirFryPotAction.快速旋转: + TurnMachineGearsControl(2);//执行搅拌臂速度3挡操作 + break; + case StirFryPotAction.停止旋转: + TurnMachineGearsControl(0);//执行搅拌臂速度0挡操作 + break; + } + } + })); + Task.WhenAll(taskRobot, taskPot).Wait();//等待所有线程结束 + Task.Delay(res.During * 1000).Wait();//当前流程延迟 + if (morkF.MainProcessWait) + { + + KitchenAdjustGears(0);//关闭灶加热 + morkF.MinorProessStatus = false; + morkF.MainProcessStatus = true; + //阻塞辅流程 + minorReset.WaitOne(); + } + morkF.MinorProessStatus = true; + morkF.MainProcessStatus = false; + } + morkF.MinorOutMealComplete = true; + } + else + { + morkF.MinorProcessExcuteLock = false;//解除辅流程自锁 + } + }); + } + } + + //机器人,锅灶主流程执行 + public void MainProcessExecute() + { + if (!morkF.MainProcessExcuteLock) + { + morkF.MainProcessExcuteLock = true; Task.Run(new Action(() => { - if (!morkF.RoobotIdle && morkF.InitialComplete && morkF.TakeMaterialQueue.Count > 0) + if (!morkF.RoobotIdle && morkF.InitialComplete && morkF.TakeMaterialQueue.Count > 0 && morkF.MainProcessFlag) { - foreach (var res in stirFryBom.StirFryActions)//遍历所有流程 + morkF.MainProcessStatus = true; + morkF.MinorProessStatus = false; + StirFryBom bom = morkF.listStirBom.ElementAt(0); + morkF.listStirBom.RemoveAt(0); + foreach (var res in bom.StirFryActions)//遍历所有流程 { MessageLog.GetInstance.Show($"执行流程{res.Time}"); //机器人线程 @@ -416,7 +542,6 @@ namespace BPASmartClient.MorkF break; case StirFryRobotAction.加入C料: TakeBurdenCTask();//执行取C料操作 - break; case StirFryRobotAction.灶取锅: OutDishTask();//执行出餐操作 @@ -477,14 +602,26 @@ namespace BPASmartClient.MorkF } } })); + Task.WhenAll(taskRobot, taskPot).Wait();//等待所有线程结束 - Task.Delay(res.During * 1000).Wait();//当前流程延迟 + Task.Delay(res.During * 1000).Wait();//当前流程延迟 + if (morkF.MinorProcessWait) + { + KitchenAdjustGears(0);//关闭灶加热 + morkF.MinorProessStatus = true; + morkF.MainProcessStatus = false; + //阻塞主流程 + mainReset.WaitOne(); + } + morkF.MinorProessStatus = false; + morkF.MainProcessStatus = true; + } - morkF.OutMealComplete = true; + morkF.MainOutMealComplete = true; } else { - morkF.ProcessExcuteLock = false;//解除流程互锁 + morkF.MainProcessExcuteLock = false;//解除流程自锁 } })); } @@ -498,13 +635,20 @@ namespace BPASmartClient.MorkF //出餐完成,相应变量复位 - if (morkF.OutMealComplete) + if (morkF.MainOutMealComplete) { morkF.TakePlateLock = false; - morkF.TakePotLock = false; morkF.PotInPlace = false; - morkF.ProcessExcuteLock = false; - morkF.SingelOrderMaterialCom = false; + morkF.MainProcessExcuteLock = false; + morkF.MainOrderMaterialCom = false; + } + + if (morkF.MinorOutMealComplete) + { + morkF.TakePlateLock = false; + morkF.PotInPlace = false; + morkF.MinorProcessExcuteLock = false; + morkF.MinorOrderMaterialCom = false; } } @@ -564,8 +708,9 @@ namespace BPASmartClient.MorkF StartTakePlate(); morkF.CurrentOrderId = order.SuborderId; morkF.TakePlateLock = true; //订单完成后置false - morkF.OutMealComplete = false; - // OrderChange(morkF.CurrentOrderId, ORDER_STATUS.COOKING); + morkF.MainOutMealComplete = false; + morkF.MinorOutMealComplete = false; + // OrderChange(morkF.CurrentOrderId, ORDER_STATUS.COOKING); MessageLog.GetInstance.Show($"订单【{ morkF.CurrentOrderId}】执行取碗控制"); } } @@ -577,7 +722,11 @@ namespace BPASmartClient.MorkF /// private void TakePotTask() { - while (!(!morkF.CleanModule && !morkF.KitchenOneStatus && morkF.CleanComplete))//等待清洗1准备就绪 + //while (!((!morkF.CleanModule && !morkF.KitchenOneStatus && morkF.CleanComplete) || (!morkF.SecondCleanModule && !morkF.KitchenSecondStatus && morkF.SecondCleanComplete))) + //{ + // Task.Delay(5).Wait(); + //} + while ((!morkF.CleanModule||!morkF.SecondCleanModule)&&(!morkF.KitchenOneStatus||!morkF.KitchenSecondStatus)&&(morkF.CleanComplete|| morkF.SecondCleanComplete))//等待取锅条件满足 { Task.Delay(5).Wait(); } @@ -639,10 +788,10 @@ namespace BPASmartClient.MorkF { Task.Delay(5).Wait(); } - morkF.SingelOrderMaterialCom = false; + morkF.MainOrderMaterialCom = false; WriteData("M14.1", false);//机器人取料完成复位 morkF.TurnTableLock = false;//转台互锁解除 - + } /// @@ -666,7 +815,7 @@ namespace BPASmartClient.MorkF { Task.Delay(5).Wait(); } - morkF.SingelOrderMaterialCom = false; + morkF.MainOrderMaterialCom = false; WriteData("M14.1", false);//机器人取料完成复位 morkF.TurnTableLock = false;//转台互锁解除 //while (!morkF.FallMaterialComplete)//等待倒料完成 @@ -698,7 +847,7 @@ namespace BPASmartClient.MorkF { Task.Delay(5).Wait(); } - morkF.SingelOrderMaterialCom = false; + morkF.MainOrderMaterialCom = false; WriteData("M14.1", false);//机器人取料完成复位 morkF.TurnTableLock = false;//转台互锁解除 //while (!morkF.FallMaterialComplete) @@ -733,17 +882,24 @@ namespace BPASmartClient.MorkF /// private void CleanPotTask() { - - while (!morkF.PlaceRinseTableComplete || morkF.CleanModule) { Task.Delay(5).Wait(); } MessageLog.GetInstance.Show($"订单【{morkF.CurrentOrderId}】出餐完成"); WriteData("M14.2", false);//机器人出餐完成复位 - //OrderChange(morkF.CurrentOrderId, ORDER_STATUS.COMPLETED_COOK); - + //OrderChange(morkF.CurrentOrderId, ORDER_STATUS.COMPLETED_COOK); CleanModuleControl("Start"); + if (morkF.MainProcessStatus)//主流程 + { + morkF.MainProcessFlag = false; + minorReset.Set(); + } + else if (morkF.MinorProessStatus)//辅流程 + { + morkF.MinorProcessFlag = false; + mainReset.Set(); + } } /// /// 任务复位重启 @@ -784,7 +940,14 @@ namespace BPASmartClient.MorkF } WriteData("M8.3", false);//下降完成复位 MessageLog.GetInstance.Show($"翻转机下降完成"); - + //if (morkF.MaterialCount == 3 && morkF.MainProcessStatus) + //{ + // morkF.MainProcessWait = true; + //} + //else if (morkF.MaterialCount == 3 && morkF.MinorProessStatus) + //{ + // morkF.MinorProcessWait = true; + //} } /// @@ -802,17 +965,59 @@ namespace BPASmartClient.MorkF Task.Delay(5).Wait(); } WriteData("M8.1", false);//上升完成复位 - if (!morkF.SingelOrderMaterialCom) + if (morkF.MainProcessStatus)//代表主流程执行的操作 + { + if (!morkF.MainOrderMaterialCom) + { + WriteData("M14.3", true);//倒料 + while (!morkF.FallMaterialComplete)//等待倒料完成 + { + Task.Delay(5).Wait(); + } + morkF.MaterialCount++; + WriteData("M14.3", false);//倒料复位 + if (morkF.MaterialCount == 3) + { + //允许执行下一个订单流程 + morkF.MaterialCount = 0; + morkF.MinorProcessFlag = true; + + } + morkF.MainOrderMaterialCom = true; + MessageLog.GetInstance.Show($"订单【{ morkF.CurrentOrderId}】,配料倒料完成"); + } + else //主流程准备阻塞 + { + morkF.MainProcessWait = true; + } + } + else if (morkF.MinorProessStatus)//代表辅流程执行的操作 { - WriteData("M14.3", true);//倒料 - while (!morkF.FallMaterialComplete)//等待倒料完成 + if (!morkF.MinorOrderMaterialCom) { - Task.Delay(5).Wait(); + WriteData("M14.3", true);//倒料 + while (!morkF.FallMaterialComplete)//等待倒料完成 + { + Task.Delay(5).Wait(); + } + morkF.MaterialCount++; + WriteData("M14.3", false);//倒料复位 + if (morkF.MaterialCount == 3) + { + //允许执行下一个订单流程 + morkF.MaterialCount = 0; + morkF.MainProcessFlag = true; + + } + morkF.MinorOrderMaterialCom = true; + MessageLog.GetInstance.Show($"订单【{ morkF.CurrentOrderId}】,配料倒料完成"); + } + else //辅流程准备阻塞 + { + morkF.MinorProcessWait = true; } - WriteData("M14.3", false);//倒料复位 - morkF.SingelOrderMaterialCom = true; - MessageLog.GetInstance.Show($"订单【{ morkF.CurrentOrderId}】,配料倒料完成"); } + MessageLog.GetInstance.Show("翻转机上升完成"); } diff --git a/BPASmartClient.MorkF/GVL_MorkF.cs b/BPASmartClient.MorkF/GVL_MorkF.cs index 14a3155e..773f54ed 100644 --- a/BPASmartClient.MorkF/GVL_MorkF.cs +++ b/BPASmartClient.MorkF/GVL_MorkF.cs @@ -1,4 +1,5 @@ -using System; +using BPA.Models; +using System; using System.Collections.Concurrent; using System.Collections.Generic; using System.Linq; @@ -25,14 +26,29 @@ namespace BPASmartClient.MorkF /// 清洗模组1状态 忙碌1 空闲0 /// public bool CleanModule { get; set; } + + /// + /// 清洗模组2状态 忙碌1 空闲0 + /// + public bool SecondCleanModule { get; set; } /// /// 清洗模组1完成状态 /// public bool CleanComplete { get; set; } + + // + /// 清洗模组2完成状态 + /// + public bool SecondCleanComplete { get; set; } /// /// 锅灶1状态 忙碌1 空闲0 /// public bool KitchenOneStatus { get; set; } + + /// + /// 锅灶1状态 忙碌1 空闲0 + /// + public bool KitchenSecondStatus { get; set; } /// /// 注油完成状态 /// @@ -159,20 +175,68 @@ namespace BPASmartClient.MorkF /// 转台互锁 /// public bool TurnTableLock { get; set; } - - public bool ProcessExcuteLock { get; set; } + /// + /// 主流程自锁 + /// + public bool MainProcessExcuteLock { get; set; } + /// + /// 辅流程自锁 + /// + public bool MinorProcessExcuteLock { get; set; } /// /// 开始取料标志 /// public bool AllowTakeMaterial { get; set; } /// - /// 当前订单完成标志 + /// 主流程订单完成标志 + /// + public bool MainOutMealComplete { get; set; } + /// + /// 辅流程订单完成标志 + /// + public bool MinorOutMealComplete { get; set; } + /// + /// 主流程订单取料结束 + /// + public bool MainOrderMaterialCom { get; set; } + /// + /// 主流程等待 + /// + public bool MainProcessWait { get; set; } + /// + /// 辅流程等待 + /// + public bool MinorProcessWait { get; set; } + /// + /// 辅流程订单取料结束 + /// + public bool MinorOrderMaterialCom { get; set; } + /// + /// 存储订单对应流程对象 + /// + public List listStirBom=new List(); + + + /// + /// 下配料次数 + /// + public int MaterialCount { get; set; } + /// + /// 允许执行辅流程标识 + /// + public bool MinorProcessFlag { get; set; } + /// + /// 辅流程执行状态 + /// + public bool MinorProessStatus { get; set; } + /// + /// 允许执行主流程标识 /// - public bool OutMealComplete { get; set; } + public bool MainProcessFlag { get; set; } = true; /// - /// 单个订单取料结束 + /// 主流程执行状态 /// - public bool SingelOrderMaterialCom { get; set; } + public bool MainProcessStatus { get; set; } } } diff --git a/BPASmartClient/App.config b/BPASmartClient/App.config index 0004434b..81af1bb0 100644 --- a/BPASmartClient/App.config +++ b/BPASmartClient/App.config @@ -3,7 +3,7 @@ - + diff --git a/BPASmartClient/DeviceInfo.xml b/BPASmartClient/DeviceInfo.xml index f59cf981..e9948716 100644 --- a/BPASmartClient/DeviceInfo.xml +++ b/BPASmartClient/DeviceInfo.xml @@ -43,7 +43,7 @@ --> - + - + + -->-->