From 8139b1c6b761391ef4bb2cfa674f2ee392cc926c Mon Sep 17 00:00:00 2001
From: Junjie <xjj@123>
Date: 星期二, 23 四月 2024 08:51:47 +0800
Subject: [PATCH] #
---
zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/core/action/ShuttleAction.java | 236 ++++++++++++++++++++++++++++++++++++++++++++++++++++------
1 files changed, 209 insertions(+), 27 deletions(-)
diff --git a/zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/core/action/ShuttleAction.java b/zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/core/action/ShuttleAction.java
index 4a15a5d..977fba7 100644
--- a/zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/core/action/ShuttleAction.java
+++ b/zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/core/action/ShuttleAction.java
@@ -1,16 +1,22 @@
package com.zy.asrs.wcs.core.action;
import com.alibaba.fastjson.JSON;
-import com.alibaba.fastjson.JSONObject;
-import com.zy.asrs.wcs.core.entity.BasShuttle;
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.zy.asrs.wcs.core.entity.Loc;
+import com.zy.asrs.wcs.core.entity.Task;
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.ShuttleRedisCommand;
import com.zy.asrs.wcs.core.model.enums.ShuttleCommandModeType;
+import com.zy.asrs.wcs.core.model.enums.ShuttleTaskModeType;
import com.zy.asrs.wcs.core.service.BasShuttleService;
+import com.zy.asrs.wcs.core.service.LocService;
import com.zy.asrs.wcs.core.utils.NavigateMapUtils;
import com.zy.asrs.wcs.core.utils.RedisUtil;
+import com.zy.asrs.wcs.core.utils.ShuttleDispatcher;
import com.zy.asrs.wcs.core.utils.Utils;
import com.zy.asrs.wcs.rcs.News;
import com.zy.asrs.wcs.rcs.cache.SlaveConnection;
@@ -23,6 +29,7 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
+import java.util.ArrayList;
import java.util.List;
@Component
@@ -34,6 +41,12 @@
private NavigateMapUtils navigateMapUtils;
@Autowired
private BasShuttleService basShuttleService;
+ @Autowired
+ private LocService locService;
+ @Autowired
+ private ShuttleDispatcher shuttleDispatcher;
+ @Autowired
+ private ObjectMapper objectMapper;
public synchronized boolean assignWork(Device device, ShuttleAssignCommand assignCommand) {
ShuttleThread shuttleThread = (ShuttleThread) SlaveConnection.get(SlaveType.Shuttle, device.getId().intValue());
@@ -49,17 +62,22 @@
ShuttleRedisCommand redisCommand = new ShuttleRedisCommand();
redisCommand.setShuttleNo(assignCommand.getShuttleNo());//鍥涘悜绌挎杞﹀彿
- redisCommand.setWrkNo(assignCommand.getTaskNo());//宸ヤ綔鍙�
+ redisCommand.setTaskNo(assignCommand.getTaskNo());//宸ヤ綔鍙�
redisCommand.setCommandStep(0);//鍛戒护鎵ц姝ュ簭
redisCommand.setAssignCommand(assignCommand);//鍛戒护
//浠诲姟鏁版嵁淇濆瓨鍒皉edis
if (redisUtil.set(DeviceRedisConstant.SHUTTLE_WORK_FLAG + assignCommand.getTaskNo(), JSON.toJSONString(redisCommand))) {
- //涓嬪彂琛岄┒璺緞
- boolean result = shuttleThread.movePath(assignCommand.getNodes(), assignCommand.getTaskNo().intValue());
- if (!result) {
- return false;
+ if (assignCommand.getTaskMode() == ShuttleTaskModeType.PAK_IN.id
+ || assignCommand.getTaskMode() == ShuttleTaskModeType.PAK_OUT.id
+ || assignCommand.getTaskMode() == ShuttleTaskModeType.MOVE_LOC_NO.id
+ || assignCommand.getTaskMode() == ShuttleTaskModeType.SHUTTLE_MOVE_LOC_NO.id) {
+ //涓嬪彂琛岄┒璺緞
+ boolean result = shuttleThread.movePath(assignCommand.getNodes(), assignCommand.getDeviceTaskNo());
+ if (!result) {
+ return false;
+ }
}
- shuttleProtocol.setTaskNo(assignCommand.getTaskNo().intValue());
+ shuttleProtocol.setSyncTaskNo(assignCommand.getTaskNo());
return true;
}
return false;
@@ -70,7 +88,14 @@
if (obj == null) {
return false;
}
- ShuttleRedisCommand redisCommand = JSON.parseObject(obj.toString(), ShuttleRedisCommand.class);
+
+ ShuttleRedisCommand redisCommand = null;
+ try {
+ redisCommand = objectMapper.readValue(String.valueOf(obj), ShuttleRedisCommand.class);
+ } catch (JsonProcessingException e) {
+ throw new RuntimeException(e);
+ }
+
if (redisCommand == null) {
return false;
}
@@ -85,10 +110,18 @@
return false;
}
- //鍥涘悜绌挎杞︾┖闂层�佹湁浠诲姟銆佹爣璁颁负true銆佸瓨鍦ㄤ换鍔℃寚浠わ紝闇�瑕佹墽琛屼换鍔$殑涓嬩竴鏉℃寚浠�
- if (!shuttleProtocol.getIdle()
- || shuttleProtocol.getTaskNo() == 0
- || !shuttleProtocol.getPakMk()) {
+ //鍒ゆ柇璁惧鏄惁绌洪棽
+ if (!shuttleThread.isDeviceIdle()) {
+ return false;
+ }
+// if (!shuttleThread.isIdle(() -> {
+// return shuttleProtocol.getTaskNo().equals(taskNo);
+// })) {
+// return false;
+// }
+
+ //鍒ゆ柇宸ヤ綔鍙锋槸鍚︾浉鍚�
+ if (!shuttleProtocol.getTaskNo().equals(taskNo)) {
return false;
}
@@ -125,10 +158,11 @@
// 鎵樼洏椤跺崌
//鍒ゆ柇鏄惁椤跺崌鍒颁綅
if (shuttleProtocol.getHasLift()) {
- //鍒ゆ柇鏄惁鏈夌墿
- if (shuttleProtocol.getHasPallet()) {
- command.setComplete(true);
- }
+ command.setComplete(true);
+// //鍒ゆ柇鏄惁鏈夌墿
+// if (shuttleProtocol.getHasPallet()) {
+// command.setComplete(true);
+// }
}
} else if (command.getMode() == ShuttleCommandModeType.PALLET_DOWN.id) {
// 鎵樼洏涓嬮檷鍛戒护
@@ -136,8 +170,8 @@
if (!shuttleProtocol.getHasLift()) {
command.setComplete(true);
}
- } else if (command.getMode() == ShuttleCommandModeType.CHARGE.id) {
- // 鍏呯數寮�鍏�
+ } else if (command.getMode() == ShuttleCommandModeType.CHARGE_OPEN.id) {
+ // 鍏呯數寮�
//鍒ゆ柇灏忚溅鍏呯數鐘舵��
if (shuttleProtocol.getHasCharge()) {
command.setComplete(true);
@@ -147,7 +181,7 @@
}
// 鏇存柊redis鏁版嵁
- redisUtil.set(DeviceRedisConstant.SHUTTLE_WORK_FLAG + redisCommand.getWrkNo(), JSON.toJSONString(redisCommand));
+ redisUtil.set(DeviceRedisConstant.SHUTTLE_WORK_FLAG + redisCommand.getTaskNo(), JSON.toJSONString(redisCommand));
if (!command.getComplete()) {
return false;
@@ -162,25 +196,25 @@
if (assignCommand.getAuto()) {
if (!assignCommand.getCharge()) {
//瀵逛富绾跨▼鎶涘嚭绛夊緟纭鐘舵�亀aiting
- shuttleProtocol.setProtocolStatus(ShuttleProtocolStatusType.WAITING);
+ shuttleThread.setProtocolStatus(ShuttleProtocolStatusType.WAITING);
}else {
- shuttleProtocol.setProtocolStatus(ShuttleProtocolStatusType.CHARGING_WAITING);
+ shuttleThread.setProtocolStatus(ShuttleProtocolStatusType.CHARGING_WAITING);
}
News.info("鍥涘悜绌挎杞︿换鍔℃墽琛屼笅鍙戝畬鎴愮瓑寰呮墽琛岀粨鏉燂紝绌挎杞﹀彿={}锛屼换鍔℃暟鎹�={}", shuttleProtocol.getShuttleNo(), JSON.toJSON(command));
// 鎵嬪姩浠诲姟
} else {
//鎵嬪姩妯″紡涓嶆姏鍑虹瓑寰呯姸鎬侊紝鐩存帴澶嶄綅绌洪棽鐘舵��
- shuttleProtocol.setProtocolStatus(ShuttleProtocolStatusType.IDLE);
+ shuttleThread.setProtocolStatus(ShuttleProtocolStatusType.IDLE);
//浠诲姟鍙锋竻闆�
- shuttleProtocol.setTaskNo(0);
+ shuttleThread.setSyncTaskNo(0);
//鏍囪澶嶄綅
- shuttleProtocol.setPakMk(true);
+ shuttleThread.setPakMk(true);
News.info("鍥涘悜绌挎杞︽墜鍔ㄤ换鍔℃墽琛屽畬鎴愶紝绌挎杞﹀彿={}锛屼换鍔℃暟鎹�={}", shuttleProtocol.getShuttleNo(), JSON.toJSON(command));
}
//鍒犻櫎redis
- redisUtil.del(DeviceRedisConstant.SHUTTLE_WORK_FLAG + redisCommand.getWrkNo());
+ redisUtil.del(DeviceRedisConstant.SHUTTLE_WORK_FLAG + redisCommand.getTaskNo());
return false;//绂佹鍐嶄笅鍙戝懡浠�
}
}
@@ -194,7 +228,154 @@
return false;
}
+ shuttleThread.setProtocolStatus(ShuttleProtocolStatusType.WORKING);
+ commandStep++;
+ //鏇存柊redis鏁版嵁
+ redisCommand.setCommandStep(commandStep);
+ //浠诲姟鏁版嵁淇濆瓨鍒皉edis
+ redisUtil.set(DeviceRedisConstant.SHUTTLE_WORK_FLAG + redisCommand.getTaskNo(), JSON.toJSONString(redisCommand));
return true;
+ }
+
+ //璺戝簱绋嬪簭
+ public synchronized void moveLoc(Device device) {
+ ShuttleThread shuttleThread = (ShuttleThread) SlaveConnection.get(SlaveType.Shuttle, device.getId().intValue());
+ if (shuttleThread == null) {
+ return;
+ }
+ ShuttleProtocol shuttleProtocol = shuttleThread.getStatus();
+ if (shuttleProtocol == null) {
+ return;
+ }
+
+ //灏忚溅寮�鍚窇搴撴ā寮�
+ if (!shuttleProtocol.getMoveLoc()) {
+ return;
+ }
+
+ //灏忚溅绌洪棽
+ if (!shuttleThread.isIdle()) {
+ return;
+ }
+
+ int lev = Utils.getLev(shuttleProtocol.getCurrentLocNo());//灏忚溅褰撳墠妤煎眰
+ if (shuttleProtocol.getYCurrent() > shuttleProtocol.getYTarget()) {
+ //璺戝簱缁撴潫
+ shuttleProtocol.setMoveLoc(false);
+ shuttleProtocol.setMoveType(0);
+ shuttleProtocol.setXStart(0);
+ shuttleProtocol.setXTarget(0);
+ shuttleProtocol.setXCurrent(0);
+ shuttleProtocol.setYStart(0);
+ shuttleProtocol.setYTarget(0);
+ shuttleProtocol.setYCurrent(0);
+ return;
+ }
+
+ if (shuttleProtocol.getMoveType() == 0) {//璺戣建閬�
+ ArrayList<String> locs = new ArrayList<>();
+ for (int i = shuttleProtocol.getXCurrent(); i <= shuttleProtocol.getXTarget(); i++) {
+ String locNo = Utils.getLocNo(i, shuttleProtocol.getYCurrent(), lev);
+ locs.add(locNo);
+ }
+
+ List<Loc> locList = locService.list(new LambdaQueryWrapper<Loc>()
+ .in(Loc::getLocNo, locs));
+ if (locList.isEmpty()) {
+ //绌哄簱浣�
+ shuttleProtocol.setYCurrent(shuttleProtocol.getYCurrent() + 1);
+ return;
+ }
+
+ Loc start = locList.get(0);
+ Loc target = locList.get(locList.size() - 1);
+ //鍒ゆ柇灏忚溅鏄惁鍦ㄨ捣鐐逛綅缃�
+ if (!shuttleProtocol.getCurrentLocNo().equals(start.getLocNo())) {//涓嶅湪璧风偣浣嶇疆锛岃皟搴﹀幓璧风偣浣嶇疆
+ shuttleDispatcher.generateMoveTask(device, start.getLocNo());
+ }else {
+ //鍦ㄨ捣鐐逛綅缃紝璋冨害鍘荤洰鏍囦綅缃�
+ if (shuttleProtocol.getCurrentLocNo().equals(target.getLocNo())) {
+ shuttleProtocol.setYCurrent(shuttleProtocol.getYCurrent() + 1);//灏忚溅鍜岀洰鏍囦綅缃竴鑷达紝璺宠繃
+ }else {
+ shuttleDispatcher.generateMoveTask(device, start.getLocNo());
+ shuttleProtocol.setYCurrent(shuttleProtocol.getYCurrent() + 1);
+ }
+ }
+ } else if (shuttleProtocol.getMoveType() == 1) {//璺戝簱浣�
+ Integer xCurrent = shuttleProtocol.getXCurrent();
+ if (xCurrent > shuttleProtocol.getXTarget()) {//褰揦鍊煎ぇ浜嶺鐩爣鍊硷紝杩涜褰掗浂涓擸鏂瑰悜+1
+ shuttleProtocol.setXCurrent(shuttleProtocol.getXStart());
+ shuttleProtocol.setYCurrent(shuttleProtocol.getYCurrent() + 1);
+ return;
+ }
+
+ Integer yCurrent = shuttleProtocol.getYCurrent();
+ String locNo = Utils.getLocNo(xCurrent, yCurrent, lev);
+ Loc target = locService.getOne(new LambdaQueryWrapper<Loc>()
+ .eq(Loc::getLocNo, locNo)
+ .eq(Loc::getHostId, device.getHostId()));
+ if (target == null) {
+ shuttleProtocol.setXCurrent(shuttleProtocol.getXCurrent() + 1);
+ return;
+ }
+
+// if (!target.getLocSts().equals("O")) {
+// shuttleProtocol.setXCurrent(shuttleProtocol.getXCurrent() + 1);
+// return;
+// }
+
+ //璋冨害鍘荤洰鏍囦綅缃�
+ if (shuttleProtocol.getCurrentLocNo().equals(target.getLocNo())) {
+ shuttleProtocol.setXCurrent(shuttleProtocol.getXCurrent() + 1);//灏忚溅鍜岀洰鏍囦綅缃竴鑷达紝璺宠繃
+ } else {
+ shuttleDispatcher.generateMoveTask(device, target.getLocNo());
+ shuttleProtocol.setXCurrent(shuttleProtocol.getXCurrent() + 1);
+ }
+ } else if (shuttleProtocol.getMoveType() == 2) {//姣嶈建閬撳惊鐜窇
+ Integer xCurrent = shuttleProtocol.getXCurrent();
+ Integer yCurrent = shuttleProtocol.getYCurrent();
+
+ String locNo = Utils.getLocNo(xCurrent, yCurrent, lev);
+ //璋冨害鍘荤洰鏍囦綅缃�
+ if (shuttleProtocol.getCurrentLocNo().equals(locNo)) {
+ if (yCurrent.equals(shuttleProtocol.getYStart())) {
+ shuttleProtocol.setYCurrent(shuttleProtocol.getYTarget());//灏忚溅鍜岀洰鏍囦綅缃竴鑷达紝鍒囨崲搴撲綅
+ } else {
+ shuttleProtocol.setYCurrent(shuttleProtocol.getYStart());//灏忚溅鍜岀洰鏍囦綅缃竴鑷达紝鍒囨崲搴撲綅
+ }
+ } else {
+ Task result = shuttleDispatcher.generateMoveTask(device, locNo);
+ if (result != null) {//璋冨害鎴愬姛
+ if (yCurrent.equals(shuttleProtocol.getYStart())) {
+ shuttleProtocol.setYCurrent(shuttleProtocol.getYTarget());//鍒囨崲搴撲綅
+ } else {
+ shuttleProtocol.setYCurrent(shuttleProtocol.getYStart());//鍒囨崲搴撲綅
+ }
+ }
+ }
+ } else if (shuttleProtocol.getMoveType() == 3) {//瀛愯建閬撳惊鐜窇
+ Integer xCurrent = shuttleProtocol.getXCurrent();
+ Integer yCurrent = shuttleProtocol.getYCurrent();
+
+ String locNo = Utils.getLocNo(xCurrent, yCurrent, lev);
+ //璋冨害鍘荤洰鏍囦綅缃�
+ if (shuttleProtocol.getCurrentLocNo().equals(locNo)) {
+ if (xCurrent.equals(shuttleProtocol.getXStart())) {
+ shuttleProtocol.setXCurrent(shuttleProtocol.getXTarget());//灏忚溅鍜岀洰鏍囦綅缃竴鑷达紝鍒囨崲搴撲綅
+ } else {
+ shuttleProtocol.setXCurrent(shuttleProtocol.getXStart());//灏忚溅鍜岀洰鏍囦綅缃竴鑷达紝鍒囨崲搴撲綅
+ }
+ } else {
+ Task result = shuttleDispatcher.generateMoveTask(device, locNo);
+ if (result != null) {//璋冨害鎴愬姛
+ if (xCurrent.equals(shuttleProtocol.getXStart())) {
+ shuttleProtocol.setXCurrent(shuttleProtocol.getXTarget());//鍒囨崲搴撲綅
+ } else {
+ shuttleProtocol.setXCurrent(shuttleProtocol.getXStart());//鍒囨崲搴撲綅
+ }
+ }
+ }
+ }
}
private synchronized boolean write(ShuttleCommand command, Device device) {
@@ -211,7 +392,8 @@
} else if (command.getMode() == ShuttleCommandModeType.PALLET_LIFT.id
|| command.getMode() == ShuttleCommandModeType.PALLET_DOWN.id) {//椤跺崌
result = shuttleThread.lift(command);
- } else if (command.getMode() == ShuttleCommandModeType.CHARGE.id) {//鍏呯數
+ } else if (command.getMode() == ShuttleCommandModeType.CHARGE_OPEN.id
+ || command.getMode() == ShuttleCommandModeType.CHARGE_CLOSE.id) {//鍏呯數
result = shuttleThread.charge(command);
} else if (command.getMode() == ShuttleCommandModeType.RESET.id) {//澶嶄綅
result = shuttleThread.reset(command);
--
Gitblit v1.9.1