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

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