From 00d9f3f5cf3b046cb42098c9bc13f2313a435f53 Mon Sep 17 00:00:00 2001 From: Junjie <fallin.jie@qq.com> Date: 星期二, 27 六月 2023 10:32:50 +0800 Subject: [PATCH] 提升机搬运前判断目标站是否可入 --- src/main/java/com/zy/core/thread/LiftThread.java | 198 ++++++++++++++++++++++++++---------------------- 1 files changed, 107 insertions(+), 91 deletions(-) diff --git a/src/main/java/com/zy/core/thread/LiftThread.java b/src/main/java/com/zy/core/thread/LiftThread.java index d5d2986..2504792 100644 --- a/src/main/java/com/zy/core/thread/LiftThread.java +++ b/src/main/java/com/zy/core/thread/LiftThread.java @@ -6,6 +6,7 @@ import HslCommunication.ModBus.ModbusTcpNet; import com.alibaba.fastjson.JSON; import com.core.common.DateUtils; +import com.core.common.RadixTools; import com.core.common.SpringUtils; import com.core.exception.CoolException; import com.zy.asrs.entity.BasLift; @@ -14,15 +15,18 @@ import com.zy.asrs.service.BasLiftService; import com.zy.common.utils.CommonUtils; import com.zy.common.utils.RedisUtil; +import com.zy.core.DevpThread; 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.LiftSlave; 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.StaProtocol; import lombok.Data; import lombok.extern.slf4j.Slf4j; @@ -124,35 +128,37 @@ //浣嶇疆鍒拌揪鍙嶉 liftProtocol.setPositionArrivalFeedback(modbusTcpNet.getByteTransform().TransInt16(content,2)); - byte by = modbusTcpNet.getByteTransform().TransByte(content, 5); - int[] datas = CommonUtils.byteToBits(by); - //鍑嗗灏辩华 - liftProtocol.setReady(CommonUtils.intToBoolean(datas[0])); - //杩愯涓� - liftProtocol.setRunning(CommonUtils.intToBoolean(datas[1])); - //鑱旀満/鍗曟満 - liftProtocol.setMode(CommonUtils.intToBoolean(datas[2])); - //杈撻�佺嚎鍓嶇鍏夌數鏈夎揣 - liftProtocol.setLineFrontHasStock(CommonUtils.intToBoolean(datas[3])); - //杈撻�佺嚎姝h浆鍙嶉 - liftProtocol.setForwardRotationFeedback(CommonUtils.intToBoolean(datas[4])); - //杈撻�佺嚎鍙嶈浆鍙嶉 - liftProtocol.setReverseFeedback(CommonUtils.intToBoolean(datas[5])); - //杈撻�佺嚎鐢垫満杩囪浇 - liftProtocol.setMotorOverload(CommonUtils.intToBoolean(datas[6])); - //杈撻�佺嚎鏈鍏夌數鏈夎揣 - liftProtocol.setLineEndHasStock(CommonUtils.intToBoolean(datas[7])); - //杩涜緭閫佺嚎鍗℃墭鐩樻姤璀� - liftProtocol.setInConveyLineCardTrayAlarm(CommonUtils.intToBoolean(datas[8])); - //鍑鸿緭閫佺嚎鍗℃墭鐩樻姤璀� - liftProtocol.setOutConveyLineCardTrayAlarm(CommonUtils.intToBoolean(datas[9])); - //骞冲彴浣嶇疆鍋忓樊鎶ヨ - liftProtocol.setPlatPositionDeviationAlarm(CommonUtils.intToBoolean(datas[10])); - //骞冲彴鎵煩鍋忓樊鎶ヨ - liftProtocol.setPlatTorqueDeviationAlarm(CommonUtils.intToBoolean(datas[11])); - //骞冲彴鍥涘悜杞︽娴� - liftProtocol.setPlatShuttleCheck(CommonUtils.intToBoolean(datas[12])); + byte b1 = modbusTcpNet.getByteTransform().TransByte(content, 5); + byte b2 = modbusTcpNet.getByteTransform().TransByte(content, 4); + int[] datas1 = CommonUtils.byteToBits(b1); + int[] datas2 = CommonUtils.byteToBits(b2); + //鍑嗗灏辩华 + liftProtocol.setReady(CommonUtils.intToBoolean(datas1[0])); + //杩愯涓� + liftProtocol.setRunning(CommonUtils.intToBoolean(datas1[1])); + //鑱旀満/鍗曟満 + liftProtocol.setMode(CommonUtils.intToBoolean(datas1[2])); + //杈撻�佺嚎鍓嶇鍏夌數鏈夎揣 + liftProtocol.setLineFrontHasStock(CommonUtils.intToBoolean(datas1[3])); + //杈撻�佺嚎姝h浆鍙嶉 + liftProtocol.setForwardRotationFeedback(CommonUtils.intToBoolean(datas1[4])); + //杈撻�佺嚎鍙嶈浆鍙嶉 + liftProtocol.setReverseFeedback(CommonUtils.intToBoolean(datas1[5])); + //杈撻�佺嚎鐢垫満杩囪浇 + liftProtocol.setMotorOverload(CommonUtils.intToBoolean(datas1[6])); + //杈撻�佺嚎鏈鍏夌數鏈夎揣 + liftProtocol.setLineEndHasStock(CommonUtils.intToBoolean(datas1[7])); + //杩涜緭閫佺嚎鍗℃墭鐩樻姤璀� + liftProtocol.setInConveyLineCardTrayAlarm(CommonUtils.intToBoolean(datas2[0])); + //鍑鸿緭閫佺嚎鍗℃墭鐩樻姤璀� + liftProtocol.setOutConveyLineCardTrayAlarm(CommonUtils.intToBoolean(datas2[1])); + //骞冲彴浣嶇疆鍋忓樊鎶ヨ + liftProtocol.setPlatPositionDeviationAlarm(CommonUtils.intToBoolean(datas2[2])); + //骞冲彴鎵煩鍋忓樊鎶ヨ + liftProtocol.setPlatTorqueDeviationAlarm(CommonUtils.intToBoolean(datas2[3])); + //骞冲彴鍥涘悜杞︽娴� + liftProtocol.setPlatShuttleCheck(CommonUtils.intToBoolean(datas2[4])); //鏈氨缁姸鎬� liftProtocol.setNotReady(modbusTcpNet.getByteTransform().TransInt16(content,6)); @@ -169,15 +175,13 @@ ///璇诲彇鎻愬崌鏈虹姸鎬�-end - //灏忚溅澶勪簬杩愯鐘舵�侊紝灏嗘爣璁扮疆涓簍rue + //鎻愬崌鏈哄浜庤繍琛岀姸鎬侊紝灏嗘爣璁扮疆涓簍rue if (liftProtocol.getRunning()) { liftProtocol.setPakMk(true); } - //鎻愬崌鏈哄浜庨攣瀹氥�佹湭杩愯銆佸氨缁�佹爣璁皌rue銆佹湁浠诲姟鍙� - if (liftProtocol.getLiftLock() - && !liftProtocol.getRunning() - && liftProtocol.getReady() + //鎻愬崌鏈哄浜庢湭杩愯銆佸氨缁�佹爣璁皌rue銆佹湁浠诲姟鍙� + if (!liftProtocol.getRunning() && liftProtocol.getPakMk() && liftProtocol.getTaskNo() != 0) { //杩樻湁鏈畬鎴愮殑鍛戒护 @@ -273,6 +277,20 @@ array[29] = command.getLiftLockShortValue(); } + if (array[2] == 0) { + // 寮�濮嬩换鍔� + short[] tmp = new short[2]; + tmp[0] = array[0]; + tmp[1] = array[1]; + array = tmp; + } + + try { + Thread.sleep(1000);//鍛戒护涓嬪彂鍓嶄紤鐪�1s + } catch (InterruptedException e) { + throw new RuntimeException(e); + } + OperateResult result = modbusTcpNet.Write("41088", array);; if (result != null && result.IsSuccess) { News.info("鎻愬崌鏈哄懡浠や笅鍙慬id:{}] >>>>> {}", slave.getId(), JSON.toJSON(command)); @@ -345,9 +363,6 @@ return false; } - //灏嗘爣璁扮疆涓篺alse(闃叉閲嶅彂) - liftProtocol.setPakMk(false); - Object o = redisUtil.get("lift_wrk_no_" + wrkNo); if (o == null) { return false; @@ -362,12 +377,51 @@ //鍙栧嚭鍛戒护 LiftCommand command = commands.get(commandStep); + if (command.getOperaStaNo() != null && command.getDevpId() != null) { + //绔欑偣鍜岃緭閫佺嚎ID涓嶄负null锛岄渶瑕佷笅鍙戠珯鐐规寚浠よ皟搴︽寚瀹氱珯鐐硅繘琛岄摼鏉¤浆鍔� + DevpThread devpThread = (DevpThread) SlaveConnection.get(SlaveType.Devp, command.getDevpId()); + StaProtocol staProtocol = devpThread.getStation().get(command.getOperaStaNo().intValue()); + if (!staProtocol.isLiftArrival()) {//閾炬潯杞姩鏉′欢锛岄渶瑕佹湁鎻愬崌鏈哄埌浣嶄俊鍙� + liftProtocol.setPakMk(true); + return false; + } + staProtocol.setWorkNo(wrkNo);//璁剧疆浠诲姟鍙� + if (command.getStaNo() != null) { + staProtocol.setStaNo(command.getStaNo());//璁剧疆鐩爣绔� + } + + if (command.getRotationDire() != null) { + staProtocol.setRotationDire(command.getRotationDire());//绔欑偣閾炬潯杞姩淇″彿 + } + Integer devpId = command.getDevpId(); + boolean result1 = MessageQueue.offer(SlaveType.Devp, devpId, new Task(3, staProtocol));//涓嬪彂鍛戒护浣胯緭閫佺嚎閾炬潯杩愯浆 + } + //涓嬪彂鍛戒护 if (!write(command)) { News.error("鎻愬崌鏈哄懡浠や笅鍙戝け璐ワ紝鎻愬崌鏈哄彿={}锛屼换鍔℃暟鎹�={}", command.getLiftNo(), JSON.toJSON(command)); return false; }else { News.info("鎻愬崌鏈哄懡浠や笅鍙戞垚鍔燂紝鎻愬崌鏈哄彿={}锛屼换鍔℃暟鎹�={}", command.getLiftNo(), JSON.toJSON(command)); + liftProtocol.setWrkTime(new Date());//鏇存柊宸ヤ綔鏃堕棿 + + //灏嗘爣璁扮疆涓篺alse(闃叉閲嶅彂) + liftProtocol.setPakMk(false); + + //淇濆瓨鏁版嵁鍒版暟鎹簱鍋氭祦姘� + BasLiftOptService liftOptService = SpringUtils.getBean(BasLiftOptService.class); + if (liftOptService != null) { + BasLiftOpt opt = new BasLiftOpt( + redisCommand.getWrkNo().intValue(), + redisCommand.getLiftNo().intValue(), + new Date(), + null, + null, + null, + JSON.toJSONString(command) + ); + liftOptService.insert(opt); + } //鍒ゆ柇鏁版嵁鏄惁鎵ц瀹屾垚 if (commandStep < size - 1) { @@ -379,37 +433,12 @@ redisUtil.set("lift_wrk_no_" + redisCommand.getWrkNo(), JSON.toJSONString(redisCommand)); }else { //宸叉墽琛屽畬鎴� - //淇濆瓨鏁版嵁鍒版暟鎹簱鍋氭祦姘� - BasLiftOptService liftOptService = SpringUtils.getBean(BasLiftOptService.class); - if (liftOptService != null) { - BasLiftOpt opt = new BasLiftOpt( - redisCommand.getWrkNo().intValue(), - redisCommand.getLiftNo().intValue(), - new Date(), - null, - null, - null, - JSON.toJSONString(assignCommand) - ); - liftOptService.insert(opt); - } //鍒犻櫎redis redisUtil.del("lift_wrk_no_" + redisCommand.getWrkNo()); - if (assignCommand.getAuto()) { - //瀵逛富绾跨▼鎶涘嚭绛夊緟纭鐘舵�亀aiting - liftProtocol.setProtocolStatus(LiftProtocolStatusType.WAITING); - News.info("鎻愬崌鏈轰换鍔℃墽琛屽畬鎴愮瓑寰呯‘璁や腑锛屾彁鍗囨満鍙�={}锛屼换鍔℃暟鎹�={}", command.getLiftNo(), JSON.toJSON(command)); - }else { - //鎵嬪姩妯″紡涓嶆姏鍑虹瓑寰呯姸鎬� - liftProtocol.setTaskNo((short) 0); - liftProtocol.setShuttleNo((short) 0); - liftProtocol.setProtocolStatus(LiftProtocolStatusType.IDLE); - liftProtocol.setPakMk(true); - liftProtocol.setSecurityMk(false); - News.info("鎻愬崌鏈烘墜鍔ㄤ换鍔℃墽琛屽畬鎴愶紝鎻愬崌鏈哄彿={}锛屼换鍔℃暟鎹�={}", command.getLiftNo(), JSON.toJSON(command)); - } - + //瀵逛富绾跨▼鎶涘嚭绛夊緟纭鐘舵�亀aiting + liftProtocol.setProtocolStatus(LiftProtocolStatusType.WAITING); + News.info("鎻愬崌鏈轰换鍔℃墽琛屼笅鍙戝畬鎴愮瓑寰呮墽琛岀粨鏉燂紝鎻愬崌鏈哄彿={}锛屼换鍔℃暟鎹�={}", command.getLiftNo(), JSON.toJSON(command)); } } @@ -443,44 +472,31 @@ public LiftCommand getLiftUpDownCommand(Integer lev) { LiftCommand command = new LiftCommand(); command.setRun((short) 1);//鍗囬檷 - Short position = 1; - switch (lev) { - case 1: - position = 1; - break; - case 2: - position = 2; - break; - case 3: - position = 4; - break; - case 4: - position = 8; - break; - case 5: - position = 16; - break; - default: - position = 1; - } + Short position = LiftLevType.getRealLev(lev);//鑾峰彇鎻愬崌鏈哄疄闄呮ゼ灞傛暟鍊� command.setDistPosition(position); - command.setSpeed((short) 200); - command.setHeight2((short) 180); - command.setHeight3((short) 1645); - command.setHeight4((short) (2 * 1645)); - command.setHeight5((short) (3 * 1645)); +// command.setSpeed((short) 200); +// command.setHeight2((short) 180); +// command.setHeight3((short) 1645); +// command.setHeight4((short) (2 * 1645)); +// command.setHeight5((short) (3 * 1645)); return command; } /** * 鑾峰彇鎻愬崌鏈轰笂鍗囦笅闄嶅懡浠� */ - public LiftCommand getLiftUpDownCommand(Short liftNo, Short taskNo, Short lev) { + public LiftCommand getLiftUpDownCommand(Short liftNo, Short taskNo, Integer lev) { LiftCommand command = new LiftCommand(); + Short position = LiftLevType.getRealLev(lev);//鑾峰彇鎻愬崌鏈哄疄闄呮ゼ灞傛暟鍊� command.setRun((short) 1);//鍗囬檷 command.setLiftNo(liftNo);//鎻愬崌鏈哄彿 command.setTaskNo(taskNo);//浠诲姟鍙� - command.setDistPosition(lev);//鐩爣妤煎眰1灞� + command.setDistPosition(position);//鐩爣妤煎眰 +// command.setSpeed((short) 200); +// command.setHeight2((short) 180); +// command.setHeight3((short) 1645); +// command.setHeight4((short) 3290); +// command.setHeight5((short) 4945); return command; } -- Gitblit v1.9.1