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

918 lines
35 KiB

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Configuration;
  4. using System.Linq;
  5. using System.Threading;
  6. using System.Collections.Concurrent;
  7. using System.Diagnostics;
  8. using System.Threading.Tasks;
  9. using BPASmartClient.Device;
  10. using BPA.Message.Enum;
  11. using BPA.Message;
  12. using BPASmartClient.Helper;
  13. using BPASmartClient.Model.咖啡机.Enum;
  14. using BPASmartClient.Model;
  15. using BPASmartClient.EventBus;
  16. using static BPASmartClient.EventBus.EventBus;
  17. using BPASmartClient.Message;
  18. using BPASmartClient.Model.乐白机器人;
  19. using BPASmartClient.Model.单片机;
  20. using BPASmartClient.Model.PLC;
  21. namespace BPASmartClient.MorkT_BarCounter
  22. {
  23. /*
  24. * 冰淇淋咖啡机组合套装
  25. * 物料位置:
  26. * 1:冰淇料
  27. * 2:冰淇淋杯
  28. * 5:咖啡
  29. * 6:咖啡杯
  30. * 9: 茶
  31. * 10: 茶杯
  32. */
  33. public class Control_MorkT_BarCounter : BaseDevice
  34. {
  35. private Dictionary<string, PolymerBatching> batchings = new Dictionary<string, PolymerBatching>();
  36. //容器位置
  37. private string holderLoc;
  38. //主料位置
  39. private string mainMaterialLoc;
  40. public override global::BPA.Message.Enum.DeviceClientType DeviceType { get { return BPA.Message.Enum.DeviceClientType.MORKT; } }
  41. GVL_MorkT morkTJaka =new GVL_MorkT();
  42. /// <summary>
  43. /// 果汁机做法,true:热饮,false:冷饮
  44. /// </summary>
  45. private bool GuMake = false;
  46. /// <summary>
  47. /// 订单是否加冰
  48. /// </summary>
  49. private bool IsAddIce = false;
  50. public override void DoMain()
  51. {
  52. if (Json<KeepDataBase>.Data.IsVerify)
  53. {
  54. IsHealth = true;
  55. }
  56. IsHealth = true;
  57. serverInit();
  58. DataParse();
  59. ActionManage.GetInstance.Register(new Action<object>((o) => { SimOrder(o); }), "SimOrder");//模拟订单委托注册
  60. }
  61. private void serverInit()
  62. {
  63. EventBus.EventBus.GetInstance().Subscribe<MaterialDeliveryEvent>(DeviceId, delegate (IEvent @event, EventCallBackHandle callBack)
  64. {
  65. if (@event == null) return;
  66. if (@event is MaterialDeliveryEvent material)
  67. {
  68. orderMaterialDelivery = material.orderMaterialDelivery;
  69. }
  70. });
  71. }
  72. private void DataParse()
  73. {
  74. EventBus.EventBus.GetInstance().Subscribe<DoOrderEvent>(DeviceId, delegate (IEvent @event, EventCallBackHandle callBackHandle)
  75. {
  76. if (@event == null) return;
  77. if (@event is DoOrderEvent order)
  78. {
  79. if (order.MorkOrder.GoodBatchings == null) return;
  80. OrderCount++;
  81. DeviceProcessLogShow($"接收到{OrderCount}次订单");
  82. batchings = PolymerBatching.BuildAll();
  83. //商品类型
  84. GOODS_TYPE currentGoodsType = GOODS_TYPE.NEITHER;
  85. foreach (var item in order.MorkOrder.GoodBatchings)
  86. {
  87. var res = orderMaterialDelivery?.BatchingInfo?.FirstOrDefault(p => p.BatchingId == item.BatchingId);
  88. if (res != null)
  89. {
  90. //验证商品是做的某种饮料
  91. if (ValidateGoodsByBatching(res.BatchingLoc) != GOODS_TYPE.NEITHER)
  92. {
  93. //获取当前物料所属商品类型
  94. currentGoodsType = ValidateGoodsByBatching(res.BatchingLoc);
  95. }
  96. //
  97. switch (batchings[res.BatchingLoc].BatchingClass)
  98. {
  99. case BATCHING_CLASS.HOLDER:
  100. holderLoc = res.BatchingLoc;
  101. break;
  102. case BATCHING_CLASS.MAIN_MATERIAL:
  103. mainMaterialLoc = res.BatchingLoc;
  104. break;
  105. }
  106. //根据商品类型执行具体制作流程
  107. switch (currentGoodsType)
  108. {
  109. case GOODS_TYPE.COFFEE:
  110. IsAddIce = order.MorkOrder.MakeID == "3";//判断是否加冰
  111. if (morkTJaka.morkOrderPushesCoffee.FirstOrDefault(p => p.SuborderId == order.MorkOrder.SuborderId) == null)
  112. {
  113. morkTJaka.morkOrderPushesCoffee.Enqueue(new OrderLocInfo()
  114. {
  115. SuborderId = order.MorkOrder.SuborderId,
  116. BatchingId = res.BatchingId,
  117. Loc = ushort.Parse( mainMaterialLoc),
  118. GoodName = order.MorkOrder.GoodsName,
  119. });
  120. }
  121. break;
  122. case GOODS_TYPE.JUICE:
  123. if (morkTJaka.morkOrderPushesJuicer.FirstOrDefault(p => p.SuborderId == order.MorkOrder.SuborderId) == null)
  124. {
  125. morkTJaka.morkOrderPushesJuicer.Enqueue(new OrderLocInfo()
  126. {
  127. SuborderId = order.MorkOrder.SuborderId,
  128. BatchingId = res.BatchingId,
  129. Loc = ushort.Parse(mainMaterialLoc),
  130. GoodName = order.MorkOrder.GoodsName,
  131. MakeID = ushort.Parse(order.MorkOrder.MakeID),
  132. });
  133. }
  134. break;
  135. case GOODS_TYPE.TEA:
  136. if (morkTJaka.morkOrderPushesTea.FirstOrDefault(p => p.SuborderId == order.MorkOrder.SuborderId) == null)
  137. {
  138. morkTJaka.morkOrderPushesTea.Enqueue(new OrderLocInfo()
  139. {
  140. SuborderId = order.MorkOrder.SuborderId,
  141. BatchingId = res.BatchingId,
  142. Loc = ushort.Parse(mainMaterialLoc),
  143. GoodName = order.MorkOrder.GoodsName,
  144. });
  145. }
  146. break;
  147. case GOODS_TYPE.WATER:
  148. if (morkTJaka.morkOrderPushesWater.FirstOrDefault(p => p.SuborderId == order.MorkOrder.SuborderId) == null)
  149. {
  150. morkTJaka.morkOrderPushesWater.Enqueue(new OrderLocInfo()
  151. {
  152. SuborderId = order.MorkOrder.SuborderId,
  153. BatchingId = res.BatchingId,
  154. Loc = ushort.Parse(mainMaterialLoc),
  155. GoodName = order.MorkOrder.GoodsName,
  156. });
  157. }
  158. break;
  159. case GOODS_TYPE.NEITHER:
  160. DeviceProcessLogShow("未知的商品类型");
  161. break;
  162. }
  163. }
  164. }
  165. }
  166. });
  167. }
  168. /// <summary>
  169. /// 将空杯放好到接饮料的地方的标志位
  170. /// </summary>
  171. private bool bFirstTrig_TeaWater = false;
  172. private bool bFirstTrig_Coffee = false;
  173. private bool bFirstTrig_Juice = false;
  174. /// <summary>
  175. /// 延迟的超时时间
  176. /// </summary>
  177. DateTime delayTimeOut_Water;
  178. DateTime delayTimeOut_Coffee;
  179. DateTime delayTimeOut_Juice;
  180. public override void MainTask()
  181. {
  182. EventBus.EventBus.GetInstance().Subscribe<DRCoffee_CoffeEndCookEvent>(DeviceId, delegate (IEvent @event, EventCallBackHandle callBack)
  183. {
  184. if (morkTJaka.IsHaveCoffeeCup)
  185. morkTJaka.MakeCoffeeEnd = true;
  186. });
  187. if (pickUpCoffeeHaveCup)
  188. {
  189. if (!bFirstTrig_Coffee)
  190. {
  191. bFirstTrig_Coffee = true;
  192. delayTimeOut_Coffee = DateTime.Now;
  193. }
  194. else if (DateTime.Now.Subtract(delayTimeOut_Coffee).TotalSeconds > 180 && bFirstTrig_Coffee == true)
  195. {
  196. bFirstTrig_Coffee = false;
  197. if (morkTJaka.IsHaveCoffeeCup)
  198. morkTJaka.MakeCoffeeEnd = true;
  199. }
  200. }
  201. if (morkTJaka.IsHaveJuiceCup)
  202. {
  203. var Juicestate = GetStatus<int[]>("GetDeviceStatus");
  204. if (Juicestate != null)
  205. {
  206. if (Juicestate.Length > 0)
  207. {
  208. var Juicestate1 = Convert.ToString(Juicestate[0], 2);
  209. var Juicestate2 = Juicestate[1];
  210. if (Juicestate1.IndexOf("0") == 1 && Juicestate2 == 0)
  211. {
  212. morkTJaka.MakeJuiceEnd = true;
  213. }
  214. }
  215. }
  216. //若无状态返回 则加延迟
  217. if (!bFirstTrig_Juice)
  218. {
  219. bFirstTrig_Juice = true;
  220. delayTimeOut_Juice = DateTime.Now;
  221. }
  222. else if (DateTime.Now.Subtract(delayTimeOut_Juice).TotalSeconds > 30 && bFirstTrig_Juice==true)
  223. {
  224. bFirstTrig_Juice = false;
  225. morkTJaka.MakeJuiceEnd = true;
  226. }
  227. }
  228. if (morkTJaka.IsHaveTeaWaterCup)
  229. {
  230. if (!bFirstTrig_TeaWater)
  231. {
  232. bFirstTrig_TeaWater = true;
  233. delayTimeOut_Water = DateTime.Now;//开启接水信号后,记录当前时间
  234. }
  235. else if (DateTime.Now.Subtract(delayTimeOut_Water).TotalSeconds >= 50 && bFirstTrig_TeaWater == true)//接水超过50s后,启动接水完成标志,开启接水程序
  236. {
  237. bFirstTrig_TeaWater = false;
  238. morkTJaka.MakeTeaEnd = true;
  239. }
  240. }
  241. DoCoffee();
  242. DoJuice();
  243. DoBoiledTea();
  244. DoBoiledWater();
  245. }
  246. /// <summary>
  247. /// 订单状态改变
  248. /// </summary>
  249. /// <param name="subid"></param>
  250. /// <param name="oRDER_STATUS"></param>
  251. private void OrderChange(string subid, ORDER_STATUS oRDER_STATUS)
  252. {
  253. EventBus.EventBus.GetInstance().Publish(new OrderStatusChangedEvent() { Status = oRDER_STATUS, SubOrderId = subid, deviceClientType = DeviceType });
  254. }
  255. /// <summary>
  256. /// 验证商品是做的某种饮料
  257. /// </summary>
  258. /// <param name="batchingLoc">物料位置</param>
  259. private GOODS_TYPE ValidateGoodsByBatching(string batchingLoc)
  260. {
  261. if (batchings.ContainsKey(batchingLoc))
  262. return batchings[batchingLoc].GoodsType;
  263. return GOODS_TYPE.NEITHER;
  264. }
  265. /// <summary>
  266. /// 乐白的场景结束等待
  267. /// </summary>
  268. /// <param name="value"></param>
  269. private void Wait(int value = 101)
  270. {
  271. while (!((bool)peripheralStatus["RobotOK"] && (int)peripheralStatus["RobotValue"] == value))
  272. {
  273. Thread.Sleep(5);
  274. }
  275. new LebaiRobot_SetValueEvent { DeviceId = DeviceId, RobotSetValue = 0 }.Publish();
  276. }
  277. /// <summary>
  278. /// 乐白的场景
  279. /// </summary>
  280. /// <param name="sen"></param>
  281. private void Sence(int sen)
  282. {
  283. new LebaiRobot_LebaiSenceEvent { DeviceId = DeviceId, LebaiSence = sen }.Publish();
  284. }
  285. /// <summary>
  286. /// 乐白的数字量输出
  287. /// </summary>
  288. /// <param name="value"></param>
  289. /// <param name="pin"></param>
  290. private void Output(bool value,int pin)
  291. {
  292. new LebaiRobot_SetOutPutEvent { DeviceId = DeviceId, Pin = pin,Value=value }.Publish();
  293. }
  294. private T GetStatus<T>(string key)
  295. {
  296. if (peripheralStatus.ContainsKey(key))
  297. {
  298. if (peripheralStatus[key] != null)
  299. {
  300. return (T)(peripheralStatus[key]);
  301. }
  302. }
  303. return default;
  304. }
  305. int[] devStatusBy = new int[2] { 0, 0 };
  306. bool outCupCheck = false;//放纸杯位置有无判断
  307. /// <summary>
  308. /// 判断接咖啡的位置是否有杯子
  309. /// </summary>
  310. bool pickUpCoffeeHaveCup = false;
  311. /// <summary>
  312. /// 判断接果汁的位置是否有杯子
  313. /// </summary>
  314. bool pickUpJuiceHaveCup = false;
  315. /// <summary>
  316. /// 判断接开水的位置是否有杯子
  317. /// </summary>
  318. bool pickUpHotWaterHaveCup = false;
  319. /// <summary>
  320. /// 传感器的输入信号 0:无意义 1:有信号 2:无信号 3:信号不正确
  321. /// </summary>
  322. int bSensorInput;
  323. private bool IsMakeCoffee()
  324. {
  325. bool bMake = (IsHealth && morkTJaka.morkOrderPushesCoffee.Count > 0 && !morkTJaka.IsHaveCoffeeCup) ? true : false;
  326. return bMake;
  327. }
  328. private bool IsMakeJuice()
  329. {
  330. bool bMake = (IsHealth && morkTJaka.morkOrderPushesJuicer.Count > 0 && !morkTJaka.IsHaveJuiceCup) ? true : false;
  331. return bMake;
  332. }
  333. private bool IsMakeTeaWater()
  334. {
  335. bool bMake = (IsHealth && morkTJaka.morkOrderPushesTea.Count > 0 && !morkTJaka.IsHaveTeaWaterCup) ? true : false;
  336. return bMake;
  337. }
  338. private bool IsMakeWater()
  339. {
  340. bool bMake = (IsHealth && morkTJaka.morkOrderPushesWater.Count > 0 && !morkTJaka.IsHaveTeaWaterCup) ? true : false;
  341. return bMake;
  342. }
  343. /// <summary>
  344. /// 做咖啡流程
  345. /// </summary>
  346. private void DoCoffee()
  347. {
  348. if (IsMakeCoffee())
  349. {
  350. if (morkTJaka.morkOrderPushesCoffee.TryDequeue(out OrderLocInfo orderLoc))
  351. {
  352. PickUpCoffee();//接咖啡
  353. morkTJaka.IsHaveCoffeeCup = true;
  354. }
  355. }
  356. else if(morkTJaka.MakeCoffeeEnd)
  357. {
  358. PutCoffeeCup();
  359. pickUpCoffeeHaveCup = false;
  360. morkTJaka.IsHaveCoffeeCup = false;
  361. }
  362. }
  363. private void DoJuice()
  364. {
  365. if (IsMakeJuice())
  366. {
  367. if (morkTJaka.morkOrderPushesJuicer.TryDequeue(out OrderLocInfo orderLoc))
  368. {
  369. switch (morkTJaka.morkOrderPushesJuicer.ElementAt(0).Loc)
  370. {
  371. case 1:
  372. GuMake = true;
  373. IsAddIce = false;
  374. break;
  375. case 2:
  376. GuMake = false;
  377. IsAddIce = false;
  378. break;
  379. case 3:
  380. GuMake = false;
  381. IsAddIce = true;
  382. break;
  383. default:
  384. break;
  385. }
  386. PickUpJuicer();
  387. morkTJaka.IsHaveJuiceCup = true;
  388. }
  389. }
  390. else if (morkTJaka.MakeJuiceEnd)
  391. {
  392. Thread.Sleep(5000);//延迟五秒,防止接饮料口滴饮料
  393. putJuice();
  394. pickUpJuiceHaveCup = false;
  395. morkTJaka.IsHaveJuiceCup = false;
  396. morkTJaka.MakeJuiceEnd = false;
  397. }
  398. }
  399. private void DoBoiledTea()
  400. {
  401. if (IsMakeTeaWater())
  402. {
  403. if (morkTJaka.morkOrderPushesTea.TryDequeue(out OrderLocInfo orderLoc))
  404. {
  405. PickUpTea();
  406. morkTJaka.IsHaveTeaWaterCup = true;
  407. }
  408. }
  409. else if(morkTJaka.MakeTeaEnd)
  410. {
  411. PutWaterCup();
  412. pickUpHotWaterHaveCup = false;
  413. morkTJaka.IsHaveTeaWaterCup = false ;
  414. morkTJaka.MakeTeaEnd = false;
  415. }
  416. }
  417. private void DoBoiledWater()
  418. {
  419. if (IsMakeWater())
  420. {
  421. if (morkTJaka.morkOrderPushesWater.TryDequeue(out OrderLocInfo orderLoc))
  422. {
  423. PickUpWater();
  424. }
  425. }
  426. else if (morkTJaka.MakeTeaEnd)
  427. {
  428. PutWaterCup();
  429. pickUpHotWaterHaveCup = false;
  430. morkTJaka.IsHaveTeaWaterCup = false;
  431. morkTJaka.MakeTeaEnd = false;
  432. }
  433. }
  434. #region 做咖啡流程
  435. /// <summary>
  436. /// 接咖啡
  437. /// </summary>
  438. private void PickUpCoffee()
  439. {
  440. if (!pickUpCoffeeHaveCup)
  441. {
  442. outCupCheck = false;
  443. OrderChange(morkTJaka.morkOrderPushesCoffee.ElementAt(0).SuborderId, BPA.Message.Enum.ORDER_STATUS.COOKING);
  444. int resultTakeCup = takeCup();
  445. if (resultTakeCup == 1)
  446. {
  447. new LebaiRobot_SetValueEvent { DeviceId = DeviceId, RobotSetValue = 0 }.Publish();
  448. Sence(GVL_MorkT.机器人安全位);
  449. Wait();
  450. WritePLCData("",2);//将轴移动到接咖啡的位置
  451. DeviceProcessLogShow("咖啡杯取杯完成");
  452. new LebaiRobot_SetValueEvent { DeviceId = DeviceId, RobotSetValue = 0 }.Publish();
  453. Sence(GVL_MorkT.接咖啡);
  454. Wait();
  455. pickUpCoffeeHaveCup = true;
  456. new DRCoffee_MakeCoffeeEvent() { DrinkCode = (DrCoffeeDrinksCode)(morkTJaka.morkOrderPushesCoffee.ElementAt(0).Loc) }.Publish(); //接咖啡控制 //DrCoffeeDrinksCode.热水
  457. }
  458. else
  459. {
  460. DeviceProcessLogShow("取杯失败 回到初始位,请及时处理!!");
  461. Sence(GVL_MorkT.机器人初始位);
  462. }
  463. }
  464. }
  465. /// <summary>
  466. /// 咖啡杯接好,放咖啡杯
  467. /// </summary>
  468. private void PutCoffeeCup()
  469. {
  470. while (GetStatus<bool>("RobotValue1"))//判断放杯位置是否有物品
  471. {
  472. if (!outCupCheck)
  473. DeviceProcessLogShow("成品处有纸杯存在,请取走!!");
  474. outCupCheck = true;
  475. }
  476. outCupCheck = false;
  477. new LebaiRobot_SetValueEvent { DeviceId = DeviceId, RobotSetValue = 0 }.Publish();
  478. Sence(GVL_MorkT.机器人安全位);
  479. Wait();
  480. WritePLCData("", 2);//将轴移动到接咖啡的位置
  481. new LebaiRobot_SetValueEvent { DeviceId = DeviceId, RobotSetValue = 0 }.Publish();
  482. Sence(GVL_MorkT.放咖啡杯);
  483. Wait();
  484. OrderChange(morkTJaka.morkOrderPushesCoffee.ElementAt(0).SuborderId, BPA.Message.Enum.ORDER_STATUS.COMPLETED_TAKE);
  485. DeviceProcessLogShow("咖啡制作完成");
  486. }
  487. #endregion
  488. #region 做开水流程
  489. /// <summary>
  490. /// 接开水
  491. /// </summary>
  492. private void PickUpWater()
  493. {
  494. #region 接水流程
  495. if (!pickUpHotWaterHaveCup)
  496. {
  497. OrderChange(morkTJaka.morkOrderPushesWater.ElementAt(0).SuborderId, BPA.Message.Enum.ORDER_STATUS.COOKING);
  498. int resultTakeCup = takeCup();
  499. if (resultTakeCup == 1)
  500. {
  501. new LebaiRobot_SetValueEvent { DeviceId = DeviceId, RobotSetValue = 0 }.Publish();
  502. Sence(GVL_MorkT.接开水);
  503. Wait();
  504. Output(false, 1);
  505. Output(false, 0);
  506. Thread.Sleep(100);
  507. Output(true, 0);
  508. Thread.Sleep(3000);
  509. Output(false, 0);
  510. Thread.Sleep(100);
  511. Output(false, 1);
  512. Thread.Sleep(100);
  513. Output(true, 1);
  514. Thread.Sleep(500);
  515. Output(false, 1);
  516. }
  517. else
  518. {
  519. return;
  520. }
  521. }
  522. #endregion
  523. }
  524. #endregion
  525. #region 做茶流程
  526. /// <summary>
  527. /// 做茶
  528. /// </summary>
  529. private void PickUpTea()
  530. {
  531. #region 接茶流程
  532. if (!pickUpHotWaterHaveCup)
  533. {
  534. OrderChange(morkTJaka.morkOrderPushesTea.ElementAt(0).SuborderId, BPA.Message.Enum.ORDER_STATUS.COOKING);
  535. int resultTakeCup = takeCup();
  536. if (resultTakeCup == 1)
  537. {
  538. DeviceProcessLogShow("取茶杯完成");
  539. new LebaiRobot_SetValueEvent { DeviceId = DeviceId, RobotSetValue = 0 }.Publish();
  540. Sence(GVL_MorkT.接茶叶);
  541. Wait();
  542. new WriteMcu() { TagName = "ServoControl", Address = "1", Value = 90 }.Publish();
  543. Thread.Sleep(1000);
  544. new WriteMcu() { TagName = "ServoControl", Address = "1", Value = 150 }.Publish();
  545. Thread.Sleep(1000);
  546. new WriteMcu() { TagName = "ServoControl", Address = "1", Value = 90 }.Publish();
  547. Thread.Sleep(3000);
  548. new LebaiRobot_SetValueEvent { DeviceId = DeviceId, RobotSetValue = 0 }.Publish();
  549. Sence(GVL_MorkT.接茶水);
  550. Wait();
  551. Output(false, 1);
  552. Output(false, 0);
  553. Thread.Sleep(100);
  554. Output(true, 0);
  555. Thread.Sleep(3000);
  556. Output(false, 0);
  557. Thread.Sleep(100);
  558. Output(false, 1);
  559. Thread.Sleep(100);
  560. Output(true, 1);
  561. Thread.Sleep(500);
  562. Output(false, 1);
  563. pickUpHotWaterHaveCup = true;
  564. }
  565. else
  566. {
  567. return;
  568. }
  569. }
  570. #endregion
  571. }
  572. /// <summary>
  573. /// 放水杯流程
  574. /// </summary>
  575. private void PutWaterCup()
  576. {
  577. while (GetStatus<bool>("RobotValue1"))//判断放杯位置是否有物品
  578. {
  579. if (!outCupCheck)
  580. DeviceProcessLogShow("成品处有纸杯存在,请取走!!");
  581. outCupCheck = true;
  582. }
  583. outCupCheck = false;
  584. new LebaiRobot_SetValueEvent { DeviceId = DeviceId, RobotSetValue = 0 }.Publish();
  585. Sence(GVL_MorkT.放水杯);
  586. Wait();
  587. OrderChange(morkTJaka.morkOrderPushesWater.ElementAt(0).SuborderId, BPA.Message.Enum.ORDER_STATUS.COMPLETED_TAKE);
  588. DeviceProcessLogShow("茶水制作完成");
  589. }
  590. #endregion
  591. #region 做果汁流程
  592. /// <summary>
  593. /// 果汁机控制信号
  594. /// </summary>
  595. private byte JuicerNum;
  596. private void getIce()
  597. {
  598. IsAddIceNow = IsAddIce;
  599. if (IsAddIce)
  600. {
  601. new LebaiRobot_SetValueEvent { DeviceId = DeviceId, RobotSetValue = 0 }.Publish();
  602. Sence(GVL_MorkT.取杯位_机器人安全位);
  603. Wait();
  604. WritePLCData("",3);//将模组移动到接冰的位置
  605. new LebaiRobot_SetValueEvent { DeviceId = DeviceId, RobotSetValue = 0 }.Publish();
  606. Sence(GVL_MorkT.接冰块);
  607. Wait();
  608. new StartMakeIce() { }.Publish();
  609. new LebaiRobot_SetValueEvent { DeviceId = DeviceId, RobotSetValue = 0 }.Publish();
  610. Sence(GVL_MorkT.接冰_机器人安全位);
  611. Wait();
  612. }
  613. }
  614. /// <summary>
  615. /// 当前订单是否加冰
  616. /// </summary>
  617. private bool IsAddIceNow = false;
  618. private int JuiceCH;
  619. /// <summary>
  620. /// 接果汁
  621. /// </summary>
  622. private void PickUpJuicer()
  623. {
  624. #region 接果汁流程
  625. if (!pickUpJuiceHaveCup)
  626. {
  627. OrderChange(morkTJaka.morkOrderPushesJuicer.ElementAt(0).SuborderId, BPA.Message.Enum.ORDER_STATUS.COOKING);
  628. int resultTakeCup = takeCup();
  629. JuiceCH = morkTJaka.morkOrderPushesJuicer.ElementAt(0).Loc;
  630. if (resultTakeCup == 1)
  631. {
  632. getIce();
  633. new LebaiRobot_SetValueEvent { DeviceId = DeviceId, RobotSetValue = 0 }.Publish();
  634. Sence(GVL_MorkT.机器人安全位);
  635. Wait();
  636. WritePLCData("", 3);//将模组移动到接冰的位置
  637. new LebaiRobot_SetValueEvent { DeviceId = DeviceId, RobotSetValue = 0 }.Publish();
  638. Sence(GVL_MorkT.接果汁过渡位);
  639. Wait();
  640. switch (JuiceCH)
  641. {
  642. case 52:
  643. if (GuMake)
  644. JuicerNum = 0x00;
  645. else
  646. JuicerNum = 0x01;
  647. new LebaiRobot_SetValueEvent { DeviceId = DeviceId, RobotSetValue = 0 }.Publish();
  648. Sence(GVL_MorkT.接果汁1);
  649. Wait();
  650. break;
  651. case 53:
  652. if (GuMake)
  653. JuicerNum = 0x02;
  654. else
  655. JuicerNum = 0x03;
  656. new LebaiRobot_SetValueEvent { DeviceId = DeviceId, RobotSetValue = 0 }.Publish();
  657. Sence(GVL_MorkT.接果汁2);
  658. Wait();
  659. break;
  660. case 54:
  661. if (GuMake)
  662. JuicerNum = 0x04;
  663. else
  664. JuicerNum = 0x05;
  665. new LebaiRobot_SetValueEvent { DeviceId = DeviceId, RobotSetValue = 0 }.Publish();
  666. Sence(GVL_MorkT.接果汁3);
  667. Wait();
  668. break;
  669. case 55:
  670. if (GuMake)
  671. JuicerNum = 0x06;
  672. else
  673. JuicerNum = 0x07;
  674. new LebaiRobot_SetValueEvent { DeviceId = DeviceId, RobotSetValue = 0 }.Publish();
  675. Sence(GVL_MorkT.接果汁4);
  676. Wait();
  677. break;
  678. default:
  679. JuicerNum = 0x00;
  680. new LebaiRobot_SetValueEvent { DeviceId = DeviceId, RobotSetValue = 0 }.Publish();
  681. Sence(GVL_MorkT.接果汁1);
  682. Wait();
  683. break;
  684. }
  685. new WriteJuicer() { Value = JuicerNum }.Publish();
  686. pickUpJuiceHaveCup = true;
  687. }
  688. else
  689. {
  690. return;
  691. }
  692. }
  693. #endregion
  694. }
  695. /// <summary>
  696. /// 取接好果汁杯
  697. /// </summary>
  698. private void putJuice()
  699. {
  700. while (GetStatus<bool>("RobotValue1"))//判断放杯位置是否有物品
  701. {
  702. if (!outCupCheck)
  703. DeviceProcessLogShow("成品处有纸杯存在,请取走!!");
  704. outCupCheck = true;
  705. }
  706. outCupCheck = false;
  707. switch (JuiceCH)
  708. {
  709. case 52:
  710. new LebaiRobot_SetValueEvent { DeviceId = DeviceId, RobotSetValue = 0 }.Publish();
  711. Sence(GVL_MorkT.放果汁杯1);
  712. Wait();
  713. break;
  714. case 53:
  715. new LebaiRobot_SetValueEvent { DeviceId = DeviceId, RobotSetValue = 0 }.Publish();
  716. Sence(GVL_MorkT.放果汁杯2);
  717. Wait();
  718. break;
  719. case 54:
  720. new LebaiRobot_SetValueEvent { DeviceId = DeviceId, RobotSetValue = 0 }.Publish();
  721. Sence(GVL_MorkT.放果汁杯3);
  722. Wait();
  723. break;
  724. case 55:
  725. new LebaiRobot_SetValueEvent { DeviceId = DeviceId, RobotSetValue = 0 }.Publish();
  726. Sence(GVL_MorkT.放果汁杯4);
  727. Wait();
  728. break;
  729. default:
  730. new LebaiRobot_SetValueEvent { DeviceId = DeviceId, RobotSetValue = 0 }.Publish();
  731. Sence(GVL_MorkT.放果汁杯1);
  732. Wait();
  733. break;
  734. }
  735. OrderChange(morkTJaka.morkOrderPushesJuicer.ElementAt(0).SuborderId, BPA.Message.Enum.ORDER_STATUS.COMPLETED_TAKE);
  736. DeviceProcessLogShow("果汁制作完成");
  737. }
  738. #endregion
  739. /// <summary>
  740. /// 取杯的次数
  741. /// </summary>
  742. private int nCnt;
  743. /// <summary>
  744. /// 取杯流程
  745. /// </summary>
  746. /// <returns>0:无意义,1:取杯成功 2:取杯失败</returns>
  747. private int takeCup()
  748. {
  749. try
  750. {
  751. nCnt = 0;
  752. new LebaiRobot_SetValueEvent { DeviceId = DeviceId, RobotSetValue = 0 }.Publish();
  753. Sence(GVL_MorkT.机器人初始位);
  754. Wait();
  755. new LebaiRobot_SetValueEvent { DeviceId = DeviceId, RobotSetValue = 0 }.Publish();
  756. Sence(GVL_MorkT.机器人安全位);
  757. Wait();
  758. WritePLCData("", SendToPlc.取杯);
  759. if (!morkTJaka.sensorGetCup)
  760. {
  761. WritePLCData("", 2);
  762. }
  763. new LebaiRobot_SetValueEvent { DeviceId = DeviceId, RobotSetValue = 0 }.Publish();
  764. Sence(GVL_MorkT.取纸杯);
  765. Wait();
  766. new LebaiRobot_SetValueEvent { DeviceId = DeviceId, RobotSetValue = 0 }.Publish();
  767. Sence(GVL_MorkT.取纸杯检测);
  768. Wait();
  769. nCnt++;
  770. Thread.Sleep(2000);
  771. while (!GetStatus<bool>("GetInput")) //读取传感器的值
  772. {
  773. if (nCnt > 3)
  774. {
  775. nCnt = 0;
  776. DeviceProcessLogShow("三次取杯失败,回原点");
  777. new LebaiRobot_SetValueEvent { DeviceId = DeviceId, RobotSetValue = 0 }.Publish();
  778. Sence(GVL_MorkT.机器人安全位);
  779. Wait();
  780. new LebaiRobot_SetValueEvent { DeviceId = DeviceId, RobotSetValue = 0 }.Publish();
  781. Sence(GVL_MorkT.机器人初始位);
  782. Wait();
  783. return 2;
  784. }
  785. else
  786. {
  787. nCnt++;
  788. new LebaiRobot_SetValueEvent { DeviceId = DeviceId, RobotSetValue = 0 }.Publish();
  789. Sence(GVL_MorkT.二次取杯);
  790. Wait();
  791. new LebaiRobot_SetValueEvent { DeviceId = DeviceId, RobotSetValue = 0 }.Publish();
  792. Sence(GVL_MorkT.取纸杯检测);
  793. Wait();
  794. }
  795. Thread.Sleep(1000);
  796. }
  797. new LebaiRobot_SetValueEvent { DeviceId = DeviceId, RobotSetValue = 0 }.Publish();
  798. Sence(GVL_MorkT.取杯位_机器人安全位);
  799. Wait();
  800. return 1;
  801. }
  802. catch (Exception ex)
  803. {
  804. DeviceProcessLogShow(ex.ToString());
  805. }
  806. return 2;
  807. }
  808. /// <summary>
  809. /// 放杯
  810. /// </summary>
  811. /// <returns>0:无意义 1:放杯成功 2:执行失败(传感器还有信号) 3:放杯异常</returns>
  812. private int putCup()
  813. {
  814. try
  815. {
  816. if (GetStatus<bool>("GetInput2")) return 2;
  817. Sence(GVL_MorkT.JUICE_放杯);
  818. Wait();
  819. new LebaiRobot_SetValueEvent() { RobotSetValue = 1 }.Publish();
  820. Sence(GVL_MorkT.JUICE_放杯检测);
  821. Wait();
  822. new LebaiRobot_SetValueEvent() { RobotSetValue = 1 }.Publish();
  823. if (GetStatus<bool>("GetInput2"))
  824. {
  825. return 1;
  826. }
  827. else
  828. {
  829. return 3;
  830. }
  831. }
  832. catch (Exception ex)
  833. {
  834. DeviceProcessLogShow(ex.ToString());
  835. return 0;
  836. }
  837. }
  838. public void SimOrder<T>(T simOrder)
  839. {
  840. }
  841. #region PLC 控制函数
  842. private void WritePLCData(string address, object value)
  843. {
  844. EventBus.EventBus.GetInstance().Publish(new WriteModel() { DeviceId = DeviceId, Address = address, Value = value });
  845. }
  846. private void GetStatus(string key, Action<object> action)
  847. {
  848. if (peripheralStatus.ContainsKey(key))
  849. {
  850. if (peripheralStatus[key] != null)
  851. {
  852. action?.Invoke(peripheralStatus[key]);
  853. }
  854. }
  855. }
  856. public override void ReadData()
  857. {
  858. GetStatus("", new Action<object>((obj) =>
  859. {
  860. if (obj is bool[] bools && bools.Length > 0 && bools.Length <= 24)
  861. {
  862. }
  863. }));
  864. }
  865. #endregion
  866. public override void Stop()
  867. {
  868. }
  869. public override void ResetProgram()
  870. {
  871. }
  872. public override void SimOrder()
  873. {
  874. }
  875. }
  876. }