终端一体化运控平台
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

799 lines
32 KiB

  1. using BPA.Message.Enum;
  2. using BPASmartClient.Device;
  3. using BPASmartClient.DRCoffee;
  4. using BPASmartClient.EventBus;
  5. using BPASmartClient.GSIceCream;
  6. using BPASmartClient.Helper;
  7. using BPASmartClient.Lebai;
  8. using BPASmartClient.LebaiRobot;
  9. using BPASmartClient.Message;
  10. using BPASmartClient.Model;
  11. using BPASmartClient.Model.乐白机器人;
  12. using BPASmartClient.Model.乐白机器人.Enum;
  13. using BPASmartClient.Model.冰淇淋.Enum;
  14. using BPASmartClient.Model.单片机;
  15. using BPASmartClient.Model.单片机.Enum;
  16. using BPASmartClient.MorkT.Model;
  17. using BPASmartClient.Peripheral;
  18. using Robotc;
  19. using System;
  20. using System.Collections.Generic;
  21. using System.Linq;
  22. using System.Text;
  23. using System.Threading;
  24. using System.Threading.Tasks;
  25. using static BPASmartClient.EventBus.EventBus;
  26. namespace BPASmartClient.MorkT
  27. {
  28. public class Control_MorkT : BaseDevice
  29. {
  30. public override global::BPA.Message.Enum.DeviceClientType DeviceType { get { return BPA.Message.Enum.DeviceClientType.MORKT; } }
  31. GLV_MorkT morkT = new GLV_MorkT();
  32. DateTime morkTime = DateTime.Now;
  33. public override void DoMain()
  34. {
  35. if (Json<KeepDataBase>.Data.IsVerify)
  36. {
  37. IsHealth = true;
  38. }
  39. IsHealth = true;
  40. ServerInit();
  41. DataParse();
  42. EventBus.EventBus.GetInstance().Subscribe<DRCoffee_CoffeEndCookEvent>(DeviceId, delegate (IEvent @event, EventCallBackHandle callBack)
  43. {
  44. if (morkT.MakeCoffeeOrder != null)
  45. morkT.MakeCoffeeOrder.OrderStatus = 1;
  46. });
  47. int i = 0;
  48. EventBus.EventBus.GetInstance().Publish(new GSIceCream_ModeSetEvent { DeviceId = DeviceId, Mode = MORKI_MODE.制冷模式 });
  49. PreventSleep.SleepControl(true);//防止电脑休眠
  50. MessageLog.GetInstance.Show("MORKT 设备初始化完成");
  51. }
  52. public override void ResetProgram()
  53. {
  54. morkT = null;
  55. morkT = new GLV_MorkT();
  56. }
  57. private void GetStatus(string key, Action<object> action)
  58. {
  59. if (peripheralStatus.ContainsKey(key))
  60. {
  61. if (peripheralStatus[key] != null)
  62. {
  63. action?.Invoke(peripheralStatus[key]);
  64. }
  65. }
  66. }
  67. public override void MainTask()
  68. {
  69. if (morkTime.AddMinutes(Global.TimeInterval).Minute == DateTime.Now.Minute)
  70. {
  71. morkTime = DateTime.Now;
  72. if ((ELebaiRModel)peripheralStatus["RobotMode"] == ELebaiRModel.空闲状态)
  73. {
  74. MessageLog.GetInstance.Show("机器人开始自嗨!");
  75. EventBus.EventBus.GetInstance().Publish(new LebaiRobot_SetValueEvent { DeviceId = DeviceId, RobotSetValue = 0 }, (o) => { });
  76. EventBus.EventBus.GetInstance().Publish(new LebaiRobot_LebaiSenceEvent { DeviceId = DeviceId, LebaiSence = Lebai_qsqdCode.SENCE_自嗨 });
  77. Wait();
  78. EventBus.EventBus.GetInstance().Publish(new LebaiRobot_SetValueEvent { DeviceId = DeviceId, RobotSetValue = 1 }, (o) => { });
  79. Thread.Sleep(50);
  80. }
  81. }
  82. else if (morkTime.AddMinutes(Global.TimeInterval) < DateTime.Now) morkTime = DateTime.Now;
  83. #region morkt流程
  84. //if (morkT.waitMorkOrder != null)//更新订单取走状态
  85. //{
  86. // EventBus.EventBus.GetInstance().Publish(new LebaiRobot_GetInputEvent() { DeviceId = DeviceId, Pin = 0 }, (o) =>
  87. // {
  88. // if (o != null && o.Length > 0 && o[0] is bool res)
  89. // {
  90. // if (!res)
  91. // {
  92. // OrderChange(morkT.waitMorkOrder.SuborderId, ORDER_STATUS.COMPLETED_TAKE);
  93. // DeviceProcessLogShow("订单取餐完成");
  94. // morkT.waitMorkOrder = null;
  95. // }
  96. // }
  97. // });
  98. //}
  99. //MakeCoffeeProcess();
  100. //EventBus.EventBus.GetInstance().Publish(new LebaiRobot_GetInputEvent { DeviceId = DeviceId, Pin = 0 }, (o) =>
  101. // {
  102. // if (o != null && o.Length > 0 && o[0] is bool resultValue)
  103. // {
  104. // if (!resultValue)//取餐口有空余位置
  105. // {
  106. // MakeIceCreamProcess();
  107. // MakeCoffeeComplete();
  108. // }
  109. // }
  110. // });
  111. #endregion
  112. }
  113. public override void ReadData()
  114. {
  115. GetStatus("RobotIsConnected", new Action<object>((o) =>
  116. {
  117. if (o is bool b)
  118. {
  119. morkT.RobotIsConnected = b;
  120. }
  121. }));
  122. GetStatus("RobotMode", new Action<object>((o) =>
  123. {
  124. if (o is ELebaiRModel eLebaiRModel)
  125. {
  126. morkT.RobotMode = eLebaiRModel;
  127. }
  128. }));
  129. GetStatus("IceCreamIsConnected", new Action<object>((o) =>
  130. {
  131. if (o is bool b)
  132. {
  133. morkT.IceCreamIsConnected = b;
  134. }
  135. }));
  136. GetStatus("IceCreamYLWD", new Action<object>((o) =>
  137. {
  138. if (o is short s)
  139. {
  140. morkT.YLWD = s;
  141. }
  142. }));
  143. GetStatus("IceCreamHQWD", new Action<object>((o) =>
  144. {
  145. if (o is short s)
  146. {
  147. morkT.HQWD = s;
  148. }
  149. }));
  150. GetStatus("IceCreamDL", new Action<object>((o) =>
  151. {
  152. if (o is short s)
  153. {
  154. morkT.DL = s;
  155. }
  156. }));
  157. GetStatus("IceCreamDY", new Action<object>((o) =>
  158. {
  159. if (o is short s)
  160. {
  161. morkT.DY = s;
  162. }
  163. }));
  164. GetStatus("IceCreamCXB", new Action<object>((o) =>
  165. {
  166. if (o is byte bt)
  167. {
  168. morkT.CBX = bt;
  169. }
  170. }));
  171. GetStatus("IceCreamCurrentMode", new Action<object>((o) =>
  172. {
  173. if (o is MORKI_MODE mORKI_MODE)
  174. {
  175. morkT.IceCreamMode = mORKI_MODE;
  176. }
  177. }));
  178. GetStatus("IceCreamFault", new Action<object>((o) =>
  179. {
  180. if (o is MORKI_FAULT mORKI_FAULT)
  181. {
  182. morkT.IceCreamFault = mORKI_FAULT;
  183. }
  184. }));
  185. GetStatus("IceCreamError", new Action<object>((o) =>
  186. {
  187. if (o is string error)
  188. {
  189. morkT.IceCreamError = error;
  190. }
  191. }));
  192. GetStatus("IceCreamDLCompleted", new Action<object>((o) =>
  193. {
  194. if (o is bool b)
  195. {
  196. morkT.DLCompleted = b;
  197. }
  198. }));
  199. GetStatus("CoffeeIsConnected", new Action<object>((o) =>
  200. {
  201. if (o is bool b)
  202. {
  203. morkT.CoffeeIsConnected = b;
  204. }
  205. }));
  206. GetStatus("CoffeeStatus", new Action<object>((o) =>
  207. {
  208. if (o is DrCoffeeStatus coffeeStatus)
  209. {
  210. morkT.DrCoffeeStatus = coffeeStatus;
  211. }
  212. }));
  213. GetStatus("CoffeeAppStatus", new Action<object>((o) =>
  214. {
  215. if (o is DrCoffeeAppStatus appStatus)
  216. {
  217. morkT.CoffeeAppStatus = appStatus;
  218. }
  219. }));
  220. GetStatus("CoffeeWarning", new Action<object>((o) =>
  221. {
  222. if (o is DrCoffeeWarning coffeeWarning)
  223. {
  224. morkT.CoffeeWarning = coffeeWarning;
  225. }
  226. }));
  227. GetStatus("CoffeeFault", new Action<object>((o) =>
  228. {
  229. if (o is DrCoffeeFault coffeeFault)
  230. {
  231. morkT.CaffeeFault = coffeeFault;
  232. }
  233. }));
  234. GetStatus("SCChipIsConnect", new Action<object>((o) =>
  235. {
  236. if (o is bool b)
  237. {
  238. morkT.SCChipIsConnect = b;
  239. }
  240. }));
  241. }
  242. public override void Stop()
  243. {
  244. }
  245. private void ServerInit()
  246. {
  247. //物料信息
  248. EventBus.EventBus.GetInstance().Subscribe<MaterialDeliveryEvent>(DeviceId, delegate (IEvent @event, EventCallBackHandle callBack)
  249. {
  250. if (@event == null) return;
  251. if (@event is MaterialDeliveryEvent material)
  252. {
  253. orderMaterialDelivery = material.orderMaterialDelivery;
  254. }
  255. });
  256. //配方数据信息
  257. EventBus.EventBus.GetInstance().Subscribe<RecipeBomEvent>(DeviceId, delegate (IEvent @event, EventCallBackHandle callBack)
  258. {
  259. if (@event == null) return;
  260. if (@event is RecipeBomEvent recipe)
  261. {
  262. recipeBoms = recipe.recipeBoms;
  263. }
  264. });
  265. }
  266. /// <summary>
  267. /// 数据解析
  268. /// </summary>
  269. private void DataParse()
  270. {
  271. EventBus.EventBus.GetInstance().Subscribe<DoOrderEvent>(DeviceId, delegate (IEvent @event, EventCallBackHandle callBackHandle)
  272. {
  273. if (@event == null) return;
  274. if (@event is DoOrderEvent order)
  275. {
  276. if (order.MorkOrder.GoodBatchings == null) return;
  277. OrderCount++;
  278. DeviceProcessLogShow($"接收到{OrderCount}次订单");
  279. //构建所有商品物料信息
  280. morkT.batchings = PolymerBatching.BuildAll();
  281. //商品类型
  282. GOODS_TYPE currentGoodsType = GOODS_TYPE.NEITHER;
  283. foreach (var item in order.MorkOrder.GoodBatchings)
  284. {
  285. var res = orderMaterialDelivery?.BatchingInfo?.FirstOrDefault(p => p.BatchingId == item.BatchingId);
  286. if (res != null)
  287. {
  288. //验证商品是咖啡还是冰淇淋
  289. if (ValidateGoodsByBatching(res.BatchingLoc) != GOODS_TYPE.NEITHER)
  290. {
  291. //获取当前物料所属商品类型
  292. currentGoodsType = ValidateGoodsByBatching(res.BatchingLoc);
  293. }
  294. string loc_Goods = string.Empty;
  295. //获取主料和容器位置
  296. if (morkT.batchings[res.BatchingLoc].BatchingClass == BATCHING_CLASS.MAIN_MATERIAL) loc_Goods = res.BatchingLoc;
  297. if (!string.IsNullOrEmpty(loc_Goods))
  298. {
  299. switch (currentGoodsType)
  300. {
  301. case GOODS_TYPE.COFFEE:
  302. if (morkT.morkOrderPushesCoffee.FirstOrDefault(p => p.SuborderId == order.MorkOrder.SuborderId) == null)
  303. {
  304. morkT.morkOrderPushesCoffee.Enqueue(new OrderLocInfo()
  305. {
  306. SuborderId = order.MorkOrder.SuborderId,
  307. BatchingId = res.BatchingId,
  308. Loc = loc_Goods,
  309. GoodsName = order.MorkOrder.GoodsName,
  310. SortNum = order.MorkOrder.SortNum
  311. });
  312. }
  313. break;
  314. case GOODS_TYPE.ICECREAM:
  315. if (morkT.morkOrderPushesIceCream.FirstOrDefault(p => p.SuborderId == order.MorkOrder.SuborderId) == null)
  316. {
  317. morkT.morkOrderPushesIceCream.Enqueue(new OrderLocInfo()
  318. {
  319. SuborderId = order.MorkOrder.SuborderId,
  320. BatchingId = res.BatchingId,
  321. Loc = loc_Goods,
  322. GoodsName = order.MorkOrder.GoodsName,
  323. SortNum = order.MorkOrder.SortNum
  324. });
  325. }
  326. break;
  327. case GOODS_TYPE.NEITHER:
  328. DeviceProcessLogShow("未知的商品类型");
  329. break;
  330. }
  331. }
  332. }
  333. }
  334. }
  335. });
  336. }
  337. /// <summary>
  338. /// 验证当前是做咖啡还是做冰淇淋
  339. /// </summary>
  340. /// <param name="batchingLoc">物料位置</param>
  341. private GOODS_TYPE ValidateGoodsByBatching(string batchingLoc)
  342. {
  343. if (morkT.batchings.ContainsKey(batchingLoc))
  344. return morkT.batchings[batchingLoc].GoodsType;
  345. return GOODS_TYPE.NEITHER;
  346. }
  347. private void OrderChange(string subid, ORDER_STATUS oRDER_STATUS)
  348. {
  349. EventBus.EventBus.GetInstance().Publish(new OrderStatusChangedEvent() { Status = oRDER_STATUS, SubOrderId = subid, deviceClientType = DeviceType });
  350. }
  351. private void Wait(int value = 101)
  352. {
  353. while (!((bool)peripheralStatus["RobotOK"] && (int)peripheralStatus["RobotValue"] == value))
  354. {
  355. Thread.Sleep(5);
  356. }
  357. }
  358. /// <summary>
  359. /// 是否可以开始制作咖啡
  360. /// </summary>
  361. /// <returns></returns>
  362. private bool CoffeeCanMake()
  363. {
  364. bool canMake = (IsHealth && morkT.morkOrderPushesCoffee.Count > 0 && !morkT.IsCoffeeMake) ? true : false;
  365. return canMake;
  366. }
  367. /// <summary>
  368. /// 制作咖啡流程
  369. /// </summary>
  370. private void MakeCoffeeProcess()
  371. {
  372. if (CoffeeCanMake())
  373. {
  374. if (morkT.morkOrderPushesCoffee.TryDequeue(out OrderLocInfo orderLoc))
  375. {
  376. DeviceProcessLogShow($"开始制作 [咖啡] 订单[{orderLoc.SortNum}]");
  377. GetAndCheeckCoffe(orderLoc);//取咖啡杯
  378. if (!morkT.GetCoffeeCup) return;
  379. EventBus.EventBus.GetInstance().Publish(new LebaiRobot_LebaiSenceEvent { DeviceId = DeviceId, LebaiSence = Lebai_qsqdCode.SENCE_接咖啡后回原点 }); //接咖啡后回原点
  380. Wait();
  381. EventBus.EventBus.GetInstance().Publish(new LebaiRobot_SetValueEvent { DeviceId = DeviceId, RobotSetValue = 1 }, (o) => { });
  382. EventBus.EventBus.GetInstance().Publish(new DRCoffee_MakeCoffeeEvent() {DeviceId = DeviceId, DrinkCode = (BPASmartClient.Model.咖啡机.Enum.DrCoffeeDrinksCode)int.Parse(orderLoc.Loc) });//接咖啡控制
  383. DeviceProcessLogShow($"发送咖啡机制作{orderLoc.Loc}!");
  384. morkT.IsCoffeeMake = true; morkT.MakeCoffeeOrder = orderLoc;
  385. }
  386. }
  387. }
  388. /// <summary>
  389. /// 咖啡机制作完咖啡,取走并放到取餐口,最后回原点
  390. /// </summary>
  391. private void MakeCoffeeComplete()
  392. {
  393. if (morkT.IsCoffeeMake && IsHealth)
  394. {
  395. if (morkT.MakeCoffeeOrder != null && morkT.MakeCoffeeOrder.OrderStatus == 1)
  396. {
  397. DeviceProcessLogShow($"将咖啡移动到取餐位 [咖啡] 订单[{morkT.MakeCoffeeOrder.SortNum}]");
  398. DoCoffeeQC(morkT.MakeCoffeeOrder);
  399. morkT.MakeCoffeeOrder = null;
  400. morkT.IsCoffeeMake = false;
  401. }
  402. }
  403. }
  404. /// <summary>
  405. /// 将咖啡杯从咖啡机 取走到 取餐口
  406. /// </summary>
  407. private void DoCoffeeQC(OrderLocInfo order)
  408. {
  409. EventBus.EventBus.GetInstance().Publish(new LebaiRobot_LebaiSenceEvent { DeviceId = DeviceId, LebaiSence = Lebai_qsqdCode.SENCE_取咖啡出餐 }); //SENCE_取咖啡出餐
  410. Wait();
  411. EventBus.EventBus.GetInstance().Publish(new LebaiRobot_SetValueEvent { DeviceId = DeviceId, RobotSetValue = 1 }, (o) => { });
  412. //订单状态改变:完成
  413. OrderChange(order.SuborderId, ORDER_STATUS.COMPLETED_COOK);
  414. morkT.waitMorkOrder = order;
  415. DeviceProcessLogShow($"{order.GoodsName}等待取餐");
  416. //WaitTakeMealOrder.Enqueue(order);
  417. }
  418. /// <summary>
  419. /// 取咖啡杯&&咖啡杯检测 若检测失败机器人回原点
  420. /// </summary>
  421. /// <param name="order"></param>
  422. private void GetAndCheeckCoffe(OrderLocInfo order)
  423. {
  424. EventBus.EventBus.GetInstance().Publish(new LebaiRobot_SetValueEvent { DeviceId = DeviceId, RobotSetValue = 0 },(o)=>{ });
  425. OrderChange(order.SuborderId, ORDER_STATUS.COOKING);
  426. EventBus.EventBus.GetInstance().Publish(new LebaiRobot_LebaiSenceEvent { DeviceId = DeviceId, LebaiSence = Lebai_qsqdCode.SENCE_取咖啡杯 }); //SENCE_取咖啡杯
  427. Wait();
  428. EventBus.EventBus.GetInstance().Publish(new SCChip_TakeCupEvent { DeviceId = DeviceId, Cup = IC_CUP.CUP_COFFEE });//落碗控制
  429. Thread.Sleep(500);
  430. DeviceProcessLogShow("尝试取咖啡杯!");
  431. EventBus.EventBus.GetInstance().Publish(new LebaiRobot_SetValueEvent { DeviceId = DeviceId, RobotSetValue = 1 }, (o) => { });
  432. int count = 1;
  433. bool result = true;
  434. p:
  435. EventBus.EventBus.GetInstance().Publish(new LebaiRobot_LebaiSenceEvent { DeviceId = DeviceId, LebaiSence = Lebai_qsqdCode.SENCE_咖啡杯检测 }); //SENCE_咖啡杯检测
  436. Wait();
  437. EventBus.EventBus.GetInstance().Publish(new LebaiRobot_SetValueEvent { DeviceId = DeviceId, RobotSetValue = 1 }, (o) => { });
  438. EventBus.EventBus.GetInstance().Publish(new LebaiRobot_GetTCPInputEvent { DeviceId = DeviceId, Pin = 1 }, (o)=>
  439. {
  440. if (o != null && o.Length > 0 && o[0] is bool resultValue)
  441. {
  442. result = resultValue;
  443. }
  444. });
  445. if (!result)
  446. {
  447. if (count >= 3)
  448. {
  449. //退出循环回到初始位置
  450. DeviceProcessLogShow($"执行{count}次取咖啡杯,仍为成功,订单默认废弃,机器人回到初始位置!");
  451. EventBus.EventBus.GetInstance().Publish(new LebaiRobot_LebaiSenceEvent { DeviceId = DeviceId, LebaiSence = Lebai_qsqdCode.SENCE_咖啡杯回原点 }); //SENCE_咖啡杯回原点
  452. Wait();
  453. EventBus.EventBus.GetInstance().Publish(new LebaiRobot_SetValueEvent { DeviceId = DeviceId, RobotSetValue = 1 }, (o) => { });
  454. morkT.GetCoffeeCup = false;
  455. return;
  456. }
  457. DeviceProcessLogShow("执行二次取咖啡杯");
  458. EventBus.EventBus.GetInstance().Publish(new LebaiRobot_LebaiSenceEvent { DeviceId = DeviceId, LebaiSence = Lebai_qsqdCode.SENCE_二次取咖啡杯 }); //SENCE_二次取咖啡杯
  459. Wait();
  460. EventBus.EventBus.GetInstance().Publish(new SCChip_TakeCupEvent { DeviceId = DeviceId, Cup = IC_CUP.CUP_COFFEE });//落碗控制
  461. EventBus.EventBus.GetInstance().Publish(new LebaiRobot_SetValueEvent { DeviceId = DeviceId, RobotSetValue = 1 }, (o) => { });
  462. count++;
  463. goto p;
  464. }
  465. morkT.GetCoffeeCup = true;
  466. DeviceProcessLogShow("取咖啡杯完成");
  467. }
  468. /// <summary>
  469. /// 冰淇淋是否可以开始制作
  470. /// </summary>
  471. /// <returns></returns>
  472. private bool IceCreamCanMake()
  473. {
  474. bool canMake = (IsHealth && morkT.morkOrderPushesIceCream.Count > 0) ? true : false;
  475. return canMake;
  476. }
  477. /// <summary>
  478. /// 制作冰淇淋流程
  479. /// </summary>
  480. private void MakeIceCreamProcess()
  481. {
  482. if (IceCreamCanMake())
  483. {
  484. //if (morkT.morkOrderPushesIceCream.TryDequeue(out OrderLocInfo order))
  485. //{
  486. // DoIceCream(order);
  487. //}
  488. if (peripheralStatus.ContainsKey("IceCreamCurrentMode"))
  489. {
  490. if ((MORKI_MODE)peripheralStatus["IceCreamCurrentMode"] != MORKI_MODE.制冷模式) EventBus.EventBus.GetInstance().Publish(new GSIceCream_ModeSetEvent { DeviceId = DeviceId, Mode = MORKI_MODE.制冷模式 });
  491. }
  492. if (peripheralStatus.ContainsKey("IceCreamCXB"))
  493. {
  494. if ((byte)peripheralStatus["IceCreamCXB"] >= 86 && morkT.morkOrderPushesIceCream.Count > 0)//成型比大于86才可以制作
  495. {
  496. bool result = true;
  497. EventBus.EventBus.GetInstance().Publish(new LebaiRobot_GetInputEvent { DeviceId = DeviceId, Pin = 3 }, (res) =>
  498. {
  499. if (res[0] is bool resultValue)
  500. {
  501. result = resultValue;
  502. }
  503. });
  504. if (result)
  505. {
  506. if (morkT.IceIsOK) DeviceProcessLogShow("请检查冰淇淋出料口有无遮挡");
  507. morkT.IceIsOK = false;
  508. }
  509. else if (morkT.morkOrderPushesIceCream.TryDequeue(out OrderLocInfo order))
  510. {
  511. morkT.IceIsOK = true;
  512. DeviceProcessLogShow($"开始制作 [冰淇淋] 订单[{order.SortNum}]");
  513. DoIceCream(order);
  514. }
  515. }
  516. }
  517. }
  518. }
  519. /// <summary>
  520. /// 做冰淇淋
  521. /// </summary>
  522. private void DoIceCream(OrderLocInfo order)
  523. {
  524. GetIceCreamCup();
  525. CheckICeCreaCup();
  526. if (morkT.GetIceCreamCup)
  527. {
  528. GetIceCream(order);
  529. PutIceCream(order);
  530. }
  531. }
  532. /// <summary>
  533. /// 取冰淇淋杯
  534. /// </summary>
  535. private void GetIceCreamCup()
  536. {
  537. MessageLog.GetInstance.Show("准备开始制作冰淇淋");
  538. EventBus.EventBus.GetInstance().Publish(new LebaiRobot_SetValueEvent { DeviceId = DeviceId, RobotSetValue = 0 }, (o) => { });
  539. EventBus.EventBus.GetInstance().Publish(new LebaiRobot_LebaiSenceEvent { DeviceId = DeviceId, LebaiSence = Lebai_qsqdCode.SENCE_取冰淇淋杯 }); //SENCE_取冰淇淋杯
  540. Wait();
  541. EventBus.EventBus.GetInstance().Publish(new SCChip_TakeCupEvent { DeviceId = DeviceId, Cup = IC_CUP.CUP_ICECREAM });//落碗控制
  542. Thread.Sleep(500);
  543. DeviceProcessLogShow("尝试取冰淇淋杯!");
  544. }
  545. /// <summary>
  546. /// 冰淇淋杯检测,失败后机器人回到原点
  547. /// </summary>
  548. private void CheckICeCreaCup()
  549. {
  550. int count = 2;
  551. bool result = true;
  552. EventBus.EventBus.GetInstance().Publish(new LebaiRobot_SetValueEvent { DeviceId = DeviceId, RobotSetValue = 1 }, (o) => { });
  553. p:
  554. EventBus.EventBus.GetInstance().Publish(new LebaiRobot_LebaiSenceEvent { DeviceId = DeviceId, LebaiSence = Lebai_qsqdCode.SENCE_冰淇淋杯检测 }); //SENCE_冰淇淋杯检测
  555. Wait();
  556. Thread.Sleep(500);
  557. EventBus.EventBus.GetInstance().Publish(new LebaiRobot_SetValueEvent { DeviceId = DeviceId, RobotSetValue = 1 }, (o) =>
  558. {
  559. if (o != null && o.Length > 0 && o[0] is SignalResult res)
  560. {
  561. MessageLog.GetInstance.Show(res.ToString());
  562. }
  563. });
  564. while((int)peripheralStatus["RobotValue"] != 0)
  565. {
  566. Thread.Sleep(10);
  567. }
  568. MessageLog.GetInstance.Show($"乐白机器人信号值{peripheralStatus["RobotValue"].ToString()}");
  569. //while ((ELebaiRModel)peripheralStatus["RobotMode"] !=ELebaiRModel.空闲状态)
  570. //{
  571. // EventBus.EventBus.GetInstance().Publish(new LebaiRobot_SetValueEvent { DeviceId = DeviceId, RobotSetValue = 1 });
  572. // Thread.Sleep(500);
  573. //}
  574. EventBus.EventBus.GetInstance().Publish(new LebaiRobot_GetTCPInputEvent { DeviceId = DeviceId, Pin = 1 }, (o) =>
  575. {
  576. if (o != null && o.Length > 0 && o[0] is bool resultValue)
  577. {
  578. result = resultValue;
  579. }
  580. });
  581. if (!result)
  582. {
  583. if (count >= 3)
  584. {
  585. //退出循环回到初始位置
  586. DeviceProcessLogShow($"执行{count}次取冰淇淋杯,仍未成功,订单默认废弃,机器人回到初始位置!");
  587. EventBus.EventBus.GetInstance().Publish(new LebaiRobot_LebaiSenceEvent { DeviceId = DeviceId, LebaiSence = Lebai_qsqdCode.SENCE_冰淇淋杯回原点 }); //SENCE_冰淇淋杯回原点
  588. Wait();
  589. EventBus.EventBus.GetInstance().Publish(new LebaiRobot_SetValueEvent { DeviceId = DeviceId, RobotSetValue = 1 },(o) => { });
  590. morkT.GetIceCreamCup = false;
  591. return;
  592. }
  593. DeviceProcessLogShow($"执行{count}次取冰淇淋杯!");
  594. EventBus.EventBus.GetInstance().Publish(new LebaiRobot_LebaiSenceEvent { DeviceId = DeviceId, LebaiSence = Lebai_qsqdCode.SENCE_二次取冰淇淋杯 }); //SENCE_二次取冰淇淋杯
  595. EventBus.EventBus.GetInstance().Equals(new SCChip_TakeCupEvent { DeviceId = DeviceId, Cup = IC_CUP.CUP_ICECREAM });//落碗控制
  596. Wait();
  597. EventBus.EventBus.GetInstance().Publish(new LebaiRobot_SetValueEvent { DeviceId = DeviceId, RobotSetValue = 1 }, (o) => { });
  598. count++;
  599. goto p;
  600. }
  601. morkT.GetIceCreamCup = true;
  602. DeviceProcessLogShow("冰淇淋杯检测完成");
  603. }
  604. /// <summary>
  605. /// 机器人取接冰淇淋
  606. /// </summary>
  607. /// <param name="order"></param>
  608. private void GetIceCream(OrderLocInfo order)
  609. {
  610. //制冷模式
  611. EventBus.EventBus.GetInstance().Publish(new GSIceCream_ModeSetEvent { DeviceId = DeviceId, Mode = MORKI_MODE.制冷模式 });
  612. EventBus.EventBus.GetInstance().Publish(new LebaiRobot_SetValueEvent { DeviceId = DeviceId, RobotSetValue = 0 }, (o) => { });
  613. OrderChange(order.SuborderId, ORDER_STATUS.COOKING);
  614. EventBus.EventBus.GetInstance().Publish(new LebaiRobot_LebaiSenceEvent { DeviceId = DeviceId, LebaiSence = Lebai_qsqdCode.SENCE_接1号冰淇淋 }); //SENCE_接1号冰淇淋
  615. Wait();
  616. bool doItResult = true;
  617. //出料
  618. //EventBus.EventBus.GetInstance().Publish(new SCChip_RotorSwitchEvent { DeviceId = DeviceId, TurnOn = true });
  619. //Thread.Sleep(500);
  620. //EventBus.EventBus.GetInstance().Publish(new SCChip_RotorSwitchEvent { DeviceId = DeviceId, TurnOn = false });
  621. //EventBus.EventBus.GetInstance().Publish(new LebaiRobot_SetOutPutEvent { DeviceId = DeviceId, bDO = true ,pin = 1});
  622. //Thread.Sleep(500);
  623. //EventBus.EventBus.GetInstance().Publish(new LebaiRobot_SetOutPutEvent { DeviceId = DeviceId, bDO = false, pin = 1 });
  624. //Thread.Sleep(500);
  625. //EventBus.EventBus.GetInstance().Publish(new SCChip_MakeIceCreamEvent { DeviceId = DeviceId, SteeringEngine = IC_SE.SE_2 });//冰淇淋出料
  626. //DeviceProcessLogShow("开始等待6s");
  627. //Thread.Sleep(5000);
  628. //出料
  629. EventBus.EventBus.GetInstance().Publish(new GSIceCream_DischargeEvent { DeviceId = DeviceId }, (o) =>
  630. {
  631. doItResult = (bool)o[0];
  632. });
  633. if (doItResult)
  634. {
  635. IceCreamCookCheck();
  636. }
  637. else
  638. {
  639. int count_1 = 0;
  640. while ((byte)peripheralStatus["IceCreamCXB"] <= 86)
  641. {
  642. Thread.Sleep(5);
  643. count_1++;
  644. if (count_1 >= 2000)
  645. break;
  646. }
  647. IceCreamCookCheck();
  648. }
  649. EventBus.EventBus.GetInstance().Publish(new LebaiRobot_SetValueEvent { DeviceId = DeviceId, RobotSetValue = 1 }, (o) => { });
  650. }
  651. /// <summary>
  652. /// 把冰淇淋放到取餐位后回原点
  653. /// </summary>
  654. /// <param name="order"></param>
  655. private void PutIceCream(OrderLocInfo order)
  656. {
  657. bool resultValue = true;
  658. while (resultValue)
  659. {
  660. EventBus.EventBus.GetInstance().Publish(new LebaiRobot_GetInputEvent { DeviceId = DeviceId, Pin = 0 }, (res) =>
  661. {
  662. if (res[0] is bool b)
  663. {
  664. resultValue = b;
  665. }
  666. });
  667. Thread.Sleep(500);
  668. }
  669. EventBus.EventBus.GetInstance().Publish(new LebaiRobot_LebaiSenceEvent { DeviceId = DeviceId, LebaiSence = Lebai_qsqdCode.SENCE_放冰淇淋位置 }); //SENCE_放冰淇淋位置
  670. Wait();
  671. EventBus.EventBus.GetInstance().Publish(new LebaiRobot_SetValueEvent { DeviceId = DeviceId, RobotSetValue = 1 }, (o) => { });
  672. //订单状态改变:完成
  673. OrderChange(order.SuborderId, ORDER_STATUS.COMPLETED_COOK);
  674. morkT.waitMorkOrder = order;
  675. DeviceProcessLogShow($"{order.GoodsName}等待取餐");
  676. //WaitTakeMealOrder.Enqueue(order);
  677. }
  678. /// <summary>
  679. /// 冰淇淋机器制作冰淇淋
  680. /// </summary>
  681. public void IceCreamCookCheck()
  682. {
  683. bool result = false;
  684. int retry = 3;
  685. DateTime beginTime = DateTime.Now;
  686. while (!result)
  687. {
  688. EventBus.EventBus.GetInstance().Publish(new LebaiRobot_GetInputEvent { DeviceId = DeviceId, Pin = 3 }, (res) =>
  689. {
  690. if (res[0] is bool resultValue)
  691. {
  692. result = resultValue;
  693. }
  694. });
  695. if (retry <= 0 || DateTime.Now.Subtract(beginTime).TotalSeconds >= 10)
  696. {
  697. DeviceProcessLogShow("超时未出料,重试次数用尽");
  698. break;
  699. }
  700. if (DateTime.Now.Subtract(beginTime).TotalSeconds > 5)
  701. {
  702. DeviceProcessLogShow("超时未出料,重新发送打料指令");
  703. EventBus.EventBus.GetInstance().Publish(new GSIceCream_ModeSetEvent() { DeviceId = DeviceId, Mode = MORKI_MODE.打料 });
  704. beginTime = DateTime.Now;
  705. retry--;
  706. }
  707. Thread.Sleep(10);
  708. }
  709. DeviceProcessLogShow("开始等待6s");
  710. Thread.Sleep(5000);
  711. }
  712. public override void SimOrder()
  713. {
  714. }
  715. }
  716. }