|
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160 |
- using System;
- using System.Collections.Generic;
- using System.Configuration;
- using System.Linq;
- using System.Threading;
- using System.Collections.Concurrent;
- using System.Diagnostics;
- using System.Threading.Tasks;
- using BPASmartClient.Device;
- using BPA.Message.Enum;
- using BPA.Message;
- using BPASmartClient.Helper;
- using BPASmartClient.Model.咖啡机.Enum;
- using BPASmartClient.Model;
- using BPASmartClient.EventBus;
- using static BPASmartClient.EventBus.EventBus;
- using BPASmartClient.Message;
- using BPASmartClient.Model.乐白机器人;
- using BPASmartClient.Model.单片机;
- using BPASmartClient.Model.PLC;
- using BPASmartClient.DRCoffee;
- using BPASmartClient.LebaiRobot;
-
- namespace BPASmartClient.MorkT_BarCounter
- {
- /*
- * 冰淇淋咖啡机组合套装
- * 物料位置:
- * 1:冰淇料
- * 2:冰淇淋杯
- * 5:咖啡
- * 6:咖啡杯
- * 9: 茶
- * 10: 茶杯
- */
- public class Control_MorkT_BarCounter : BaseDevice
- {
- private Dictionary<string, PolymerBatching> batchings = new Dictionary<string, PolymerBatching>();
- //容器位置
- private string holderLoc;
- //主料位置
- private string mainMaterialLoc;
- public override global::BPA.Message.Enum.DeviceClientType DeviceType { get { return BPA.Message.Enum.DeviceClientType.MORKT; } }
-
- GVL_MorkT morkTLebaiJC =new GVL_MorkT();
- /// <summary>
- /// 果汁机做法,true:热饮,false:冷饮
- /// </summary>
- private bool GuMake = false;
- /// <summary>
- /// 订单是否加冰
- /// </summary>
- private bool IsAddIce = false;
- public override void DoMain()
- {
- if (Json<KeepDataBase>.Data.IsVerify)
- {
- IsHealth = true;
- }
- IsHealth = true;
- serverInit();
- DataParse();
- ActionManage.GetInstance.Register(new Action<object>((o) => { SimOrder(o); }), "SimOrder");//模拟订单委托注册
- }
-
- private void serverInit()
- {
- EventBus.EventBus.GetInstance().Subscribe<MaterialDeliveryEvent>(DeviceId, delegate (IEvent @event, EventCallBackHandle callBack)
- {
- if (@event == null) return;
- if (@event is MaterialDeliveryEvent material)
- {
- orderMaterialDelivery = material.orderMaterialDelivery;
- }
- });
- }
- private void DataParse()
- {
-
- EventBus.EventBus.GetInstance().Subscribe<DoOrderEvent>(DeviceId, delegate (IEvent @event, EventCallBackHandle callBackHandle)
- {
- if (@event == null) return;
- if (@event is DoOrderEvent order)
- {
- if (order.MorkOrder.GoodBatchings == null) return;
- OrderCount++;
- DeviceProcessLogShow($"接收到{OrderCount}次订单");
- batchings = PolymerBatching.BuildAll();
- //商品类型
- GOODS_TYPE currentGoodsType = GOODS_TYPE.NEITHER;
- foreach (var item in order.MorkOrder.GoodBatchings)
- {
- var res = orderMaterialDelivery?.BatchingInfo?.FirstOrDefault(p => p.BatchingId == item.BatchingId);
- if (res != null)
- {
- //验证商品是做的某种饮料
- if (ValidateGoodsByBatching(res.BatchingLoc) != GOODS_TYPE.NEITHER)
- {
- //获取当前物料所属商品类型
- currentGoodsType = ValidateGoodsByBatching(res.BatchingLoc);
- }
- switch (batchings[res.BatchingLoc].BatchingClass)
- {
- case BATCHING_CLASS.HOLDER:
- holderLoc = res.BatchingLoc;
- break;
- case BATCHING_CLASS.MAIN_MATERIAL:
- mainMaterialLoc = res.BatchingLoc;
- break;
- }
- //根据商品类型执行具体制作流程
- switch (currentGoodsType)
- {
- case GOODS_TYPE.COFFEE:
-
- if (morkTLebaiJC.morkOrderPushesCoffee.FirstOrDefault(p => p.SuborderId == order.MorkOrder.SuborderId) == null)
- {
- morkTLebaiJC.morkOrderPushesCoffee.Enqueue(new OrderLocInfo()
- {
- SuborderId = order.MorkOrder.SuborderId,
- BatchingId = res.BatchingId,
- Loc = ushort.Parse( mainMaterialLoc),
- GoodName = order.MorkOrder.GoodsName,
- });
- }
- break;
- case GOODS_TYPE.JUICE:
-
- if (morkTLebaiJC.morkOrderPushesJuicer.FirstOrDefault(p => p.SuborderId == order.MorkOrder.SuborderId) == null)
- {
- morkTLebaiJC.morkOrderPushesJuicer.Enqueue(new OrderLocInfo()
- {
- SuborderId = order.MorkOrder.SuborderId,
- BatchingId = res.BatchingId,
- Loc = ushort.Parse(mainMaterialLoc),
- GoodName = order.MorkOrder.GoodsName,
- makeID = order.MorkOrder.MakeID,
- });
- }
- break;
- case GOODS_TYPE.TEA:
- if (morkTLebaiJC.morkOrderPushesTea.FirstOrDefault(p => p.SuborderId == order.MorkOrder.SuborderId) == null)
- {
- morkTLebaiJC.morkOrderPushesTea.Enqueue(new OrderLocInfo()
- {
- SuborderId = order.MorkOrder.SuborderId,
- BatchingId = res.BatchingId,
- Loc = ushort.Parse(mainMaterialLoc),
- GoodName = order.MorkOrder.GoodsName,
- });
- }
- break;
- case GOODS_TYPE.WATER:
- if (morkTLebaiJC.morkOrderPushesWater.FirstOrDefault(p => p.SuborderId == order.MorkOrder.SuborderId) == null)
- {
- morkTLebaiJC.morkOrderPushesWater.Enqueue(new OrderLocInfo()
- {
- SuborderId = order.MorkOrder.SuborderId,
- BatchingId = res.BatchingId,
- Loc = ushort.Parse(mainMaterialLoc),
- GoodName = order.MorkOrder.GoodsName,
- });
- }
- break;
- case GOODS_TYPE.NEITHER:
- DeviceProcessLogShow("未知的商品类型");
- break;
- }
- }
- }
- }
- });
- }
- /// <summary>
- /// 将空杯放好到接饮料的地方的标志位
- /// </summary>
- private bool bFirstTrig_TeaWater = false;
- private bool bFirstTrig_Coffee = false;
- private bool bFirstTrig_Juice = false;
- /// <summary>
- /// 延迟的超时时间
- /// </summary>
- DateTime delayTimeOut_Water;
- DateTime delayTimeOut_Coffee;
- DateTime delayTimeOut_Juice;
- public override void MainTask()
- {
- EventBus.EventBus.GetInstance().Subscribe<DRCoffee_CoffeEndCookEvent>(DeviceId, delegate (IEvent @event, EventCallBackHandle callBack)
- {
- if (morkTLebaiJC.IsHaveCoffeeCup && morkTLebaiJC.MakeCoffeeEnd != true)
- morkTLebaiJC.MakeCoffeeEnd = true;
- });
- if (morkTLebaiJC.IsHaveCoffeeCup && morkTLebaiJC.MakeCoffeeEnd != true)
- {
- if (!bFirstTrig_Coffee)
- {
- bFirstTrig_Coffee = true;
- delayTimeOut_Coffee = DateTime.Now;
- }
- else if (DateTime.Now.Subtract(delayTimeOut_Coffee).TotalSeconds > 18 && bFirstTrig_Coffee == true)
- {
- DeviceProcessLogShow("接咖啡超时,接咖啡结束,等待取咖啡");
- bFirstTrig_Coffee = false;
- if (morkTLebaiJC.IsHaveCoffeeCup)
- morkTLebaiJC.MakeCoffeeEnd = true;
- }
- }
-
- if (morkTLebaiJC.IsHaveJuiceCup && morkTLebaiJC.MakeJuiceEnd != true)
- {
- var Juicestate = GetStatus<int[]>("GetDeviceStatus");
- if (Juicestate != null)
- {
- if (Juicestate.Length > 0)
- {
- var Juicestate1 = Convert.ToString(Juicestate[0], 2);
- var Juicestate2 = Juicestate[1];
- if (Juicestate1.IndexOf("0") == 1 && Juicestate2 == 0)
- {
- morkTLebaiJC.MakeJuiceEnd = true;
- bFirstTrig_Juice = false;
- }
- }
- }
- if (!morkTLebaiJC.MakeJuiceEnd)
- {
- //若无状态返回 则加延迟
- if (!bFirstTrig_Juice)
- {
- bFirstTrig_Juice = true;
- delayTimeOut_Juice = DateTime.Now;
- }
- else if (DateTime.Now.Subtract(delayTimeOut_Juice).TotalSeconds > 3 && bFirstTrig_Juice == true)
- {
- DeviceProcessLogShow("接果汁超时,接果汁结束,等待取果汁");
- bFirstTrig_Juice = false;
- morkTLebaiJC.MakeJuiceEnd = true;
- }
- }
- }
- if (morkTLebaiJC.IsHaveTeaWaterCup && morkTLebaiJC.MakeTeaEnd != true)
- {
- if (!bFirstTrig_TeaWater)
- {
- bFirstTrig_TeaWater = true;
- delayTimeOut_Water = DateTime.Now;//开启接水信号后,记录当前时间
- }
- else if (DateTime.Now.Subtract(delayTimeOut_Water).TotalSeconds >= 5 && bFirstTrig_TeaWater == true)//接水超过50s后,启动接水完成标志,开启接水程序
- {
- DeviceProcessLogShow("接茶或水延迟时间结束");
- bFirstTrig_TeaWater = false;
- morkTLebaiJC.MakeTeaEnd = true;
- }
- }
- DoCoffee();
- DoJuice();
- DoBoiledTea();
- DoBoiledWater();
- }
-
- /// <summary>
- /// 订单状态改变
- /// </summary>
- /// <param name="subid"></param>
- /// <param name="oRDER_STATUS"></param>
- private void OrderChange(string subid, ORDER_STATUS oRDER_STATUS)
- {
- EventBus.EventBus.GetInstance().Publish(new OrderStatusChangedEvent() { Status = oRDER_STATUS, SubOrderId = subid, deviceClientType = DeviceType });
- }
- /// <summary>
- /// 验证商品是做的某种饮料
- /// </summary>
- /// <param name="batchingLoc">物料位置</param>
- private GOODS_TYPE ValidateGoodsByBatching(string batchingLoc)
- {
- if (batchings.ContainsKey(batchingLoc))
- return batchings[batchingLoc].GoodsType;
- return GOODS_TYPE.NEITHER;
- }
- /// <summary>
- /// 乐白的场景结束等待
- /// </summary>
- /// <param name="value"></param>
- private void Wait(int value = 101)
- {
- while (!((bool)peripheralStatus["RobotOK"] && (int)peripheralStatus["RobotValue"] == value))
- {
- Thread.Sleep(5);
- }
- new LebaiRobot_SetValueEvent { DeviceId = DeviceId, RobotSetValue = 0 }.Publish();
- }
- /// <summary>
- /// 乐白的场景
- /// </summary>
- /// <param name="sen"></param>
- private void Sence(int sen)
- {
- new LebaiRobot_LebaiSenceEvent { DeviceId = DeviceId, LebaiSence = sen }.Publish();
- }
- /// <summary>
- /// 乐白的数字量输出
- /// </summary>
- /// <param name="value"></param>
- /// <param name="pin"></param>
- private void Output(bool value,int pin)
- {
- new LebaiRobot_SetOutPutEvent { DeviceId = DeviceId, Pin = pin,Value=value }.Publish();
- }
- private T GetStatus<T>(string key)
- {
- if (peripheralStatus.ContainsKey(key))
- {
- if (peripheralStatus[key] != null)
- {
- return (T)(peripheralStatus[key]);
- }
- }
- return default;
- }
- int[] devStatusBy = new int[2] { 0, 0 };
- bool outCupCheck = false;//放纸杯位置有无判断
- /// <summary>
- /// 传感器的输入信号 0:无意义 1:有信号 2:无信号 3:信号不正确
- /// </summary>
- int bSensorInput;
-
- /// <summary>
- /// 判断是否有咖啡订单
- /// </summary>
- /// <returns></returns>
- private bool IsMakeCoffee()
- {
- bool bMake = (IsHealth && morkTLebaiJC.morkOrderPushesCoffee.Count > 0 && !morkTLebaiJC.IsHaveCoffeeCup) ? true : false;
- return bMake;
- }
- /// <summary>
- /// 判断是否有果汁订单
- /// </summary>
- /// <returns></returns>
- private bool IsMakeJuice()
- {
- bool bMake = (IsHealth && morkTLebaiJC.morkOrderPushesJuicer.Count > 0 && !morkTLebaiJC.IsHaveJuiceCup) ? true : false;
- return bMake;
- }
- /// <summary>
- /// 判断是否有茶订单
- /// </summary>
- /// <returns></returns>
- private bool IsMakeTeaWater()
- {
- bool bMake = (IsHealth && morkTLebaiJC.morkOrderPushesTea.Count > 0 && !morkTLebaiJC.IsHaveTeaWaterCup) ? true : false;
- return bMake;
- }
- /// <summary>
- /// 判断是否有开水订单
- /// </summary>
- /// <returns></returns>
- private bool IsMakeWater()
- {
- bool bMake = (IsHealth && morkTLebaiJC.morkOrderPushesWater.Count > 0 && !morkTLebaiJC.IsHaveTeaWaterCup) ? true : false;
- return bMake;
- }
- /// <summary>
- /// 做咖啡流程
- /// </summary>
- private void DoCoffee()
- {
- if (IsMakeCoffee())
- {
- PickUpCoffee();//接咖啡
- morkTLebaiJC.IsHaveCoffeeCup = true;
- }
- else if(morkTLebaiJC.MakeCoffeeEnd)
- {
- try
- {
- PutCoffeeCup();
- morkTLebaiJC.MakeCoffeeEnd = false;
- morkTLebaiJC.IsHaveCoffeeCup = false;
- morkTLebaiJC.morkOrderPushesCoffee.TryDequeue(out OrderLocInfo orderLoc);
- }
- catch (Exception ex)
- {
- MessageLog.GetInstance.ShowEx(ex.ToString());
- }
- }
- }
- private void DoJuice()
- {
- if (IsMakeJuice())
- {
- switch (morkTLebaiJC.morkOrderPushesJuicer.ElementAt(0).makeID)
- {
- case "1":
- GuMake = true;
- IsAddIce = false;
- break;
- case "2":
- GuMake = false;
- IsAddIce = false;
- break;
- case "3":
- GuMake = false;
- IsAddIce = true;
- break;
- default:
- break;
- }
- PickUpJuicer();
- morkTLebaiJC.IsHaveJuiceCup = true;
- }
- else if (morkTLebaiJC.MakeJuiceEnd)
- {
- try
- {
- Thread.Sleep(5000);//延迟五秒,防止饮料口滴饮料
- putJuice();
- morkTLebaiJC.IsHaveJuiceCup = false;
- morkTLebaiJC.MakeJuiceEnd = false;
- morkTLebaiJC.morkOrderPushesJuicer.TryDequeue(out OrderLocInfo orderLoc);
- }
- catch (Exception ex)
- {
- MessageLog.GetInstance.ShowEx(ex.ToString());
- }
- }
- }
- public bool DoTeaOrWater;
- private void DoBoiledTea()
- {
- if (IsMakeTeaWater())
- {
- PickUpTea();
- morkTLebaiJC.IsHaveTeaWaterCup = true;
- DoTeaOrWater = true;
- }
- else if (morkTLebaiJC.MakeTeaEnd && morkTLebaiJC.morkOrderPushesTea.Count > 0 && DoTeaOrWater)
- {
- try
- {
- PutWaterCup();
- OrderChange(morkTLebaiJC.morkOrderPushesTea.ElementAt(0).SuborderId, BPA.Message.Enum.ORDER_STATUS.COMPLETED_TAKE);
- DeviceProcessLogShow("-------------茶 制作完成------------");
- morkTLebaiJC.IsHaveTeaWaterCup = false;
- morkTLebaiJC.MakeTeaEnd = false;
- morkTLebaiJC.morkOrderPushesTea.TryDequeue(out OrderLocInfo orderLoc);
- }
- catch (Exception ex)
- {
- MessageLog.GetInstance.ShowEx(ex.ToString());
- }
- }
- }
- private void DoBoiledWater()
- {
- if (IsMakeWater())
- {
- PickUpWater();
- morkTLebaiJC.IsHaveTeaWaterCup = true;
- DoTeaOrWater = false;
- }
- else if (morkTLebaiJC.MakeTeaEnd && morkTLebaiJC.morkOrderPushesWater.Count > 0 && DoTeaOrWater == false)
- {
- try
- {
- PutWaterCup();
- OrderChange(morkTLebaiJC.morkOrderPushesWater.ElementAt(0).SuborderId, BPA.Message.Enum.ORDER_STATUS.COMPLETED_TAKE);
- DeviceProcessLogShow("-------------开水 制作完成------------");
- morkTLebaiJC.IsHaveTeaWaterCup = false;
- morkTLebaiJC.MakeTeaEnd = false;
- morkTLebaiJC.morkOrderPushesWater.TryDequeue(out OrderLocInfo orderLoc);
- }
- catch (Exception ex)
- {
- MessageLog.GetInstance.ShowEx(ex.ToString());
- }
- }
- }
-
-
- #region 做咖啡流程
- /// <summary>
- /// 接咖啡
- /// </summary>
- private void PickUpCoffee()
- {
- if (!morkTLebaiJC.IsHaveCoffeeCup)
- {
- outCupCheck = false;
- OrderChange(morkTLebaiJC.morkOrderPushesCoffee.ElementAt(0).SuborderId, BPA.Message.Enum.ORDER_STATUS.COOKING);
- int resultTakeCup = takeCup();
- if (resultTakeCup == 1)
- {
- new LebaiRobot_SetValueEvent { DeviceId = DeviceId, RobotSetValue = 0 }.Publish();
- Sence(GVL_MorkT.机器人安全位);
- //Wait();
-
- WritePLCData("",2);//将轴移动到接咖啡的位置
- DeviceProcessLogShow("伺服电机移动到接咖啡的位置");
-
- DeviceProcessLogShow("咖啡杯取杯完成");
- new LebaiRobot_SetValueEvent { DeviceId = DeviceId, RobotSetValue = 0 }.Publish();
- Sence(GVL_MorkT.接咖啡);
- //Wait();
- new DRCoffee_MakeCoffeeEvent() { DrinkCode = (DrCoffeeDrinksCode)(morkTLebaiJC.morkOrderPushesCoffee.ElementAt(0).Loc)}.Publish(); //接咖啡控制 //DrCoffeeDrinksCode.热水
- }
- else
- {
- /*DeviceProcessLogShow("取杯失败 回到初始位,请及时处理!!");
- new LebaiRobot_SetValueEvent { DeviceId = DeviceId, RobotSetValue = 0 }.Publish();
- Sence(GVL_MorkT.机器人初始位);
- //Wait();*/
- }
- }
- }
- /// <summary>
- /// 咖啡杯接好,放咖啡杯
- /// </summary>
- private void PutCoffeeCup()
- {
- while (GetStatus<bool>("RobotValue1"))//判断放杯位置是否有物品
- {
- if (!outCupCheck)
- DeviceProcessLogShow("成品处有纸杯存在,请取走!!");
- outCupCheck = true;
- }
- outCupCheck = false;
- new LebaiRobot_SetValueEvent { DeviceId = DeviceId, RobotSetValue = 0 }.Publish();
- Sence(GVL_MorkT.机器人安全位);
- //Wait();
-
- WritePLCData("", 2);//将轴移动到接咖啡的位置
- new LebaiRobot_SetValueEvent { DeviceId = DeviceId, RobotSetValue = 0 }.Publish();
- Sence(GVL_MorkT.放咖啡杯);
- //Wait();
- OrderChange(morkTLebaiJC.morkOrderPushesCoffee.ElementAt(0).SuborderId, BPA.Message.Enum.ORDER_STATUS.COMPLETED_TAKE);
- DeviceProcessLogShow($"-------------{morkTLebaiJC.morkOrderPushesCoffee.ElementAt(0).GoodName}制作完成------------");
- }
- #endregion
- #region 做开水流程
- /// <summary>
- /// 接开水
- /// </summary>
- private void PickUpWater()
- {
- #region 接水流程
- if (!morkTLebaiJC.IsHaveTeaWaterCup)
- {
- OrderChange(morkTLebaiJC.morkOrderPushesWater.ElementAt(0).SuborderId, BPA.Message.Enum.ORDER_STATUS.COOKING);
- int resultTakeCup = takeCup();
- if (resultTakeCup == 1)
- {
- new LebaiRobot_SetValueEvent { DeviceId = DeviceId, RobotSetValue = 0 }.Publish();
- Sence(GVL_MorkT.接开水);
- //Wait();
- Output(false, 1);
- Output(false, 0);
- Thread.Sleep(100);
- Output(true, 0);
- Thread.Sleep(3000);
- Output(false, 0);
- Thread.Sleep(100);
-
- Output(false, 1);
- Thread.Sleep(100);
- Output(true, 1);
- Thread.Sleep(500);
- Output(false, 1);
- }
- else
- {
- return;
- }
- }
- #endregion
- }
- #endregion
- #region 做茶流程
- /// <summary>
- /// 做茶
- /// </summary>
- private void PickUpTea()
- {
- #region 接茶流程
- if (!morkTLebaiJC.IsHaveTeaWaterCup)
- {
- OrderChange(morkTLebaiJC.morkOrderPushesTea.ElementAt(0).SuborderId, BPA.Message.Enum.ORDER_STATUS.COOKING);
- int resultTakeCup = takeCup();
- if (resultTakeCup == 1)
- {
- DeviceProcessLogShow("取茶杯完成");
- new LebaiRobot_SetValueEvent { DeviceId = DeviceId, RobotSetValue = 0 }.Publish();
- Sence(GVL_MorkT.接茶叶);
- //Wait();
-
- new WriteMcu() { TagName = "ServoControl", Address = "1", Value = 90 }.Publish();
- Thread.Sleep(1000);
- new WriteMcu() { TagName = "ServoControl", Address = "1", Value = 150 }.Publish();
- Thread.Sleep(1000);
- new WriteMcu() { TagName = "ServoControl", Address = "1", Value = 90 }.Publish();
-
- Thread.Sleep(3000);
- new LebaiRobot_SetValueEvent { DeviceId = DeviceId, RobotSetValue = 0 }.Publish();
- Sence(GVL_MorkT.接茶水);
- //Wait();
- Output(false, 1);
- Output(false, 0);
- Thread.Sleep(100);
- Output(true, 0);
- Thread.Sleep(3000);
- Output(false, 0);
- Thread.Sleep(100);
-
- Output(false, 1);
- Thread.Sleep(100);
- Output(true, 1);
- Thread.Sleep(500);
- Output(false, 1);
- morkTLebaiJC.IsHaveTeaWaterCup = true;
- }
- else
- {
- return;
- }
- }
- #endregion
- }
- /// <summary>
- /// 放水杯流程
- /// </summary>
- private void PutWaterCup()
- {
- while (GetStatus<bool>("RobotValue1"))//判断放杯位置是否有物品
- {
- if (!outCupCheck)
- DeviceProcessLogShow("成品处有纸杯存在,请取走!!");
- outCupCheck = true;
- }
- outCupCheck = false;
- new LebaiRobot_SetValueEvent { DeviceId = DeviceId, RobotSetValue = 0 }.Publish();
- Sence(GVL_MorkT.放水杯);
- }
-
- #endregion
- #region 做果汁流程
- /// <summary>
- /// 果汁机控制信号
- /// </summary>
- private byte JuicerNum;
-
- private void getIce()
- {
- IsAddIceNow = IsAddIce;
- if (IsAddIce)
- {
- new LebaiRobot_SetValueEvent { DeviceId = DeviceId, RobotSetValue = 0 }.Publish();
- Sence(GVL_MorkT.取杯位_机器人安全位);
- //Wait();
-
- WritePLCData("",3);//将模组移动到接冰的位置
-
- new LebaiRobot_SetValueEvent { DeviceId = DeviceId, RobotSetValue = 0 }.Publish();
- Sence(GVL_MorkT.接冰块);
- //Wait();
- if (Math.Pow(1, GetStatus<byte>("GetMakeIceDeviceStatus")) == 0)//制冰机在待机状态才可以制作冰
- {
- new StartMakeIce() { }.Publish();
- }
- new LebaiRobot_SetValueEvent { DeviceId = DeviceId, RobotSetValue = 0 }.Publish();
- Sence(GVL_MorkT.接冰_机器人安全位);
- //Wait();
- }
- }
- /// <summary>
- /// 当前订单是否加冰
- /// </summary>
- private bool IsAddIceNow = false;
- private int JuiceCH;
- /// <summary>
- /// 接果汁
- /// </summary>
- private void PickUpJuicer()
- {
- #region 接果汁流程
- if (!morkTLebaiJC.IsHaveJuiceCup)
- {
- OrderChange(morkTLebaiJC.morkOrderPushesJuicer.ElementAt(0).SuborderId, BPA.Message.Enum.ORDER_STATUS.COOKING);
- int resultTakeCup = takeCup();
- JuiceCH = morkTLebaiJC.morkOrderPushesJuicer.ElementAt(0).Loc;
- if (resultTakeCup == 1)
- {
- getIce();
- new LebaiRobot_SetValueEvent { DeviceId = DeviceId, RobotSetValue = 0 }.Publish();
- Sence(GVL_MorkT.机器人安全位);
- //Wait();
- WritePLCData("", 3);//将模组移动到接冰的位置
- new LebaiRobot_SetValueEvent { DeviceId = DeviceId, RobotSetValue = 0 }.Publish();
- Sence(GVL_MorkT.接果汁过渡位);
- //Wait();
- switch (JuiceCH)
- {
- case 52:
- if (GuMake)
- JuicerNum = 0x00;
- else
- JuicerNum = 0x01;
- new LebaiRobot_SetValueEvent { DeviceId = DeviceId, RobotSetValue = 0 }.Publish();
- Sence(GVL_MorkT.接果汁1);
- //Wait();
- break;
- case 53:
- if (GuMake)
- JuicerNum = 0x02;
- else
- JuicerNum = 0x03;
- new LebaiRobot_SetValueEvent { DeviceId = DeviceId, RobotSetValue = 0 }.Publish();
- Sence(GVL_MorkT.接果汁2);
- //Wait();
- break;
- case 54:
- if (GuMake)
- JuicerNum = 0x04;
- else
- JuicerNum = 0x05;
- new LebaiRobot_SetValueEvent { DeviceId = DeviceId, RobotSetValue = 0 }.Publish();
- Sence(GVL_MorkT.接果汁3);
- //Wait();
- break;
- case 55:
- if (GuMake)
- JuicerNum = 0x06;
- else
- JuicerNum = 0x07;
- new LebaiRobot_SetValueEvent { DeviceId = DeviceId, RobotSetValue = 0 }.Publish();
- Sence(GVL_MorkT.接果汁4);
- //Wait();
- break;
- default:
- JuicerNum = 0x00;
- new LebaiRobot_SetValueEvent { DeviceId = DeviceId, RobotSetValue = 0 }.Publish();
- Sence(GVL_MorkT.接果汁1);
- //Wait();
- break;
- }
- new WriteJuicer() { Value = JuicerNum }.Publish();
- morkTLebaiJC.IsHaveJuiceCup = true;
- }
- else
- {
- return;
- }
- }
- #endregion
- }
- /// <summary>
- /// 取接好果汁杯
- /// </summary>
- private void putJuice()
- {
- while (GetStatus<bool>("RobotValue1"))//判断放杯位置是否有物品
- {
- if (!outCupCheck)
- DeviceProcessLogShow("成品处有纸杯存在,请取走!!");
- outCupCheck = true;
- }
- outCupCheck = false;
- switch (JuiceCH)
- {
- case 52:
- new LebaiRobot_SetValueEvent { DeviceId = DeviceId, RobotSetValue = 0 }.Publish();
- Sence(GVL_MorkT.放果汁杯1);
- //Wait();
- break;
- case 53:
- new LebaiRobot_SetValueEvent { DeviceId = DeviceId, RobotSetValue = 0 }.Publish();
- Sence(GVL_MorkT.放果汁杯2);
- //Wait();
- break;
- case 54:
- new LebaiRobot_SetValueEvent { DeviceId = DeviceId, RobotSetValue = 0 }.Publish();
- Sence(GVL_MorkT.放果汁杯3);
- //Wait();
- break;
- case 55:
- new LebaiRobot_SetValueEvent { DeviceId = DeviceId, RobotSetValue = 0 }.Publish();
- Sence(GVL_MorkT.放果汁杯4);
- //Wait();
- break;
- default:
- new LebaiRobot_SetValueEvent { DeviceId = DeviceId, RobotSetValue = 0 }.Publish();
- Sence(GVL_MorkT.放果汁杯1);
- //Wait();
- break;
- }
- OrderChange(morkTLebaiJC.morkOrderPushesJuicer.ElementAt(0).SuborderId, BPA.Message.Enum.ORDER_STATUS.COMPLETED_TAKE);
- DeviceProcessLogShow($"-------------{morkTLebaiJC.morkOrderPushesJuicer.ElementAt(0).GoodName}果汁 制作完成------------");
- }
- #endregion
-
- /// <summary>
- /// 取杯的次数
- /// </summary>
- private int nCnt;
- /// <summary>
- /// 取杯流程
- /// </summary>
- /// <returns>0:无意义,1:取杯成功 2:取杯失败</returns>
- private int takeCup()
- {
- try
- {
- nCnt = 0;
- new LebaiRobot_SetValueEvent { DeviceId = DeviceId, RobotSetValue = 0 }.Publish();
- Sence(GVL_MorkT.机器人初始位);
- //Wait();
-
- new LebaiRobot_SetValueEvent { DeviceId = DeviceId, RobotSetValue = 0 }.Publish();
- Sence(GVL_MorkT.机器人安全位);
- //Wait();
-
- WritePLCData("", 1);
-
- new LebaiRobot_SetValueEvent { DeviceId = DeviceId, RobotSetValue = 0 }.Publish();
- Sence(GVL_MorkT.取纸杯);
- //Wait();
-
- new LebaiRobot_SetValueEvent { DeviceId = DeviceId, RobotSetValue = 0 }.Publish();
- Sence(GVL_MorkT.取纸杯检测);
- //Wait();
- nCnt++;
- Thread.Sleep(2000);
- while (!GetStatus<bool>("GetInput")) //读取传感器的值
- {
- if (nCnt > 3)
- {
- nCnt = 0;
- DeviceProcessLogShow("三次取杯失败,回原点");
- new LebaiRobot_SetValueEvent { DeviceId = DeviceId, RobotSetValue = 0 }.Publish();
- Sence(GVL_MorkT.机器人安全位);
- //Wait();
- new LebaiRobot_SetValueEvent { DeviceId = DeviceId, RobotSetValue = 0 }.Publish();
- Sence(GVL_MorkT.机器人初始位);
- //Wait();
- return 2;
- }
- else
- {
- nCnt++;
- new LebaiRobot_SetValueEvent { DeviceId = DeviceId, RobotSetValue = 0 }.Publish();
- Sence(GVL_MorkT.二次取杯);
- //Wait();
- new LebaiRobot_SetValueEvent { DeviceId = DeviceId, RobotSetValue = 0 }.Publish();
- Sence(GVL_MorkT.取纸杯检测);
- //Wait();
- }
- Thread.Sleep(1000);
- }
- new LebaiRobot_SetValueEvent { DeviceId = DeviceId, RobotSetValue = 0 }.Publish();
- Sence(GVL_MorkT.取杯位_机器人安全位);
- //Wait();
- return 1;
- }
- catch (Exception ex)
- {
- DeviceProcessLogShow(ex.ToString());
- }
- return 2;
- }
- /// <summary>
- /// 放杯
- /// </summary>
- /// <returns>0:无意义 1:放杯成功 2:执行失败(传感器还有信号) 3:放杯异常</returns>
- private int putCup()
- {
- try
- {
- if (GetStatus<bool>("GetInput2")) return 2;
- Sence(GVL_MorkT.JUICE_放杯);
- //Wait();
- new LebaiRobot_SetValueEvent() { RobotSetValue = 1 }.Publish();
- Sence(GVL_MorkT.JUICE_放杯检测);
- //Wait();
- new LebaiRobot_SetValueEvent() { RobotSetValue = 1 }.Publish();
- if (GetStatus<bool>("GetInput2"))
- {
- return 1;
- }
- else
- {
- return 3;
- }
- }
- catch (Exception ex)
- {
- DeviceProcessLogShow(ex.ToString());
- return 0;
- }
- }
- public void SimOrder<T>(T simOrder)
- {
-
- }
- #region PLC 控制函数
-
- private void WritePLCData(string address, object value)
- {
- EventBus.EventBus.GetInstance().Publish(new WriteModel() { DeviceId = DeviceId, Address = address, Value = value });
- }
- private void GetStatus(string key, Action<object> action)
- {
- if (peripheralStatus.ContainsKey(key))
- {
- if (peripheralStatus[key] != null)
- {
- action?.Invoke(peripheralStatus[key]);
- }
- }
- }
-
- public override void ReadData()
- {
- #region 乐白机器人状态
- GetStatus("RobotIsConnected", new Action<object>((o) =>
- {
- if (o is bool b)
- {
- morkTLebaiJC.RobotIsConnected = b;
- }
- }));
- GetStatus("RobotMode", new Action<object>((o) =>
- {
- if (o is ELebaiRModel eLebaiRModel)
- {
- morkTLebaiJC.RobotMode = eLebaiRModel;
- }
- }));
- GetStatus("LeibaiGetTcpInput", new Action<object>((o) =>
- {
- if (o is bool b)
- {
- morkTLebaiJC.RobotGetTcpInput = b;
- }
- }));
- GetStatus("LeibaiGetInput1", new Action<object>((o) =>
- {
- if (o is bool b)
- {
- morkTLebaiJC.RobotGetInput0 = b;
- }
- }));
- GetStatus("LeibaiGetInput2", new Action<object>((o) =>
- {
- if (o is bool b)
- {
- morkTLebaiJC.RobotGetInput1 = b;
- }
- }));
- GetStatus("LeibaiGetInput3", new Action<object>((o) =>
- {
- if (o is bool b)
- {
- morkTLebaiJC.RobotGetInput2 = b;
- }
- }));
- GetStatus("LeibaiGetInput4", new Action<object>((o) =>
- {
- if (o is bool b)
- {
- morkTLebaiJC.RobotGetInput3 = b;
- }
- }));
-
- #endregion
- #region 制冰机状态
- GetStatus("MakeIceConnected", new Action<object>((o) =>
- {
- if (o is bool bt)
- {
- morkTLebaiJC.IceMakerConnect = bt;
- }
- }));
- GetStatus("MakeIceDeviceStatus", new Action<object>((o) =>
- {
- if (o is byte bt)
- {
- morkTLebaiJC.IceMakerState = bt;
- }
- }));
- #endregion
- #region 咖啡机状态
- GetStatus("CoffeeIsConnected", new Action<object>((o) =>
- {
- if (o is bool b)
- {
- morkTLebaiJC.CoffeeIsConnected = b;
- }
- }));
-
- GetStatus("CoffeeStatus", new Action<object>((o) =>
- {
- if (o is DrCoffeeStatus coffeeStatus)
- {
- morkTLebaiJC.DrCoffeeStatus = coffeeStatus;
- }
- }));
-
- GetStatus("CoffeeAppStatus", new Action<object>((o) =>
- {
- if (o is DrCoffeeAppStatus appStatus)
- {
- morkTLebaiJC.CoffeeAppStatus = appStatus;
- }
- }));
-
- GetStatus("CoffeeWarning", new Action<object>((o) =>
- {
- if (o is DrCoffeeWarning coffeeWarning)
- {
- morkTLebaiJC.CoffeeWarning = coffeeWarning;
- }
- }));
- GetStatus("CoffeeFault", new Action<object>((o) =>
- {
- if (o is DrCoffeeFault coffeeFault)
- {
- morkTLebaiJC.CaffeeFault = coffeeFault;
- }
- }));
- #endregion
- #region 单片机状态
- EventBus.EventBus.GetInstance().Publish(new ReadMcu() { DeviceId = DeviceId, ReadPar = 0, TagName = "SCChipGetInput0" });
- EventBus.EventBus.GetInstance().Publish(new ReadMcu() { DeviceId = DeviceId, ReadPar = 0, TagName = "SCChipGetInput1" });
- EventBus.EventBus.GetInstance().Publish(new ReadMcu() { DeviceId = DeviceId, ReadPar = 0, TagName = "SCChipGetInput2" });
- EventBus.EventBus.GetInstance().Publish(new ReadMcu() { DeviceId = DeviceId, ReadPar = 0, TagName = "SCChipGetInput3" });
- EventBus.EventBus.GetInstance().Publish(new ReadMcu() { DeviceId = DeviceId, ReadPar = 0, TagName = "SCChipGetInput4" });
- EventBus.EventBus.GetInstance().Publish(new ReadMcu() { DeviceId = DeviceId, ReadPar = 0, TagName = "SCChipGetInput5" });
- EventBus.EventBus.GetInstance().Publish(new ReadMcu() { DeviceId = DeviceId, ReadPar = 0, TagName = "SCChipGetInput6" });
- EventBus.EventBus.GetInstance().Publish(new ReadMcu() { DeviceId = DeviceId, ReadPar = 0, TagName = "SCChipGetInput7" });
- GetStatus("SCChipIsConnect", new Action<object>((o) =>
- {
- if (o is bool b)
- {
- morkTLebaiJC.SCChipIsConnect = b;
- }
- }));
- GetStatus("SCChipGetInput0", new Action<object>((o) =>
- {
- if (o is bool b)
- {
- morkTLebaiJC.SCChipInput0 = b;
- }
- }));
- GetStatus("SCChipGetInput1", new Action<object>((o) =>
- {
- if (o is bool b)
- {
- morkTLebaiJC.SCChipInput1 = b;
- }
- }));
- GetStatus("SCChipGetInput2", new Action<object>((o) =>
- {
- if (o is bool b)
- {
- morkTLebaiJC.SCChipInput2 = b;
- }
- }));
- GetStatus("SCChipGetInput3", new Action<object>((o) =>
- {
- if (o is bool b)
- {
- morkTLebaiJC.SCChipInput3 = b;
- }
- }));
- GetStatus("SCChipGetInput4", new Action<object>((o) =>
- {
- if (o is bool b)
- {
- morkTLebaiJC.SCChipInput4 = b;
- }
- }));
- GetStatus("SCChipGetInput5", new Action<object>((o) =>
- {
- if (o is bool b)
- {
- morkTLebaiJC.SCChipInput5 = b;
- }
- }));
- GetStatus("SCChipGetInput6", new Action<object>((o) =>
- {
- if (o is bool b)
- {
- morkTLebaiJC.SCChipInput6 = b;
- }
- }));
- GetStatus("SCChipGetInput7", new Action<object>((o) =>
- {
- if (o is bool b)
- {
- morkTLebaiJC.SCChipInput7 = b;
- }
- }));
-
- #endregion
- #region 果汁机
- GetStatus("GetJuicerConnected", new Action<object>((o) =>
- {
- if (o is bool b)
- {
- morkTLebaiJC.JuicerConnected = b;
- }
- }));
- GetStatus("GetJuicerDeviceStatus", new Action<object>((o) =>
- {
- if (o is int[] b)
- {
- morkTLebaiJC.JuicerState = b;
- }
- }));
- #endregion
- }
- #endregion
- public override void Stop()
- {
-
- }
-
- public override void ResetProgram()
- {
-
- }
-
- public override void SimOrder()
- {
- EventBus.EventBus.GetInstance().Subscribe<MorkTSimOrder>(0, delegate (IEvent @event, EventCallBackHandle callBackHandle)
- {
- string guid = Guid.NewGuid().ToString();
- if (@event != null && @event is MorkTSimOrder msm)
- {
- DeviceProcessLogShow("----开始模拟订单----");
- if (msm.OrderNum == 1)
- {
- morkTLebaiJC.morkOrderPushesCoffee.Enqueue(new OrderLocInfo() { Loc =(ushort)msm.DrinkCode, SuborderId = guid, GoodName="模拟咖啡订单" });
- }
- else if (msm.OrderNum == 2)
- {
- morkTLebaiJC.morkOrderPushesJuicer.Enqueue(new OrderLocInfo() { Loc = (ushort) (msm.JuiceList + 51), makeID = msm.JuiceMakeID, SuborderId = guid, GoodName = "模拟果汁订单" });
- }
- else if (msm.OrderNum == 3)
- {
- morkTLebaiJC.morkOrderPushesTea.Enqueue(new OrderLocInfo() { SuborderId = guid, GoodName = "模拟茶水订单" });
- }
- else if (msm.OrderNum == 4)
- {
- morkTLebaiJC.morkOrderPushesWater.Enqueue(new OrderLocInfo() { SuborderId = guid, GoodName = "模拟开水订单" });
- }
- }
- });
- }
- }
- }
|