| | |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.zy.asrs.entity.DeviceConfig; |
| | | import com.zy.core.enums.CrnStatusType; |
| | | import com.zy.core.enums.CrnTaskModeType; |
| | | import com.zy.core.enums.DualCrnTaskModeType; |
| | | import com.zy.core.model.CommandResponse; |
| | | import com.zy.core.model.command.DualCrnCommand; |
| | | import com.zy.core.network.api.ZyDualCrnConnectApi; |
| | |
| | | |
| | | private ZyDualCrnStatusEntity crnStatus; |
| | | private DeviceConfig deviceConfig; |
| | | private final ExecutorService executor = Executors.newSingleThreadExecutor(); |
| | | // 允许并行执行多个命令任务(固定线程池)。如需更高并发可调整大小。 |
| | | private final ExecutorService executor = Executors |
| | | .newFixedThreadPool(9999); |
| | | private int taskExecuteStation = 0; |
| | | |
| | | public ZyDualCrnFakeConnect(DeviceConfig deviceConfig) { |
| | | this.deviceConfig = deviceConfig; |
| | |
| | | @Override |
| | | public CommandResponse sendCommand(DualCrnCommand command) { |
| | | CommandResponse response = new CommandResponse(false); |
| | | if (command.getTaskMode().intValue() == CrnTaskModeType.LOC_MOVE.id) { |
| | | if (command.getTaskMode().intValue() == DualCrnTaskModeType.TRANSFER.id) { |
| | | //取放货 |
| | | executor.submit(() -> commandTake(command)); |
| | | } else if (command.getTaskMode().intValue() == CrnTaskModeType.CRN_MOVE.id) { |
| | | } else if (command.getTaskMode().intValue() == DualCrnTaskModeType.PICK.id) { |
| | | //取货 |
| | | executor.submit(() -> commandPick(command)); |
| | | } else if (command.getTaskMode().intValue() == DualCrnTaskModeType.PUT.id) { |
| | | //放货 |
| | | executor.submit(() -> commandPut(command)); |
| | | } else if (command.getTaskMode().intValue() == DualCrnTaskModeType.MOVE.id) { |
| | | //移动 |
| | | executor.submit(() -> commandMove(command)); |
| | | } else if (command.getTaskMode().intValue() == CrnTaskModeType.NONE.id) { |
| | | } else if (command.getTaskMode().intValue() == DualCrnTaskModeType.CONFIRM.id) { |
| | | //复位 |
| | | executor.submit(() -> commandTaskComplete(command)); |
| | | } |
| | |
| | | } |
| | | |
| | | private void commandTaskComplete(DualCrnCommand command) { |
| | | this.crnStatus.setTaskNo(0); |
| | | this.crnStatus.setStatus(CrnStatusType.IDLE.id); |
| | | if(command.getStation() == 1) { |
| | | if (crnStatus.getLoaded() == 0) { |
| | | this.crnStatus.setTaskNo(0); |
| | | } |
| | | this.crnStatus.setTaskReceive(0); |
| | | this.crnStatus.setStatus(CrnStatusType.IDLE.id); |
| | | }else { |
| | | if (crnStatus.getLoadedTwo() == 0) { |
| | | this.crnStatus.setTaskNoTwo(0); |
| | | } |
| | | this.crnStatus.setTaskReceiveTwo(0); |
| | | this.crnStatus.setStatusTwo(CrnStatusType.IDLE.id); |
| | | } |
| | | } |
| | | |
| | | private void commandMove(DualCrnCommand command) { |
| | | int destinationPosX = command.getDestinationPosX().intValue(); |
| | | int destinationPosY = command.getDestinationPosY().intValue(); |
| | | int destinationPosZ = command.getDestinationPosZ().intValue(); |
| | | int taskMode = command.getTaskMode().intValue(); |
| | | int taskNo = command.getTaskNo().intValue(); |
| | | int destinationPosX = command.getDestinationPosX(); |
| | | int destinationPosY = command.getDestinationPosY(); |
| | | int destinationPosZ = command.getDestinationPosZ(); |
| | | int taskMode = command.getTaskMode(); |
| | | int taskNo = command.getTaskNo(); |
| | | int station = command.getStation(); |
| | | |
| | | while (true) { |
| | | if (taskExecuteStation == 0) { |
| | | taskExecuteStation = station; |
| | | } |
| | | |
| | | if (taskExecuteStation == station) { |
| | | break; |
| | | } |
| | | |
| | | sleep(200); |
| | | } |
| | | |
| | | if(command.getStation() == 1) { |
| | | this.crnStatus.setTaskNo(taskNo); |
| | | this.crnStatus.setStatus(CrnStatusType.MOVING.id); |
| | | moveY(this.crnStatus.getBay(), destinationPosY, command.getStation().intValue()); |
| | | moveZ(this.crnStatus.getLevel(), destinationPosZ, command.getStation().intValue()); |
| | | this.crnStatus.setTaskReceive(1); |
| | | moveYZ(this.crnStatus.getBay(), destinationPosY, this.crnStatus.getLevel(), destinationPosZ, command.getStation()); |
| | | this.crnStatus.setStatus(CrnStatusType.WAITING.id); |
| | | }else { |
| | | this.crnStatus.setTaskNoTwo(taskNo); |
| | | this.crnStatus.setStatusTwo(CrnStatusType.MOVING.id); |
| | | moveY(this.crnStatus.getBayTwo(), destinationPosY, command.getStation().intValue()); |
| | | moveZ(this.crnStatus.getLevelTwo(), destinationPosZ, command.getStation().intValue()); |
| | | this.crnStatus.setTaskReceive(1); |
| | | moveYZ(this.crnStatus.getBay(), destinationPosY, this.crnStatus.getLevel(), destinationPosZ, command.getStation()); |
| | | this.crnStatus.setStatusTwo(CrnStatusType.WAITING.id); |
| | | } |
| | | |
| | | taskExecuteStation = 0; |
| | | } |
| | | |
| | | private void commandTake(DualCrnCommand command) { |
| | | int sourcePosX = command.getSourcePosX().intValue(); |
| | | int sourcePosY = command.getSourcePosY().intValue(); |
| | | int sourcePosZ = command.getSourcePosZ().intValue(); |
| | | int destinationPosX = command.getDestinationPosX().intValue(); |
| | | int destinationPosY = command.getDestinationPosY().intValue(); |
| | | int destinationPosZ = command.getDestinationPosZ().intValue(); |
| | | int taskMode = command.getTaskMode().intValue(); |
| | | int taskNo = command.getTaskNo().intValue(); |
| | | int sourcePosX = command.getSourcePosX(); |
| | | int sourcePosY = command.getSourcePosY(); |
| | | int sourcePosZ = command.getSourcePosZ(); |
| | | int destinationPosX = command.getDestinationPosX(); |
| | | int destinationPosY = command.getDestinationPosY(); |
| | | int destinationPosZ = command.getDestinationPosZ(); |
| | | int taskMode = command.getTaskMode(); |
| | | int taskNo = command.getTaskNo(); |
| | | int station = command.getStation(); |
| | | |
| | | this.crnStatus.setMode(taskMode); |
| | | while (true) { |
| | | if (taskExecuteStation == 0) { |
| | | taskExecuteStation = station; |
| | | } |
| | | |
| | | if (taskExecuteStation == station) { |
| | | break; |
| | | } |
| | | |
| | | sleep(200); |
| | | } |
| | | |
| | | if(command.getStation() == 1) { |
| | | this.crnStatus.setTaskNo(taskNo); |
| | | this.crnStatus.setStatus(CrnStatusType.FETCH_MOVING.id); |
| | | this.crnStatus.setTaskReceive(1); |
| | | |
| | | moveY(this.crnStatus.getBay(), sourcePosY, command.getStation().intValue()); |
| | | moveZ(this.crnStatus.getLevel(), sourcePosZ, command.getStation().intValue()); |
| | | moveYZ(this.crnStatus.getBay(), sourcePosY,this.crnStatus.getLevel(), sourcePosZ,command.getStation()); |
| | | this.crnStatus.setStatus(CrnStatusType.FETCHING.id); |
| | | sleep(2000); |
| | | if (Thread.currentThread().isInterrupted()) { |
| | |
| | | |
| | | this.crnStatus.setLoaded(1); |
| | | this.crnStatus.setStatus(CrnStatusType.PUT_MOVING.id); |
| | | moveY(this.crnStatus.getBay(), destinationPosY, command.getStation().intValue()); |
| | | moveZ(this.crnStatus.getLevel(), destinationPosZ, command.getStation().intValue()); |
| | | moveYZ(this.crnStatus.getBay(), destinationPosY,this.crnStatus.getLevel(), destinationPosZ, command.getStation()); |
| | | this.crnStatus.setStatus(CrnStatusType.PUTTING.id); |
| | | sleep(2000); |
| | | if (Thread.currentThread().isInterrupted()) { |
| | |
| | | }else { |
| | | this.crnStatus.setTaskNoTwo(taskNo); |
| | | this.crnStatus.setStatusTwo(CrnStatusType.FETCH_MOVING.id); |
| | | this.crnStatus.setTaskReceiveTwo(1); |
| | | |
| | | moveY(this.crnStatus.getBayTwo(), sourcePosY, command.getStation().intValue()); |
| | | moveZ(this.crnStatus.getLevelTwo(), sourcePosZ, command.getStation().intValue()); |
| | | moveYZ(this.crnStatus.getBay(), sourcePosY,this.crnStatus.getLevel(), sourcePosZ, command.getStation()); |
| | | this.crnStatus.setStatusTwo(CrnStatusType.FETCHING.id); |
| | | sleep(2000); |
| | | if (Thread.currentThread().isInterrupted()) { |
| | |
| | | |
| | | this.crnStatus.setLoadedTwo(1); |
| | | this.crnStatus.setStatusTwo(CrnStatusType.PUT_MOVING.id); |
| | | moveY(this.crnStatus.getBayTwo(), destinationPosY, command.getStation().intValue()); |
| | | moveZ(this.crnStatus.getLevelTwo(), destinationPosZ, command.getStation().intValue()); |
| | | moveYZ(this.crnStatus.getBay(), destinationPosY,this.crnStatus.getLevel(), destinationPosZ, command.getStation()); |
| | | this.crnStatus.setStatusTwo(CrnStatusType.PUTTING.id); |
| | | sleep(2000); |
| | | if (Thread.currentThread().isInterrupted()) { |
| | |
| | | this.crnStatus.setLoadedTwo(0); |
| | | this.crnStatus.setStatusTwo(CrnStatusType.WAITING.id); |
| | | } |
| | | |
| | | taskExecuteStation = 0; |
| | | } |
| | | |
| | | private void commandPick(DualCrnCommand command) { |
| | | int destinationPosX = command.getDestinationPosX(); |
| | | int destinationPosY = command.getDestinationPosY(); |
| | | int destinationPosZ = command.getDestinationPosZ(); |
| | | int taskMode = command.getTaskMode(); |
| | | int taskNo = command.getTaskNo(); |
| | | int station = command.getStation(); |
| | | |
| | | while (true) { |
| | | if (taskExecuteStation == 0) { |
| | | taskExecuteStation = station; |
| | | } |
| | | |
| | | if (taskExecuteStation == station) { |
| | | break; |
| | | } |
| | | |
| | | sleep(200); |
| | | } |
| | | |
| | | if(command.getStation() == 1) { |
| | | this.crnStatus.setTaskNo(taskNo); |
| | | this.crnStatus.setStatus(CrnStatusType.FETCH_MOVING.id); |
| | | this.crnStatus.setTaskReceive(1); |
| | | |
| | | moveYZ(this.crnStatus.getBay(), destinationPosY,this.crnStatus.getLevel(), destinationPosZ, command.getStation()); |
| | | this.crnStatus.setStatus(CrnStatusType.FETCHING.id); |
| | | sleep(3000); |
| | | if (Thread.currentThread().isInterrupted()) { |
| | | return; |
| | | } |
| | | this.crnStatus.setLoaded(1); |
| | | this.crnStatus.setStatus(CrnStatusType.WAITING.id); |
| | | }else { |
| | | this.crnStatus.setTaskNoTwo(taskNo); |
| | | this.crnStatus.setStatusTwo(CrnStatusType.FETCH_MOVING.id); |
| | | this.crnStatus.setTaskReceiveTwo(1); |
| | | |
| | | moveYZ(this.crnStatus.getBay(), destinationPosY,this.crnStatus.getLevel(), destinationPosZ, command.getStation()); |
| | | this.crnStatus.setStatusTwo(CrnStatusType.FETCHING.id); |
| | | sleep(3000); |
| | | if (Thread.currentThread().isInterrupted()) { |
| | | return; |
| | | } |
| | | this.crnStatus.setLoadedTwo(1); |
| | | this.crnStatus.setStatusTwo(CrnStatusType.WAITING.id); |
| | | } |
| | | |
| | | taskExecuteStation = 0; |
| | | } |
| | | |
| | | private void commandPut(DualCrnCommand command) { |
| | | int destinationPosX = command.getDestinationPosX(); |
| | | int destinationPosY = command.getDestinationPosY(); |
| | | int destinationPosZ = command.getDestinationPosZ(); |
| | | int taskMode = command.getTaskMode(); |
| | | int taskNo = command.getTaskNo(); |
| | | int station = command.getStation(); |
| | | |
| | | while (true) { |
| | | if (taskExecuteStation == 0) { |
| | | taskExecuteStation = station; |
| | | } |
| | | |
| | | if (taskExecuteStation == station) { |
| | | break; |
| | | } |
| | | |
| | | sleep(200); |
| | | } |
| | | |
| | | if(command.getStation() == 1) { |
| | | this.crnStatus.setTaskNo(taskNo); |
| | | this.crnStatus.setStatus(CrnStatusType.PUT_MOVING.id); |
| | | this.crnStatus.setTaskReceive(1); |
| | | |
| | | moveYZ(this.crnStatus.getBay(), destinationPosY,this.crnStatus.getLevel(), destinationPosZ, command.getStation()); |
| | | this.crnStatus.setStatus(CrnStatusType.PUTTING.id); |
| | | sleep(3000); |
| | | if (Thread.currentThread().isInterrupted()) { |
| | | return; |
| | | } |
| | | this.crnStatus.setLoaded(0); |
| | | this.crnStatus.setStatus(CrnStatusType.WAITING.id); |
| | | }else { |
| | | this.crnStatus.setTaskNoTwo(taskNo); |
| | | this.crnStatus.setStatusTwo(CrnStatusType.PUT_MOVING.id); |
| | | this.crnStatus.setTaskReceiveTwo(1); |
| | | |
| | | moveYZ(this.crnStatus.getBay(), destinationPosY,this.crnStatus.getLevel(), destinationPosZ, command.getStation()); |
| | | this.crnStatus.setStatusTwo(CrnStatusType.PUTTING.id); |
| | | sleep(3000); |
| | | if (Thread.currentThread().isInterrupted()) { |
| | | return; |
| | | } |
| | | this.crnStatus.setLoadedTwo(0); |
| | | this.crnStatus.setStatusTwo(CrnStatusType.WAITING.id); |
| | | } |
| | | |
| | | taskExecuteStation = 0; |
| | | } |
| | | |
| | | private void moveZ(int sourcePosZ, int destinationPosZ, int station) { |
| | |
| | | int initSourcePosZ = sourcePosZ; |
| | | for(int i = 0; i < moveLength; i++) { |
| | | initSourcePosZ++; |
| | | if(station == 1) { |
| | | this.crnStatus.setLevel(initSourcePosZ); |
| | | }else { |
| | | this.crnStatus.setLevelTwo(initSourcePosZ); |
| | | } |
| | | this.crnStatus.setLevel(initSourcePosZ); |
| | | sleep(1000); |
| | | if (Thread.currentThread().isInterrupted()) { |
| | | return; |
| | |
| | | int initSourcePosZ = sourcePosZ; |
| | | for(int i = 0; i < moveLength; i++) { |
| | | initSourcePosZ--; |
| | | if(station == 1) { |
| | | this.crnStatus.setLevel(initSourcePosZ); |
| | | }else { |
| | | this.crnStatus.setLevelTwo(initSourcePosZ); |
| | | } |
| | | this.crnStatus.setLevel(initSourcePosZ); |
| | | this.crnStatus.setLevel(initSourcePosZ); |
| | | sleep(1000); |
| | | if (Thread.currentThread().isInterrupted()) { |
| | |
| | | int initSourcePosY = sourcePosY; |
| | | for(int i = 0; i < moveLength; i++) { |
| | | initSourcePosY++; |
| | | if(station == 1) { |
| | | this.crnStatus.setBay(initSourcePosY); |
| | | }else { |
| | | this.crnStatus.setBayTwo(initSourcePosY); |
| | | } |
| | | sleep(1000); |
| | | this.crnStatus.setBay(initSourcePosY); |
| | | sleep(500); |
| | | if (Thread.currentThread().isInterrupted()) { |
| | | return; |
| | | } |
| | |
| | | int initSourcePosY = sourcePosY; |
| | | for(int i = 0; i < moveLength; i++) { |
| | | initSourcePosY--; |
| | | if(station == 1) { |
| | | this.crnStatus.setBay(initSourcePosY); |
| | | }else { |
| | | this.crnStatus.setBayTwo(initSourcePosY); |
| | | } |
| | | sleep(1000); |
| | | this.crnStatus.setBay(initSourcePosY); |
| | | sleep(500); |
| | | if (Thread.currentThread().isInterrupted()) { |
| | | return; |
| | | } |
| | |
| | | } |
| | | } |
| | | |
| | | private void moveYZ(int sourcePosY, int destinationPosY, int sourcePosZ, int destinationPosZ, int station) { |
| | | moveY(sourcePosY, destinationPosY, station); |
| | | moveZ(sourcePosZ, destinationPosZ, station); |
| | | } |
| | | |
| | | private void sleep(long ms) { |
| | | try { |
| | | Thread.sleep(ms); |