终端一体化运控平台
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
33 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. /// <summary>
  348. /// 订单状态改变
  349. /// </summary>
  350. /// <param name="subid"></param>
  351. /// <param name="oRDER_STATUS"></param>
  352. private void OrderChange(string subid, ORDER_STATUS oRDER_STATUS)
  353. {
  354. EventBus.EventBus.GetInstance().Publish(new OrderStatusChangedEvent() { Status = oRDER_STATUS, SubOrderId = subid, deviceClientType = DeviceType });
  355. }
  356. private void Wait(int value = 101)
  357. {
  358. while (!((bool)peripheralStatus["RobotOK"] && (int)peripheralStatus["RobotValue"] == value))
  359. {
  360. Thread.Sleep(5);
  361. }
  362. }
  363. /// <summary>
  364. /// 是否可以开始制作咖啡
  365. /// </summary>
  366. /// <returns></returns>
  367. private bool CoffeeCanMake()
  368. {
  369. bool canMake = (IsHealth && morkT.morkOrderPushesCoffee.Count > 0 && !morkT.IsCoffeeMake) ? true : false;
  370. return canMake;
  371. }
  372. /// <summary>
  373. /// 制作咖啡流程
  374. /// </summary>
  375. private void MakeCoffeeProcess()
  376. {
  377. if (CoffeeCanMake())
  378. {
  379. if (morkT.morkOrderPushesCoffee.TryDequeue(out OrderLocInfo orderLoc))
  380. {
  381. DeviceProcessLogShow($"开始制作 [咖啡] 订单[{orderLoc.SortNum}]");
  382. GetAndCheeckCoffe(orderLoc);//取咖啡杯
  383. if (!morkT.GetCoffeeCup) return;
  384. EventBus.EventBus.GetInstance().Publish(new LebaiRobot_LebaiSenceEvent { DeviceId = DeviceId, LebaiSence = Lebai_qsqdCode.SENCE_接咖啡后回原点 }); //接咖啡后回原点
  385. Wait();
  386. EventBus.EventBus.GetInstance().Publish(new LebaiRobot_SetValueEvent { DeviceId = DeviceId, RobotSetValue = 1 }, (o) => { });
  387. EventBus.EventBus.GetInstance().Publish(new DRCoffee_MakeCoffeeEvent() {DeviceId = DeviceId, DrinkCode = (BPASmartClient.Model.咖啡机.Enum.DrCoffeeDrinksCode)int.Parse(orderLoc.Loc) });//接咖啡控制
  388. DeviceProcessLogShow($"发送咖啡机制作{orderLoc.Loc}!");
  389. morkT.IsCoffeeMake = true; morkT.MakeCoffeeOrder = orderLoc;
  390. }
  391. }
  392. }
  393. /// <summary>
  394. /// 咖啡机制作完咖啡,取走并放到取餐口,最后回原点
  395. /// </summary>
  396. private void MakeCoffeeComplete()
  397. {
  398. if (morkT.IsCoffeeMake && IsHealth)
  399. {
  400. if (morkT.MakeCoffeeOrder != null && morkT.MakeCoffeeOrder.OrderStatus == 1)
  401. {
  402. DeviceProcessLogShow($"将咖啡移动到取餐位 [咖啡] 订单[{morkT.MakeCoffeeOrder.SortNum}]");
  403. DoCoffeeQC(morkT.MakeCoffeeOrder);
  404. morkT.MakeCoffeeOrder = null;
  405. morkT.IsCoffeeMake = false;
  406. }
  407. }
  408. }
  409. /// <summary>
  410. /// 将咖啡杯从咖啡机 取走到 取餐口
  411. /// </summary>
  412. private void DoCoffeeQC(OrderLocInfo order)
  413. {
  414. EventBus.EventBus.GetInstance().Publish(new LebaiRobot_LebaiSenceEvent { DeviceId = DeviceId, LebaiSence = Lebai_qsqdCode.SENCE_取咖啡出餐 }); //SENCE_取咖啡出餐
  415. Wait();
  416. EventBus.EventBus.GetInstance().Publish(new LebaiRobot_SetValueEvent { DeviceId = DeviceId, RobotSetValue = 1 }, (o) => { });
  417. //订单状态改变:完成
  418. OrderChange(order.SuborderId, ORDER_STATUS.COMPLETED_COOK);
  419. morkT.waitMorkOrder = order;
  420. DeviceProcessLogShow($"{order.GoodsName}等待取餐");
  421. //WaitTakeMealOrder.Enqueue(order);
  422. }
  423. /// <summary>
  424. /// 取咖啡杯&&咖啡杯检测 若检测失败机器人回原点
  425. /// </summary>
  426. /// <param name="order"></param>
  427. private void GetAndCheeckCoffe(OrderLocInfo order)
  428. {
  429. EventBus.EventBus.GetInstance().Publish(new LebaiRobot_SetValueEvent { DeviceId = DeviceId, RobotSetValue = 0 },(o)=>{ });
  430. OrderChange(order.SuborderId, ORDER_STATUS.COOKING);
  431. EventBus.EventBus.GetInstance().Publish(new LebaiRobot_LebaiSenceEvent { DeviceId = DeviceId, LebaiSence = Lebai_qsqdCode.SENCE_取咖啡杯 }); //SENCE_取咖啡杯
  432. Wait();
  433. // EventBus.EventBus.GetInstance().Publish(new SCChip_TakeCupEvent { DeviceId = DeviceId, Cup = IC_CUP.CUP_COFFEE });//落碗控制
  434. EventBus.EventBus.GetInstance().Publish(new LebaiRobot_SetOutPutEvent { DeviceId = DeviceId, Value = true, Pin = 1 });
  435. EventBus.EventBus.GetInstance().Publish(new LebaiRobot_GetInputEvent { DeviceId = DeviceId, Pin = 1 }, (o) =>
  436. {
  437. //if (o != null && o.Length > 0 && o[0] is bool resultValue)
  438. //{
  439. // result = resultValue;
  440. //}
  441. });
  442. Thread.Sleep(500);
  443. DeviceProcessLogShow("尝试取咖啡杯!");
  444. EventBus.EventBus.GetInstance().Publish(new LebaiRobot_SetValueEvent { DeviceId = DeviceId, RobotSetValue = 1 }, (o) => { });
  445. int count = 1;
  446. bool result = true;
  447. p:
  448. EventBus.EventBus.GetInstance().Publish(new LebaiRobot_LebaiSenceEvent { DeviceId = DeviceId, LebaiSence = Lebai_qsqdCode.SENCE_咖啡杯检测 }); //SENCE_咖啡杯检测
  449. Wait();
  450. EventBus.EventBus.GetInstance().Publish(new LebaiRobot_SetValueEvent { DeviceId = DeviceId, RobotSetValue = 1 }, (o) => { });
  451. EventBus.EventBus.GetInstance().Publish(new LebaiRobot_GetTCPInputEvent { DeviceId = DeviceId, Pin = 1 }, (o)=>
  452. {
  453. if (o != null && o.Length > 0 && o[0] is bool resultValue)
  454. {
  455. result = resultValue;
  456. }
  457. });
  458. if (!result)
  459. {
  460. if (count >= 3)
  461. {
  462. //退出循环回到初始位置
  463. DeviceProcessLogShow($"执行{count}次取咖啡杯,仍为成功,订单默认废弃,机器人回到初始位置!");
  464. EventBus.EventBus.GetInstance().Publish(new LebaiRobot_LebaiSenceEvent { DeviceId = DeviceId, LebaiSence = Lebai_qsqdCode.SENCE_咖啡杯回原点 }); //SENCE_咖啡杯回原点
  465. Wait();
  466. EventBus.EventBus.GetInstance().Publish(new LebaiRobot_SetValueEvent { DeviceId = DeviceId, RobotSetValue = 1 }, (o) => { });
  467. morkT.GetCoffeeCup = false;
  468. return;
  469. }
  470. DeviceProcessLogShow("执行二次取咖啡杯");
  471. EventBus.EventBus.GetInstance().Publish(new LebaiRobot_LebaiSenceEvent { DeviceId = DeviceId, LebaiSence = Lebai_qsqdCode.SENCE_二次取咖啡杯 }); //SENCE_二次取咖啡杯
  472. Wait();
  473. EventBus.EventBus.GetInstance().Publish(new SCChip_TakeCupEvent { DeviceId = DeviceId, Cup = IC_CUP.CUP_COFFEE });//落碗控制
  474. EventBus.EventBus.GetInstance().Publish(new LebaiRobot_SetValueEvent { DeviceId = DeviceId, RobotSetValue = 1 }, (o) => { });
  475. count++;
  476. goto p;
  477. }
  478. morkT.GetCoffeeCup = true;
  479. DeviceProcessLogShow("取咖啡杯完成");
  480. }
  481. /// <summary>
  482. /// 冰淇淋是否可以开始制作
  483. /// </summary>
  484. /// <returns></returns>
  485. private bool IceCreamCanMake()
  486. {
  487. bool canMake = (IsHealth && morkT.morkOrderPushesIceCream.Count > 0) ? true : false;
  488. return canMake;
  489. }
  490. /// <summary>
  491. /// 制作冰淇淋流程
  492. /// </summary>
  493. private void MakeIceCreamProcess()
  494. {
  495. if (IceCreamCanMake())
  496. {
  497. //if (morkT.morkOrderPushesIceCream.TryDequeue(out OrderLocInfo order))
  498. //{
  499. // DoIceCream(order);
  500. //}
  501. if (peripheralStatus.ContainsKey("IceCreamCurrentMode"))
  502. {
  503. if ((MORKI_MODE)peripheralStatus["IceCreamCurrentMode"] != MORKI_MODE.制冷模式) EventBus.EventBus.GetInstance().Publish(new GSIceCream_ModeSetEvent { DeviceId = DeviceId, Mode = MORKI_MODE.制冷模式 });
  504. }
  505. if (peripheralStatus.ContainsKey("IceCreamCXB"))
  506. {
  507. if ((byte)peripheralStatus["IceCreamCXB"] >= 86 && morkT.morkOrderPushesIceCream.Count > 0)//成型比大于86才可以制作
  508. {
  509. bool result = true;
  510. EventBus.EventBus.GetInstance().Publish(new LebaiRobot_GetInputEvent { DeviceId = DeviceId, Pin = 3 }, (res) =>
  511. {
  512. if (res[0] is bool resultValue)
  513. {
  514. result = resultValue;
  515. }
  516. });
  517. if (result)
  518. {
  519. if (morkT.IceIsOK) DeviceProcessLogShow("请检查冰淇淋出料口有无遮挡");
  520. morkT.IceIsOK = false;
  521. }
  522. else if (morkT.morkOrderPushesIceCream.TryDequeue(out OrderLocInfo order))
  523. {
  524. morkT.IceIsOK = true;
  525. DeviceProcessLogShow($"开始制作 [冰淇淋] 订单[{order.SortNum}]");
  526. DoIceCream(order);
  527. }
  528. }
  529. }
  530. }
  531. }
  532. /// <summary>
  533. /// 做冰淇淋
  534. /// </summary>
  535. private void DoIceCream(OrderLocInfo order)
  536. {
  537. GetIceCreamCup();
  538. CheckICeCreaCup();
  539. if (morkT.GetIceCreamCup)
  540. {
  541. GetIceCream(order);
  542. PutIceCream(order);
  543. }
  544. }
  545. /// <summary>
  546. /// 取冰淇淋杯
  547. /// </summary>
  548. private void GetIceCreamCup()
  549. {
  550. MessageLog.GetInstance.Show("准备开始制作冰淇淋");
  551. EventBus.EventBus.GetInstance().Publish(new LebaiRobot_SetValueEvent { DeviceId = DeviceId, RobotSetValue = 0 }, (o) => { });
  552. EventBus.EventBus.GetInstance().Publish(new LebaiRobot_LebaiSenceEvent { DeviceId = DeviceId, LebaiSence = Lebai_qsqdCode.SENCE_取冰淇淋杯 }); //SENCE_取冰淇淋杯
  553. Wait();
  554. EventBus.EventBus.GetInstance().Publish(new SCChip_TakeCupEvent { DeviceId = DeviceId, Cup = IC_CUP.CUP_ICECREAM });//落碗控制
  555. Thread.Sleep(500);
  556. DeviceProcessLogShow("尝试取冰淇淋杯!");
  557. }
  558. /// <summary>
  559. /// 冰淇淋杯检测,失败后机器人回到原点
  560. /// </summary>
  561. private void CheckICeCreaCup()
  562. {
  563. int count = 2;
  564. bool result = true;
  565. EventBus.EventBus.GetInstance().Publish(new LebaiRobot_SetValueEvent { DeviceId = DeviceId, RobotSetValue = 1 }, (o) => { });
  566. p:
  567. EventBus.EventBus.GetInstance().Publish(new LebaiRobot_LebaiSenceEvent { DeviceId = DeviceId, LebaiSence = Lebai_qsqdCode.SENCE_冰淇淋杯检测 }); //SENCE_冰淇淋杯检测
  568. Wait();
  569. Thread.Sleep(500);
  570. EventBus.EventBus.GetInstance().Publish(new LebaiRobot_SetValueEvent { DeviceId = DeviceId, RobotSetValue = 1 }, (o) =>
  571. {
  572. if (o != null && o.Length > 0 && o[0] is SignalResult res)
  573. {
  574. MessageLog.GetInstance.Show(res.ToString());
  575. }
  576. });
  577. while((int)peripheralStatus["RobotValue"] != 0)
  578. {
  579. Thread.Sleep(10);
  580. }
  581. MessageLog.GetInstance.Show($"乐白机器人信号值{peripheralStatus["RobotValue"].ToString()}");
  582. //while ((ELebaiRModel)peripheralStatus["RobotMode"] !=ELebaiRModel.空闲状态)
  583. //{
  584. // EventBus.EventBus.GetInstance().Publish(new LebaiRobot_SetValueEvent { DeviceId = DeviceId, RobotSetValue = 1 });
  585. // Thread.Sleep(500);
  586. //}
  587. EventBus.EventBus.GetInstance().Publish(new LebaiRobot_GetTCPInputEvent { DeviceId = DeviceId, Pin = 1 }, (o) =>
  588. {
  589. if (o != null && o.Length > 0 && o[0] is bool resultValue)
  590. {
  591. result = resultValue;
  592. }
  593. });
  594. if (!result)
  595. {
  596. if (count >= 3)
  597. {
  598. //退出循环回到初始位置
  599. DeviceProcessLogShow($"执行{count}次取冰淇淋杯,仍未成功,订单默认废弃,机器人回到初始位置!");
  600. EventBus.EventBus.GetInstance().Publish(new LebaiRobot_LebaiSenceEvent { DeviceId = DeviceId, LebaiSence = Lebai_qsqdCode.SENCE_冰淇淋杯回原点 }); //SENCE_冰淇淋杯回原点
  601. Wait();
  602. EventBus.EventBus.GetInstance().Publish(new LebaiRobot_SetValueEvent { DeviceId = DeviceId, RobotSetValue = 1 },(o) => { });
  603. morkT.GetIceCreamCup = false;
  604. return;
  605. }
  606. DeviceProcessLogShow($"执行{count}次取冰淇淋杯!");
  607. EventBus.EventBus.GetInstance().Publish(new LebaiRobot_LebaiSenceEvent { DeviceId = DeviceId, LebaiSence = Lebai_qsqdCode.SENCE_二次取冰淇淋杯 }); //SENCE_二次取冰淇淋杯
  608. EventBus.EventBus.GetInstance().Equals(new SCChip_TakeCupEvent { DeviceId = DeviceId, Cup = IC_CUP.CUP_ICECREAM });//落碗控制
  609. Wait();
  610. EventBus.EventBus.GetInstance().Publish(new LebaiRobot_SetValueEvent { DeviceId = DeviceId, RobotSetValue = 1 }, (o) => { });
  611. count++;
  612. goto p;
  613. }
  614. morkT.GetIceCreamCup = true;
  615. DeviceProcessLogShow("冰淇淋杯检测完成");
  616. }
  617. /// <summary>
  618. /// 机器人取接冰淇淋
  619. /// </summary>
  620. /// <param name="order"></param>
  621. private void GetIceCream(OrderLocInfo order)
  622. {
  623. //制冷模式
  624. EventBus.EventBus.GetInstance().Publish(new GSIceCream_ModeSetEvent { DeviceId = DeviceId, Mode = MORKI_MODE.制冷模式 });
  625. EventBus.EventBus.GetInstance().Publish(new LebaiRobot_SetValueEvent { DeviceId = DeviceId, RobotSetValue = 0 }, (o) => { });
  626. OrderChange(order.SuborderId, ORDER_STATUS.COOKING);
  627. EventBus.EventBus.GetInstance().Publish(new LebaiRobot_LebaiSenceEvent { DeviceId = DeviceId, LebaiSence = Lebai_qsqdCode.SENCE_接1号冰淇淋 }); //SENCE_接1号冰淇淋
  628. Wait();
  629. bool doItResult = true;
  630. //出料
  631. //EventBus.EventBus.GetInstance().Publish(new SCChip_RotorSwitchEvent { DeviceId = DeviceId, TurnOn = true });
  632. //Thread.Sleep(500);
  633. //EventBus.EventBus.GetInstance().Publish(new SCChip_RotorSwitchEvent { DeviceId = DeviceId, TurnOn = false });
  634. //EventBus.EventBus.GetInstance().Publish(new LebaiRobot_SetOutPutEvent { DeviceId = DeviceId, bDO = true ,pin = 1});
  635. //Thread.Sleep(500);
  636. //EventBus.EventBus.GetInstance().Publish(new LebaiRobot_SetOutPutEvent { DeviceId = DeviceId, bDO = false, pin = 1 });
  637. //Thread.Sleep(500);
  638. //EventBus.EventBus.GetInstance().Publish(new SCChip_MakeIceCreamEvent { DeviceId = DeviceId, SteeringEngine = IC_SE.SE_2 });//冰淇淋出料
  639. //DeviceProcessLogShow("开始等待6s");
  640. //Thread.Sleep(5000);
  641. //出料
  642. EventBus.EventBus.GetInstance().Publish(new GSIceCream_DischargeEvent { DeviceId = DeviceId }, (o) =>
  643. {
  644. doItResult = (bool)o[0];
  645. });
  646. if (doItResult)
  647. {
  648. IceCreamCookCheck();
  649. }
  650. else
  651. {
  652. int count_1 = 0;
  653. while ((byte)peripheralStatus["IceCreamCXB"] <= 86)
  654. {
  655. Thread.Sleep(5);
  656. count_1++;
  657. if (count_1 >= 2000)
  658. break;
  659. }
  660. IceCreamCookCheck();
  661. }
  662. EventBus.EventBus.GetInstance().Publish(new LebaiRobot_SetValueEvent { DeviceId = DeviceId, RobotSetValue = 1 }, (o) => { });
  663. }
  664. /// <summary>
  665. /// 把冰淇淋放到取餐位后回原点
  666. /// </summary>
  667. /// <param name="order"></param>
  668. private void PutIceCream(OrderLocInfo order)
  669. {
  670. bool resultValue = true;
  671. while (resultValue)
  672. {
  673. EventBus.EventBus.GetInstance().Publish(new LebaiRobot_GetInputEvent { DeviceId = DeviceId, Pin = 0 }, (res) =>
  674. {
  675. if (res[0] is bool b)
  676. {
  677. resultValue = b;
  678. }
  679. });
  680. Thread.Sleep(500);
  681. }
  682. EventBus.EventBus.GetInstance().Publish(new LebaiRobot_LebaiSenceEvent { DeviceId = DeviceId, LebaiSence = Lebai_qsqdCode.SENCE_放冰淇淋位置 }); //SENCE_放冰淇淋位置
  683. Wait();
  684. EventBus.EventBus.GetInstance().Publish(new LebaiRobot_SetValueEvent { DeviceId = DeviceId, RobotSetValue = 1 }, (o) => { });
  685. //订单状态改变:完成
  686. OrderChange(order.SuborderId, ORDER_STATUS.COMPLETED_COOK);
  687. morkT.waitMorkOrder = order;
  688. DeviceProcessLogShow($"{order.GoodsName}等待取餐");
  689. //WaitTakeMealOrder.Enqueue(order);
  690. }
  691. /// <summary>
  692. /// 冰淇淋机器制作冰淇淋
  693. /// </summary>
  694. public void IceCreamCookCheck()
  695. {
  696. bool result = false;
  697. int retry = 3;
  698. DateTime beginTime = DateTime.Now;
  699. while (!result)
  700. {
  701. EventBus.EventBus.GetInstance().Publish(new LebaiRobot_GetInputEvent { DeviceId = DeviceId, Pin = 3 }, (res) =>
  702. {
  703. if (res[0] is bool resultValue)
  704. {
  705. result = resultValue;
  706. }
  707. });
  708. if (retry <= 0 || DateTime.Now.Subtract(beginTime).TotalSeconds >= 10)
  709. {
  710. DeviceProcessLogShow("超时未出料,重试次数用尽");
  711. break;
  712. }
  713. if (DateTime.Now.Subtract(beginTime).TotalSeconds > 5)
  714. {
  715. DeviceProcessLogShow("超时未出料,重新发送打料指令");
  716. EventBus.EventBus.GetInstance().Publish(new GSIceCream_ModeSetEvent() { DeviceId = DeviceId, Mode = MORKI_MODE.打料 });
  717. beginTime = DateTime.Now;
  718. retry--;
  719. }
  720. Thread.Sleep(10);
  721. }
  722. DeviceProcessLogShow("开始等待6s");
  723. Thread.Sleep(5000);
  724. }
  725. public override void SimOrder()
  726. {
  727. }
  728. }
  729. }