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.

82 lines
3.1 KiB

1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
  1. package com.iflytop.a800.device;
  2. import com.iflytop.a800.resource.IncubatorSlot;
  3. import com.iflytop.a800.resource.TestCard;
  4. import com.iflytop.uf.UfActuatorCmdExecutor;
  5. import com.iflytop.uf.UfCmdSnippetExecutor;
  6. import com.iflytop.uf.model.UfMdbOption;
  7. import java.util.ArrayList;
  8. import java.util.List;
  9. import java.util.Map;
  10. public class Incubator extends DeviceComponent {
  11. // 槽位
  12. private final List<IncubatorSlot> slots;
  13. // 槽位起始索引
  14. private Integer slotStartIndex = 0;
  15. // 构造函数
  16. public Incubator() {
  17. this.slotStartIndex = 0;
  18. this.slots = new ArrayList<>();
  19. for ( int i = 0; i < 20; i++ ) {
  20. var slot = new IncubatorSlot();
  21. slot.index = i;
  22. this.slots.add(slot);
  23. }
  24. }
  25. // 移动至提交位置
  26. public void moveToCommitPos( IncubatorSlot slot ) {
  27. Integer commitStartPos = UfMdbOption.getInteger("IncubatorSlotCommitStartPos");
  28. Integer commitDistance = UfMdbOption.getInteger("IncubatorSlotCommitDistance");
  29. int commitPos = commitStartPos + commitDistance * slot.index;
  30. UfActuatorCmdExecutor.execute("MotorIncubatorRotate", "motor_easy_move_to", Integer.toString(commitPos));
  31. }
  32. // 推送新卡片
  33. public IncubatorSlot pushNewCard(TestCard card) {
  34. var lock = this.lock("PushNewCard");
  35. IncubatorSlot slot = null;
  36. for ( int i=0; i<20; i++ ) {
  37. var tmpSlot = this.slots.get(this.slotStartIndex);
  38. this.slotStartIndex = (this.slotStartIndex + 1) % 20;
  39. if ( tmpSlot.card != null ) {
  40. continue ;
  41. }
  42. slot = tmpSlot;
  43. break;
  44. }
  45. if ( slot == null ) {
  46. throw new RuntimeException("无可用孵育盘槽位");
  47. }
  48. Integer boxPos = UfMdbOption.getInteger(String.format("TestCardWarehouseBox.%d", card.boxIndex));
  49. Integer slotStartPos = UfMdbOption.getInteger("IncubatorSlotStartPos");
  50. Integer slotDistance = UfMdbOption.getInteger("IncubatorSlotDistance");
  51. Integer slotPos = slotStartPos + slotDistance * slot.index;
  52. Integer commitStartPos = UfMdbOption.getInteger("IncubatorSlotCommitStartPos");
  53. Integer commitDistance = UfMdbOption.getInteger("IncubatorSlotCommitDistance");
  54. Integer commitPos = commitStartPos + commitDistance * slot.index;
  55. Map<String,Object> params = Map.of(
  56. "box", boxPos,
  57. "slot", slotPos,
  58. "commit", commitPos
  59. );
  60. UfCmdSnippetExecutor.execute("IncubatorTestCardPushIn", params);
  61. slot.card = card;
  62. this.unlock(lock);
  63. return slot;
  64. }
  65. // 退出到扫描
  66. public void exitCardToScanner( IncubatorSlot slot ) {
  67. Integer startPos = UfMdbOption.getInteger("IncubatorSlotExitStartPos");
  68. Integer distance = UfMdbOption.getInteger("IncubatorSlotExitDistance");
  69. Integer slotPos = startPos + distance * slot.index;
  70. Map<String,Object> params = Map.of("slot", slotPos);
  71. UfCmdSnippetExecutor.execute("IncubatorTestCardExitToScanner", params);
  72. slot.card = null;
  73. }
  74. }