From d9cea3d7757a8d580bb0574d419ba6dd9c2478e7 Mon Sep 17 00:00:00 2001
From: Junjie <540245094@qq.com>
Date: 星期五, 13 十二月 2024 15:11:50 +0800
Subject: [PATCH] #search shuttle
---
zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/core/action/ShuttleAction.java | 486 +++++++++++++++++++++++++++++++++++++++++++----------
1 files changed, 389 insertions(+), 97 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 791709f..22114d2 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,37 +1,42 @@
package com.zy.asrs.wcs.core.action;
import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.serializer.SerializerFeature;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
+import com.zy.asrs.wcs.common.ExecuteSupport;
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.LocStsType;
+import com.zy.asrs.wcs.core.model.enums.MotionCtgType;
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.core.utils.*;
import com.zy.asrs.wcs.rcs.News;
import com.zy.asrs.wcs.rcs.cache.SlaveConnection;
import com.zy.asrs.wcs.rcs.constant.DeviceRedisConstant;
+import com.zy.asrs.wcs.rcs.entity.BasShuttleOpt;
import com.zy.asrs.wcs.rcs.entity.Device;
+import com.zy.asrs.wcs.rcs.model.CommandResponse;
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.ShuttleProtocol;
+import com.zy.asrs.wcs.rcs.service.BasShuttleOptService;
import com.zy.asrs.wcs.rcs.thread.ShuttleThread;
-import org.aspectj.apache.bcel.generic.RET;
+import com.zy.asrs.wcs.system.entity.Dict;
+import com.zy.asrs.wcs.system.service.DictService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
-import java.util.ArrayList;
-import java.util.List;
+import java.util.*;
@Component
public class ShuttleAction {
@@ -48,6 +53,12 @@
private ShuttleDispatcher shuttleDispatcher;
@Autowired
private ObjectMapper objectMapper;
+ @Autowired
+ private DictService dictService;
+ @Autowired
+ private ConveyorDispatcher conveyorDispatcher;
+ @Autowired
+ private BasShuttleOptService basShuttleOptService;
public synchronized boolean assignWork(Device device, ShuttleAssignCommand assignCommand) {
ShuttleThread shuttleThread = (ShuttleThread) SlaveConnection.get(SlaveType.Shuttle, device.getId().intValue());
@@ -63,17 +74,18 @@
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))) {
- 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) {
+ if (redisUtil.set(DeviceRedisConstant.SHUTTLE_WORK_FLAG + assignCommand.getTaskNo(), JSON.toJSONString(redisCommand, SerializerFeature.DisableCircularReferenceDetect))) {
+ if (assignCommand.getTaskMode() == ShuttleTaskModeType.SHUTTLE_MOVE.id
+ || assignCommand.getTaskMode() == ShuttleTaskModeType.TRANSPORT.id
+ || assignCommand.getTaskMode() == ShuttleTaskModeType.MOVE_PALLET_LIFT.id
+ || assignCommand.getTaskMode() == ShuttleTaskModeType.MOVE_PALLET_DOWN.id) {
//涓嬪彂琛岄┒璺緞
- boolean result = shuttleThread.movePath(assignCommand.getNodes(), assignCommand.getTaskNo());
+ CommandResponse response = shuttleThread.movePath(assignCommand.getNodes(), assignCommand.getDeviceTaskNo());
+ Boolean result = response.getResult();
if (!result) {
return false;
}
@@ -111,16 +123,6 @@
return false;
}
- //鍒ゆ柇璁惧鏄惁绌洪棽
- if (!shuttleThread.isDeviceIdle()) {
- return false;
- }
-// if (!shuttleThread.isIdle(() -> {
-// return shuttleProtocol.getTaskNo().equals(taskNo);
-// })) {
-// return false;
-// }
-
//鍒ゆ柇宸ヤ綔鍙锋槸鍚︾浉鍚�
if (!shuttleProtocol.getTaskNo().equals(taskNo)) {
return false;
@@ -134,15 +136,46 @@
ShuttleAssignCommand assignCommand = redisCommand.getAssignCommand();
int commandStep = redisCommand.getCommandStep();
+ Integer mode = -1;
+ if(commandStep < commands.size()) {
+ //鍙栧嚭鍛戒护
+ ShuttleCommand currentCommand = commands.get(commandStep);
+ mode = currentCommand.getMode();
+ }
+
+ //鍒ゆ柇璁惧鏄惁绌洪棽
+ Integer finalMode = mode;
+ if (!shuttleThread.isDeviceIdle(new ExecuteSupport() {
+ @Override
+ public Boolean judgement() {
+ if (ShuttleCommandModeType.CHARGE_CLOSE.id.equals(finalMode)) {//鍏抽棴鍏呯數motion
+ return false;//涓嶉渶瑕佸垽鏂姸鎬�
+ }
+ return true;//闇�瑕佸垽鏂姸鎬�
+ }
+ })) {
+ return false;
+ }
+
// 瀹岀粨涓婁竴鏉″懡浠�
+ boolean updateCommand = false;
if (commandStep != 0) {
ShuttleCommand command = commands.get(commandStep - 1);
if (command.getMode() == ShuttleCommandModeType.MOVE.id) {
// 姝e父绉诲姩
if (command.getTargetLocNo().equals(shuttleProtocol.getCurrentLocNo())) {
command.setComplete(true);
+ updateCommand = true;
//瑙i攣閿佸畾璺緞锛屼笂涓�鏉¤矾寰�
- List<NavigateNode> nodes = JSON.parseArray(JSON.toJSONString(command.getNodes()), NavigateNode.class);//杩涜娣卞害copy
+ List<NavigateNode> nodes = null;
+ try {
+ String nodesStr = objectMapper.writeValueAsString(command.getNodes());
+ nodes = objectMapper.readValue(nodesStr, new TypeReference<List<NavigateNode>>() {
+ });
+ } catch (JsonProcessingException e) {
+ throw new RuntimeException(e);
+ }
+
if (nodes != null) {
NavigateNode targetNode = assignCommand.getNodes().get(assignCommand.getNodes().size() - 1);//鏈�缁堣妭鐐�
NavigateNode node = nodes.get(nodes.size() - 1);
@@ -160,6 +193,7 @@
//鍒ゆ柇鏄惁椤跺崌鍒颁綅
if (shuttleProtocol.getHasLift()) {
command.setComplete(true);
+ updateCommand = true;
// //鍒ゆ柇鏄惁鏈夌墿
// if (shuttleProtocol.getHasPallet()) {
// command.setComplete(true);
@@ -170,19 +204,24 @@
// 鍒ゆ柇鏄惁涓嬮檷鍒颁綅
if (!shuttleProtocol.getHasLift()) {
command.setComplete(true);
+ updateCommand = true;
}
} else if (command.getMode() == ShuttleCommandModeType.CHARGE_OPEN.id) {
// 鍏呯數寮�
//鍒ゆ柇灏忚溅鍏呯數鐘舵��
if (shuttleProtocol.getHasCharge()) {
command.setComplete(true);
+ updateCommand = true;
}
}else {
command.setComplete(true);//鍏朵粬鍛戒护榛樿璁や负瀹屾垚
+ updateCommand = true;
}
- // 鏇存柊redis鏁版嵁
- redisUtil.set(DeviceRedisConstant.SHUTTLE_WORK_FLAG + redisCommand.getWrkNo(), JSON.toJSONString(redisCommand));
+ if(updateCommand) {
+ // 鏇存柊redis鏁版嵁
+ redisUtil.set(DeviceRedisConstant.SHUTTLE_WORK_FLAG + redisCommand.getTaskNo(), JSON.toJSONString(redisCommand, SerializerFeature.DisableCircularReferenceDetect));
+ }
if (!command.getComplete()) {
return false;
@@ -215,7 +254,7 @@
}
//鍒犻櫎redis
- redisUtil.del(DeviceRedisConstant.SHUTTLE_WORK_FLAG + redisCommand.getWrkNo());
+ redisUtil.del(DeviceRedisConstant.SHUTTLE_WORK_FLAG + redisCommand.getTaskNo());
return false;//绂佹鍐嶄笅鍙戝懡浠�
}
}
@@ -224,7 +263,28 @@
ShuttleCommand command = commands.get(commandStep);
// 涓嬪彂鍛戒护
- if (!write(command, device)) {
+ CommandResponse response = write(command, device);
+
+ //淇濆瓨鍛戒护鏃ュ織
+ BasShuttleOpt basShuttleOpt = new BasShuttleOpt();
+ basShuttleOpt.setTaskNo(redisCommand.getTaskNo());
+ basShuttleOpt.setShuttleNo(Integer.parseInt(device.getDeviceNo()));
+
+ basShuttleOpt.setMode(ShuttleTaskModeType.get(assignCommand.getTaskMode()).desc);
+ basShuttleOpt.setSourceLocNo(assignCommand.getSourceLocNo());
+ basShuttleOpt.setDistLocNo(assignCommand.getLocNo());
+ basShuttleOpt.setCommand(JSON.toJSONString(command));
+ basShuttleOpt.setSystemStatus(JSON.toJSONString(shuttleProtocol));
+ basShuttleOpt.setDeviceId(device.getId());
+ basShuttleOpt.setDeviceWrk(String.valueOf(command.getTaskNo()));
+ basShuttleOpt.setResponse(response.getMessage());//鑾峰彇鍝嶅簲
+ basShuttleOpt.setSendTime(new Date());//鎸囦护涓嬪彂鏃堕棿
+ basShuttleOpt.setSend(response.getResult() ? 1 : 0);
+ basShuttleOpt.setHostId(device.getHostId());
+ //淇濆瓨鍛戒护娴佹按
+ basShuttleOptService.save(basShuttleOpt);
+
+ if (!response.getResult()) {
News.error("鍥涘悜绌挎杞﹀懡浠や笅鍙戝け璐ワ紝绌挎杞﹀彿={}锛屼换鍔℃暟鎹�={}", shuttleProtocol.getShuttleNo(), JSON.toJSON(command));
return false;
}
@@ -234,7 +294,7 @@
//鏇存柊redis鏁版嵁
redisCommand.setCommandStep(commandStep);
//浠诲姟鏁版嵁淇濆瓨鍒皉edis
- redisUtil.set(DeviceRedisConstant.SHUTTLE_WORK_FLAG + redisCommand.getWrkNo(), JSON.toJSONString(redisCommand));
+ redisUtil.set(DeviceRedisConstant.SHUTTLE_WORK_FLAG + redisCommand.getTaskNo(), JSON.toJSONString(redisCommand));
return true;
}
@@ -244,8 +304,7 @@
if (shuttleThread == null) {
return;
}
-
- ShuttleProtocol shuttleProtocol = shuttleThread.getStatus();
+ ShuttleProtocol shuttleProtocol = shuttleThread.getStatus(false);
if (shuttleProtocol == null) {
return;
}
@@ -261,77 +320,245 @@
}
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);
+ //鏍规嵁鍦板浘鏂瑰悜鍐冲畾璺憍鎴杫
+ Dict dict = dictService.getOne(new LambdaQueryWrapper<Dict>()
+ .eq(Dict::getFlag, "direction_map")
+ .eq(Dict::getStatus, 1));
+ if (dict == null) {
+ //璺戝簱缁撴潫
+ 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;
}
+ String direction = dict.getValue();
- 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());
+ if (direction.equals("y")) {//璺憍杞存柟鍚戯紝璺戝畬x杞村啀鍒囨崲y杞�
+ 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>()
+ .eq(Loc::getLocSts, LocStsType.O.val())
+ .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 {
+ //鍦ㄨ捣鐐逛綅缃紝璋冨害鍘荤洰鏍囦綅缃�
+ Task task = shuttleDispatcher.generateMoveTask(device, target.getLocNo());
+ if (task != null) {
+ shuttleProtocol.setYCurrent(shuttleProtocol.getYCurrent() + 1);//鍒囨崲y杞�
+ }
+
+ if(shuttleProtocol.getYCurrent() > shuttleProtocol.getYTarget()) {
+ //y杞翠篃璺戝畬浜嗭紝缁撴潫璺戝簱
+ 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;
+ }
+ }
+ }else {//璺憏杞存柟鍚戯紝璺戝畬y杞村啀鍒囨崲x杞�
+ ArrayList<String> locs = new ArrayList<>();
+ for (int i = shuttleProtocol.getYCurrent(); i <= shuttleProtocol.getYTarget(); i++) {
+ String locNo = Utils.getLocNo(shuttleProtocol.getXCurrent(), i, lev);
+ locs.add(locNo);
+ }
+
+ List<Loc> locList = locService.list(new LambdaQueryWrapper<Loc>()
+ .eq(Loc::getLocSts, LocStsType.O.val())
+ .in(Loc::getLocNo, locs));
+ if (locList.isEmpty()) {
+ //绌哄簱浣�
+ shuttleProtocol.setXCurrent(shuttleProtocol.getXCurrent() + 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 {
+ //鍦ㄨ捣鐐逛綅缃紝璋冨害鍘荤洰鏍囦綅缃�
+ Task task = shuttleDispatcher.generateMoveTask(device, target.getLocNo());
+ if (task != null) {
+ shuttleProtocol.setXCurrent(shuttleProtocol.getXCurrent() + 1);//鍒囨崲x杞�
+ }
+
+ if(shuttleProtocol.getXCurrent() > shuttleProtocol.getXTarget()) {
+ //y杞翠篃璺戝畬浜嗭紝缁撴潫璺戝簱
+ 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;
+ }
}
}
+
} else if (shuttleProtocol.getMoveType() == 1) {//璺戝簱浣�
- Integer xCurrent = shuttleProtocol.getXCurrent();
- if (xCurrent > shuttleProtocol.getXTarget()) {//褰揦鍊煎ぇ浜嶺鐩爣鍊硷紝杩涜褰掗浂涓擸鏂瑰悜+1
- shuttleProtocol.setXCurrent(shuttleProtocol.getXStart());
- shuttleProtocol.setYCurrent(shuttleProtocol.getYCurrent() + 1);
+ //鏍规嵁鍦板浘鏂瑰悜鍐冲畾璺憍鎴杫
+ Dict dict = dictService.getOne(new LambdaQueryWrapper<Dict>()
+ .eq(Dict::getFlag, "direction_map")
+ .eq(Dict::getStatus, 1));
+ if (dict == null) {
+ //璺戝簱缁撴潫
+ 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;
}
+ String direction = dict.getValue();
- 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 (direction.equals("y")) {//璺憍杞存柟鍚戯紝璺戝畬x杞村啀鍒囨崲y杞�
+ Integer xCurrent = shuttleProtocol.getXCurrent();
-// if (!target.getLocSts().equals("O")) {
-// shuttleProtocol.setXCurrent(shuttleProtocol.getXCurrent() + 1);
-// return;
-// }
+ //鑾峰彇寰呰窇搴撲綅鍙�
+ String locNo = Utils.getLocNo(xCurrent, shuttleProtocol.getYCurrent(), lev);
+ Loc target = locService.getOne(new LambdaQueryWrapper<Loc>()
+ .eq(Loc::getLocNo, locNo)
+ .eq(Loc::getLocSts, LocStsType.O.val())
+ .eq(Loc::getHostId, device.getHostId()));
+ if (target == null || shuttleProtocol.getCurrentLocNo().equals(locNo)) {//搴撲綅涓嶅瓨鍦ㄦ垨灏忚溅宸插湪褰撳墠浣嶇疆
+ shuttleProtocol.setXCurrent(xCurrent + 1);
+ if (shuttleProtocol.getXCurrent() > shuttleProtocol.getXTarget()) {
+ //x杞磋窇瀹岋紝鍒囨崲y杞�
+ shuttleProtocol.setXCurrent(shuttleProtocol.getXStart());
+ shuttleProtocol.setYCurrent(shuttleProtocol.getYCurrent() + 1);
- //璋冨害鍘荤洰鏍囦綅缃�
- if (shuttleProtocol.getCurrentLocNo().equals(target.getLocNo())) {
- shuttleProtocol.setXCurrent(shuttleProtocol.getXCurrent() + 1);//灏忚溅鍜岀洰鏍囦綅缃竴鑷达紝璺宠繃
- } else {
- shuttleDispatcher.generateMoveTask(device, target.getLocNo());
- shuttleProtocol.setXCurrent(shuttleProtocol.getXCurrent() + 1);
+ if(shuttleProtocol.getYCurrent() > shuttleProtocol.getYTarget()) {
+ //y杞翠篃璺戝畬浜嗭紝缁撴潫璺戝簱
+ 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;
+ }
+ }
+ return;
+ }
+
+ //璋冨害鍘诲簱浣�
+ Task task = shuttleDispatcher.generateMoveTask(device, locNo);
+ if (task == null) {
+ return;//璋冨害澶辫触
+ }
+
+ shuttleProtocol.setXCurrent(xCurrent + 1);
+ if (shuttleProtocol.getXCurrent() > shuttleProtocol.getXTarget()) {
+ //x杞磋窇瀹岋紝鍒囨崲y杞�
+ shuttleProtocol.setXCurrent(shuttleProtocol.getXStart());
+ shuttleProtocol.setYCurrent(shuttleProtocol.getYCurrent() + 1);
+
+ if(shuttleProtocol.getYCurrent() > shuttleProtocol.getYTarget()) {
+ //y杞翠篃璺戝畬浜嗭紝缁撴潫璺戝簱
+ 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;
+ }
+ }
+
+ }else {//璺憏杞存柟鍚戯紝璺戝畬y杞村啀鍒囨崲x杞�
+ Integer yCurrent = shuttleProtocol.getYCurrent();
+
+ //鑾峰彇寰呰窇搴撲綅鍙�
+ String locNo = Utils.getLocNo(shuttleProtocol.getXCurrent(), yCurrent, lev);
+ Loc target = locService.getOne(new LambdaQueryWrapper<Loc>()
+ .eq(Loc::getLocNo, locNo)
+ .eq(Loc::getLocSts, LocStsType.O.val())
+ .eq(Loc::getHostId, device.getHostId()));
+ if (target == null || shuttleProtocol.getCurrentLocNo().equals(locNo)) {//搴撲綅涓嶅瓨鍦ㄦ垨灏忚溅宸插湪褰撳墠浣嶇疆
+ shuttleProtocol.setYCurrent(yCurrent + 1);
+ if (shuttleProtocol.getYCurrent() > shuttleProtocol.getYTarget()) {
+ //y杞磋窇瀹岋紝鍒囨崲x杞�
+ shuttleProtocol.setYCurrent(shuttleProtocol.getYStart());
+ shuttleProtocol.setXCurrent(shuttleProtocol.getXCurrent() + 1);
+
+ if(shuttleProtocol.getXCurrent() > shuttleProtocol.getXTarget()) {
+ //x杞翠篃璺戝畬浜嗭紝缁撴潫璺戝簱
+ 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;
+ }
+ }
+ return;
+ }
+
+ //璋冨害鍘诲簱浣�
+ Task task = shuttleDispatcher.generateMoveTask(device, locNo);
+ if (task == null) {
+ return;//璋冨害澶辫触
+ }
+
+ shuttleProtocol.setYCurrent(yCurrent + 1);
+ if (shuttleProtocol.getYCurrent() > shuttleProtocol.getYTarget()) {
+ //y杞磋窇瀹岋紝鍒囨崲x杞�
+ shuttleProtocol.setYCurrent(shuttleProtocol.getYStart());
+ shuttleProtocol.setXCurrent(shuttleProtocol.getXCurrent() + 1);
+
+ if(shuttleProtocol.getXCurrent() > shuttleProtocol.getXTarget()) {
+ //x杞翠篃璺戝畬浜嗭紝缁撴潫璺戝簱
+ 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;
+ }
+ }
+
}
} else if (shuttleProtocol.getMoveType() == 2) {//姣嶈建閬撳惊鐜窇
Integer xCurrent = shuttleProtocol.getXCurrent();
@@ -377,30 +604,95 @@
}
}
}
+ } else if (shuttleProtocol.getMoveType() == 4) {//鍙栨斁璐�
+ Integer xCurrent = shuttleProtocol.getXCurrent();
+ if (xCurrent > shuttleProtocol.getXTarget()) {//褰揦鍊煎ぇ浜嶺鐩爣鍊�
+ shuttleProtocol.setXCurrent(shuttleProtocol.getXStart());
+ shuttleProtocol.setYCurrent(shuttleProtocol.getYStart());
+ return;
+ }
+
+ //鍒ゆ柇x杞磋揣浣嶆槸鍚︽斁婊�
+ boolean flag = true;
+ for (Loc loc : locService.list(new LambdaQueryWrapper<Loc>()
+ .eq(Loc::getHostId, device.getHostId())
+ .eq(Loc::getRow, xCurrent)
+ .ge(Loc::getBay, shuttleProtocol.getYStart())
+ .le(Loc::getBay, shuttleProtocol.getYTarget()))) {
+ if (loc.getLocSts() != LocStsType.F.val()) {
+ flag = false;//鏈弧
+ break;
+ }
+ }
+ if (flag) {
+ shuttleProtocol.setXCurrent(shuttleProtocol.getXCurrent() + 1);
+ return;
+ }
+
+ //鎼滅储鏈夎揣搴撲綅
+ List<Loc> list = locService.list(new LambdaQueryWrapper<Loc>()
+ .eq(Loc::getLocSts, LocStsType.F.val())
+ .eq(Loc::getHostId, device.getHostId())
+ .notIn(Loc::getRow, xCurrent)
+ .eq(Loc::getStatus, 1));
+ if (list.isEmpty()) {
+ return;
+ }
+
+ Loc start = list.get(0);
+
+ List<Loc> locList = locService.list(new LambdaQueryWrapper<Loc>()
+ .eq(Loc::getHostId, device.getHostId())
+ .eq(Loc::getStatus, 1)
+ .eq(Loc::getLocSts, LocStsType.O.val())
+ .eq(Loc::getRow, xCurrent)
+ .orderByDesc(Loc::getBay)
+ .orderByAsc(Loc::getRow));
+ if (locList.isEmpty()) {
+ return;
+ }
+
+ Loc target = locList.get(0);
+ if (target == null) {
+ return;
+ }
+
+ //璋冨害鍘荤洰鏍囦綅缃�
+ if (!shuttleProtocol.getCurrentLocNo().equals(target.getLocNo())) {
+ Task task = shuttleDispatcher.generateManuaTakeMoveTask(device, start.getLocNo(), target.getLocNo());
+// if(task != null) {//璋冨害鎴愬姛
+// shuttleProtocol.setXCurrent(shuttleProtocol.getXCurrent() + 1);
+// }
+ }
}
}
- private synchronized boolean write(ShuttleCommand command, Device device) {
+ private synchronized CommandResponse write(ShuttleCommand command, Device device) {
+ CommandResponse response = new CommandResponse(false);
if (null == command) {
News.error("鍥涘悜绌挎杞﹀啓鍏ュ懡浠や负绌�");
- return false;
+ response.setMessage("鍥涘悜绌挎杞﹀啓鍏ュ懡浠や负绌�");
+ return response;
}
ShuttleThread shuttleThread = (ShuttleThread) SlaveConnection.get(SlaveType.Shuttle, device.getId().intValue());
- boolean result = false;
if (command.getMode() == ShuttleCommandModeType.MOVE.id
|| command.getMode() == ShuttleCommandModeType.IN_LIFT.id
|| command.getMode() == ShuttleCommandModeType.OUT_LIFT.id) {//绉诲姩
- result = shuttleThread.move(command);
+ response = shuttleThread.move(command);
} else if (command.getMode() == ShuttleCommandModeType.PALLET_LIFT.id
|| command.getMode() == ShuttleCommandModeType.PALLET_DOWN.id) {//椤跺崌
- result = shuttleThread.lift(command);
+ response = shuttleThread.lift(command);
} else if (command.getMode() == ShuttleCommandModeType.CHARGE_OPEN.id
|| command.getMode() == ShuttleCommandModeType.CHARGE_CLOSE.id) {//鍏呯數
- result = shuttleThread.charge(command);
+ response = shuttleThread.charge(command);
} else if (command.getMode() == ShuttleCommandModeType.RESET.id) {//澶嶄綅
- result = shuttleThread.reset(command);
+ response = shuttleThread.reset(command);
+ } else if (command.getMode() == ShuttleCommandModeType.UPDATE_LOCATION.id) {//鏇存柊鍧愭爣
+ response = shuttleThread.updateLocation(command);
}
- return result;
+
+ News.info("鍥涘悜绌挎杞﹀懡浠や笅鍙戯紝绌挎杞﹀彿={}锛屼换鍔℃暟鎹�={}", device.getDeviceNo(), JSON.toJSON(command));
+ return response;
}
}
--
Gitblit v1.9.1