From 7b0ede04d77803011d09d28364820b9fe5d60359 Mon Sep 17 00:00:00 2001
From: Junjie <fallin.jie@qq.com>
Date: 星期二, 04 四月 2023 14:59:17 +0800
Subject: [PATCH] 提升机配置文件
---
src/main/java/com/zy/core/thread/ShuttleThread.java | 270 +++++++++++++++++++++++++++++++++++++----------------
1 files changed, 188 insertions(+), 82 deletions(-)
diff --git a/src/main/java/com/zy/core/thread/ShuttleThread.java b/src/main/java/com/zy/core/thread/ShuttleThread.java
index e91d81a..7f4a6fa 100644
--- a/src/main/java/com/zy/core/thread/ShuttleThread.java
+++ b/src/main/java/com/zy/core/thread/ShuttleThread.java
@@ -5,12 +5,13 @@
import HslCommunication.Core.Types.OperateResultExOne;
import HslCommunication.ModBus.ModbusTcpNet;
import com.alibaba.fastjson.JSON;
-import com.alibaba.fastjson.JSONObject;
import com.core.common.DateUtils;
import com.core.common.SpringUtils;
import com.core.exception.CoolException;
+import com.zy.asrs.entity.BasShuttle;
import com.zy.asrs.entity.BasShuttleOpt;
import com.zy.asrs.service.BasShuttleOptService;
+import com.zy.asrs.service.BasShuttleService;
import com.zy.common.model.NavigateNode;
import com.zy.common.utils.CommonUtils;
import com.zy.common.utils.NavigatePositionConvert;
@@ -23,6 +24,7 @@
import com.zy.core.enums.*;
import com.zy.core.model.ShuttleSlave;
import com.zy.core.model.Task;
+import com.zy.core.model.command.LiftCommand;
import com.zy.core.model.command.ShuttleAssignCommand;
import com.zy.core.model.command.ShuttleCommand;
import com.zy.core.model.protocol.ShuttleProtocol;
@@ -161,18 +163,74 @@
///璇诲彇鍥涘悜绌挎杞︾姸鎬�-end
- 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()));
-
//灏忚溅澶勪簬蹇欑鐘舵�侊紝灏嗘爣璁扮疆涓簍rue
if (shuttleProtocol.getBusyStatusType() == ShuttleStatusType.BUSY) {
shuttleProtocol.setPakMk(true);
}
- //鍥涘悜绌挎杞︾┖闂层�佹湁浠诲姟涓旀爣璁颁负true锛岄渶瑕佹墽琛屼换鍔$殑涓嬩竴鏉℃寚浠�
- if (shuttleProtocol.getBusyStatusType() == ShuttleStatusType.IDLE && shuttleProtocol.getTaskNo() != 0 && shuttleProtocol.getPakMk()) {
+ //鍥涘悜绌挎杞︾┖闂层�佹湁浠诲姟銆佹爣璁颁负true銆佸瓨鍦ㄤ换鍔℃寚浠わ紝闇�瑕佹墽琛屼换鍔$殑涓嬩竴鏉℃寚浠�
+ if (shuttleProtocol.getBusyStatusType() == ShuttleStatusType.IDLE
+ && shuttleProtocol.getTaskNo() != 0
+ && shuttleProtocol.getPakMk()
+ && shuttleProtocol.getAssignCommand() != null) {
//鎵ц涓嬩竴姝ユ寚浠�
executeWork(shuttleProtocol.getAssignCommand());
+ }
+
+ //灏嗗洓鍚戠┛姊溅鐘舵�佷繚瀛樿嚦鏁版嵁搴�
+ BasShuttleService shuttleService = SpringUtils.getBean(BasShuttleService.class);
+ BasShuttle basShuttle = shuttleService.selectById(shuttleProtocol.getShuttleNo());
+ 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()));
}
}else {
@@ -292,17 +350,94 @@
//灏嗘map瀛樺叆redis涓�
HashMap<String, Object> map = new HashMap<>();
- //璁$畻璺緞
- List<NavigateNode> calc = NavigateUtils.calc(assignCommand.getSourceLocNo(), assignCommand.getDistLocNo(), assignCommand.getTaskMode().intValue());
- if (calc != null) {
- //鑾峰彇鍒嗘璺緞
- ArrayList<ArrayList<NavigateNode>> data = NavigateUtils.getSectionPath(calc);
- //璺緞鏁版嵁
- map.put("path", data);
- //璺緞娆℃暟
- map.put("pathSize", data.size());
+// if (assignCommand.getTaskMode() == ShuttleTaskModeType.PAK_IN.id.shortValue()
+// || assignCommand.getTaskMode() == ShuttleTaskModeType.PAK_OUT.id.shortValue()) {
+// //鍏ュ簱鎴栧嚭搴撴ā寮忥紝璁$畻璺緞
+// //璁$畻璺緞
+// List<NavigateNode> calc = NavigateUtils.calc(assignCommand.getSourceLocNo(), assignCommand.getLocNo(), assignCommand.getTaskMode().intValue());
+// if (calc != null) {
+// //鑾峰彇鍒嗘璺緞
+// ArrayList<ArrayList<NavigateNode>> data = NavigateUtils.getSectionPath(calc);
+// //璺緞鏁版嵁
+// map.put("path", data);
+// //璺緞娆℃暟
+// map.put("pathSize", data.size());
+// }else {
+// if (assignCommand.getTaskMode() == ShuttleTaskModeType.PAK_IN.id.shortValue() || assignCommand.getTaskMode() == ShuttleTaskModeType.PAK_OUT.id.shortValue()) {
+// //灞炰簬鍏ュ簱鍑哄簱锛屽繀椤昏璁$畻璺緞锛屽垯鎶涘嚭寮傚父
+// throw new Exception("鏈兘鎵惧埌杩愯璺緞");
+// }
+// }
+// }
+
+ if (!assignCommand.getAuto()) {
+ List<ShuttleCommand> commands = new ArrayList<>();
+ ShuttleCommand command = new ShuttleCommand();
+ switch (assignCommand.getTaskMode()) {
+ case 1://鍏ュ簱
+ case 2://鍑哄簱
+ //灏忚溅绉诲姩鍒版彁鍗囨満鍙o紝璁$畻璺緞
+ //璁$畻灏忚溅璧风偣鍒颁腑鐐规墍闇�鍛戒护
+ List<NavigateNode> calc = NavigateUtils.calc(assignCommand.getSourceLocNo(), assignCommand.getLocNo(), ShuttleTaskModeType.PAK_IN.id);
+ if (calc != null) {
+ //鑾峰彇鍒嗘璺緞
+ ArrayList<ArrayList<NavigateNode>> data = NavigateUtils.getSectionPath(calc);
+ //灏嗘瘡涓�娈佃矾寰勫垎鎴恈ommand鎸囦护
+ for (ArrayList<NavigateNode> nodes : data) {
+ //寮�濮嬭矾寰�
+ NavigateNode startPath = nodes.get(0);
+ //鐩爣璺緞
+ NavigateNode endPath = nodes.get(nodes.size() - 1);
+ Integer allDistance = NavigateUtils.getCurrentPathAllDistance(nodes);//璁$畻褰撳墠璺緞琛岃蛋鎬昏窛绂�
+
+ ShuttleCommand command1 = new ShuttleCommand();
+ command1.setCommandWord((short) 1);
+ command1.setStartCodeNum(NavigatePositionConvert.xyToPosition(startPath.getX(), startPath.getY()));
+ command1.setMiddleCodeNum((short) 0);
+ command1.setDistCodeNum(NavigatePositionConvert.xyToPosition(endPath.getX(), endPath.getY()));
+ command1.setStartToDistDistance(allDistance);
+ command1.setMiddleToDistDistance(1000);
+ command1.setRunDirection(ShuttleRunDirection.get(startPath.getDirection()).id);
+ command1.setPalletLift((short) 1);
+ command1.setForceMoveDistance(1000);
+ command1.setChargeSwitch((short) 2);
+ command1.setIOControl((short) 0);
+ command1.setRunSpeed((short) 1000);
+ command1.setRadarTmp((short) 0);
+ command1.setCommandEnd((short) 1);
+ commands.add(command1);
+ }
+ }
+ break;
+ case 3://鎵樼洏椤跺崌
+ case 4://鎵樼洏涓嬮檷
+ command.setCommandWord((short) 2);
+ command.setPalletLift(assignCommand.getTaskMode() == 3 ? (short)1 : (short)2);
+ command.setCommandEnd((short) 1);
+ commands.add(command);
+ break;
+ case 5://寮哄埗宸︾Щ
+ case 6://寮哄埗鍙崇Щ
+ case 7://寮哄埗涓婄Щ
+ case 8://寮哄埗涓嬬Щ
+ command.setCommandWord((short) 3);
+ command.setForceMoveDistance(1000);
+ command.setRunDirection((short) (assignCommand.getTaskMode() - 4));
+ command.setCommandEnd((short) 1);
+ commands.add(command);
+ break;
+ case 9://鐘舵�佸浣�
+ command.setCommandWord((short) 0);
+ command.setCommandEnd((short) 1);
+ commands.add(command);
+ break;
+ default:
+ }
+ assignCommand.setCommands(commands);
}
+ //鍥涘悜绌挎杞﹀彿
+ map.put("shuttle_no", assignCommand.getShuttleNo());
//宸ヤ綔鍙�
map.put("wrk_no", assignCommand.getTaskNo());
//鍛戒护鎵ц姝ュ簭
@@ -311,6 +446,7 @@
map.put("assignCommand", assignCommand);
shuttleProtocol.setTaskNo(assignCommand.getTaskNo());
shuttleProtocol.setAssignCommand(assignCommand);
+ shuttleProtocol.setProtocolStatus(ShuttleProtocolStatusType.WORKING);
//浠诲姟鏁版嵁淇濆瓨鍒皉edis
redisUtil.set("wrk_no_" + assignCommand.getTaskNo(), JSON.toJSONString(map));
//鎵ц涓嬪彂浠诲姟
@@ -318,81 +454,35 @@
}
//鎵ц涓嬪彂鐨勬寚浠�
- private void executeWork(ShuttleAssignCommand assignCommand) {
+ private boolean executeWork(ShuttleAssignCommand assignCommand) {
//璇诲彇redis鏁版嵁
+ if (assignCommand == null) {
+ return false;
+ }
+
+ //灏嗘爣璁扮疆涓篺alse(闃叉閲嶅彂)
+ shuttleProtocol.setPakMk(false);
+
Object o = redisUtil.get("wrk_no_" + assignCommand.getTaskNo());
+ if (o == null) {
+ return false;
+ }
HashMap map = JSON.parseObject(o.toString(), HashMap.class);
+ List<ShuttleCommand> commands = assignCommand.getCommands();
//褰撳墠姝ュ簭
int commandStep = Integer.parseInt(map.get("commandStep").toString());
//path璺緞鏁扮洰
- int size = 0;
- //涓嬪彂鍛戒护
- ShuttleCommand command = new ShuttleCommand();
- switch (assignCommand.getTaskMode()) {
- case 1://鍏ュ簱
- case 2://鍑哄簱
- //褰撳墠璺緞鏁版嵁
- Object data = map.get("path");
- ArrayList pathList = JSON.parseObject(data.toString(), ArrayList.class);
- //鍙栫涓�鏉¤矾寰�
- Object o1 = pathList.get(commandStep);
- ArrayList path = JSON.parseObject(o1.toString(), ArrayList.class);
+ int size = commands.size();
- size = Integer.parseInt(map.get("pathSize").toString());
- //寮�濮嬭矾寰�
- JSONObject startPath = JSON.parseObject(path.get(0).toString());
- //鐩爣璺緞
- JSONObject endPath = JSON.parseObject(path.get(path.size() - 1).toString());
+ //鍙栧嚭鍛戒护
+ ShuttleCommand command = commands.get(commandStep);
- command.setCommandWord((short) 1);
- command.setStartCodeNum(NavigatePositionConvert.xyToPosition(startPath.getIntValue("x"), startPath.getIntValue("y")));
- command.setMiddleCodeNum((short) 0);
- command.setDistCodeNum(NavigatePositionConvert.xyToPosition(endPath.getIntValue("x"), endPath.getIntValue("y")));
- command.setStartToDistDistance(1000);
- command.setMiddleToDistDistance(1000);
- command.setRunDirection(ShuttleRunDirection.get(startPath.get("direction").toString()).id);
- command.setPalletLift((short) 1);
- command.setForceMoveDistance(1000);
- command.setChargeSwitch((short) 2);
- command.setIOControl((short) 0);
- command.setRunSpeed((short) 1000);
- command.setRadarTmp((short) 0);
-
- break;
- case 3://鎵樼洏椤跺崌
- case 4://鎵樼洏涓嬮檷
- command.setCommandWord((short) 2);
- command.setPalletLift(assignCommand.getTaskMode() == 3 ? (short)1 : (short)2);
- command.setCommandEnd((short) 1);
- break;
- case 5://寮哄埗宸︾Щ
- case 6://寮哄埗鍙崇Щ
- case 7://寮哄埗涓婄Щ
- case 8://寮哄埗涓嬬Щ
- command.setCommandWord((short) 3);
- command.setForceMoveDistance(1000);
- command.setRunDirection((short) (assignCommand.getTaskMode() - 4));
- command.setCommandEnd((short) 1);
- break;
- case 9://鐘舵�佸浣�
- command.setCommandWord((short) 0);
- //璁剧疆鍥涘悜绌挎杞︿负绌洪棽鐘舵��
- shuttleProtocol.setProtocolStatus(ShuttleProtocolStatusType.IDLE);
- //浠诲姟鍙锋竻闆�
- shuttleProtocol.setTaskNo((short) 0);
- break;
- default:
- }
-
- command.setCommandEnd((short) 1);
//涓嬪彂鍛戒护
if (!write(command)) {
News.error("鍥涘悜绌挎杞﹀懡浠や笅鍙戝け璐ワ紝绌挎杞﹀彿={}锛屼换鍔℃暟鎹�={}", shuttleProtocol.getShuttleNo(), JSON.toJSON(command));
+ return false;
} else {
News.info("鍥涘悜绌挎杞﹀懡浠や笅鍙戞垚鍔燂紝绌挎杞﹀彿={}锛屼换鍔℃暟鎹�={}", shuttleProtocol.getShuttleNo(), JSON.toJSON(command));
-
- //灏嗘爣璁扮疆涓篺alse(闃叉閲嶅彂)
- shuttleProtocol.setPakMk(false);
//鍒ゆ柇鏁版嵁鏄惁鎵ц瀹屾垚
if (commandStep < size - 1) {
@@ -413,24 +503,40 @@
new Date(),
ShuttleTaskModeType.get(assignCommand.getTaskMode()).desc,
assignCommand.getSourceLocNo(),
- assignCommand.getDistLocNo(),
+ assignCommand.getLocNo(),
null,
null,
null,
- JSON.toJSONString(command)
+ JSON.toJSONString(assignCommand)
);
shuttleOptService.insert(opt);
}
//鍒犻櫎redis
redisUtil.del("wrk_no_" + map.get("wrk_no").toString());
- //瀵逛富绾跨▼鎶涘嚭绛夊緟纭鐘舵�亀aiting
- shuttleProtocol.setProtocolStatus(ShuttleProtocolStatusType.WAITING);
+ if (!assignCommand.getAuto()) {
+ //鎵嬪姩妯″紡涓嶆姏鍑虹瓑寰呯姸鎬侊紝鐩存帴澶嶄綅
+ if (assignCommand.getTaskMode() == 9) {
+ //璁剧疆鍥涘悜绌挎杞︿负绌洪棽鐘舵��
+ shuttleProtocol.setProtocolStatus(ShuttleProtocolStatusType.IDLE);
+ //浠诲姟鍙锋竻闆�
+ shuttleProtocol.setTaskNo((short) 0);
+ //鏍囪澶嶄綅
+ shuttleProtocol.setPakMk(true);
+ //浠诲姟鎸囦护娓呴浂
+ shuttleProtocol.setAssignCommand(null);
+ }
+ News.info("鍥涘悜绌挎杞︽墜鍔ㄤ换鍔℃墽琛屽畬鎴愶紝绌挎杞﹀彿={}锛屼换鍔℃暟鎹�={}", shuttleProtocol.getShuttleNo(), JSON.toJSON(command));
+ }else {
+ //瀵逛富绾跨▼鎶涘嚭绛夊緟纭鐘舵�亀aiting
+ shuttleProtocol.setProtocolStatus(ShuttleProtocolStatusType.WAITING);
+ News.info("鍥涘悜绌挎杞︿换鍔℃墽琛屽畬鎴愮瓑寰呯‘璁や腑锛岀┛姊溅鍙�={}锛屼换鍔℃暟鎹�={}", shuttleProtocol.getShuttleNo(), JSON.toJSON(command));
+ }
- News.info("鍥涘悜绌挎杞︿换鍔℃墽琛屽畬鎴愮瓑寰呯‘璁や腑锛岀┛姊溅鍙�={}锛屼换鍔℃暟鎹�={}", shuttleProtocol.getShuttleNo(), JSON.toJSON(command));
}
}
+ return true;
}
/******************************************************************************************/
--
Gitblit v1.9.1