From 81188cbe3d51e951ce4c853edb886272a4eb51a3 Mon Sep 17 00:00:00 2001 From: Junjie <540245094@qq.com> Date: 星期三, 11 十二月 2024 15:59:00 +0800 Subject: [PATCH] #path similarity --- zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/core/kernel/command/ShuttleCommandService.java | 539 +++++++++++++++++++++++++++++++++++++++++++++-------------- 1 files changed, 411 insertions(+), 128 deletions(-) diff --git a/zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/core/kernel/command/ShuttleCommandService.java b/zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/core/kernel/command/ShuttleCommandService.java index e276f9a..f3e8394 100644 --- a/zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/core/kernel/command/ShuttleCommandService.java +++ b/zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/core/kernel/command/ShuttleCommandService.java @@ -1,37 +1,37 @@ package com.zy.asrs.wcs.core.kernel.command; +import com.alibaba.fastjson.JSON; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.zy.asrs.framework.common.Cools; +import com.zy.asrs.framework.common.SpringUtils; import com.zy.asrs.framework.exception.CoolException; +import com.zy.asrs.wcs.common.ExecuteSupport; import com.zy.asrs.wcs.core.action.LiftAction; import com.zy.asrs.wcs.core.action.ShuttleAction; -import com.zy.asrs.wcs.core.entity.Loc; +import com.zy.asrs.wcs.core.entity.*; import com.zy.asrs.wcs.core.model.NavigateNode; -import com.zy.asrs.wcs.core.model.command.ShuttleAssignCommand; -import com.zy.asrs.wcs.core.model.command.ShuttleCommand; +import com.zy.asrs.wcs.core.model.command.*; import com.zy.asrs.wcs.core.model.enums.*; -import com.zy.asrs.wcs.core.service.BasShuttleService; -import com.zy.asrs.wcs.core.service.LocService; -import com.zy.asrs.wcs.core.service.TaskService; +import com.zy.asrs.wcs.core.service.*; import com.zy.asrs.wcs.core.utils.*; import com.zy.asrs.wcs.rcs.News; import com.zy.asrs.wcs.rcs.cache.SlaveConnection; -import com.zy.asrs.wcs.core.entity.Motion; +import com.zy.asrs.wcs.rcs.entity.Device; import com.zy.asrs.wcs.rcs.model.enums.ShuttleProtocolStatusType; import com.zy.asrs.wcs.rcs.model.enums.SlaveType; import com.zy.asrs.wcs.rcs.model.protocol.LiftProtocol; import com.zy.asrs.wcs.rcs.model.protocol.ShuttleProtocol; -import com.zy.asrs.wcs.core.service.MotionService; +import com.zy.asrs.wcs.rcs.model.protocol.StaProtocol; +import com.zy.asrs.wcs.rcs.thread.DevpThread; import com.zy.asrs.wcs.rcs.thread.LiftThread; import com.zy.asrs.wcs.rcs.thread.ShuttleThread; +import com.zy.asrs.wcs.system.entity.Dict; +import com.zy.asrs.wcs.system.service.DictService; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; -import java.util.ArrayList; -import java.util.List; -import java.util.Objects; -import java.util.Optional; +import java.util.*; /** * Created by vincent on 2023/10/23 @@ -58,21 +58,45 @@ private ShuttleAction shuttleAction; @Autowired private LiftAction liftAction; + @Autowired + private LiftDispatcher liftDispatcher; + @Autowired + private BasConveyorService basConveyorService; + @Autowired + private BasConveyorStaService basConveyorStaService; + @Autowired + private ShuttleDispatcher shuttleDispatcher; + @Autowired + private NavigateUtils navigateUtils; + @Autowired + private DictService dictService; // 璁$畻 public Boolean accept(Motion motion) { Integer deviceNo = Integer.parseInt(motion.getDevice()); ShuttleThread shuttleThread = (ShuttleThread) SlaveConnection.get(SlaveType.Shuttle, deviceNo); + if (shuttleThread == null) { + return false; + } + Device shuttleDevice = shuttleThread.getDevice(); + ShuttleProtocol shuttleProtocol = shuttleThread.getStatus(); if (null == shuttleProtocol) { return false; } - if (!shuttleProtocol.getIdle()) {//璁惧涓嶇┖闂� + + if (!shuttleThread.isIdle(new ExecuteSupport() { + @Override + public Boolean judgement() { + if (Objects.equals(MotionCtgType.get(motion.getMotionCtgEl()), MotionCtgType.SHUTTLE_CHARGE_OFF)) {//闈炲叧闂厖鐢祄otion锛岄渶瑕佸垽鏂澶囩姸鎬� + return false;//涓嶉渶瑕佸垽鏂姸鎬� + } + return true;//闇�瑕佸垽鏂姸鎬� + } + })) {//璁惧涓嶇┖闂� return false; } - if (!shuttleProtocol.getPakMk()) { - return false; - } + if (motionService.count(new LambdaQueryWrapper<Motion>() .eq(Motion::getDeviceCtg, DeviceCtgType.SHUTTLE.val()) .eq(Motion::getDevice, motion.getDevice()) @@ -80,11 +104,18 @@ return false; } + Task task = taskService.getOne(new LambdaQueryWrapper<Task>().eq(Task::getTaskNo, motion.getTaskNo())); + if (task == null) { + return false; + } + ShuttleAssignCommand assignCommand = new ShuttleAssignCommand(); assignCommand.setShuttleNo(deviceNo); - assignCommand.setTaskNo(motion.getWrkNo()); + assignCommand.setTaskNo(motion.getTaskNo()); + assignCommand.setDeviceTaskNo(shuttleThread.generateDeviceTaskNo(motion.getTaskNo(), MotionCtgType.get(motion.getMotionCtgEl()))); assignCommand.setSourceLocNo(motion.getOrigin()); assignCommand.setLocNo(motion.getTarget()); + assignCommand.setDeviceId(Integer.parseInt(motion.getDevice())); List<ShuttleCommand> shuttleCommands = new ArrayList<>(); ShuttleTaskModeType shuttleTaskModeType = null; @@ -92,34 +123,101 @@ LiftThread liftThread = null; LiftProtocol liftProtocol = null; - //鍒ゆ柇灏忚溅鐘舵�� - if (shuttleProtocol.getIdle() - && shuttleProtocol.getProtocolStatusType().equals(ShuttleProtocolStatusType.IDLE) - && shuttleProtocol.getTaskNo() != 0 - ) { - return false; - } - switch (Objects.requireNonNull(MotionCtgType.get(motion.getMotionCtgEl()))){ case SHUTTLE_MOVE: + // 濡傛灉宸茬粡鍦ㄥ綋鍓嶆潯鐮佸垯杩囨护 + if (String.valueOf(shuttleProtocol.getCurrentCode()).equals(locService.getOne(new LambdaQueryWrapper<Loc>() + .eq(Loc::getLocNo, motion.getTarget()) + .eq(Loc::getHostId, motion.getHostId())).getCode())) { + return true; + } + shuttleCommands = this.shuttleAssignCommand(motion.getOrigin(), motion.getTarget(), NavigationMapType.NORMAL.id, assignCommand, shuttleThread); + shuttleTaskModeType = ShuttleTaskModeType.SHUTTLE_MOVE; + + if (!checkSimilarityPath(motion, assignCommand)) { + return false; + } + + break; + case SHUTTLE_TRANSPORT://绌挎杞﹁浇璐ц璧� // 濡傛灉宸茬粡鍦ㄥ綋鍓嶆潯鐮佸垯杩囨护 if (String.valueOf(shuttleProtocol.getCurrentCode()).equals(locService.getOne(new LambdaQueryWrapper<Loc>() .eq(Loc::getLocNo, motion.getTarget()) .eq(Loc::getHostId, motion.getHostId())).getCode())) { return true; } - shuttleCommands = this.shuttleAssignCommand(motion.getOrigin(), motion.getTarget(), NavigationMapType.NORMAL.id, assignCommand, shuttleThread); - shuttleTaskModeType = ShuttleTaskModeType.SHUTTLE_MOVE_LOC_NO; + shuttleCommands = this.shuttleAssignCommand(motion.getOrigin(), motion.getTarget(), NavigationMapType.DFX.id, assignCommand, shuttleThread); + shuttleTaskModeType = ShuttleTaskModeType.TRANSPORT; + + if (!checkSimilarityPath(motion, assignCommand)) { + return false; + } + + if (motion.getReleaseLift() == 2) {//鎵ц涓噴鏀炬彁鍗囨満 + task.setLiftNo(0); + task.setUpdateTime(new Date()); + if (!taskService.updateById(task)) { + return false; + } + } + + break; + case SHUTTLE_TRANSPORT_TO_CONVEYOR://绌挎杞﹁浇璐ц繘杈撻�佺嚎 + BasConveyorSta originStaObj = basConveyorStaService.selectBySiteNo(motion.getDockNo());//鑾峰彇杈撻�佺珯鐐� + if (originStaObj == null) { + return false; + } + + BasConveyor basConveyor = basConveyorService.getById(originStaObj.getConveyorId()); + if(basConveyor == null) { + return false; + } + + DevpThread devpThread = (DevpThread) SlaveConnection.get(SlaveType.Conveyor, basConveyor.getDeviceId().intValue()); + if (devpThread == null) { + return false; + } + StaProtocol staProtocol = devpThread.getStation().get(Integer.parseInt(motion.getDockNo()));//杈撻�佺珯 + if (staProtocol == null) { + return false; + } + if (!(staProtocol.isAutoing() && !staProtocol.isLoading() && staProtocol.getWorkNo() == 0 && staProtocol.isOutEnable())) { + return false; + } + + // 濡傛灉宸茬粡鍦ㄥ綋鍓嶆潯鐮佸垯杩囨护 + if (String.valueOf(shuttleProtocol.getCurrentCode()).equals(locService.getOne(new LambdaQueryWrapper<Loc>() + .eq(Loc::getLocNo, motion.getTarget()) + .eq(Loc::getHostId, motion.getHostId())).getCode())) { + return true; + } + shuttleCommands = this.shuttleAssignCommand(motion.getOrigin(), motion.getTarget(), NavigationMapType.DFX.id, assignCommand, shuttleThread); + shuttleTaskModeType = ShuttleTaskModeType.TRANSPORT_TO_CONVEYOR; + + if (!checkSimilarityPath(motion, assignCommand)) { + return false; + } + break; case SHUTTLE_MOVE_LIFT_PALLET://绌挎杞﹂《鍗囧苟绉诲姩 shuttleCommands = this.shuttleAssignCommand(motion.getOrigin(), motion.getTarget(), NavigationMapType.DFX.id, assignCommand, shuttleThread); - shuttleTaskModeType = ShuttleTaskModeType.PAK_IN; - shuttleCommands.add(0, shuttleThread.getLiftCommand(motion.getWrkNo(), true)); + shuttleTaskModeType = ShuttleTaskModeType.MOVE_PALLET_LIFT; + + if (!checkSimilarityPath(motion, assignCommand)) { + return false; + } + + shuttleCommands.add(0, shuttleThread.getLiftCommand(motion.getTaskNo(), true)); break; case SHUTTLE_MOVE_DOWN_PALLET://绌挎杞︾Щ鍔ㄥ苟鎵樼洏涓嬮檷 shuttleCommands = this.shuttleAssignCommand(motion.getOrigin(), motion.getTarget(), NavigationMapType.DFX.id, assignCommand, shuttleThread); - shuttleTaskModeType = ShuttleTaskModeType.PAK_IN; - shuttleCommands.add(shuttleCommands.size(), shuttleThread.getLiftCommand(motion.getWrkNo(), false)); + shuttleTaskModeType = ShuttleTaskModeType.MOVE_PALLET_DOWN; + + if (!checkSimilarityPath(motion, assignCommand)) { + return false; + } + + shuttleCommands.add(shuttleCommands.size(), shuttleThread.getLiftCommand(motion.getTaskNo(), false)); break; case SHUTTLE_MOVE_FROM_LIFT://鍑烘彁鍗囨満 // 鍒ゆ柇鎻愬崌鏈虹姸鎬� @@ -134,37 +232,31 @@ } // 鍒ゆ柇鎻愬崌鏈烘槸鍚︾┖闂� - if (!liftThread.isIdle()) { + if (!liftThread.isIdle(MotionCtgType.SHUTTLE_MOVE_FROM_LIFT)) { return false; } - if (liftProtocol.getLev() != Utils.getLev(motion.getTarget())) {//鍒ゆ柇鎻愬崌鏈烘槸鍚﹁揪鍒扮洰鏍囧眰 + if (liftProtocol.getLev() != liftDispatcher.getLiftLevOffset(liftThread.getDevice().getId().intValue(), Utils.getLev(motion.getTarget()))) {//鍒ゆ柇鎻愬崌鏈烘槸鍚﹁揪鍒扮洰鏍囧眰 return false; } -// //鍒ゆ柇鎻愬崌鏈烘槸鍚﹁閿佸畾 -// if (!liftProtocol.getLock()) { -// //閿佸畾鎻愬崌鏈� -// LiftCommand lockCommand = liftThread.getLockCommand(motion.getWrkNo(), true);//鑾峰彇鎻愬崌鏈洪攣瀹氬懡浠� -// -// LiftAssignCommand liftAssignCommand = new LiftAssignCommand(); -// liftAssignCommand.setLiftNo(liftThread.getStatus().getLiftNo()); -// liftAssignCommand.setTaskNo(motion.getWrkNo()); -// ArrayList<LiftCommand> list = new ArrayList<>(); -// list.add(lockCommand); -// liftAssignCommand.setCommands(list); -// -// liftAction.assignWork(liftThread.getDevice(), liftAssignCommand); -// return false;//绛夊緟涓嬩竴娆¤疆璇� + //鍒ゆ柇鎻愬崌鏈烘槸鍚﹁閿佸畾 + if (!liftThread.isLock(new ExecuteSupport() { + @Override + public Boolean judgement() { + return true; + } + })) { + return false; + } + +// //鍒ゆ柇鎻愬崌鏈哄伐浣滃彿鏄惁鍜屽綋鍓嶄换鍔$浉鍚� +// if (liftProtocol.getTaskNo().intValue() != motion.getTaskNo()) { +// return false; // } - //鍒ゆ柇鎻愬崌鏈哄伐浣滃彿鏄惁鍜屽綋鍓嶄换鍔$浉鍚� - if (liftProtocol.getTaskNo().intValue() != motion.getWrkNo()) { - return false; - } - - shuttleCommands = this.shuttleAssignCommand(motion.getOrigin(), motion.getTarget(), NavigationMapType.NORMAL.id, assignCommand, shuttleThread); - shuttleTaskModeType = ShuttleTaskModeType.SHUTTLE_MOVE_LOC_NO; + shuttleCommands = this.shuttleInOutLiftCommand(motion.getOrigin(), motion.getTarget(), NavigationMapType.NORMAL.id, assignCommand, shuttleThread); + shuttleTaskModeType = ShuttleTaskModeType.MOVE_OUT_LIFT; break; case SHUTTLE_MOVE_TO_LIFT://杩涙彁鍗囨満 // 鍒ゆ柇鎻愬崌鏈虹姸鎬� @@ -177,49 +269,72 @@ return false; } // 鍒ゆ柇鎻愬崌鏈烘槸鍚︾┖闂� - if (!liftThread.isIdle()) { + if (!liftThread.isIdle(MotionCtgType.SHUTTLE_MOVE_TO_LIFT)) { return false; } - if (liftProtocol.getLev() != Utils.getLev(motion.getTarget())) {//鍒ゆ柇鎻愬崌鏈烘槸鍚﹁揪鍒扮洰鏍囧眰 + if (liftProtocol.getLev() != liftDispatcher.getLiftLevOffset(liftThread.getDevice().getId().intValue(), Utils.getLev(motion.getTarget()))) {//鍒ゆ柇鎻愬崌鏈烘槸鍚﹁揪鍒扮洰鏍囧眰 return false; } -// //鍒ゆ柇鎻愬崌鏈烘槸鍚﹁閿佸畾 -// if (!liftProtocol.getLiftLock()) { -// //閿佸畾鎻愬崌鏈� -// LiftCommand lockCommand = liftThread.getLockCommand(true);//鑾峰彇鎻愬崌鏈洪攣瀹氬懡浠� -// lockCommand.setLiftNo(liftProtocol.getLiftNo()); -// lockCommand.setTaskNo(motion.getWrkNo().shortValue());//鑾峰彇浠诲姟鍙� -// liftThread.assignWork(lockCommand); -// return false;//绛夊緟涓嬩竴娆¤疆璇� + //鍒ゆ柇鎻愬崌鏈烘槸鍚﹁閿佸畾 + if (!liftThread.isLock(new ExecuteSupport() { + @Override + public Boolean judgement() { + return true;//鐗涚溂娌℃湁鎻愬崌鏈洪攣锛岀洿鎺ヨ繑鍥瀟rue + } + })) { + return false; + } + +// //鍒ゆ柇鎻愬崌鏈哄伐浣滃彿鏄惁鍜屽綋鍓嶄换鍔$浉鍚� +// if (liftProtocol.getTaskNo().intValue() != motion.getTaskNo()) { +// return false; // } - //鍒ゆ柇鎻愬崌鏈哄伐浣滃彿鏄惁鍜屽綋鍓嶄换鍔$浉鍚� - if (liftProtocol.getTaskNo().intValue() != motion.getWrkNo()) { - return false; - } - - shuttleCommands = this.shuttleAssignCommand(motion.getOrigin(), motion.getTarget(), NavigationMapType.NORMAL.id, assignCommand, shuttleThread); - shuttleTaskModeType = ShuttleTaskModeType.SHUTTLE_MOVE_LOC_NO; + shuttleCommands = this.shuttleInOutLiftCommand(motion.getOrigin(), motion.getTarget(), NavigationMapType.NORMAL.id, assignCommand, shuttleThread); + shuttleTaskModeType = ShuttleTaskModeType.MOVE_TO_LIFT; break; case SHUTTLE_CHARGE_ON://鍏呯數寮� - shuttleTaskModeType = ShuttleTaskModeType.CHARGE; - shuttleCommands.add(shuttleThread.getChargeCommand(motion.getWrkNo(), true)); + shuttleTaskModeType = ShuttleTaskModeType.CHARGE_ON; + shuttleCommands.add(shuttleThread.getChargeCommand(motion.getTaskNo(), true)); assignCommand.setCharge(Boolean.TRUE); break; case SHUTTLE_CHARGE_OFF://鍏呯數鍏� - shuttleTaskModeType = ShuttleTaskModeType.CHARGE; - shuttleCommands.add(shuttleThread.getChargeCommand(motion.getWrkNo(), false)); + shuttleTaskModeType = ShuttleTaskModeType.CHARGE_OFF; + shuttleCommands.add(shuttleThread.getChargeCommand(motion.getTaskNo(), false)); assignCommand.setCharge(Boolean.TRUE); break; case SHUTTLE_PALLET_LIFT://鎵樼洏椤跺崌 shuttleTaskModeType = ShuttleTaskModeType.PALLET_LIFT; - shuttleCommands.add(shuttleThread.getLiftCommand(motion.getWrkNo(), true)); + shuttleCommands.add(shuttleThread.getLiftCommand(motion.getTaskNo(), true)); break; case SHUTTLE_PALLET_DOWN://鎵樼洏涓嬮檷 shuttleTaskModeType = ShuttleTaskModeType.PALLET_DOWN; - shuttleCommands.add(shuttleThread.getLiftCommand(motion.getWrkNo(), false)); + shuttleCommands.add(shuttleThread.getLiftCommand(motion.getTaskNo(), false)); + break; + case SHUTTLE_UPDATE_LOCATION://灏忚溅鍧愭爣鏇存柊 + shuttleTaskModeType = ShuttleTaskModeType.SHUTTLE_UPDATE_LOCATION; + shuttleCommands.add(shuttleThread.getUpdateLocationCommand(motion.getTaskNo(), motion.getTarget())); + break; + case SHUTTLE_MOVE_STANDBY://绌挎杞︾Щ鍔ㄥ埌寰呮満浣� + shuttleTaskModeType = ShuttleTaskModeType.SHUTTLE_MOVE; + + //鑾峰彇鍏ㄩ儴寰呮満浣� + List<String> standbyLocs = JSON.parseArray(motion.getTemp(), String.class); + //鑾峰彇鍙敤寰呮満浣� + String shuttleFromLiftStandbyLoc = shuttleDispatcher.searchAvailableLocNo(Integer.valueOf(shuttleDevice.getDeviceNo()), shuttleDevice.getHostId(), shuttleThread.getStatus().getCurrentLocNo(), standbyLocs); + shuttleCommands = this.shuttleAssignCommand(motion.getOrigin(), shuttleFromLiftStandbyLoc, NavigationMapType.NORMAL.id, assignCommand, shuttleThread); + + if (!checkSimilarityPath(motion, assignCommand)) { + return false; + } + + //鏇存柊鍔ㄤ綔鍙敤寰呮満浣� + motion.setTarget(shuttleFromLiftStandbyLoc); + motion.setUpdateTime(new Date()); + motionService.updateById(motion); + break; default: throw new CoolException(motion.getMotionCtgEl() + "娌℃湁鎸囧畾浠诲姟浣滀笟娴佺▼锛侊紒锛�"); @@ -235,7 +350,7 @@ if (motion.getOrigin() != null && motion.getTarget() != null) { //鎵�浣跨敤鐨勮矾寰勮繘琛岄攣瀹氱鐢� - boolean lockResult = navigateMapUtils.writeNavigateNodeToRedisMap(Utils.getLev(motion.getTarget()), shuttleProtocol.getShuttleNo(), assignCommand.getNodes(), true);//鎵�浣跨敤鐨勮矾寰勮繘琛岄攣瀹氱鐢� + boolean lockResult = navigateMapUtils.writeNavigateNodeToRedisMap(Utils.getLev(motion.getTarget()), shuttleProtocol.getShuttleNo(), assignCommand.getNodesDeepCopy(), true);//鎵�浣跨敤鐨勮矾寰勮繘琛岄攣瀹氱鐢� if (!lockResult) { return false;//閿佸畾澶辫触 } @@ -253,17 +368,19 @@ return false; } - if (shuttleProtocol.getTaskNo() != 0 && shuttleProtocol.getTaskNo().intValue() != motion.getWrkNo()) { + if (shuttleProtocol.getTaskNo() != 0 && shuttleProtocol.getTaskNo().intValue() != motion.getTaskNo()) { return false; } //鍏呯數浠诲姟 if (Objects.requireNonNull(MotionCtgType.get(motion.getMotionCtgEl())).equals(MotionCtgType.SHUTTLE_CHARGE_ON)) { - // 澶嶄綅绌挎杞� - shuttleProtocol.setTaskNo(0); - shuttleProtocol.setProtocolStatus(ShuttleProtocolStatusType.IDLE); - shuttleProtocol.setPakMk(true); - return true; + if (shuttleProtocol.getHasCharge() || shuttleProtocol.getProtocolStatusType().equals(ShuttleProtocolStatusType.CHARGING_WAITING)) { + // 澶嶄綅绌挎杞� + shuttleThread.setSyncTaskNo(0); + shuttleThread.setProtocolStatus(ShuttleProtocolStatusType.IDLE); + shuttleThread.setPakMk(true); + return true; + } } if (!shuttleProtocol.getProtocolStatusType().equals(ShuttleProtocolStatusType.WAITING) @@ -277,6 +394,11 @@ return false; } + Task task = taskService.getOne(new LambdaQueryWrapper<Task>().eq(Task::getTaskNo, motion.getTaskNo())); + if (task == null) { + return false; + } + LiftThread liftThread = null; LiftProtocol liftProtocol = null; @@ -286,12 +408,83 @@ case SHUTTLE_MOVE_DOWN_PALLET: case SHUTTLE_MOVE_TO_CONVEYOR: case SHUTTLE_MOVE_FROM_CONVEYOR: + case SHUTTLE_TRANSPORT_TO_CONVEYOR://绌挎杞﹁浇璐ц繘杈撻�佺嚎 + case SHUTTLE_TRANSPORT://绌挎杞﹁浇璐ц璧� if (!shuttleProtocol.getCurrentLocNo().equals(motion.getTarget())) { return false; } + + if (Optional.ofNullable(motion.getReleaseShuttle()).orElse(0) == 1) {//閲婃斁绌挎杞� + task.setShuttleNo(0); + task.setUpdateTime(new Date()); + if (!taskService.updateById(task)) { + return false; + } + } + break; case SHUTTLE_MOVE_TO_LIFT: + liftThread = (LiftThread) SlaveConnection.get(SlaveType.Lift, Integer.parseInt(motion.getTemp())); + if (liftThread == null) { + return false; + } + liftProtocol = liftThread.getStatus(); + + if (!shuttleProtocol.getCurrentLocNo().equals(motion.getTarget())) { + return false; + } + + //鍒ゆ柇鎻愬崌鏈烘槸鍚﹁閿佸畾 + if (!liftThread.isLock(new ExecuteSupport() { + @Override + public Boolean judgement() { + return false; + } + })) { + return false; + } + + //鍒ゆ柇灏忚溅鏄惁宸插埌浣� + if (!liftProtocol.getHasCar()) { + return false; + } + +// //鍒ゆ柇鎻愬崌鏈哄伐浣滃彿鏄惁鍜屽綋鍓嶄换鍔$浉鍚� +// if (liftProtocol.getTaskNo().intValue() != motion.getTaskNo()) { +// return false; +// } + break; case SHUTTLE_MOVE_FROM_LIFT: + liftThread = (LiftThread) SlaveConnection.get(SlaveType.Lift, Integer.parseInt(motion.getTemp())); + if (liftThread == null) { + return false; + } + liftProtocol = liftThread.getStatus(); + + if (!shuttleProtocol.getCurrentLocNo().equals(motion.getTarget())) { + return false; + } + + //鍒ゆ柇鎻愬崌鏈烘槸鍚﹁閿佸畾 + if (!liftThread.isLock(new ExecuteSupport() { + @Override + public Boolean judgement() { + return false; + } + })) { + return false; + } + + //鍒ゆ柇灏忚溅鏄惁宸茬寮� + if (liftProtocol.getHasCar()) { + return false; + } + +// //鍒ゆ柇鎻愬崌鏈哄伐浣滃彿鏄惁鍜屽綋鍓嶄换鍔$浉鍚� +// if (liftProtocol.getTaskNo().intValue() != motion.getTaskNo()) { +// return false; +// } + break; case SHUTTLE_TRANSPORT_FROM_LIFT: case SHUTTLE_TRANSPORT_TO_LIFT: case SHUTTLE_MOVE_FROM_LIFT_TO_CONVEYOR: @@ -305,86 +498,90 @@ return false; } -// //鍒ゆ柇鎻愬崌鏈烘槸鍚﹁閿佸畾 -// if (liftProtocol.getLiftLock()) { -// //瑙i攣鎻愬崌鏈� -// LiftCommand lockCommand = liftThread.getLockCommand(false);//鑾峰彇鎻愬崌鏈鸿В閿佸懡浠� -// lockCommand.setLiftNo(liftProtocol.getLiftNo()); -// lockCommand.setTaskNo(motion.getWrkNo().shortValue());//鑾峰彇浠诲姟鍙� -// liftThread.assignWork(lockCommand); -// return false; -// } - - //鍒ゆ柇鎻愬崌鏈哄伐浣滃彿鏄惁鍜屽綋鍓嶄换鍔$浉鍚� - if (liftProtocol.getTaskNo().intValue() != motion.getWrkNo()) { + //鍒ゆ柇鎻愬崌鏈烘槸鍚﹁閿佸畾 + if (liftThread.isLock(new ExecuteSupport() { + @Override + public Boolean judgement() { + return false; + } + })) { return false; } -// if (liftProtocol.getTaskNo() != 0) { -// //娓呯┖鎻愬崌鏈哄彿 -// liftThread.setTaskNo(0); -// } + //鍒ゆ柇鎻愬崌鏈哄伐浣滃彿鏄惁鍜屽綋鍓嶄换鍔$浉鍚� + if (liftProtocol.getTaskNo().intValue() != motion.getTaskNo()) { + return false; + } + break; + case SHUTTLE_UPDATE_LOCATION://灏忚溅鍧愭爣鏇存柊 + break; + case SHUTTLE_PALLET_LIFT://鎵樼洏椤跺崌 + if (!shuttleProtocol.getHasLift()) { + return false; + } + break; + case SHUTTLE_PALLET_DOWN://鎵樼洏涓嬮檷 + if (shuttleProtocol.getHasLift()) { + return false; + } + break; + case SHUTTLE_MOVE_STANDBY://绌挎杞︾Щ鍔ㄥ埌寰呮満浣� + if (!shuttleProtocol.getCurrentLocNo().equals(motion.getTarget())) { + return false; + } + if (Optional.ofNullable(motion.getReleaseShuttle()).orElse(0) == 1) {//閲婃斁绌挎杞� + task.setShuttleNo(0); + task.setUpdateTime(new Date()); + if (!taskService.updateById(task)) { + return false; + } + } break; default: break; } // 澶嶄綅绌挎杞� - shuttleProtocol.setTaskNo(0); - shuttleProtocol.setProtocolStatus(ShuttleProtocolStatusType.IDLE); - shuttleProtocol.setPakMk(true); + shuttleThread.setSyncTaskNo(0); + shuttleThread.setProtocolStatus(ShuttleProtocolStatusType.IDLE); + shuttleThread.setPakMk(true); return true; } public synchronized List<ShuttleCommand> shuttleAssignCommand(String startLocNo, String endLocNo, Integer mapType, ShuttleAssignCommand assignCommand, ShuttleThread shuttleThread) { //鑾峰彇灏忚溅绉诲姩閫熷害 - Integer runSpeed = Optional.ofNullable(basShuttleService.getById(assignCommand.getShuttleNo()).getRunSpeed()).orElse(1000); + Integer runSpeed = Optional.ofNullable(basShuttleService.getOne(new LambdaQueryWrapper<BasShuttle>().eq(BasShuttle::getDeviceId, assignCommand.getDeviceId())).getRunSpeed()).orElse(1000); Long hostId = shuttleThread.getDevice().getHostId(); - List<NavigateNode> nodeList = NavigateUtils.calc(startLocNo, endLocNo, mapType, Utils.getShuttlePoints(Integer.parseInt(shuttleThread.getDevice().getDeviceNo()), Utils.getLev(startLocNo))); + List<NavigateNode> nodeList = navigateUtils.calc(startLocNo, endLocNo, mapType, Utils.getShuttlePoints(Integer.parseInt(shuttleThread.getDevice().getDeviceNo()), Utils.getLev(startLocNo))); if (nodeList == null) { News.error("{} dash {} can't find navigate path!", startLocNo, endLocNo); return null; } - List<NavigateNode> allNode = new ArrayList<>(nodeList); + + List<NavigateNode> allNode = new ArrayList<>(); + for (NavigateNode node : nodeList) { + allNode.add(node.clone()); + } List<ShuttleCommand> commands = new ArrayList<>(); //鑾峰彇鍒嗘璺緞 - ArrayList<ArrayList<NavigateNode>> data = NavigateUtils.getSectionPath(nodeList); + ArrayList<ArrayList<NavigateNode>> data = navigateUtils.getSectionPath(nodeList); //灏嗘瘡涓�娈佃矾寰勫垎鎴恈ommand鎸囦护 for (ArrayList<NavigateNode> nodes : data) { //寮�濮嬭矾寰� NavigateNode startPath = nodes.get(0); - //涓棿璺緞 - NavigateNode middlePath = null; - //閫氳繃xy鍧愭爣灏忚溅浜岀淮鐮� - String middleCodeNum = null; - Integer middleToDistDistance = null;//璁$畻涓棿鐐瑰埌鐩爣鐐硅璧拌窛绂� - if (nodes.size() > 10) {//涓鐮佷紶鍊掓暟绗笁涓� - //涓棿璺緞 - middlePath = nodes.get(nodes.size() - 3); - //閫氳繃xy鍧愭爣灏忚溅浜岀淮鐮� - middleCodeNum = NavigatePositionConvert.xyToPosition(middlePath.getX(), middlePath.getY(), middlePath.getZ(), hostId); - middleToDistDistance = NavigateUtils.getMiddleToDistDistance(nodes, middlePath);//璁$畻涓棿鐐瑰埌鐩爣鐐硅璧拌窛绂� - } else if (nodes.size() > 5) {//涓鐮佷紶鍊掓暟绗簩涓� - //涓棿璺緞 - middlePath = nodes.get(nodes.size() - 2); - //閫氳繃xy鍧愭爣灏忚溅浜岀淮鐮� - middleCodeNum = NavigatePositionConvert.xyToPosition(middlePath.getX(), middlePath.getY(), middlePath.getZ(), hostId); - middleToDistDistance = NavigateUtils.getMiddleToDistDistance(nodes, middlePath);//璁$畻涓棿鐐瑰埌鐩爣鐐硅璧拌窛绂� - } - //鐩爣璺緞 NavigateNode endPath = nodes.get(nodes.size() - 1); - Integer allDistance = NavigateUtils.getCurrentPathAllDistance(nodes);//璁$畻褰撳墠璺緞琛岃蛋鎬昏窛绂� + Integer allDistance = navigateUtils.getCurrentPathAllDistance(nodes);//璁$畻褰撳墠璺緞琛岃蛋鎬昏窛绂� //閫氳繃xy鍧愭爣灏忚溅浜岀淮鐮� String startCodeNum = NavigatePositionConvert.xyToPosition(startPath.getX(), startPath.getY(), startPath.getZ(), hostId); //閫氳繃xy鍧愭爣灏忚溅浜岀淮鐮� String distCodeNum = NavigatePositionConvert.xyToPosition(endPath.getX(), endPath.getY(), endPath.getZ(), hostId); //鑾峰彇绉诲姩鍛戒护 - ShuttleCommand command = shuttleThread.getMoveCommand(assignCommand.getTaskNo().intValue(), startCodeNum, distCodeNum, allDistance, ShuttleRunDirection.get(startPath.getDirection()).id.intValue(), runSpeed); + ShuttleCommand command = shuttleThread.getMoveCommand(assignCommand.getDeviceTaskNo(), startCodeNum, distCodeNum, allDistance, ShuttleRunDirection.get(startPath.getDirection()).id.intValue(), runSpeed, nodes); command.setNodes(nodes);//灏嗚璧拌妭鐐规坊鍔犲埌姣忎竴姝ュ懡浠や腑 commands.add(command); } @@ -394,5 +591,91 @@ return commands; } + public synchronized List<ShuttleCommand> shuttleInOutLiftCommand(String startLocNo, String endLocNo, Integer mapType, ShuttleAssignCommand assignCommand, ShuttleThread shuttleThread) { + NavigateNode startNode = NavigatePositionConvert.locNoToNode(startLocNo); + NavigateNode endNode = NavigatePositionConvert.locNoToNode(endLocNo); + List<NavigateNode> unlockPath = new ArrayList<>(); + unlockPath.add(startNode); + unlockPath.add(endNode); + + ShuttleProtocol shuttleProtocol = shuttleThread.getStatus(); + + //鎵�浣跨敤鐨勮矾寰勮繘琛岄攣瀹�/瑙i攣 + boolean lockResult = navigateMapUtils.writeNavigateNodeToRedisMap(Utils.getLev(endLocNo), shuttleProtocol.getShuttleNo(), unlockPath, false);//鎵�浣跨敤鐨勮矾寰勮繘琛岃В閿� + if (!lockResult) { + News.error("{} dash {} can't find unlock path!", startLocNo, endLocNo); + return null;//瑙i攣澶辫触 + } + + //鑾峰彇灏忚溅绉诲姩閫熷害 + Integer runSpeed = Optional.ofNullable(basShuttleService.getOne(new LambdaQueryWrapper<BasShuttle>().eq(BasShuttle::getDeviceId, assignCommand.getDeviceId())).getRunSpeed()).orElse(1000); + Long hostId = shuttleThread.getDevice().getHostId(); + List<NavigateNode> nodeList = navigateUtils.calc(startLocNo, endLocNo, mapType, Utils.getShuttlePoints(Integer.parseInt(shuttleThread.getDevice().getDeviceNo()), Utils.getLev(startLocNo))); + if (nodeList == null) { + News.error("{} dash {} can't find navigate path!", startLocNo, endLocNo); + return null; + } + + List<NavigateNode> allNode = new ArrayList<>(); + for (NavigateNode node : nodeList) { + allNode.add(node.clone()); + } + + List<ShuttleCommand> commands = new ArrayList<>(); + //鑾峰彇鍒嗘璺緞 + ArrayList<ArrayList<NavigateNode>> data = navigateUtils.getSectionPath(nodeList); + //灏嗘瘡涓�娈佃矾寰勫垎鎴恈ommand鎸囦护 + for (ArrayList<NavigateNode> nodes : data) { + //寮�濮嬭矾寰� + NavigateNode startPath = nodes.get(0); + + //鐩爣璺緞 + NavigateNode endPath = nodes.get(nodes.size() - 1); + Integer allDistance = navigateUtils.getCurrentPathAllDistance(nodes);//璁$畻褰撳墠璺緞琛岃蛋鎬昏窛绂� + //閫氳繃xy鍧愭爣灏忚溅浜岀淮鐮� + String startCodeNum = NavigatePositionConvert.xyToPosition(startPath.getX(), startPath.getY(), startPath.getZ(), hostId); + //閫氳繃xy鍧愭爣灏忚溅浜岀淮鐮� + String distCodeNum = NavigatePositionConvert.xyToPosition(endPath.getX(), endPath.getY(), endPath.getZ(), hostId); + //鑾峰彇绉诲姩鍛戒护 + ShuttleCommand command = shuttleThread.getMoveCommand(assignCommand.getDeviceTaskNo(), startCodeNum, distCodeNum, allDistance, ShuttleRunDirection.get(startPath.getDirection()).id.intValue(), runSpeed, nodes); + command.setNodes(nodes);//灏嗚璧拌妭鐐规坊鍔犲埌姣忎竴姝ュ懡浠や腑 + commands.add(command); + } + + assignCommand.setNodes(allNode);//褰撳墠浠诲姟鎵�鍗犵敤鐨勮妭鐐筶ist + + return commands; + } + + private boolean checkSimilarityPath(Motion motion, ShuttleAssignCommand assignCommand) { + String movePath = motion.getMovePath(); + if (Cools.isEmpty(movePath)) { + return false; + } + + Double similarityRef = 0.9D; + Dict similarityRefDict = dictService.getOne(new LambdaQueryWrapper<Dict>() + .eq(Dict::getFlag, "similarityRef") + .eq(Dict::getStatus, 1)); + if (similarityRefDict != null) { + similarityRef = Double.parseDouble(similarityRefDict.getValue()); + } + + List<NavigateNode> originPath = JSON.parseArray(movePath, NavigateNode.class); + List<NavigateNode> finalPath = assignCommand.getNodes(); + + if (finalPath == null) { + return false; + } + + Double similarity = navigateUtils.similarityPath(originPath, finalPath); + if (similarity <= similarityRef) { + News.error("{} dash {} path similarity mismatch!", motion.getOrigin(), motion.getTarget()); + return false; + } + + return true; + } + } -- Gitblit v1.9.1