|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798 |
- using BPA.Message.Enum;
- using BPASmartClient.Device;
- using BPASmartClient.DRCoffee;
- using BPASmartClient.EventBus;
- using BPASmartClient.GSIceCream;
- using BPASmartClient.Helper;
- using BPASmartClient.Lebai;
- using BPASmartClient.LebaiRobot;
- using BPASmartClient.Message;
- using BPASmartClient.Model;
- using BPASmartClient.Model.乐白机器人;
- using BPASmartClient.Model.乐白机器人.Enum;
- using BPASmartClient.Model.冰淇淋.Enum;
- using BPASmartClient.Model.单片机;
- using BPASmartClient.Model.单片机.Enum;
- using BPASmartClient.MorkT.Model;
- using BPASmartClient.Peripheral;
- using Robotc;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading;
- using System.Threading.Tasks;
- using static BPASmartClient.EventBus.EventBus;
-
- namespace BPASmartClient.MorkT
- {
- public class Control_MorkT : BaseDevice
- {
- public override global::BPA.Message.Enum.DeviceClientType DeviceType { get { return BPA.Message.Enum.DeviceClientType.MORKT; } }
-
- GLV_MorkT morkT = new GLV_MorkT();
-
- DateTime morkTime = DateTime.Now;
-
- public override void DoMain()
- {
- if (Json<KeepDataBase>.Data.IsVerify)
- {
- IsHealth = true;
- }
- IsHealth = true;
- ServerInit();
- DataParse();
- EventBus.EventBus.GetInstance().Subscribe<DRCoffee_CoffeEndCookEvent>(DeviceId, delegate (IEvent @event, EventCallBackHandle callBack)
- {
- if (morkT.MakeCoffeeOrder != null)
- morkT.MakeCoffeeOrder.OrderStatus = 1;
- });
- int i = 0;
- EventBus.EventBus.GetInstance().Publish(new GSIceCream_ModeSetEvent { DeviceId = DeviceId, Mode = MORKI_MODE.制冷模式 });
- PreventSleep.SleepControl(true);//防止电脑休眠
- MessageLog.GetInstance.Show("MORKT 设备初始化完成");
- }
-
- public override void ResetProgram()
- {
- morkT = null;
- morkT = new GLV_MorkT();
- }
-
- private void GetStatus(string key, Action<object> action)
- {
- if (peripheralStatus.ContainsKey(key))
- {
- if (peripheralStatus[key] != null)
- {
- action?.Invoke(peripheralStatus[key]);
- }
- }
- }
-
- public override void MainTask()
- {
- //if (morkTime.AddMinutes(Global.TimeInterval).Minute == DateTime.Now.Minute)
- //{
- // morkTime = DateTime.Now;
- // if ((ELebaiRModel)peripheralStatus["RobotMode"] == ELebaiRModel.空闲状态)
- // {
- // MessageLog.GetInstance.Show("机器人开始自嗨!");
- // EventBus.EventBus.GetInstance().Publish(new LebaiRobot_SetValueEvent { DeviceId = DeviceId, RobotSetValue = 0 }, (o) => { });
- // EventBus.EventBus.GetInstance().Publish(new LebaiRobot_LebaiSenceEvent { DeviceId = DeviceId, LebaiSence = Lebai_qsqdCode.SENCE_自嗨 });
- // Wait();
- // EventBus.EventBus.GetInstance().Publish(new LebaiRobot_SetValueEvent { DeviceId = DeviceId, RobotSetValue = 1 }, (o) => { });
- // Thread.Sleep(50);
- // }
- //}
- //else if (morkTime.AddMinutes(Global.TimeInterval) < DateTime.Now) morkTime = DateTime.Now;
- #region morkt流程
- if (morkT.waitMorkOrder != null)//更新订单取走状态
- {
- EventBus.EventBus.GetInstance().Publish(new LebaiRobot_GetInputEvent() { DeviceId = DeviceId, Pin = 0 }, (o) =>
- {
- if (o != null && o.Length > 0 && o[0] is bool res)
- {
- if (!res)
- {
- OrderChange(morkT.waitMorkOrder.SuborderId, ORDER_STATUS.COMPLETED_TAKE);
- DeviceProcessLogShow("订单取餐完成");
- morkT.waitMorkOrder = null;
- }
- }
- });
- }
- MakeCoffeeProcess();
- EventBus.EventBus.GetInstance().Publish(new LebaiRobot_GetInputEvent { DeviceId = DeviceId, Pin = 0 }, (o) =>
- {
- if (o != null && o.Length > 0 && o[0] is bool resultValue)
- {
- if (!resultValue)//取餐口有空余位置
- {
- MakeIceCreamProcess();
- //MakeCoffeeComplete();
- }
- }
- });
- #endregion
- }
-
- public override void ReadData()
- {
- GetStatus("RobotIsConnected", new Action<object>((o) =>
- {
- if (o is bool b)
- {
- morkT.RobotIsConnected = b;
- }
- }));
-
- GetStatus("RobotMode", new Action<object>((o) =>
- {
- if (o is ELebaiRModel eLebaiRModel)
- {
- morkT.RobotMode = eLebaiRModel;
- }
- }));
-
-
- GetStatus("IceCreamIsConnected", new Action<object>((o) =>
- {
- if (o is bool b)
- {
- morkT.IceCreamIsConnected = b;
- }
- }));
-
- GetStatus("IceCreamYLWD", new Action<object>((o) =>
- {
- if (o is short s)
- {
- morkT.YLWD = s;
- }
- }));
-
- GetStatus("IceCreamHQWD", new Action<object>((o) =>
- {
- if (o is short s)
- {
- morkT.HQWD = s;
- }
- }));
-
- GetStatus("IceCreamDL", new Action<object>((o) =>
- {
- if (o is short s)
- {
- morkT.DL = s;
- }
- }));
-
- GetStatus("IceCreamDY", new Action<object>((o) =>
- {
- if (o is short s)
- {
- morkT.DY = s;
- }
- }));
-
- GetStatus("IceCreamCXB", new Action<object>((o) =>
- {
- if (o is byte bt)
- {
- morkT.CBX = bt;
- }
- }));
-
- GetStatus("IceCreamCurrentMode", new Action<object>((o) =>
- {
- if (o is MORKI_MODE mORKI_MODE)
- {
- morkT.IceCreamMode = mORKI_MODE;
- }
- }));
-
- GetStatus("IceCreamFault", new Action<object>((o) =>
- {
- if (o is MORKI_FAULT mORKI_FAULT)
- {
- morkT.IceCreamFault = mORKI_FAULT;
- }
- }));
-
- GetStatus("IceCreamError", new Action<object>((o) =>
- {
- if (o is string error)
- {
- morkT.IceCreamError = error;
- }
- }));
-
- GetStatus("IceCreamDLCompleted", new Action<object>((o) =>
- {
- if (o is bool b)
- {
- morkT.DLCompleted = b;
- }
- }));
-
- GetStatus("CoffeeIsConnected", new Action<object>((o) =>
- {
- if (o is bool b)
- {
- morkT.CoffeeIsConnected = b;
- }
- }));
-
- GetStatus("CoffeeStatus", new Action<object>((o) =>
- {
- if (o is DrCoffeeStatus coffeeStatus)
- {
- morkT.DrCoffeeStatus = coffeeStatus;
- }
- }));
-
- GetStatus("CoffeeAppStatus", new Action<object>((o) =>
- {
- if (o is DrCoffeeAppStatus appStatus)
- {
- morkT.CoffeeAppStatus = appStatus;
- }
- }));
-
- GetStatus("CoffeeWarning", new Action<object>((o) =>
- {
- if (o is DrCoffeeWarning coffeeWarning)
- {
- morkT.CoffeeWarning = coffeeWarning;
- }
- }));
- GetStatus("CoffeeFault", new Action<object>((o) =>
- {
- if (o is DrCoffeeFault coffeeFault)
- {
- morkT.CaffeeFault = coffeeFault;
- }
- }));
- GetStatus("SCChipIsConnect", new Action<object>((o) =>
- {
- if (o is bool b)
- {
- morkT.SCChipIsConnect = b;
- }
- }));
- }
-
- public override void Stop()
- {
- }
-
- 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;
- }
- });
-
- //配方数据信息
- EventBus.EventBus.GetInstance().Subscribe<RecipeBomEvent>(DeviceId, delegate (IEvent @event, EventCallBackHandle callBack)
- {
- if (@event == null) return;
- if (@event is RecipeBomEvent recipe)
- {
- recipeBoms = recipe.recipeBoms;
- }
- });
- }
-
- /// <summary>
- /// 数据解析
- /// </summary>
- 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}次订单");
- //构建所有商品物料信息
- morkT.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);
- }
- string loc_Goods = string.Empty;
- //获取主料和容器位置
- if (morkT.batchings[res.BatchingLoc].BatchingClass == BATCHING_CLASS.MAIN_MATERIAL) loc_Goods = res.BatchingLoc;
- if (!string.IsNullOrEmpty(loc_Goods))
- {
- switch (currentGoodsType)
- {
- case GOODS_TYPE.COFFEE:
- if (morkT.morkOrderPushesCoffee.FirstOrDefault(p => p.SuborderId == order.MorkOrder.SuborderId) == null)
- {
- morkT.morkOrderPushesCoffee.Enqueue(new OrderLocInfo()
- {
- SuborderId = order.MorkOrder.SuborderId,
- BatchingId = res.BatchingId,
- Loc = loc_Goods,
- GoodsName = order.MorkOrder.GoodsName,
- SortNum = order.MorkOrder.SortNum
- });
- }
- break;
- case GOODS_TYPE.ICECREAM:
- if (morkT.morkOrderPushesIceCream.FirstOrDefault(p => p.SuborderId == order.MorkOrder.SuborderId) == null)
- {
- morkT.morkOrderPushesIceCream.Enqueue(new OrderLocInfo()
- {
- SuborderId = order.MorkOrder.SuborderId,
- BatchingId = res.BatchingId,
- Loc = loc_Goods,
- GoodsName = order.MorkOrder.GoodsName,
- SortNum = order.MorkOrder.SortNum
- });
- }
- break;
- case GOODS_TYPE.NEITHER:
- DeviceProcessLogShow("未知的商品类型");
- break;
- }
- }
-
- }
- }
-
- }
- });
- }
- /// <summary>
- /// 验证当前是做咖啡还是做冰淇淋
- /// </summary>
- /// <param name="batchingLoc">物料位置</param>
- private GOODS_TYPE ValidateGoodsByBatching(string batchingLoc)
- {
- if (morkT.batchings.ContainsKey(batchingLoc))
- return morkT.batchings[batchingLoc].GoodsType;
- return GOODS_TYPE.NEITHER;
- }
-
- /// <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 });
- }
-
- private void Wait(int value = 101)
- {
- while (!((bool)peripheralStatus["RobotOK"] && (int)peripheralStatus["RobotValue"] == value))
- {
- Thread.Sleep(5);
- }
- }
-
- /// <summary>
- /// 是否可以开始制作咖啡
- /// </summary>
- /// <returns></returns>
- private bool CoffeeCanMake()
- {
- bool canMake = (IsHealth && morkT.morkOrderPushesCoffee.Count > 0 && !morkT.IsCoffeeMake) ? true : false;
- return canMake;
-
- }
-
- /// <summary>
- /// 制作咖啡流程
- /// </summary>
- private void MakeCoffeeProcess()
- {
- if (CoffeeCanMake())
- {
- if (morkT.morkOrderPushesCoffee.TryDequeue(out OrderLocInfo orderLoc))
- {
- DeviceProcessLogShow($"开始制作 [咖啡] 订单[{orderLoc.SortNum}]");
- GetAndCheeckCoffe(orderLoc);//取咖啡杯
- if (!morkT.GetCoffeeCup) return;
- EventBus.EventBus.GetInstance().Publish(new LebaiRobot_LebaiSenceEvent { DeviceId = DeviceId, LebaiSence = Lebai_qsqdCode.SENCE_接咖啡后回原点 }); //接咖啡后回原点
- Wait();
- EventBus.EventBus.GetInstance().Publish(new LebaiRobot_SetValueEvent { DeviceId = DeviceId, RobotSetValue = 1 }, (o) => { });
- EventBus.EventBus.GetInstance().Publish(new DRCoffee_MakeCoffeeEvent() {DeviceId = DeviceId, DrinkCode = (BPASmartClient.Model.咖啡机.Enum.DrCoffeeDrinksCode)int.Parse(orderLoc.Loc) });//接咖啡控制
- DeviceProcessLogShow($"发送咖啡机制作{orderLoc.Loc}!");
- morkT.IsCoffeeMake = true; morkT.MakeCoffeeOrder = orderLoc;
- }
-
- }
-
-
-
- }
- /// <summary>
- /// 咖啡机制作完咖啡,取走并放到取餐口,最后回原点
- /// </summary>
- private void MakeCoffeeComplete()
- {
- if (morkT.IsCoffeeMake && IsHealth)
- {
- if (morkT.MakeCoffeeOrder != null && morkT.MakeCoffeeOrder.OrderStatus == 1)
- {
- DeviceProcessLogShow($"将咖啡移动到取餐位 [咖啡] 订单[{morkT.MakeCoffeeOrder.SortNum}]");
- DoCoffeeQC(morkT.MakeCoffeeOrder);
- morkT.MakeCoffeeOrder = null;
- morkT.IsCoffeeMake = false;
- }
- }
- }
-
- /// <summary>
- /// 将咖啡杯从咖啡机 取走到 取餐口
- /// </summary>
- private void DoCoffeeQC(OrderLocInfo order)
- {
- EventBus.EventBus.GetInstance().Publish(new LebaiRobot_LebaiSenceEvent { DeviceId = DeviceId, LebaiSence = Lebai_qsqdCode.SENCE_取咖啡出餐 }); //SENCE_取咖啡出餐
- Wait();
- EventBus.EventBus.GetInstance().Publish(new LebaiRobot_SetValueEvent { DeviceId = DeviceId, RobotSetValue = 1 }, (o) => { });
- //订单状态改变:完成
- OrderChange(order.SuborderId, ORDER_STATUS.COMPLETED_COOK);
- morkT.waitMorkOrder = order;
- DeviceProcessLogShow($"{order.GoodsName}等待取餐");
- //WaitTakeMealOrder.Enqueue(order);
-
- }
-
- /// <summary>
- /// 取咖啡杯&&咖啡杯检测 若检测失败机器人回原点
- /// </summary>
- /// <param name="order"></param>
- private void GetAndCheeckCoffe(OrderLocInfo order)
- {
- EventBus.EventBus.GetInstance().Publish(new LebaiRobot_SetValueEvent { DeviceId = DeviceId, RobotSetValue = 0 },(o)=>{ });
- OrderChange(order.SuborderId, ORDER_STATUS.COOKING);
- EventBus.EventBus.GetInstance().Publish(new LebaiRobot_LebaiSenceEvent { DeviceId = DeviceId, LebaiSence = Lebai_qsqdCode.SENCE_取咖啡杯 }); //SENCE_取咖啡杯
-
- Wait();
- // EventBus.EventBus.GetInstance().Publish(new SCChip_TakeCupEvent { DeviceId = DeviceId, Cup = IC_CUP.CUP_COFFEE });//落碗控制
- EventBus.EventBus.GetInstance().Publish(new LebaiRobot_SetOutPutEvent { DeviceId = DeviceId, Value = true, Pin = 1 });
- EventBus.EventBus.GetInstance().Publish(new LebaiRobot_GetInputEvent { DeviceId = DeviceId, Pin = 1 }, (o) =>
- {
- //if (o != null && o.Length > 0 && o[0] is bool resultValue)
- //{
- // result = resultValue;
- //}
- });
- Thread.Sleep(500);
- DeviceProcessLogShow("尝试取咖啡杯!");
- EventBus.EventBus.GetInstance().Publish(new LebaiRobot_SetValueEvent { DeviceId = DeviceId, RobotSetValue = 1 }, (o) => { });
- int count = 1;
- bool result = true;
- p:
- EventBus.EventBus.GetInstance().Publish(new LebaiRobot_LebaiSenceEvent { DeviceId = DeviceId, LebaiSence = Lebai_qsqdCode.SENCE_咖啡杯检测 }); //SENCE_咖啡杯检测
- Wait();
- EventBus.EventBus.GetInstance().Publish(new LebaiRobot_SetValueEvent { DeviceId = DeviceId, RobotSetValue = 1 }, (o) => { });
- EventBus.EventBus.GetInstance().Publish(new LebaiRobot_GetTCPInputEvent { DeviceId = DeviceId, Pin = 1 }, (o)=>
- {
- if (o != null && o.Length > 0 && o[0] is bool resultValue)
- {
- result = resultValue;
- }
- });
-
- if (!result)
- {
- if (count >= 3)
- {
- //退出循环回到初始位置
- DeviceProcessLogShow($"执行{count}次取咖啡杯,仍为成功,订单默认废弃,机器人回到初始位置!");
- EventBus.EventBus.GetInstance().Publish(new LebaiRobot_LebaiSenceEvent { DeviceId = DeviceId, LebaiSence = Lebai_qsqdCode.SENCE_咖啡杯回原点 }); //SENCE_咖啡杯回原点
- Wait();
- EventBus.EventBus.GetInstance().Publish(new LebaiRobot_SetValueEvent { DeviceId = DeviceId, RobotSetValue = 1 }, (o) => { });
- morkT.GetCoffeeCup = false;
- return;
- }
- DeviceProcessLogShow("执行二次取咖啡杯");
- EventBus.EventBus.GetInstance().Publish(new LebaiRobot_LebaiSenceEvent { DeviceId = DeviceId, LebaiSence = Lebai_qsqdCode.SENCE_二次取咖啡杯 }); //SENCE_二次取咖啡杯
- Wait();
- EventBus.EventBus.GetInstance().Publish(new SCChip_TakeCupEvent { DeviceId = DeviceId, Cup = IC_CUP.CUP_COFFEE });//落碗控制
- EventBus.EventBus.GetInstance().Publish(new LebaiRobot_SetValueEvent { DeviceId = DeviceId, RobotSetValue = 1 }, (o) => { });
- count++;
- goto p;
- }
- morkT.GetCoffeeCup = true;
- DeviceProcessLogShow("取咖啡杯完成");
- }
-
- /// <summary>
- /// 冰淇淋是否可以开始制作
- /// </summary>
- /// <returns></returns>
- private bool IceCreamCanMake()
- {
- bool canMake = (IsHealth && morkT.morkOrderPushesIceCream.Count > 0) ? true : false;
- return canMake;
- }
-
- /// <summary>
- /// 制作冰淇淋流程
- /// </summary>
- private void MakeIceCreamProcess()
- {
- if (IceCreamCanMake())
- {
- //if (morkT.morkOrderPushesIceCream.TryDequeue(out OrderLocInfo order))
- //{
- // DoIceCream(order);
- //}
-
- if (peripheralStatus.ContainsKey("IceCreamCurrentMode"))
- {
- if ((MORKI_MODE)peripheralStatus["IceCreamCurrentMode"] != MORKI_MODE.制冷模式) EventBus.EventBus.GetInstance().Publish(new GSIceCream_ModeSetEvent { DeviceId = DeviceId, Mode = MORKI_MODE.制冷模式 });
- }
-
- if (peripheralStatus.ContainsKey("IceCreamCXB"))
- {
- if ((byte)peripheralStatus["IceCreamCXB"] >= 86 && morkT.morkOrderPushesIceCream.Count > 0)//成型比大于86才可以制作
- {
- bool result = true;
- EventBus.EventBus.GetInstance().Publish(new LebaiRobot_GetInputEvent { DeviceId = DeviceId, Pin = 3 }, (res) =>
- {
- if (res[0] is bool resultValue)
- {
- result = resultValue;
- }
- });
- if (result)
- {
- if (morkT.IceIsOK) DeviceProcessLogShow("请检查冰淇淋出料口有无遮挡");
- morkT.IceIsOK = false;
- }
- else if (morkT.morkOrderPushesIceCream.TryDequeue(out OrderLocInfo order))
- {
- morkT.IceIsOK = true;
- DeviceProcessLogShow($"开始制作 [冰淇淋] 订单[{order.SortNum}]");
- DoIceCream(order);
- }
- }
- }
-
- }
- }
-
- /// <summary>
- /// 做冰淇淋
- /// </summary>
- private void DoIceCream(OrderLocInfo order)
- {
- GetIceCreamCup();
- CheckICeCreaCup();
- if (morkT.GetIceCreamCup)
- {
- GetIceCream(order);
- PutIceCream(order);
- }
-
- }
-
- /// <summary>
- /// 取冰淇淋杯
- /// </summary>
- private void GetIceCreamCup()
- {
- MessageLog.GetInstance.Show("准备开始制作冰淇淋");
- EventBus.EventBus.GetInstance().Publish(new LebaiRobot_SetValueEvent { DeviceId = DeviceId, RobotSetValue = 0 }, (o) => { });
- EventBus.EventBus.GetInstance().Publish(new LebaiRobot_LebaiSenceEvent { DeviceId = DeviceId, LebaiSence = Lebai_qsqdCode.SENCE_取冰淇淋杯 }); //SENCE_取冰淇淋杯
- Wait();
- EventBus.EventBus.GetInstance().Publish(new SCChip_TakeCupEvent { DeviceId = DeviceId, Cup = IC_CUP.CUP_ICECREAM });//落碗控制
- Thread.Sleep(500);
- DeviceProcessLogShow("尝试取冰淇淋杯!");
-
- }
-
- /// <summary>
- /// 冰淇淋杯检测,失败后机器人回到原点
- /// </summary>
- private void CheckICeCreaCup()
- {
- int count = 2;
- bool result = true;
- EventBus.EventBus.GetInstance().Publish(new LebaiRobot_SetValueEvent { DeviceId = DeviceId, RobotSetValue = 1 }, (o) => { });
- p:
- EventBus.EventBus.GetInstance().Publish(new LebaiRobot_LebaiSenceEvent { DeviceId = DeviceId, LebaiSence = Lebai_qsqdCode.SENCE_冰淇淋杯检测 }); //SENCE_冰淇淋杯检测
- Wait();
- Thread.Sleep(500);
- EventBus.EventBus.GetInstance().Publish(new LebaiRobot_SetValueEvent { DeviceId = DeviceId, RobotSetValue = 1 }, (o) =>
- {
- if (o != null && o.Length > 0 && o[0] is SignalResult res)
- {
- MessageLog.GetInstance.Show(res.ToString());
- }
- });
- while((int)peripheralStatus["RobotValue"] != 0)
- {
- Thread.Sleep(10);
- }
- MessageLog.GetInstance.Show($"乐白机器人信号值{peripheralStatus["RobotValue"].ToString()}");
-
- //while ((ELebaiRModel)peripheralStatus["RobotMode"] !=ELebaiRModel.空闲状态)
- //{
- // EventBus.EventBus.GetInstance().Publish(new LebaiRobot_SetValueEvent { DeviceId = DeviceId, RobotSetValue = 1 });
- // Thread.Sleep(500);
- //}
-
- EventBus.EventBus.GetInstance().Publish(new LebaiRobot_GetTCPInputEvent { DeviceId = DeviceId, Pin = 1 }, (o) =>
- {
- if (o != null && o.Length > 0 && o[0] is bool resultValue)
- {
- result = resultValue;
- }
- });
- if (!result)
- {
- if (count >= 3)
- {
- //退出循环回到初始位置
- DeviceProcessLogShow($"执行{count}次取冰淇淋杯,仍未成功,订单默认废弃,机器人回到初始位置!");
- EventBus.EventBus.GetInstance().Publish(new LebaiRobot_LebaiSenceEvent { DeviceId = DeviceId, LebaiSence = Lebai_qsqdCode.SENCE_冰淇淋杯回原点 }); //SENCE_冰淇淋杯回原点
- Wait();
- EventBus.EventBus.GetInstance().Publish(new LebaiRobot_SetValueEvent { DeviceId = DeviceId, RobotSetValue = 1 },(o) => { });
- morkT.GetIceCreamCup = false;
- return;
- }
- DeviceProcessLogShow($"执行{count}次取冰淇淋杯!");
- EventBus.EventBus.GetInstance().Publish(new LebaiRobot_LebaiSenceEvent { DeviceId = DeviceId, LebaiSence = Lebai_qsqdCode.SENCE_二次取冰淇淋杯 }); //SENCE_二次取冰淇淋杯
- EventBus.EventBus.GetInstance().Equals(new SCChip_TakeCupEvent { DeviceId = DeviceId, Cup = IC_CUP.CUP_ICECREAM });//落碗控制
- Wait();
- EventBus.EventBus.GetInstance().Publish(new LebaiRobot_SetValueEvent { DeviceId = DeviceId, RobotSetValue = 1 }, (o) => { });
- count++;
- goto p;
- }
- morkT.GetIceCreamCup = true;
- DeviceProcessLogShow("冰淇淋杯检测完成");
- }
-
- /// <summary>
- /// 机器人取接冰淇淋
- /// </summary>
- /// <param name="order"></param>
- private void GetIceCream(OrderLocInfo order)
- {
- //制冷模式
- EventBus.EventBus.GetInstance().Publish(new GSIceCream_ModeSetEvent { DeviceId = DeviceId, Mode = MORKI_MODE.制冷模式 });
- EventBus.EventBus.GetInstance().Publish(new LebaiRobot_SetValueEvent { DeviceId = DeviceId, RobotSetValue = 0 }, (o) => { });
- OrderChange(order.SuborderId, ORDER_STATUS.COOKING);
- EventBus.EventBus.GetInstance().Publish(new LebaiRobot_LebaiSenceEvent { DeviceId = DeviceId, LebaiSence = Lebai_qsqdCode.SENCE_接1号冰淇淋 }); //SENCE_接1号冰淇淋
- Wait();
- bool doItResult = true;
-
- //出料
- //EventBus.EventBus.GetInstance().Publish(new SCChip_RotorSwitchEvent { DeviceId = DeviceId, TurnOn = true });
- //Thread.Sleep(500);
- //EventBus.EventBus.GetInstance().Publish(new SCChip_RotorSwitchEvent { DeviceId = DeviceId, TurnOn = false });
- //EventBus.EventBus.GetInstance().Publish(new LebaiRobot_SetOutPutEvent { DeviceId = DeviceId, bDO = true ,pin = 1});
- //Thread.Sleep(500);
- //EventBus.EventBus.GetInstance().Publish(new LebaiRobot_SetOutPutEvent { DeviceId = DeviceId, bDO = false, pin = 1 });
-
- //Thread.Sleep(500);
- //EventBus.EventBus.GetInstance().Publish(new SCChip_MakeIceCreamEvent { DeviceId = DeviceId, SteeringEngine = IC_SE.SE_2 });//冰淇淋出料
- //DeviceProcessLogShow("开始等待6s");
- //Thread.Sleep(5000);
-
- //出料
- EventBus.EventBus.GetInstance().Publish(new GSIceCream_DischargeEvent { DeviceId = DeviceId }, (o) =>
- {
- doItResult = (bool)o[0];
- });
- if (doItResult)
- {
- IceCreamCookCheck();
- }
- else
- {
- int count_1 = 0;
-
- while ((byte)peripheralStatus["IceCreamCXB"] <= 86)
- {
- Thread.Sleep(5);
- count_1++;
- if (count_1 >= 2000)
- break;
- }
- IceCreamCookCheck();
- }
- EventBus.EventBus.GetInstance().Publish(new LebaiRobot_SetValueEvent { DeviceId = DeviceId, RobotSetValue = 1 }, (o) => { });
- }
-
- /// <summary>
- /// 把冰淇淋放到取餐位后回原点
- /// </summary>
- /// <param name="order"></param>
- private void PutIceCream(OrderLocInfo order)
- {
- bool resultValue = true;
- while (resultValue)
- {
- EventBus.EventBus.GetInstance().Publish(new LebaiRobot_GetInputEvent { DeviceId = DeviceId, Pin = 0 }, (res) =>
- {
- if (res[0] is bool b)
- {
- resultValue = b;
- }
- });
- Thread.Sleep(500);
- }
-
- EventBus.EventBus.GetInstance().Publish(new LebaiRobot_LebaiSenceEvent { DeviceId = DeviceId, LebaiSence = Lebai_qsqdCode.SENCE_放冰淇淋位置 }); //SENCE_放冰淇淋位置
- Wait();
- EventBus.EventBus.GetInstance().Publish(new LebaiRobot_SetValueEvent { DeviceId = DeviceId, RobotSetValue = 1 }, (o) => { });
- //订单状态改变:完成
- OrderChange(order.SuborderId, ORDER_STATUS.COMPLETED_COOK);
- morkT.waitMorkOrder = order;
- DeviceProcessLogShow($"{order.GoodsName}等待取餐");
- //WaitTakeMealOrder.Enqueue(order);
-
- }
-
- /// <summary>
- /// 冰淇淋机器制作冰淇淋
- /// </summary>
- public void IceCreamCookCheck()
- {
- bool result = false;
- int retry = 3;
- DateTime beginTime = DateTime.Now;
-
- while (!result)
- {
- EventBus.EventBus.GetInstance().Publish(new LebaiRobot_GetInputEvent { DeviceId = DeviceId, Pin = 3 }, (res) =>
- {
- if (res[0] is bool resultValue)
- {
- result = resultValue;
- }
- });
- if (retry <= 0 || DateTime.Now.Subtract(beginTime).TotalSeconds >= 10)
- {
- DeviceProcessLogShow("超时未出料,重试次数用尽");
- break;
- }
- if (DateTime.Now.Subtract(beginTime).TotalSeconds > 5)
- {
- DeviceProcessLogShow("超时未出料,重新发送打料指令");
- EventBus.EventBus.GetInstance().Publish(new GSIceCream_ModeSetEvent() { DeviceId = DeviceId, Mode = MORKI_MODE.打料 });
- beginTime = DateTime.Now;
- retry--;
- }
- Thread.Sleep(10);
- }
- DeviceProcessLogShow("开始等待6s");
- Thread.Sleep(5000);
-
- }
-
- public override void SimOrder()
- {
- }
- }
- }
|