终端一体化运控平台
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.
 
 
 

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