From 05f2733c4cdc4ea0765e08d61273728aebb70d16 Mon Sep 17 00:00:00 2001 From: Junjie <fallin.jie@qq.com> Date: 星期二, 18 三月 2025 15:51:46 +0800 Subject: [PATCH] # --- src/main/java/com/zy/core/thread/ShuttleThread.java | 1337 +-------------------------------------------------------- 1 files changed, 41 insertions(+), 1,296 deletions(-) diff --git a/src/main/java/com/zy/core/thread/ShuttleThread.java b/src/main/java/com/zy/core/thread/ShuttleThread.java index 88b5ab8..3ddda33 100644 --- a/src/main/java/com/zy/core/thread/ShuttleThread.java +++ b/src/main/java/com/zy/core/thread/ShuttleThread.java @@ -1,1333 +1,78 @@ package com.zy.core.thread; -import HslCommunication.Core.Transfer.DataFormat; -import HslCommunication.Core.Types.OperateResult; -import HslCommunication.Core.Types.OperateResultExOne; -import HslCommunication.ModBus.ModbusTcpNet; -import com.alibaba.fastjson.JSON; -import com.core.common.DateUtils; -import com.core.common.SpringUtils; -import com.core.exception.CoolException; -import com.zy.asrs.entity.*; -import com.zy.asrs.service.*; -import com.zy.asrs.utils.Utils; -import com.zy.common.model.NavigateNode; -import com.zy.common.model.enums.NavigationMapType; -import com.zy.common.utils.*; -import com.zy.core.News; -import com.zy.core.ThreadHandler; -import com.zy.core.cache.MessageQueue; -import com.zy.core.cache.OutputQueue; -import com.zy.core.cache.SlaveConnection; -import com.zy.core.enums.*; -import com.zy.core.model.ShuttleSlave; -import com.zy.core.model.Task; -import com.zy.core.model.command.*; -import com.zy.core.model.protocol.LiftProtocol; -import com.zy.core.model.protocol.ShuttleProtocol; -import com.zy.core.model.protocol.StaProtocol; -import lombok.Data; -import lombok.extern.slf4j.Slf4j; -import java.text.MessageFormat; -import java.util.ArrayList; -import java.util.Date; +import com.zy.common.ExecuteSupport; +import com.zy.common.model.NavigateNode; +import com.zy.core.ThreadHandler; +import com.zy.core.enums.ShuttleProtocolStatusType; +import com.zy.core.enums.ShuttleTaskNoType; +import com.zy.core.model.CommandResponse; +import com.zy.core.model.command.ShuttleCommand; +import com.zy.core.model.param.ShuttleMoveLocParam; +import com.zy.core.model.protocol.ShuttleProtocol; + import java.util.List; -/** - * 鍥涘悜绌挎杞︾嚎绋� - */ -@Data -@Slf4j -public class ShuttleThread implements Runnable, ThreadHandler { +public interface ShuttleThread extends ThreadHandler { - private ModbusTcpNet modbusTcpNet; - private ShuttleSlave slave; - private ShuttleProtocol shuttleProtocol; - private RedisUtil redisUtil; + ShuttleProtocol getStatus(boolean clone);//鑾峰彇鍥涘悜绌挎杞︾姸鎬� - public ShuttleThread(ShuttleSlave slave,RedisUtil redisUtil) { - this.slave = slave; - this.redisUtil = redisUtil; - } + ShuttleProtocol getStatus();//鑾峰彇鍥涘悜绌挎杞︾姸鎬�-榛樿clone - @Override - public void run() { - this.connect(); - while (true) { - try { - int step = 1; - Task task = MessageQueue.poll(SlaveType.Shuttle, slave.getId()); - if (task != null) { - step = task.getStep(); - } - switch (step) { - // 璇绘暟鎹� - case 1: - readStatus(); - break; - // 鍐欏叆鏁版嵁 - case 2: - write((ShuttleCommand) task.getData()); - break; - //涓嬪彂浠诲姟 - case 3: - assignWork((ShuttleAssignCommand) task.getData()); - break; - default: - break; - } - Thread.sleep(500); - } catch (Exception e) { - e.printStackTrace(); - } - } - } + CommandResponse movePath(List<NavigateNode> nodes, Integer taskNo);//璺緞涓嬪彂 - @Override - public boolean connect() { - boolean result = false; - //-------------------------鍥涘悜绌挎杞﹁繛鎺ユ柟娉�------------------------// - modbusTcpNet = new ModbusTcpNet(slave.getIp(), slave.getPort(), (byte) 0x01); - // 褰撲綘闇�瑕佹寚瀹氭牸寮忕殑鏁版嵁瑙f瀽鏃讹紝灏遍渶瑕佽缃笅闈㈢殑杩欎釜淇℃伅 - modbusTcpNet.setDataFormat(DataFormat.ABCD); - OperateResult connect = modbusTcpNet.ConnectServer(); - if(connect.IsSuccess){ - result = true; - OutputQueue.CRN.offer(MessageFormat.format( "銆恵0}銆戝洓鍚戠┛姊溅plc杩炴帴鎴愬姛 ===>> [id:{1}] [ip:{2}] [port:{3}]", DateUtils.convert(new Date()), slave.getId(), slave.getIp(), slave.getPort())); - log.info("鍥涘悜绌挎杞lc杩炴帴鎴愬姛 ===>> [id:{}] [ip:{}] [port:{}] ", slave.getId(), slave.getIp(), slave.getPort()); - } else { - OutputQueue.CRN.offer(MessageFormat.format("銆恵0}銆戝洓鍚戠┛姊溅plc杩炴帴澶辫触锛侊紒锛� ===>> [id:{1}] [ip:{2}] [port:{3}]", DateUtils.convert(new Date()), slave.getId(), slave.getIp(), slave.getPort())); - log.error("鍥涘悜绌挎杞lc杩炴帴澶辫触锛侊紒锛� ===>> [id:{}] [ip:{}] [port:{}] ", slave.getId(), slave.getIp(), slave.getPort()); - } - modbusTcpNet.ConnectClose(); - //-------------------------鍥涘悜绌挎杞﹁繛鎺ユ柟娉�------------------------// - return result; - } + CommandResponse move(ShuttleCommand command);//绉诲姩 - @Override - public void close() { - modbusTcpNet.ConnectClose(); - } + CommandResponse lift(ShuttleCommand command);//椤跺崌 - private void readStatus() { - try { - OperateResultExOne<byte[]> result = modbusTcpNet.Read("200", (short) 17); - if (result.IsSuccess) { - if (null == shuttleProtocol) { - shuttleProtocol = new ShuttleProtocol(); - shuttleProtocol.setShuttleNo(slave.getId().shortValue()); - shuttleProtocol.setProtocolStatus(ShuttleProtocolStatusType.IDLE); - } + CommandResponse charge(ShuttleCommand command);//鍏呯數寮�鍏� - //----------璇诲彇鍥涘悜绌挎杞︾姸鎬�----------- - //鑾峰彇鏁版嵁 - byte[] content = result.Content; - //灏忚溅蹇欑姸鎬佷綅 - shuttleProtocol.setBusyStatus(modbusTcpNet.getByteTransform().TransInt16(content,0)); - //褰撳墠浜岀淮鐮� - shuttleProtocol.setCurrentCode(modbusTcpNet.getByteTransform().TransInt16(content,2)); - //鐢垫睜鐢甸噺鐧惧垎姣� - shuttleProtocol.setBatteryPower(modbusTcpNet.getByteTransform().TransInt16(content,4)); - //鐢垫睜娓╁害 - shuttleProtocol.setBatteryTemp(modbusTcpNet.getByteTransform().TransUInt16(content, 6)); - //閿欒缂栧彿 - shuttleProtocol.setErrorCode(modbusTcpNet.getByteTransform().TransInt16(content,8)); - //Plc杈撳嚭鐘舵�両O - int plcOutIo = modbusTcpNet.getByteTransform().TransUInt16(content, 10); - int[] plcOutIos = CommonUtils.byteToBits((byte) plcOutIo); - shuttleProtocol.setPlcOutputLift(plcOutIos[1] == 1); - shuttleProtocol.setPlcOutputTransfer(plcOutIos[2] == 1); - shuttleProtocol.setPlcOutputBrake(plcOutIos[3] == 1); - shuttleProtocol.setPlcOutputCharge(plcOutIos[4] == 1); - shuttleProtocol.setPlcOutputStatusIO(modbusTcpNet.getByteTransform().TransInt16(content, 10)); - //閿欒淇℃伅鐮� - shuttleProtocol.setStatusErrorCode(modbusTcpNet.getByteTransform().TransInt16(content,12)); - int plcInIo = modbusTcpNet.getByteTransform().TransUInt16(content, 14); - int[] plcInIos = CommonUtils.byteToBits((byte) plcInIo); - //PLC杈撳叆鐘舵�� - shuttleProtocol.setPlcInputStatus((short) plcInIos[6]); - //褰撳墠鎴栬�呬箣鍓嶈鍒扮殑浜岀淮鐮佸�� - shuttleProtocol.setCurrentOrBeforeCode(modbusTcpNet.getByteTransform().TransInt16(content,16)); - //璇诲埌鐨勪簩缁寸爜X鏂瑰悜鍋忕Щ閲� - shuttleProtocol.setCodeOffsetX(modbusTcpNet.getByteTransform().TransInt16(content,18)); - //璇诲埌鐨勪簩缁寸爜Y鏂瑰悜鍋忕Щ閲� - shuttleProtocol.setCodeOffsetY(modbusTcpNet.getByteTransform().TransInt16(content,20)); - //褰撳墠鐨勭數鍘嬪�� - shuttleProtocol.setCurrentVoltage(modbusTcpNet.getByteTransform().TransUInt16(content, 22)); - //褰撳墠鐨勬ā鎷熼噺鍊� - shuttleProtocol.setCurrentAnalogValue(modbusTcpNet.getByteTransform().TransInt16(content,24)); - //褰撳墠鐨勫崌闄嶄己鏈嶉�熷害 - shuttleProtocol.setCurrentLiftServoSpeed(modbusTcpNet.getByteTransform().TransInt16(content,26)); - //褰撳墠鐨勮璧颁己鏈嶉�熷害 - shuttleProtocol.setCurrentMoveServoSpeed(modbusTcpNet.getByteTransform().TransInt16(content,28)); - //褰撳墠鐨勫崌闄嶄己鏈嶈礋杞界巼 - shuttleProtocol.setCurrentLiftServoLoad(modbusTcpNet.getByteTransform().TransInt16(content,30)); - //褰撳墠鐨勮璧颁己鏈嶈礋杞界巼 - shuttleProtocol.setCurrentMoveServoLoad(modbusTcpNet.getByteTransform().TransInt16(content,32)); + CommandResponse reset(ShuttleCommand command);//澶嶄綅寮�鍏� - ///璇诲彇鍥涘悜绌挎杞︾姸鎬�-end + CommandResponse updateLocation(ShuttleCommand command);//鏇存柊鍧愭爣 - //灏忚溅澶勪簬蹇欑鐘舵�侊紝灏嗘爣璁扮疆涓簍rue - if (shuttleProtocol.getBusyStatusType() == ShuttleStatusType.BUSY) { - shuttleProtocol.setPakMk(true); - } + boolean isIdle(); -// if (shuttleProtocol.getErrorCode() != 0 && shuttleProtocol.getProtocolStatusType() == ShuttleProtocolStatusType.WORKING) { -// //鍑虹幇閿欒 -// resetAndTryFix(shuttleProtocol.getTaskNo()); -// } -// -// if(shuttleProtocol.getProtocolStatusType() == ShuttleProtocolStatusType.FIXING -// && shuttleProtocol.getTaskNo() != 0 -// && shuttleProtocol.getBusyStatusType() == ShuttleStatusType.IDLE){ -// //澶勪簬鏁呴殰淇鐘舵�� -// //鎵ц涓嬩竴姝ユ寚浠� -// executeWork(shuttleProtocol.getTaskNo()); -// } + boolean isIdle(ExecuteSupport support);//鏄惁绌洪棽 - //鍥涘悜绌挎杞︾┖闂层�佹湁浠诲姟銆佹爣璁颁负true銆佸瓨鍦ㄤ换鍔℃寚浠わ紝闇�瑕佹墽琛屼换鍔$殑涓嬩竴鏉℃寚浠� - if (shuttleProtocol.getBusyStatusType() == ShuttleStatusType.IDLE - && shuttleProtocol.getTaskNo() != 0 - && shuttleProtocol.getPakMk()) { - //鎵ц涓嬩竴姝ユ寚浠� - executeWork(shuttleProtocol.getTaskNo()); - } + boolean isDeviceIdle();//璁惧鏄惁绌洪棽 -// //妫�娴嬫槸鍚︽湁鎻愬崌鏈洪攣瀹氭爣璁帮紝鏈夊垯妫�娴嬫彁鍗囨満鏄惁鍒颁綅锛屾槸鍚﹁兘璧颁笅涓�姝ュ懡浠� -// if (shuttleProtocol.getBusyStatusType() == ShuttleStatusType.IDLE -// && shuttleProtocol.getTaskNo() != 0) { -// Object o = redisUtil.get("shuttle_wrk_no_" + shuttleProtocol.getTaskNo()); -// if (o != null) { -// ShuttleRedisCommand redisCommand = JSON.parseObject(o.toString(), ShuttleRedisCommand.class); -// if (redisCommand.getLiftSecurityMk()) { -// //鎵ц涓嬩竴姝ユ寚浠� -// executeWork(shuttleProtocol.getTaskNo()); -// } -// } -// } + boolean isDeviceIdle(ExecuteSupport support);//璁惧鏄惁绌洪棽 - //灏嗗洓鍚戠┛姊溅鐘舵�佷繚瀛樿嚦鏁版嵁搴� - BasShuttleService shuttleService = SpringUtils.getBean(BasShuttleService.class); - BasShuttle basShuttle = shuttleService.selectById(slave.getId()); - if (basShuttle == null) { - basShuttle = new BasShuttle(); - //鍥涘悜绌挎杞﹀彿 - basShuttle.setShuttleNo(slave.getId()); - shuttleService.insert(basShuttle); - } - //灏忚溅蹇欑姸鎬佷綅 - basShuttle.setBusyStatus(shuttleProtocol.getBusyStatus().intValue()); - //褰撳墠浜岀淮鐮� - basShuttle.setCurrentCode(shuttleProtocol.getCurrentCode().intValue()); - //鐢垫睜鐢甸噺鐧惧垎姣� - basShuttle.setBatteryPower(shuttleProtocol.getBatteryPower().intValue()); - //鐢垫睜娓╁害 - basShuttle.setBatteryTemp(shuttleProtocol.getBatteryTemp().intValue()); - //閿欒缂栧彿 - basShuttle.setErrorCode(shuttleProtocol.getErrorCode().intValue()); - //Plc杈撳嚭鐘舵�両O - basShuttle.setPlcOutputStatusIo(shuttleProtocol.getPlcOutputStatusIO().intValue()); - //閿欒淇℃伅鐮� - basShuttle.setStatusErrorCode(shuttleProtocol.getStatusErrorCode().intValue()); - //PLC杈撳叆鐘舵�� - basShuttle.setPlcInputStatus(shuttleProtocol.getPlcInputStatus().intValue()); - //褰撳墠鎴栬�呬箣鍓嶈鍒扮殑浜岀淮鐮佸�� - basShuttle.setCurrentOrBeforeCode(shuttleProtocol.getCurrentOrBeforeCode().intValue()); - //璇诲埌鐨勪簩缁寸爜X鏂瑰悜鍋忕Щ閲� - basShuttle.setCodeOffsetX(shuttleProtocol.getCodeOffsetX().intValue()); - //璇诲埌鐨勪簩缁寸爜Y鏂瑰悜鍋忕Щ閲� - basShuttle.setCodeOffsetY(shuttleProtocol.getCodeOffsetY().intValue()); - //褰撳墠鐨勭數鍘嬪�� - basShuttle.setCurrentVoltage(shuttleProtocol.getCurrentVoltage().intValue()); - //褰撳墠鐨勬ā鎷熼噺鍊� - basShuttle.setCurrentAnalogValue(shuttleProtocol.getCurrentAnalogValue().intValue()); - //褰撳墠鐨勫崌闄嶄己鏈嶉�熷害 - basShuttle.setCurrentLiftServoSpeed(shuttleProtocol.getCurrentLiftServoSpeed().intValue()); - //褰撳墠鐨勮璧颁己鏈嶉�熷害 - basShuttle.setCurrentMoveServoSpeed(shuttleProtocol.getCurrentMoveServoSpeed().intValue()); - //褰撳墠鐨勫崌闄嶄己鏈嶈礋杞界巼 - basShuttle.setCurrentLiftServoLoad(shuttleProtocol.getCurrentLiftServoLoad().intValue()); - //褰撳墠鐨勮璧颁己鏈嶈礋杞界巼 - basShuttle.setCurrentMoveServoLoad(shuttleProtocol.getCurrentMoveServoLoad().intValue()); - //褰撳墠灏忚溅鐘舵�侊紙鍐呴儴鑷垜缁存姢锛� - basShuttle.setShuttleStatus(shuttleProtocol.getProtocolStatus()); - //浠诲姟鍙� - basShuttle.setWrkNo(shuttleProtocol.getTaskNo().intValue()); - //淇敼鏃堕棿 - basShuttle.setUpdateTime(new Date()); - //浣滀笟鏍囪 - basShuttle.setPakMk(shuttleProtocol.getPakMk()); - if (shuttleService.updateById(basShuttle)) { - OutputQueue.SHUTTLE.offer(MessageFormat.format("銆恵0}銆慬id:{1}] <<<<< 瀹炴椂鏁版嵁鏇存柊鎴愬姛",DateUtils.convert(new Date()), slave.getId())); -// log.info(MessageFormat.format("銆恵0}銆慬id:{1}] <<<<< 瀹炴椂鏁版嵁鏇存柊鎴愬姛",DateUtils.convert(new Date()), slave.getId())); - } + boolean isRequireCharge();//鏄惁婊¤冻鍏呯數鐘舵�� - }else { - OutputQueue.SHUTTLE.offer(MessageFormat.format("銆恵0}銆憑1}鍥涘悜绌挎杞lc鐘舵�佷俊鎭け璐�", DateUtils.convert(new Date()), slave.getId())); - throw new CoolException(MessageFormat.format( "鍥涘悜绌挎杞lc鐘舵�佷俊鎭け璐� ===>> [id:{0}] [ip:{1}] [port:{2}]", slave.getId(), slave.getIp(), slave.getPort())); - } - } catch (Exception e) { - e.printStackTrace(); - OutputQueue.SHUTTLE.offer(MessageFormat.format("銆恵0}銆戝洓鍚戠┛姊溅plc鐘舵�佷俊鎭け璐� ===>> [id:{1}] [ip:{2}] [port:{3}]", DateUtils.convert(new Date()), slave.getId(), slave.getIp(), slave.getPort())); - initShuttle(); - } - } + boolean isCharging();//鏄惁鍏呯數涓� - private boolean write(ShuttleCommand command){ - if (null == command) { - News.error("鍥涘悜绌挎杞﹀啓鍏ュ懡浠や负绌�"); - return false; - } + boolean isChargingCompleted();//鏄惁鍏呯數瀹屾垚 - BasShuttleService shuttleService = SpringUtils.getBean(BasShuttleService.class); - if (shuttleService == null) { - News.error("绯荤粺閿欒"); - return false; - } + List<NavigateNode> getMoveAdvancePath();//鑾峰彇绌挎杞︿换鍔¤矾寰� - BasShuttle basShuttle = shuttleService.selectById(slave.getId().shortValue()); - if (basShuttle == null) { - News.error("鍥涘悜绌挎杞︿笉瀛樺湪"); - return false; - } + int generateDeviceTaskNo(int taskNo, ShuttleTaskNoType type);//鐢熸垚纭欢璁惧宸ヤ綔鍙� - command.setShuttleNo(slave.getId().shortValue()); - // 寮�濮嬩换鍔� - short[] array = new short[17]; - //鎺у埗鎸囦护瀛� - array[0] = command.getCommandWord(); - if (command.getStartCodeNum() != null) { - //鍚浜岀淮缂栧彿 - array[1] = command.getStartCodeNum(); - } + boolean setProtocolStatus(ShuttleProtocolStatusType status);//璁剧疆宸ヤ綔鐘舵�� - if (command.getMiddleCodeNum() != null) { - //涓棿浜岀淮缂栧彿 - array[2] = command.getMiddleCodeNum(); - } + boolean setTaskNo(Integer taskNo);//璁剧疆宸ヤ綔鍙� - if (command.getDistCodeNum() != null) { - //鐩爣浜岀淮缂栧彿 - array[3] = command.getDistCodeNum(); - } + boolean setSyncTaskNo(Integer taskNo);//璁剧疆宸ヤ綔鍙� - if (command.getStartToDistDistance() != null) { - //璧风偣鍒扮洰鏍囩偣鐨勮窛绂婚暱搴︼紝鍏堝皢int杞负byte鏁扮粍锛屽啀灏哹yte鏁扮粍杞垚涓や釜short锛屽垎鍒崰鐢�4鍜�5绌洪棿 - short[] startToDistDistances = CommonUtils.intToShorts(command.getStartToDistDistance()); - array[4] = startToDistDistances[0]; - array[5] = startToDistDistances[1]; - } + boolean setPakMk(boolean pakMk);//璁剧疆鏍囪 - if (command.getMiddleToDistDistance() != null) { - //涓棿鐐瑰埌鐩爣鐐圭殑璺濈闀垮害锛屽厛灏唅nt杞负byte鏁扮粍锛屽啀灏哹yte鏁扮粍杞垚涓や釜short锛屽垎鍒崰鐢�4鍜�5绌洪棿 - short[] middleToDistDistances = CommonUtils.intToShorts(command.getMiddleToDistDistance()); - array[6] = middleToDistDistances[0]; - array[7] = middleToDistDistances[1]; - } + boolean enableMoveLoc(ShuttleMoveLocParam param, boolean enable); - array[8] = basShuttle.getRunSpeed().shortValue();//鍥涘悜绌挎杞﹁繍琛岄�熷害锛屼粠绯荤粺鏁版嵁搴撹鍑� - if (command.getRunDirection() != null) { - //灏忚溅杩愯鏂瑰悜 - array[8] = command.getRunDirection(); - } + boolean requestWaiting(); - if (command.getPalletLift() != null) { - //鎵樼洏椤跺崌 - array[9] = command.getPalletLift(); - } + boolean enableDemo(boolean enable);//婕旂ず妯″紡 - if (command.getForceMoveDistance() != null) { - //灏忚溅寮哄埗绉诲姩璺濈锛屽厛灏唅nt杞负byte鏁扮粍锛屽啀灏哹yte鏁扮粍杞垚涓や釜short锛屽垎鍒崰鐢�4鍜�5绌洪棿 - short[] forceMoveDistances = CommonUtils.intToShorts(command.getForceMoveDistance()); - array[10] = forceMoveDistances[0]; - array[11] = forceMoveDistances[1]; - } + boolean offerSystemMsg(String format, Object... arguments); - if (command.getChargeSwitch() != null) { - //鍏呯數寮�鍏� - array[12] = command.getChargeSwitch(); - } + //***************鑾峰彇鍛戒护***************** - if (command.getIOControl() != null) { - //灏忚溅IO鎺у埗 - array[13] = command.getIOControl(); - } + ShuttleCommand getMoveCommand(Integer taskNo, String startCodeNum, String distCodeNum, Integer allDistance, Integer runDirection, Integer runSpeed, List<NavigateNode> nodes);//鑾峰彇绉诲姩鍛戒护 - if (command.getRunSpeed() != null) { - //灏忚溅杩愯閫熷害 - array[14] = command.getRunSpeed(); - } + ShuttleCommand getLiftCommand(Integer taskNo, Boolean lift);//椤跺崌鍛戒护 true=>椤跺崌 false=>涓嬮檷 - if (command.getRadarTmp() != null) { - //灏忚溅闆疯揪澶囩敤 - array[15] = command.getRadarTmp(); - } + ShuttleCommand getChargeCommand(Integer taskNo, Boolean charge);//鍏呯數寮�鍏冲懡浠� true=>寮� false=>鍏� - //鎸囦护缁撴潫浣� - array[16] = command.getCommandEnd(); - - OperateResult result = modbusTcpNet.Write("0", array);; - if (result != null && result.IsSuccess) { - try { - Thread.sleep(3000);//鍛戒护涓嬪彂鍚庝紤鐪�1s - } catch (InterruptedException e) { - throw new RuntimeException(e); - } - News.info("鍥涘悜绌挎杞﹀懡浠や笅鍙慬id:{}] >>>>> {}", slave.getId(), JSON.toJSON(command)); - OutputQueue.SHUTTLE.offer(MessageFormat.format("銆恵0}銆慬id:{1}] >>>>> 鍛戒护涓嬪彂锛� {2}", DateUtils.convert(new Date()), slave.getId(), JSON.toJSON(command))); - return true; - } else { - OutputQueue.SHUTTLE.offer(MessageFormat.format("銆恵0}銆戝啓鍏ュ洓鍚戠┛姊溅plc鏁版嵁澶辫触 ===>> [id:{1}] [ip:{2}] [port:{3}]", DateUtils.convert(new Date()), slave.getId(), slave.getIp(), slave.getPort())); - News.error("鍐欏叆鍥涘悜绌挎杞lc鏁版嵁澶辫触 ===>> [id:{}] [ip:{}] [port:{}]", slave.getId(), slave.getIp(), slave.getPort()); - return false; - } - } - - /** - * 鍒濆鍖栧洓鍚戠┛姊溅 - */ - private void initShuttle() { - if (null == shuttleProtocol) { - shuttleProtocol = new ShuttleProtocol(); - } - } - - //鍒嗛厤浠诲姟 - private void assignWork(ShuttleAssignCommand assignCommand) { - ShuttleRedisCommand redisCommand = new ShuttleRedisCommand(); - - if (!assignCommand.getAuto()) { - List<NavigateNode> allNode = new ArrayList<>(); - List<ShuttleCommand> commands = new ArrayList<>(); - LocMastService locMastService = SpringUtils.getBean(LocMastService.class); - BasShuttleService shuttleService = SpringUtils.getBean(BasShuttleService.class); - NavigateMapData navigateMapData; - - //鑾峰彇灏忚溅绉诲姩閫熷害 - BasShuttle basShuttle = shuttleService.selectById(slave.getId()); - Integer runSpeed = 1000; - if (basShuttle != null) { - Integer runSpeed1 = basShuttle.getRunSpeed(); - if (runSpeed1 != null) { - runSpeed = runSpeed1; - } - } - - LiftThread liftThread = (LiftThread) SlaveConnection.get(SlaveType.Lift, 1); - LiftProtocol liftProtocol = liftThread.getLiftProtocol(); - - switch (assignCommand.getTaskMode()) { - case 1://鍏ュ簱 - case 2://鍑哄簱 - //灏忚溅绉诲姩鍒版彁鍗囨満鍙o紝璁$畻璺緞 - //璁$畻灏忚溅璧风偣鍒颁腑鐐规墍闇�鍛戒护 - LocMast currentLocMast = locMastService.queryByQrCode(shuttleProtocol.getCurrentCode().toString()); - List<NavigateNode> firstMastResult = NavigateUtils.calc(currentLocMast.getLocNo(), assignCommand.getSourceLocNo(), NavigationMapType.NORMAL.id, Utils.getShuttlePoints(assignCommand.getShuttleNo().intValue(), Utils.getLev(currentLocMast.getLocNo())));//灏忚溅鍒颁腑鐐癸紝澶勪簬鏃犺揣鐘舵�侊紝浣跨敤姝e父閫氶亾鍦板浘 - boolean checkResult = Utils.checkShuttlePath(firstMastResult, shuttleProtocol.getShuttleNo().intValue()); - if (firstMastResult != null && checkResult) { - allNode.addAll(firstMastResult);//灏嗚妭鐐硅繘琛屼繚瀛� - //鑾峰彇鍒嗘璺緞 - ArrayList<ArrayList<NavigateNode>> data = NavigateUtils.getSectionPath(firstMastResult); - //灏嗘瘡涓�娈佃矾寰勫垎鎴恈ommand鎸囦护 - for (ArrayList<NavigateNode> nodes : data) { - //寮�濮嬭矾寰� - NavigateNode startPath = nodes.get(0); - //涓棿璺緞 - NavigateNode middlePath = nodes.get(nodes.size() - 2); - //鐩爣璺緞 - NavigateNode endPath = nodes.get(nodes.size() - 1); - Integer allDistance = NavigateUtils.getCurrentPathAllDistance(nodes);//璁$畻褰撳墠璺緞琛岃蛋鎬昏窛绂� - Integer middleToDistDistance = NavigateUtils.getMiddleToDistDistance(nodes);//璁$畻涓棿鐐瑰埌鐩爣鐐硅璧拌窛绂� - - //姝e父绉诲姩鍛戒护 - Short startCode = NavigatePositionConvert.xyToPosition(startPath.getX(), startPath.getY(), startPath.getZ());//寮�濮嬩簩缁寸爜 - Short middleCode = NavigatePositionConvert.xyToPosition(middlePath.getX(), middlePath.getY(), middlePath.getZ());//鐩爣浜岀淮鐮� - Short distCode = NavigatePositionConvert.xyToPosition(endPath.getX(), endPath.getY(), endPath.getZ());//鐩爣浜岀淮鐮� - commands.add(getMoveCommand(startCode, distCode, allDistance, ShuttleRunDirection.get(startPath.getDirection()).id, middleCode, middleToDistDistance, runSpeed)); - } - - //鎵樼洏椤跺崌 - commands.add(getPalletCommand((short) 1)); - }else { - //娌℃湁璁$畻鍒拌矾寰勶紝鍙兘瀛樺湪灏忚溅浣嶇疆灏辨槸璧风偣浣嶇疆 - if (currentLocMast.getLocNo().equals(assignCommand.getSourceLocNo())) { - //灏忚溅浣嶇疆灏辨槸璧风偣浣嶇疆锛屾棤闇�绉诲姩锛岀洿鎺ラ《鍗� - //鎵樼洏椤跺崌 - commands.add(getPalletCommand((short) 1)); - } - } - - //璁$畻涓偣鍒扮粓鐐硅矾寰� - List<NavigateNode> secMastResult = NavigateUtils.calc(assignCommand.getSourceLocNo(), assignCommand.getLocNo(), NavigationMapType.DFX.id, Utils.getShuttlePoints(assignCommand.getShuttleNo().intValue(), Utils.getLev(assignCommand.getSourceLocNo())));//灏忚溅浠庝腑鐐瑰埌缁堢偣锛屽浜庢湁璐х姸鎬侊紝浣跨敤DFX鍦板浘 - boolean checkResult2 = Utils.checkShuttlePath(secMastResult, shuttleProtocol.getShuttleNo().intValue()); - if (secMastResult != null && checkResult2) { - allNode.addAll(secMastResult);//灏嗚妭鐐硅繘琛屼繚瀛� - //鑾峰彇鍒嗘璺緞 - ArrayList<ArrayList<NavigateNode>> data = NavigateUtils.getSectionPath(secMastResult); - //灏嗘瘡涓�娈佃矾寰勫垎鎴恈ommand鎸囦护 - for (ArrayList<NavigateNode> nodes : data) { - //寮�濮嬭矾寰� - NavigateNode startPath = nodes.get(0); - //涓棿璺緞 - NavigateNode middlePath = nodes.get(nodes.size() - 2); - //鐩爣璺緞 - NavigateNode endPath = nodes.get(nodes.size() - 1); - Integer allDistance = NavigateUtils.getCurrentPathAllDistance(nodes);//璁$畻褰撳墠璺緞琛岃蛋鎬昏窛绂� - Integer middleToDistDistance = NavigateUtils.getMiddleToDistDistance(nodes);//璁$畻涓棿鐐瑰埌鐩爣鐐硅璧拌窛绂� - - //姝e父绉诲姩鍛戒护 - Short startCode = NavigatePositionConvert.xyToPosition(startPath.getX(), startPath.getY(), startPath.getZ());//寮�濮嬩簩缁寸爜 - Short middleCode = NavigatePositionConvert.xyToPosition(middlePath.getX(), middlePath.getY(), middlePath.getZ());//涓棿浜岀淮鐮� - Short distCode = NavigatePositionConvert.xyToPosition(endPath.getX(), endPath.getY(), endPath.getZ());//鐩爣浜岀淮鐮� - commands.add(getMoveCommand(startCode, distCode, allDistance, ShuttleRunDirection.get(startPath.getDirection()).id, middleCode, middleToDistDistance, runSpeed)); - } - - //鎵樼洏涓嬮檷 - commands.add(getPalletCommand((short) 2)); - } - - if (firstMastResult == null || secMastResult == null) { - throw new CoolException(MessageFormat.format( "鍥涘悜绌挎杞﹀嚭鍏ュ簱璺緞鎼滅储澶辫触 ===>> [id:{0}] [ip:{1}] [port:{2}]", slave.getId(), slave.getIp(), slave.getPort())); - } - - navigateMapData = new NavigateMapData(Utils.getLev(currentLocMast.getLocNo())); - //鎵�浣跨敤鐨勮矾寰勮繘琛岄攣瀹氱鐢� - navigateMapData.writeNavigateNodeToRedisMap(firstMastResult, true);////鎵�浣跨敤鐨勮矾寰勮繘琛岄攣瀹氱鐢� - navigateMapData.writeNavigateNodeToRedisMap(secMastResult, true);////鎵�浣跨敤鐨勮矾寰勮繘琛岄攣瀹氱鐢� - break; - case 3://鎵樼洏椤跺崌 - case 4://鎵樼洏涓嬮檷 - commands.add(getPalletCommand(assignCommand.getTaskMode() == 3 ? (short) 1 : (short) 2)); - break; - case 5://寮哄埗宸︾Щ - commands.add(getForceMoveCommand((short) 2)); - break; - case 6://寮哄埗鍙崇Щ - commands.add(getForceMoveCommand((short) 1)); - break; - case 7://寮哄埗涓婄Щ - commands.add(getForceMoveCommand((short) 3)); - break; - case 8://寮哄埗涓嬬Щ - commands.add(getForceMoveCommand((short) 4)); - break; - case 9://鐘舵�佸浣� - ShuttleCommand reset = getResetCommand(); - commands.add(reset); - break; - case 10://姝f柟鍚�(鍙�)瀵诲簱浣� - commands.add(getFindLocCommand((short) 1)); - break; - case 11://璐熸柟鍚�(宸�)瀵诲簱浣� - commands.add(getFindLocCommand((short) 2)); - break; - case 12://鍚戞鏂瑰悜(鍓�)瀵诲簱浣� - commands.add(getFindLocCommand((short) 4)); - break; - case 13://鍚戣礋鏂瑰悜(鍚�)瀵诲簱浣� - commands.add(getFindLocCommand((short) 3)); - break; - case 14://绉诲姩鍒扮洰鏍囧簱浣� - String startQr = shuttleProtocol.getCurrentCode().toString();//璧峰浣嶇疆 - //濡傛灉绌挎杞﹀湪鎻愬崌鏈哄唴锛岀Щ鍔ㄦ椂闇�瑕佸厛涓嬪彂鍑烘彁鍗囨満鍛戒护 - if (liftProtocol.getBarcode().intValue() == shuttleProtocol.getCurrentCode().intValue()) { - //绌挎杞﹀嚭鎻愬崌鏈� - Short liftArrival = liftProtocol.getPositionArrivalFeedback();//鎻愬崌鏈轰綅缃弽棣� - String liftSiteLocNo = Utils.liftArrivalToOutInStaLocNo(liftArrival); - LocMast locMast1 = locMastService.selectById(liftSiteLocNo); - ShuttleCommand moveCommand = getMoveCommand(liftProtocol.getBarcode(), Short.parseShort(locMast1.getQrCodeValue()), 1400, ShuttleRunDirection.BOTTOM.id, liftProtocol.getBarcode(), 1400, runSpeed); - commands.add(moveCommand); - - //璧峰浣嶇疆淇敼涓烘彁鍗囨満鍙g珯鐐逛綅缃� - startQr = locMast1.getQrCodeValue(); - } - - LocMast locMast = locMastService.queryByQrCode(startQr); - List<NavigateNode> result = NavigateUtils.calc(locMast.getLocNo(), assignCommand.getLocNo(), NavigationMapType.NONE.id, Utils.getShuttlePoints(assignCommand.getShuttleNo().intValue(), Utils.getLev(locMast.getLocNo())));//鎵嬪姩鍛戒护-绉诲姩鍛戒护锛屼娇鐢ㄦ棤杩囨护鍦板浘 - boolean checkResult3 = Utils.checkShuttlePath(result, shuttleProtocol.getShuttleNo().intValue()); - if (result != null && checkResult3) { - //鎵�浣跨敤鐨勮矾寰勮繘琛岄攣瀹氱鐢� - navigateMapData = new NavigateMapData(Utils.getLev(locMast.getLocNo())); - navigateMapData.writeNavigateNodeToRedisMap(result, true);////鎵�浣跨敤鐨勮矾寰勮繘琛岄攣瀹氱鐢� - - allNode.addAll(result);//灏嗚妭鐐硅繘琛屼繚瀛� - //鑾峰彇鍒嗘璺緞 - ArrayList<ArrayList<NavigateNode>> data = NavigateUtils.getSectionPath(result); - //灏嗘瘡涓�娈佃矾寰勫垎鎴恈ommand鎸囦护 - for (ArrayList<NavigateNode> nodes : data) { - //寮�濮嬭矾寰� - NavigateNode startPath = nodes.get(0); - //涓棿璺緞 - NavigateNode middlePath = nodes.get(nodes.size() - 2); - //鐩爣璺緞 - NavigateNode endPath = nodes.get(nodes.size() - 1); - Integer allDistance = NavigateUtils.getCurrentPathAllDistance(nodes);//璁$畻褰撳墠璺緞琛岃蛋鎬昏窛绂� - Integer middleToDistDistance = NavigateUtils.getMiddleToDistDistance(nodes);//璁$畻涓棿鐐瑰埌鐩爣鐐硅璧拌窛绂� - Short startCode = NavigatePositionConvert.xyToPosition(startPath.getX(), startPath.getY(), startPath.getZ());//寮�濮嬩簩缁寸爜 - Short middleCode = NavigatePositionConvert.xyToPosition(middlePath.getX(), middlePath.getY(), middlePath.getZ());//涓棿浜岀淮鐮� - Short distCode = NavigatePositionConvert.xyToPosition(endPath.getX(), endPath.getY(), endPath.getZ());//鐩爣浜岀淮鐮� - //姝e父绉诲姩鍛戒护 - commands.add(getMoveCommand(startCode, distCode, allDistance, ShuttleRunDirection.get(startPath.getDirection()).id, middleCode, middleToDistDistance, runSpeed)); - } - } - break; - case 15://鍏呯數寮�鍏� - commands.add(getChargeSwitchCommand()); - break; - case 16://绉诲姩鍒版彁鍗囨満 - LocMast locMast1 = locMastService.queryByQrCode(shuttleProtocol.getCurrentCode().toString()); - int lev = Utils.getLev(locMast1.getLocNo());//绌挎杞﹀綋鍓嶉珮搴� - String liftSiteLocNo = Utils.levToOutInStaLocNo(lev);//褰撳墠妤煎眰绔欑偣搴撲綅鍙� - LocMast liftSitelocMast = locMastService.selectById(liftSiteLocNo); - List<NavigateNode> result1 = NavigateUtils.calc(locMast1.getLocNo(), liftSiteLocNo, NavigationMapType.NONE.id, Utils.getShuttlePoints(assignCommand.getShuttleNo().intValue(), Utils.getLev(locMast1.getLocNo())));//绉诲姩鍒版彁鍗囨満锛屼娇鐢ㄦ棤杩囨护鍦板浘 - boolean checkResult4 = Utils.checkShuttlePath(result1, shuttleProtocol.getShuttleNo().intValue()); - Short endStartCode = null; - if (result1 != null && checkResult4) { - //鎵�浣跨敤鐨勮矾寰勮繘琛岄攣瀹氱鐢� - navigateMapData = new NavigateMapData(Utils.getLev(locMast1.getLocNo())); - navigateMapData.writeNavigateNodeToRedisMap(result1, true);////鎵�浣跨敤鐨勮矾寰勮繘琛岄攣瀹氱鐢� - - allNode.addAll(result1);//灏嗚妭鐐硅繘琛屼繚瀛� - //鑾峰彇鍒嗘璺緞 - ArrayList<ArrayList<NavigateNode>> data = NavigateUtils.getSectionPath(result1); - //灏嗘瘡涓�娈佃矾寰勫垎鎴恈ommand鎸囦护 - for (ArrayList<NavigateNode> nodes : data) { - //寮�濮嬭矾寰� - NavigateNode startPath = nodes.get(0); - //涓棿璺緞 - NavigateNode middlePath = nodes.get(nodes.size() - 2); - //鐩爣璺緞 - NavigateNode endPath = nodes.get(nodes.size() - 1); - Integer allDistance = NavigateUtils.getCurrentPathAllDistance(nodes);//璁$畻褰撳墠璺緞琛岃蛋鎬昏窛绂� - Integer middleToDistDistance = NavigateUtils.getMiddleToDistDistance(nodes);//璁$畻涓棿鐐瑰埌鐩爣鐐硅璧拌窛绂� - Short startCode = NavigatePositionConvert.xyToPosition(startPath.getX(), startPath.getY(), startPath.getZ());//寮�濮嬩簩缁寸爜 - Short middleCode = NavigatePositionConvert.xyToPosition(middlePath.getX(), middlePath.getY(), middlePath.getZ());//涓棿浜岀淮鐮� - Short distCode = NavigatePositionConvert.xyToPosition(endPath.getX(), endPath.getY(), endPath.getZ());//鐩爣浜岀淮鐮� - endStartCode = distCode; - //姝e父绉诲姩鍛戒护 - commands.add(getMoveCommand(startCode, distCode, allDistance, ShuttleRunDirection.get(startPath.getDirection()).id, middleCode, middleToDistDistance, runSpeed)); - } - } - - if (endStartCode == null && shuttleProtocol.getCurrentCode() == Short.parseShort(liftSitelocMast.getQrCodeValue())) { - //绌挎杞﹀凡缁忓湪鎻愬崌鏈虹珯鐐瑰彛 - endStartCode = shuttleProtocol.getCurrentCode(); - } - - //澧炲姞绉诲姩杩涙彁鍗囨満鍛戒护 - ShuttleCommand moveCommand = getMoveCommand(endStartCode, liftProtocol.getBarcode(), 1400, ShuttleRunDirection.TOP.id, endStartCode, 1400, runSpeed); - commands.add(moveCommand); - break; - default: - } - assignCommand.setCommands(commands); - assignCommand.setNodes(allNode);//褰撳墠浠诲姟鎵�鍗犵敤鐨勮妭鐐筶ist - } - - redisCommand.setShuttleNo(assignCommand.getShuttleNo());//鍥涘悜绌挎杞﹀彿 - redisCommand.setWrkNo(assignCommand.getTaskNo());//宸ヤ綔鍙� - redisCommand.setCommandStep(0);//鍛戒护鎵ц姝ュ簭 - redisCommand.setAssignCommand(assignCommand);//鍛戒护 - redisCommand.setErrorCommands(new ArrayList<ShuttleCommand>());//鍙戠敓閿欒鏃跺皾璇曟墽琛岀殑鎸囦护锛屼紭鍏堢骇鏈�楂� - shuttleProtocol.setTaskNo(assignCommand.getTaskNo()); - shuttleProtocol.setAssignCommand(assignCommand); - shuttleProtocol.setProtocolStatus(ShuttleProtocolStatusType.WORKING); - //浠诲姟鏁版嵁淇濆瓨鍒皉edis - redisUtil.set("shuttle_wrk_no_" + assignCommand.getTaskNo(), JSON.toJSONString(redisCommand)); - //鎵ц涓嬪彂浠诲姟 - executeWork(assignCommand.getTaskNo()); - } - - //鎵ц涓嬪彂鐨勬寚浠� - private boolean executeWork(Short wrkNo) { - //璇诲彇redis鏁版嵁 - if (wrkNo == null) { - return false; - } - - Object o = redisUtil.get("shuttle_wrk_no_" + wrkNo); - if (o == null) { - return false; - } - ShuttleRedisCommand redisCommand = JSON.parseObject(o.toString(), ShuttleRedisCommand.class); - - if (!checkLiftStation(wrkNo)) {//妫�娴嬫槸鍚︽湁鎻愬崌鏈虹珯鐐癸紝鏈夊垯璋冨害鎻愬崌鏈� - return false; - } - -// List<ShuttleCommand> errorCommands = redisCommand.getErrorCommands(); -// if (errorCommands.size() > 0) { -// //浼樺厛鎵ц璇ユ寚浠� -// ShuttleCommand errorCommand = errorCommands.get(0);//鍙栧嚭鎸囦护 -// -// if(errorCommand.getCommandWord() == 1){//姝e父琛岃蛋鍛戒护锛岄渶瑕佸厛鎵ц瀹屾壘搴撲綅鍛戒护鍚庯紝鍐嶆墽琛� -// LocMastService locMastService = SpringUtils.getBean(LocMastService.class); -// LocMast locMast = locMastService.queryByQrCode(shuttleProtocol.getCurrentCode().toString()); -// LocMast distLocMast = locMastService.queryByQrCode(errorCommand.getStartCodeNum().toString()); -// if (shuttleProtocol.getCurrentCode().equals(errorCommand.getStartCodeNum())) { -// //璧风偣鍜岀粓鐐瑰睘浜庡悓涓�搴撲綅锛屾棤闇�鍐嶆墽琛岀Щ鍔ㄦ搷浣� -// errorCommands.remove(0);//绉婚櫎璇ュ懡浠� -// redisCommand.setErrorCommands(new ArrayList<ShuttleCommand>()); -// shuttleProtocol.setProtocolStatus(ShuttleProtocolStatusType.WORKING); -// //褰撳墠姝ュ簭 -// int commandStep = redisCommand.getCommandStep(); -// //姝ュ簭鍥為�� -// commandStep--; -// redisCommand.setCommandStep(commandStep); -// //浠诲姟鏁版嵁淇濆瓨鍒皉edis -// redisUtil.set("shuttle_wrk_no_" + wrkNo, JSON.toJSONString(redisCommand)); -// shuttleProtocol.setPakMk(true); -// return true; -// }else { -// List<NavigateNode> result = NavigateUtils.calc(locMast.getLocNo(), distLocMast.getLocNo(), NavigationMapType.DFX.id, Utils.getShuttlePoints(errorCommand.getShuttleNo().intValue()));//閿欒鎭㈠锛屼娇鐢―FX鍦板浘 -// if (result != null) { -// //鑾峰彇鍒嗘璺緞 -// ArrayList<ArrayList<NavigateNode>> data = NavigateUtils.getSectionPath(result); -// //灏嗘瘡涓�娈佃矾寰勫垎鎴恈ommand鎸囦护 -// for (ArrayList<NavigateNode> nodes : data) { -// //寮�濮嬭矾寰� -// NavigateNode startPath = nodes.get(0); -// //鐩爣璺緞 -// NavigateNode endPath = nodes.get(nodes.size() - 1); -// Integer allDistance = NavigateUtils.getCurrentPathAllDistance(nodes);//璁$畻褰撳墠璺緞琛岃蛋鎬昏窛绂� -// -// String qrCodeValue = distLocMast.getQrCodeValue(); -// errorCommand.setCommandWord((short) 1); -// errorCommand.setStartCodeNum(shuttleProtocol.getCurrentCode()); -// errorCommand.setMiddleCodeNum((short) 1); -// errorCommand.setDistCodeNum((short) Integer.parseInt(qrCodeValue)); -// errorCommand.setStartToDistDistance(allDistance); -// errorCommand.setRunSpeed((short) 1000); -// errorCommand.setRunDirection(ShuttleRunDirection.get(startPath.getDirection()).id); -// errorCommand.setForceMoveDistance(0); -// errorCommand.setIOControl((short) 0); -// errorCommand.setCommandEnd((short) 1); -// break; -// } -// } -// } -// -// shuttleProtocol.setProtocolStatus(ShuttleProtocolStatusType.WORKING); -// //褰撳墠姝ュ簭 -// int commandStep = redisCommand.getCommandStep(); -// //姝ュ簭鍥為�� -// commandStep--; -// redisCommand.setCommandStep(commandStep); -// } -// -// if (!write(errorCommand)) { -// News.error("鍥涘悜绌挎杞﹀懡浠や笅鍙戝け璐ワ紝绌挎杞﹀彿={}锛屼换鍔℃暟鎹�={}", shuttleProtocol.getShuttleNo(), JSON.toJSON(errorCommand)); -// return false; -// } else { -// News.info("鍥涘悜绌挎杞﹀懡浠や笅鍙戞垚鍔燂紝绌挎杞﹀彿={}锛屼换鍔℃暟鎹�={}", shuttleProtocol.getShuttleNo(), JSON.toJSON(errorCommand)); -// errorCommands.remove(0); -// redisCommand.setErrorCommands(errorCommands); -// //浠诲姟鏁版嵁淇濆瓨鍒皉edis -// redisUtil.set("shuttle_wrk_no_" + wrkNo, JSON.toJSONString(redisCommand)); -// return true; -// } -// } - - LiftThread liftThread = (LiftThread) SlaveConnection.get(SlaveType.Lift, 1); - LiftProtocol liftProtocol = liftThread.getLiftProtocol(); - - List<ShuttleCommand> commands = redisCommand.getAssignCommand().getCommands(); - //褰撳墠姝ュ簭 - int commandStep = redisCommand.getCommandStep(); - //path璺緞鏁扮洰 - int size = commands.size(); - ShuttleAssignCommand assignCommand = redisCommand.getAssignCommand(); - - if (commandStep != 0) { - //鍒ゆ柇涓婁竴鏉℃寚浠ゆ槸鍚﹀畬鎴� - ShuttleCommand command = commands.get(commandStep - 1); - if (command.getCommandWord().intValue() == 1) { - //绉诲姩鍛戒护 - if (command.getDistCodeNum().intValue() == shuttleProtocol.getCurrentCode().intValue()) { - //涓婁竴鏉℃寚浠ょ殑鐩爣浣嶇疆鍜屽綋鍓嶅皬杞︿綅缃浉鍚岋紝鍒欒瀹氫笂涓�鏉′换鍔″畬鎴� - command.setComplete(true); - - //涓婁竴鏉℃寚浠よ捣鐐规槸鎻愬崌鏈轰簩缁寸爜锛屽垯娓呴浂鎻愬崌鏈轰换鍔″彿 - if (command.getStartCodeNum().intValue() == liftProtocol.getBarcode().intValue()) { - //鍒ゆ柇鎻愬崌鏈烘槸鍚﹀浜庣┖闂� - if (liftProtocol.isIdleNoTask()) { - liftProtocol.setTaskNo((short) 0);//娓呯┖浠诲姟鍙� - } - } - } - } else if (command.getCommandWord().intValue() == 2) { - //鎵樼洏椤跺崌鍛戒护 - if (command.getPalletLift().intValue() == 1) { - //椤跺崌 - //鍒ゆ柇鏄惁椤跺崌鍒颁綅 - if (shuttleProtocol.getPlcOutputLift()) { - //鑷姩妯″紡 - if (assignCommand.getAuto() && shuttleProtocol.getPlcInputStatus().intValue() == 1) { - //椤跺崌鍒颁綅,涓旀墭鐩橀浄杈炬湁鐗╋紝璁ゅ畾浠诲姟瀹屾垚 - command.setComplete(true); - }else { - //鎵嬪姩妯″紡锛屼笉鍒ゆ柇鎵樼洏闆疯揪 - //椤跺崌鍒颁綅锛岃瀹氫换鍔″畬鎴� - command.setComplete(true); - } - } - }else { - //涓嬮檷 - //鍒ゆ柇鏄惁涓嬮檷鍒颁綅锛屽垽鏂墭鐩橀浄杈炬槸鍚︽棤鐗� - if (!shuttleProtocol.getPlcOutputLift() && !shuttleProtocol.getPlcOutputTransfer()) { - //鑷姩妯″紡 - if (assignCommand.getAuto() && shuttleProtocol.getPlcInputStatus().intValue() == 0) { - //涓嬮檷鍒颁綅锛屼笖鎵樼洏闆疯揪鏃犵墿锛岃瀹氫换鍔″畬鎴� - command.setComplete(true); - }else { - //鎵嬪姩妯″紡锛屼笉鍒ゆ柇鎵樼洏闆疯揪 - //涓嬮檷鍒颁綅锛屼笖鎵樼洏闆疯揪鏃犵墿锛岃瀹氫换鍔″畬鎴� - command.setComplete(true); - } - } - } - } else if (command.getCommandWord().intValue() == 5) { - //鍏呯數鍛戒护 - //鍒ゆ柇灏忚溅鍏呯數寮�鍏� - if (shuttleProtocol.getPlcOutputCharge()) { - //姝e父鍏呯數锛岃瀹氫换鍔″畬鎴� - command.setComplete(true); - } - } - //浠诲姟鏁版嵁淇濆瓨鍒皉edis - redisUtil.set("shuttle_wrk_no_" + redisCommand.getWrkNo(), JSON.toJSONString(redisCommand)); - - if (!command.getComplete()) { - //涓婁竴鏉′换鍔℃湭瀹屾垚锛岀姝笅鍙戝懡浠� - return false; - } - } - - //鍙栧嚭鍛戒护 - ShuttleCommand command = commands.get(commandStep); - - if (assignCommand.getTaskMode() == ShuttleTaskModeType.PAK_IN.id.shortValue() - || assignCommand.getTaskMode() == ShuttleTaskModeType.PAK_OUT.id.shortValue() - ) { - //灏忚溅澶卞幓鍧愭爣锛岀姝笅鍙戝懡浠� - if (shuttleProtocol.getCurrentCode() == 0) { - return false; - } - } - - - //鍒ゆ柇灏忚溅褰撳墠浜岀淮鐮佹槸鍚︿负鎻愬崌鏈轰簩缁寸爜 - if (shuttleProtocol.getCurrentCode().intValue() == liftProtocol.getBarcode().intValue()) { - //灏忚溅褰撳墠鍛戒护璧峰浣嶇疆灏辨槸鎻愬崌鏈轰簩缁寸爜锛岃鏄庡皬杞﹂渶瑕佸悜鎻愬崌鏈哄绉诲姩锛屽垯闇�瑕佸垽鏂姸鎬佹槸鍚︽弧瓒� - if (command.getStartCodeNum().intValue() == liftProtocol.getBarcode().intValue()){ - //鎻愬崌鏈烘槸鍚︾┖闂诧紝鎻愬崌鏈烘槸鍚﹀埌杈剧洰鏍囨ゼ灞傦紝鐩爣妤煎眰鏄惁缁欏嚭鎻愬崌鏈哄埌浣嶄俊鍙蜂綅 - if (!liftProtocol.isIdleNoTask()) { - return false;//鎻愬崌鏈哄繖锛岀姝笅鍙戝懡浠� - } - if (liftProtocol.getTaskNo().intValue() != 0 && liftProtocol.getTaskNo().intValue() != wrkNo) { - //鎻愬崌鏈哄伐浣滃彿鍜屽綋鍓嶅伐浣滀笉鐩稿悓锛岀姝笅鍙戝懡浠� - return false; - } - - Short distCodeNum = command.getDistCodeNum();//鐩爣浜岀淮鐮� - BasDevpService basDevpService = SpringUtils.getBean(BasDevpService.class); - BasDevp basDevp = basDevpService.queryByQrCode(distCodeNum.intValue());//鐩爣绔欑偣 - if (basDevp == null) { - return false;//鎵句笉鍒扮洰鏍囩珯锛岀姝笅鍙戝懡浠� - } - - int lev = Utils.getLev(basDevp.getLocNo());//鐩爣浜岀淮鐮佹墍鍦ㄦゼ灞� - int liftLev = liftProtocol.getLev().intValue();//鎻愬崌鏈烘墍鍦ㄦゼ灞� - if (liftLev != lev) { - return false;//鎻愬崌鏈轰笉鍦ㄧ洰鏍囨ゼ灞傦紝绂佹涓嬪彂鍛戒护 - } - - //鑾峰彇鐩爣绔欎俊鎭� - SiemensDevpThread devpThread = (SiemensDevpThread) SlaveConnection.get(SlaveType.Devp, 1); - StaProtocol staProtocol = devpThread.getStation().get(basDevp.getDevNo()); - if (staProtocol == null) { - return false;//绔欑偣淇℃伅涓嶅瓨鍦紝绂佹涓嬪彂鍛戒护 - } - if (!staProtocol.isLiftArrival()) { - return false;//绔欑偣鎻愬崌鏈哄埌浣嶄俊鍙穎alse锛岀姝笅鍙戝懡浠� - } - - //鏉′欢婊¤冻锛屽崰鐢ㄦ彁鍗囨満 - liftProtocol.setTaskNo(wrkNo); - } - } - - //涓嬪彂鍛戒护 - if (!write(command)) { - News.error("鍥涘悜绌挎杞﹀懡浠や笅鍙戝け璐ワ紝绌挎杞﹀彿={}锛屼换鍔℃暟鎹�={}", shuttleProtocol.getShuttleNo(), JSON.toJSON(command)); - return false; - } else { - News.info("鍥涘悜绌挎杞﹀懡浠や笅鍙戞垚鍔燂紝绌挎杞﹀彿={}锛屼换鍔℃暟鎹�={}", shuttleProtocol.getShuttleNo(), JSON.toJSON(command)); - - //灏嗘爣璁扮疆涓篺alse(闃叉閲嶅彂) - shuttleProtocol.setPakMk(false); - - //淇濆瓨鏁版嵁鍒版暟鎹簱鍋氭祦姘� - BasShuttleOptService shuttleOptService = SpringUtils.getBean(BasShuttleOptService.class); - if (shuttleOptService != null) { - BasShuttleOpt opt = new BasShuttleOpt( - assignCommand.getTaskNo().intValue(), - assignCommand.getShuttleNo().intValue(), - new Date(), - ShuttleTaskModeType.get(assignCommand.getTaskMode()).desc, - assignCommand.getSourceLocNo(), - assignCommand.getLocNo(), - null, - null, - null, - JSON.toJSONString(command) - ); - shuttleOptService.insert(opt); - } - - //鍒ゆ柇鏁版嵁鏄惁鎵ц瀹屾垚 - if (commandStep < size - 1) { - //鏇存柊redis鏁版嵁 - //姝ュ簭澧炲姞 - commandStep++; - redisCommand.setCommandStep(commandStep); - //浠诲姟鏁版嵁淇濆瓨鍒皉edis - redisUtil.set("shuttle_wrk_no_" + redisCommand.getWrkNo(), JSON.toJSONString(redisCommand)); - }else { - //宸叉墽琛屽畬鎴� - - if (redisCommand.getLiftSecurityMk()) { - //鏇鹃攣瀹氳繃鎻愬崌鏈猴紝闇�瑕佽繘琛岃В閿� - if (liftProtocol != null) { - liftProtocol.setSecurityMk(false); - } - } - - String locNo = shuttleProtocol.getLocNo() == null ? shuttleProtocol.getSourceLocNo() : shuttleProtocol.getLocNo(); - if (locNo != null) { - //瑙i櫎閿佸畾鐨勫簱浣嶈矾寰� - NavigateMapData navigateMapData = new NavigateMapData(Utils.getLev(locNo)); - navigateMapData.writeNavigateNodeToRedisMap(redisCommand.getAssignCommand().getNodes(), false); - } - - //鍒犻櫎redis - redisUtil.del("shuttle_wrk_no_" + redisCommand.getWrkNo()); - - if (!assignCommand.getAuto()) { - //鎵嬪姩妯″紡涓嶆姏鍑虹瓑寰呯姸鎬侊紝鐩存帴澶嶄綅 - //璁剧疆鍥涘悜绌挎杞︿负绌洪棽鐘舵�� - shuttleProtocol.setProtocolStatus(ShuttleProtocolStatusType.IDLE); - //浠诲姟鍙锋竻闆� - shuttleProtocol.setTaskNo((short) 0); - //鏍囪澶嶄綅 - shuttleProtocol.setPakMk(true); - News.info("鍥涘悜绌挎杞︽墜鍔ㄤ换鍔℃墽琛屽畬鎴愶紝绌挎杞﹀彿={}锛屼换鍔℃暟鎹�={}", shuttleProtocol.getShuttleNo(), JSON.toJSON(command)); - }else { - if (!assignCommand.getCharge()) { - //瀵逛富绾跨▼鎶涘嚭绛夊緟纭鐘舵�亀aiting - shuttleProtocol.setProtocolStatus(ShuttleProtocolStatusType.WAITING); - }else { - shuttleProtocol.setProtocolStatus(ShuttleProtocolStatusType.CHARGING_WAITING); - } - News.info("鍥涘悜绌挎杞︿换鍔℃墽琛屼笅鍙戝畬鎴愮瓑寰呮墽琛岀粨鏉燂紝绌挎杞﹀彿={}锛屼换鍔℃暟鎹�={}", shuttleProtocol.getShuttleNo(), JSON.toJSON(command)); - } - - } - - } - return true; - } - - /** - * 妫�娴嬫槸鍚︽湁鎻愬崌鏈虹珯鐐癸紝鏈夊垯璋冨害鎻愬崌鏈� - */ - private boolean checkLiftStation(Short wrkNo) { - //璇诲彇redis鏁版嵁 - if (wrkNo == null) { - return false; - } - - //鎷垮埌鎻愬崌鏈虹嚎绋� - LiftThread liftThread = (LiftThread) SlaveConnection.get(SlaveType.Lift, 1); - if (liftThread == null) { - return false; - } - LiftProtocol liftProtocol = liftThread.getLiftProtocol(); - if (liftProtocol == null) { - return false; - } - - Object o = redisUtil.get("shuttle_wrk_no_" + wrkNo); - if (o == null) { - return false; - } - ShuttleRedisCommand redisCommand = JSON.parseObject(o.toString(), ShuttleRedisCommand.class); - //褰撳墠姝ュ簭 - int commandStep = redisCommand.getCommandStep(); - - //妫�娴嬫槸鍚﹀瓨鍦ㄦ彁鍗囨満鍙g殑鎸囦护 - List<ShuttleCommand> commands = redisCommand.getAssignCommand().getCommands(); - if (commands.size() > 0) { - if (commands.get(commandStep).getCommandWord() != 1) { - //涓嶆槸琛岃蛋鍛戒护锛岀洿鎺ユ斁琛� - return true; - } - - if (commands.get(0).getStartCodeNum() == null) { - return false; - } - //鍛戒护璧峰浣嶇疆灏辨槸鎻愬崌鏈轰簩缁寸爜锛屽垯涓嶈繘琛屾牎楠� - if (commands.get(0).getStartCodeNum().intValue() == liftProtocol.getBarcode().intValue()) { - return true; - } - } - - BasDevpService basDevpService = SpringUtils.getBean(BasDevpService.class); - ArrayList<Short> qrCodeValues = new ArrayList<>(); - for (BasDevp basDevp : basDevpService.selectList(null)) { - //灏嗘墍鏈夋彁鍗囨満鍙d簩缁寸爜瀛樺叆list - qrCodeValues.add(Short.parseShort(basDevp.getQrCodeValue())); - } - - //閬嶅巻鎵�鏈夋寚浠わ紝鍒ゆ柇鏄惁鏈夊埌鎻愬崌鏈哄彛鐨勬寚浠ゆ垨浠庢彁鍗囨満鍙e墠寰�鎻愬崌鏈哄唴鐨勬寚浠わ紝骞惰幏鍙栧埌杈捐鎻愬崌鏈哄彛鎵�闇�姝ュ簭 - int step = 0; - Integer siteNo = null;//绔欑偣鍙� - ShuttleCommand command = null; - for (int i = 0; i < commands.size(); i++) { - command = commands.get(i); - for (Short qrCodeValue : qrCodeValues) { - //鐩爣浣嶇疆鏄彁鍗囨満鍙o紝鎴栬捣鐐逛綅缃槸鎻愬崌鏈哄彛涓旂洰鏍囨槸鍘绘彁鍗囨満鍐� - if (command.getDistCodeNum() == null || command.getStartCodeNum() == null) { - continue; - } - - if (qrCodeValue.intValue() == command.getDistCodeNum().intValue() || (qrCodeValue.intValue() == command.getStartCodeNum().intValue() && command.getDistCodeNum().intValue() == liftProtocol.getBarcode().intValue())) { - //瀛樺湪 - step = i + 1; - BasDevp basDevp = basDevpService.queryByQrCode(qrCodeValue.intValue()); - siteNo = basDevp.getDevNo(); - break; - } - } - } - - if (step == 0) { - //鏃犻渶鍚庣画妫�娴嬶紝鐩存帴鏀捐 - return true; - } - - //鍒ゆ柇涓嬩竴姝ユ槸鍚︿负鎻愬崌鏈哄彛鎴栨彁鍗囨満鍐� - if (commandStep < commands.size()) { - ShuttleCommand command1 = commands.get(commandStep); - Short distCodeNum = command1.getDistCodeNum(); - if (distCodeNum != null) { - BasDevp basDevp = basDevpService.queryByQrCode(Integer.valueOf(distCodeNum)); - if (basDevp == null && distCodeNum.intValue() != liftProtocol.getBarcode().intValue()) { - return true;//涓嬩竴姝ヤ笉鏄彁鍗囨満鍙o紝璺宠繃鍚庣画娴佺▼ - } - } - } -// if (commandStep + 1 != step) { -// //涓嬩竴姝ヤ笉鏄彁鍗囨満鍙o紝璺宠繃鍚庣画娴佺▼ -// return true; -// } - - //鑾峰彇鍥涘悜绌挎杞﹀綋鍓嶆ゼ灞� - String shuttleLocNo = shuttleProtocol.getCurrentLocNo();//浜岀淮鐮佸搴斿簱浣嶅彿 - Integer shuttleLocNoLev = shuttleLocNo == null ? 0 : Utils.getLev(shuttleLocNo);//搴撲綅鍙峰搴斿眰楂� - - //鍒ゆ柇绌挎杞﹀拰鎻愬崌鏈烘槸鍚﹀湪鐩爣妤煎眰 - if (shuttleLocNoLev >= 2) { - shuttleLocNoLev++; - } - - //鍒ゆ柇杈撻�佺嚎绔欑偣鏄惁缁欏嚭鎻愬崌鏈哄埌浣嶄俊鍙� - if (siteNo != null) { - SiemensDevpThread siemensDevpThread = (SiemensDevpThread) SlaveConnection.get(SlaveType.Devp, 1); - StaProtocol staProtocol = siemensDevpThread.getStation().get(siteNo); - if (!staProtocol.isLiftArrival()) { - //杈撻�佺嚎鍙嶉鎻愬崌鏈烘病鏈夊埌浣� - executeLift(liftThread, liftProtocol, redisCommand, shuttleLocNoLev);//璋冨害鎻愬崌鏈� - return false; - } - - if (shuttleProtocol.getCurrentCode().intValue() == liftProtocol.getBarcode().intValue()) { - //灏忚溅澶勪簬鎻愬崌鏈哄唴 - return true; - }else { - if (liftProtocol.getPositionArrivalFeedback$() == shuttleLocNoLev) { - liftProtocol.setTaskNo(wrkNo);//缁欐彁鍗囨満鍐欏伐浣滃彿锛岄槻姝㈣鍗犵敤 - return true;//鎻愬崌鏈哄埌浣� - } - executeLift(liftThread, liftProtocol, redisCommand, shuttleLocNoLev);//璋冨害鎻愬崌鏈� - return false;//鎻愬崌鏈烘病鏈夊埌浣� - } - } - - return false; - } - - private boolean executeLift(LiftThread liftThread, LiftProtocol liftProtocol, ShuttleRedisCommand redisCommand, Integer shuttleLocNoLev) {//璋冨害鎻愬崌鏈� - if (liftProtocol.getRunning()) { - //鎻愬崌鏈鸿繍琛屼腑锛岀姝笅鍙� - return false; - } - - if (redisCommand.getLiftSecurityMk()) { - //宸茬粡鎵ц杩囨彁鍗囨満鍛戒护锛岀姝笅鍙� - return false; - } - - //缁欐彁鍗囨満鍒嗛厤浠诲姟 - liftProtocol.setTaskNo(shuttleProtocol.getTaskNo());//璁剧疆浠诲姟鍙� - liftProtocol.setShuttleNo(shuttleProtocol.getShuttleNo());//璁剧疆鍥涘悜绌挎杞﹀彿 - liftProtocol.setProtocolStatus(LiftProtocolStatusType.WORKING);//璁剧疆鎻愬崌鏈虹姸鎬佷负宸ヤ綔涓� - liftProtocol.setSecurityMk(true);//鏍囪缃负true锛岄槻姝㈠叾浠栦换鍔″崰鐢ㄥ綋鍓嶆彁鍗囨満 - redisCommand.setLiftSecurityMk(true);//鏍囪缃负true锛岄槻姝㈠叾浠栦换鍔″崰鐢ㄥ綋鍓嶆彁鍗囨満 - //浠诲姟鏁版嵁淇濆瓨鍒皉edis - redisUtil.set("shuttle_wrk_no_" + redisCommand.getWrkNo(), JSON.toJSONString(redisCommand)); - - //鍛戒护list - ArrayList<LiftCommand> liftCommands = new ArrayList<>(); - LiftCommand liftCommand = liftThread.getLiftUpDownCommand(liftProtocol.getLiftNo(), liftProtocol.getTaskNo(), shuttleLocNoLev); - liftCommands.add(liftCommand);//灏嗗懡浠ゆ坊鍔犺繘list - - LiftAssignCommand liftAssignCommand = new LiftAssignCommand(); - liftAssignCommand.setCommands(liftCommands); - liftAssignCommand.setLiftNo(liftProtocol.getLiftNo()); - liftAssignCommand.setTaskNo(liftProtocol.getTaskNo()); - //涓嬪彂浠诲姟 - MessageQueue.offer(SlaveType.Lift, liftProtocol.getLiftNo().intValue(), new Task(3, liftAssignCommand)); - return true; - } - - /** - * 澶嶄綅骞跺皾璇曚慨澶嶉敊璇� - */ - private boolean resetAndTryFix(Short wrkNo) { - //璇诲彇redis鏁版嵁 - if (wrkNo == null) { - return false; - } - - Object o = redisUtil.get("shuttle_wrk_no_" + wrkNo); - if (o == null) { - return false; - } - - ShuttleRedisCommand redisCommand = JSON.parseObject(o.toString(), ShuttleRedisCommand.class); - List<ShuttleCommand> commands = redisCommand.getAssignCommand().getCommands(); - //褰撳墠姝ュ簭 - int commandStep = redisCommand.getCommandStep(); - //path璺緞鏁扮洰 - int size = commands.size(); - - ArrayList<ShuttleCommand> list = new ArrayList<>(); - - //鍙栧嚭鍛戒护 - ShuttleCommand command = commands.get(commandStep - 1); - - //澶嶄綅鍛戒护 - ShuttleCommand resetCommand = getResetCommand(); - list.add(resetCommand); - - //杞﹁締绌洪棽锛岀瓑寰呭啓鍏ユ壘搴撲綅鍛戒护 - //鎵惧簱浣嶅懡浠� - short direction = 1; - switch (command.getRunDirection()) {//杞崲杩愯鏂瑰悜 - case 1: - direction = 2; - break; - case 2: - direction = 1; - break; - case 3: - direction = 4; - break; - case 4: - direction = 3; - break; - default: - direction = 1; - } - //鎵惧簱浣嶅懡浠� - ShuttleCommand searchCommand = getFindLocCommand(direction, 1200, (short) 1000); - list.add(searchCommand); - - //绉诲姩杞﹁締锛岄渶瑕佸湪鎵ц瀹屽鎵惧畾浣嶇偣鍚庡啀鎵ц - ShuttleCommand moveCommand = new ShuttleCommand(); - moveCommand.setCommandWord((short) 1); - moveCommand.setStartCodeNum(command.getStartCodeNum());//瀛樺叆鐩爣搴撲綅鍙� - list.add(moveCommand); - - redisCommand.setErrorCommands(list); - //浠诲姟鏁版嵁淇濆瓨鍒皉edis - redisUtil.set("shuttle_wrk_no_" + wrkNo, JSON.toJSONString(redisCommand)); - shuttleProtocol.setProtocolStatus(ShuttleProtocolStatusType.FIXING); - return true; - } - - /** - * 鑾峰彇鎵樼洏椤跺崌鍛戒护 - * @param lift 1椤跺崌锛�2涓嬮檷 - */ - public ShuttleCommand getPalletCommand(Short lift) { - ShuttleCommand command = new ShuttleCommand(); - command.setCommandWord((short) 2); - command.setStartCodeNum((short) 0); - command.setMiddleCodeNum((short) 0); - command.setDistCodeNum((short) 0); - command.setStartToDistDistance(0); - command.setMiddleToDistDistance(0); - command.setRunDirection((short) 0); - command.setForceMoveDistance(0); - command.setPalletLift(lift); - command.setRunSpeed((short) 0); - command.setCommandEnd((short) 1); - return command; - } - - /** - * 姝e父绉诲姩鍛戒护,榛樿绉诲姩閫熷害1000 - */ - public ShuttleCommand getMoveCommand(Short startCodeNum, Short distCodeNum, Integer startToDistDistance, Short runDirection, Short middleCodeNum, Integer middleToDistDistance) { - return getMoveCommand(startCodeNum, distCodeNum, startToDistDistance, runDirection, middleCodeNum, middleToDistDistance, 500); - } - - /** - * 姝e父绉诲姩鍛戒护 - */ - public ShuttleCommand getMoveCommand(Short startCodeNum, Short distCodeNum, Integer startToDistDistance, Short runDirection, Short middleCodeNum, Integer middleToDistDistance, Integer runSpeed) { - ShuttleCommand command = new ShuttleCommand(); - command.setCommandWord((short) 1); - command.setStartCodeNum(startCodeNum); - command.setMiddleCodeNum(middleCodeNum); - command.setDistCodeNum(distCodeNum); - command.setStartToDistDistance(startToDistDistance); - command.setMiddleToDistDistance(middleToDistDistance); - command.setRunDirection(runDirection); - command.setForceMoveDistance(0); - command.setIOControl((short) 0); - command.setRunSpeed(runSpeed.shortValue()); - command.setCommandEnd((short) 1); - return command; - } - - /** - * 寮哄埗绉诲姩鍛戒护 - * @param direction 绉诲姩鏂瑰悜 1宸︾Щ锛�2鍙崇Щ锛�3鍓嶇Щ锛�4鍚庣Щ - */ - public ShuttleCommand getForceMoveCommand(Short direction) { - ShuttleCommand command = new ShuttleCommand(); - command.setCommandWord((short) 3); - command.setStartCodeNum((short) 0); - command.setMiddleCodeNum((short) 0); - command.setDistCodeNum((short) 0); - command.setStartToDistDistance(600); - command.setRunDirection(direction); - command.setForceMoveDistance(600); - command.setIOControl((short) 0); - command.setCommandEnd((short) 1); - command.setRunSpeed((short) 1000); - return command; - } - - /** - * 鐘舵�佸浣嶅懡浠� - */ - public ShuttleCommand getResetCommand() { - ShuttleCommand command = new ShuttleCommand(); - command.setCommandWord((short) 6); - command.setStartCodeNum((short) 0); - command.setMiddleCodeNum((short) 0); - command.setDistCodeNum((short) 0); - command.setStartToDistDistance(0); - command.setMiddleToDistDistance(0); - command.setRunDirection((short) 0); - command.setPalletLift((short) 0); - command.setPalletLift((short) 0); - command.setForceMoveDistance(0); - command.setChargeSwitch((short) 0); - command.setIOControl((short) 0); - command.setRunSpeed((short) 0); - command.setCommandEnd((short) 1); - return command; - } - - /** - * 鑾峰彇瀵诲簱浣嶅懡浠� - * @param direction 1:鍚戞鏂瑰悜(宸�)瀵诲簱浣�,2:鍚戣礋鏂瑰悜(鍙�)瀵诲簱浣�,3:鍚戣礋鏂瑰悜(鍚�)瀵诲簱浣�,4:鍚戞鏂瑰悜(鍓�)瀵诲簱浣� - */ - public ShuttleCommand getFindLocCommand(Short direction, Integer startToDistance, Short runSpeed) { - ShuttleCommand command = new ShuttleCommand(); - command.setCommandWord((short) 4); - command.setRunDirection(direction); - command.setStartToDistDistance(startToDistance); - command.setRunSpeed((short) runSpeed); - command.setCommandEnd((short) 1); - return command; - } - - /** - * 鑾峰彇瀵诲簱浣嶅懡浠わ紝榛樿绉诲姩璺濈3000锛岃繍琛岄�熷害1000 - * @param direction 1:鍚戞鏂瑰悜(宸�)瀵诲簱浣�,2:鍚戣礋鏂瑰悜(鍙�)瀵诲簱浣�,3:鍚戣礋鏂瑰悜(鍚�)瀵诲簱浣�,4:鍚戞鏂瑰悜(鍓�)瀵诲簱浣� - */ - public ShuttleCommand getFindLocCommand(Short direction) { - return getFindLocCommand(direction, 3000, (short) 1000); - } - - /** - * 鑾峰彇鍏呯數寮�鍏冲懡浠� - */ - public ShuttleCommand getChargeSwitchCommand() { - ShuttleCommand command = new ShuttleCommand(); - command.setCommandWord((short) 5); - command.setChargeSwitch((short) 1); - command.setCommandEnd((short) 1); - return command; - } - - /** - * charge锛�1=>寮�濮嬪厖鐢碉紝2=>鏂紑鍏呯數 - */ - public ShuttleCommand getChargeSwitchCommand(Short charge) { - ShuttleCommand command = new ShuttleCommand(); - command.setCommandWord((short) 5);//鍏呯數 - command.setShuttleNo(shuttleProtocol.getShuttleNo()); - command.setChargeSwitch(charge);//寮�濮嬪厖鐢� - command.setCommandEnd((short) 1); - return command; - } - - /******************************************************************************************/ - /**************************************** 娴嬭瘯涓撶敤 *****************************************/ - /*****************************************************************************************/ - public static void main(String[] args) throws InterruptedException { - ShuttleSlave slave = new ShuttleSlave(); - slave.setId(1); - slave.setIp("192.168.4.24"); - slave.setPort(502); -// ShuttleThread thread = new ShuttleThread(slave); -// thread.connect(); -// thread.readStatus(); -// -// ShuttleCommand command = new ShuttleCommand(); -// command.setCommandWord((short) 0); -// command.setStartCodeNum((short) 12323); -// command.setMiddleCodeNum((short) 22323); -// command.setDistCodeNum((short) 29999); -// command.setStartToDistDistance(109999); -// command.setMiddleToDistDistance(5000); -// command.setRunDirection((short) 1); -// command.setPalletLift((short) 2); -// command.setForceMoveDistance(3000); -// command.setChargeSwitch((short) 2); -// command.setIOControl((short) 0); -// command.setRunSpeed((short) 0); -// command.setRadarTmp((short) 0); -// command.setCommandEnd((short) 1); -// thread.write(command); + ShuttleCommand getUpdateLocationCommand(Integer taskNo, String locNo);//鑾峰彇鏇存柊鍧愭爣鍛戒护 - } } -- Gitblit v1.9.1