src/main/java/com/zy/asrs/entity/TaskWrk.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
src/main/java/com/zy/asrs/service/impl/MainServiceImpl.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
src/main/java/com/zy/asrs/utils/RouteUtils.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
src/main/java/com/zy/asrs/utils/TrackRangeUtils.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
src/main/java/com/zy/core/MainProcess.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
src/main/java/com/zy/core/cache/TaskProtocolCache.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
src/main/java/com/zy/core/model/RgvSlave.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
src/main/java/com/zy/core/model/protocol/TaskProtocol.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
src/main/java/com/zy/core/thread/RgvThread.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
src/main/resources/application-prod.yml | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 |
src/main/java/com/zy/asrs/entity/TaskWrk.java
@@ -352,4 +352,15 @@ return Math.abs(day) + "天" + Math.abs(hour) + "小时" + Math.abs(min) + "分" + Math.abs(s) + "秒"; } public Integer getTargetPointConvert(){ switch (targetPoint){ case "11": return 11; default: return null; } } } src/main/java/com/zy/asrs/service/impl/MainServiceImpl.java
@@ -13,25 +13,24 @@ import com.zy.asrs.mapper.*; import com.zy.asrs.service.*; import com.zy.asrs.utils.CommandUtils; import com.zy.asrs.utils.RouteUtils; import com.zy.asrs.utils.TrackRangeUtils; import com.zy.asrs.utils.Utils; import com.zy.common.service.CommonService; import com.zy.common.utils.HttpHandler; import com.zy.core.CrnThread; import com.zy.core.DevpThread; import com.zy.core.cache.MessageQueue; import com.zy.core.cache.RgvStatusCache; import com.zy.core.cache.SlaveConnection; import com.zy.core.cache.*; import com.zy.core.enums.*; import com.zy.core.model.CrnSlave; import com.zy.core.model.DevpSlave; import com.zy.core.model.RgvSlave; import com.zy.core.model.Task; import com.zy.core.model.command.CrnCommand; import com.zy.core.model.protocol.CrnProtocol; import com.zy.core.model.protocol.RgvProtocol; import com.zy.core.model.protocol.StaProtocol; import com.zy.core.model.protocol.*; import com.zy.core.properties.SlaveProperties; import com.zy.core.thread.BarcodeThread; import com.zy.core.thread.RgvThread; import com.zy.core.thread.SiemensDevpThread; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; @@ -42,6 +41,7 @@ import java.io.IOException; import java.util.*; import java.util.concurrent.ConcurrentHashMap; /** * 立体仓库WCS系统主流程业务 @@ -80,6 +80,8 @@ private CommonService commonService; @Autowired private CrnController crnController; @Autowired private BasDevpPositionService basDevpPositionService; @Value("${wms.url}") private String wmsUrl; @@ -99,6 +101,9 @@ @Value("${constant-parameters.trackProportion}") private Long trackProportion; @Value("${constant-parameters.avoidDistance}") private Long avoidDistance; public void generateStoreWrkFile() { try { @@ -1106,25 +1111,63 @@ return taskWrk; } public boolean deviceDetection(RgvSlave slave){ public String rgvOtherTaskWrk(RgvSlave slave){ RgvThread rgvThread = (RgvThread) SlaveConnection.get(SlaveType.Rgv, slave.getOtherId()); TaskProtocolCache taskProtocolCache = rgvThread.getTaskProtocolCache(); ConcurrentHashMap<String, TaskProtocol> allTaskProtocol = taskProtocolCache.getAllTaskProtocol(); if (!allTaskProtocol.isEmpty()){ for (TaskProtocol taskProtocol : allTaskProtocol.values()){ if (taskProtocol.getTaskNo() != 0 ){ return taskProtocol.getTaskNo().toString(); } } } return "无"; } public boolean rgvDetection(RgvSlave slave){ RgvProtocol rgvProtocol = RgvStatusCache.getRgvStatus(slave.getId()); if (rgvProtocol == null) { RgvTaskProtocol rgvTaskProtocol = RgvTaskCache.getRgvStatus(slave.getId()); if (rgvProtocol == null || rgvTaskProtocol ==null) { return false; } if (!rgvProtocol.getModeType().equals(RgvModeType.AUTO) || rgvProtocol.getRgvPos().equals(0L) if (!rgvProtocol.getModeType().equals(RgvModeType.AUTO) || rgvProtocol.getRgvPos().equals(0L) || rgvTaskProtocol.getAvoid() == -1 || rgvProtocol.getRgvPosDestination() == 0L || (!rgvProtocol.getStatusType().equals(RgvStatusType.IDLE) && !rgvProtocol.getStatusType().equals(RgvStatusType.ROAM))) { return false; } RgvProtocol rgvProtocolOther = RgvStatusCache.getRgvStatus(slave.getOtherId()); RgvTaskProtocol rgvTaskProtocolOther = RgvTaskCache.getRgvStatus(slave.getOtherId()); if (rgvProtocolOther == null) { return false; } if (rgvProtocolOther.statusEnable){ if (!rgvProtocolOther.getModeType().equals(RgvModeType.AUTO) || rgvProtocolOther.getRgvPos().equals(0L)) { if (!rgvProtocolOther.getModeType().equals(RgvModeType.AUTO) || rgvProtocolOther.getRgvPos().equals(0L) || rgvTaskProtocolOther.getAvoid() == -1 || rgvProtocolOther.getRgvPosDestination() == 0L) { return false; } } return true; } public TaskWrk deviceDetection(RgvSlave.RgvStn inSta){ DevpThread devpThread = (DevpThread) SlaveConnection.get(SlaveType.Devp, inSta.getDevpPlcId()); StaProtocol staProtocol = devpThread.getStation().get(inSta.getStaNo()); if (staProtocol == null){ return null; } // 判断是否满足取货条件 if (staProtocol.isAutoing() // && staProtocol.isLoading() && staProtocol.getWorkNo()!=0) { TaskWrk taskWrk = taskWrkService.selectByTaskNo(staProtocol.getWorkNo().toString()); if (taskWrk!=null){ return taskWrk; } } return null; } public boolean rgvOtherStatusEnable(RgvSlave slave){ @@ -1140,36 +1183,263 @@ return false; } public boolean deviceRgvDetection(Integer startSta,RgvSlave rgvSlave,Integer endSta){ BasDevpPosition basDevpPositionStartSta = basDevpPositionService.selectOne(new EntityWrapper<BasDevpPosition>().eq("DEV_NO", startSta)); if (basDevpPositionStartSta == null){ return false; } private void sc(){ BasDevpPosition basDevpPositionEndSta = basDevpPositionService.selectOne(new EntityWrapper<BasDevpPosition>().eq("DEV_NO", endSta)); if (basDevpPositionEndSta == null){ return false; } DevpThread devpThreadEnd = (DevpThread) SlaveConnection.get(SlaveType.Devp, basDevpPositionEndSta.getPlcId()); StaProtocol staProtocolEnd = devpThreadEnd.getStation().get(endSta); if (staProtocolEnd == null){ return false; } // 判断是否满足放货条件 if (!staProtocolEnd.isAutoing() || staProtocolEnd.isLoading()) { return false; } if (!rgvDetection(rgvSlave)){ return false; } // a当前 b other // b可用 // b无任务 // 半边区域内全任务 // 半边区域内取货任务 // 半边区域内放货任务 //切换B // 半边区域内全任务 // 半边区域内取货任务 // 半边区域内放货任务 //b 有任务 // 可用区域任务 // 可用区域任务内取货任务 // // b禁用 // 全区域任务 就近取货 // 根据输送线plc遍历 return false; } public synchronized void taskStart() { for (RgvSlave rgvSlave : slaveProperties.getRgv()) { if (!deviceDetection(rgvSlave)){ try{ if (rgvDetection(rgvSlave)){ for (RgvSlave.RgvStn inSta : rgvSlave.getRgvInSta()){ TaskWrk taskWrk = deviceDetection(inSta); if (taskWrk!=null){ if (deviceRgvDetection(inSta.getStaNo(),rgvSlave,taskWrk.getTargetPointConvert())){ RgvProtocol rgvStatus = RgvStatusCache.getRgvStatus(rgvSlave.getId()); } } } } } catch (Exception e){ log.error("任务生成失败===》异常信息:{}",e.getMessage()); } } } public synchronized void DevpTaskNoRun() { for (RgvSlave rgvSlave : slaveProperties.getRgv()) { try{ if (rgvDetection(rgvSlave)){ String taskNoNow = rgvOtherTaskWrk(rgvSlave); List<BasDevpPosition> basDevpPositions = basDevpPositionService.selectList(new EntityWrapper<BasDevpPosition>().orderBy("PLC_POSITION", true)); boolean itSmall = new TrackRangeUtils().IsItSmall(rgvSlave); if (basDevpPositions.isEmpty()) { log.error("获取所有站点信息异常"); continue; } List<TaskWrk> taskWrkList = new ArrayList<>(); List<Integer> staList = new ArrayList<>(); for (RgvSlave.RgvStn inSta : rgvSlave.getRgvInSta()){ TaskWrk taskWrk = deviceDetection(inSta); if (taskWrk!=null){ if (taskWrk.getTaskNo().equals(taskNoNow)) continue; taskWrkList.add(taskWrk); staList.add(inSta.getStaNo()); } } if (rgvOtherStatusEnable(rgvSlave)){ //分成上下两部分任务 List<Integer>[] avoidRange = RouteUtils.avoidRange(staList, basDevpPositions); List<Integer> rangeListSou = avoidRange[itSmall ? 0 : 1]; List<Integer> rangeListSouOther = avoidRange[itSmall ? 1 : 0]; //就近排序 RgvProtocol rgvProtocol = RgvStatusCache.getRgvStatus(rgvSlave.getId()); List<Integer> rangeList = RouteUtils.SortNearby(rangeListSou, rgvProtocol.RgvPos, basDevpPositions); List<Integer> rangeListOther = RouteUtils.SortNearby(rangeListSouOther, rgvProtocol.RgvPos, basDevpPositions); if (taskNoNow.equals("无")){ //b 无任务 //所属部分就进取货 // 半边区域内全任务 boolean sign = false; RgvProtocol rgvProtocolOther = RgvStatusCache.getRgvStatus(rgvSlave.getOtherId()); for (Integer staNoNow : rangeList){ for (RgvSlave.RgvStn rgvStn : rgvSlave.getRgvInSta()){ if (rgvStn.getStaNo().equals(staNoNow)){ TaskWrk taskWrk = deviceDetection(rgvStn); if (taskWrk!=null){ if () } } } } if (!sign){ // 半边区域内取货任务 for (Integer staNoNow : rangeList){ for (RgvSlave.RgvStn rgvStn : rgvSlave.getRgvInSta()){ if (rgvStn.getStaNo().equals(staNoNow)){ sign = taskGenerate(rgvSlave,rgvStn,0); break; } } if (sign){ break; } } } if (!sign){ // 半边区域内放货任务 for (Integer staNoNow : rangeListOther){ for (RgvSlave.RgvStn rgvStn : rgvSlave.getRgvInSta()){ if (rgvStn.getStaNo().equals(staNoNow)){ //求出当前车可运行范围 Long[] farthestPoint = new Long[]{0L,0L}; if (!rgvProtocolOther.statusEnable){ farthestPoint = new Long[]{0L,0L}; break; } } if (sign){ break; } } } //切换B continue; } else {//b 有任务 // 可用区域任务 // 可用区域任务内取货任务 //切换B continue; } break; } else { if (rgvProtocolOther.getStatusType().equals(RgvStatusType.IDLE)){ //可用区域就近取货 } } } catch (Exception e){ log.error("任务生成失败===》异常信息:{}",e.getMessage()); } } } //获取起点与终点对象 public RgvSlave.RgvStn getRgvStnNow(RgvSlave rgvSlave,Integer staNo) { for (RgvSlave.RgvStn rgvStn : rgvSlave.getRgvInSta()){ if (rgvStn.getStaNo().equals(staNo)){ return rgvStn; } } for (RgvSlave.RgvStn rgvStn : rgvSlave.getRgvOutSta()){ if (rgvStn.getStaNo().equals(staNo)){ return rgvStn; } } return null; } //获取起点与终点对象 public RgvSlave.RgvStn[] getRgvStnAll(RgvSlave rgvSlave,Integer souSta,Integer endSta) { RgvSlave.RgvStn[] rgvStns = new RgvSlave.RgvStn[2]; for (RgvSlave.RgvStn rgvStn : rgvSlave.getRgvInSta()){ if (rgvStn.getStaNo().equals(souSta)){ rgvStns[0] = rgvStn; } } for (RgvSlave.RgvStn rgvStn : rgvSlave.getRgvOutSta()){ if (rgvStn.getStaNo().equals(endSta)){ rgvStns[1] = rgvStn; } } return rgvStns; } public boolean taskGenerate(RgvSlave rgvSlave,RgvSlave.RgvStn rgvStn,Integer sign) { try{ RgvThread rgvThread = (RgvThread) SlaveConnection.get(SlaveType.Rgv, rgvSlave.getId()); TaskProtocolCache taskProtocolCache = rgvThread.getTaskProtocolCache(); TaskProtocol issuedTake = new TaskProtocol(); TaskProtocol issuedPut = new TaskProtocol(); try{ ConcurrentHashMap<String, TaskProtocol> allTaskProtocol = taskProtocolCache.getAllTaskProtocol(); if (allTaskProtocol.size() > 0){ return false; } TaskWrk taskWrk = deviceDetection(rgvStn); if (taskWrk == null){ return false; } Integer targetPointConvert = taskWrk.getTargetPointConvert(); if (targetPointConvert == null){ return false; } RgvSlave.RgvStn rgvStnEnd = getRgvStnNow(rgvSlave, targetPointConvert); if (rgvStnEnd == null){ return false; } BasDevpPosition basDevpPositionSou = basDevpPositionService.selectOne(new EntityWrapper<BasDevpPosition>().eq("DEV_NO", rgvStn.getStaNo())); BasDevpPosition basDevpPositionEnd = basDevpPositionService.selectOne(new EntityWrapper<BasDevpPosition>().eq("DEV_NO", targetPointConvert)); //执行 issuedTake.setTaskNo(Long.valueOf(taskWrk.getTaskNo())); issuedTake.setTaskStatus(1); issuedTake.setTaskNoDirection(issuedTake.gettaskNoDirection$(issuedTake.getTaskNo(),issuedTake.getTaskStatus())); issuedTake.setTargetPosition(basDevpPositionSou.getPlcPosition()); issuedTake.setIsRunning(1); issuedTake.setDirection(rgvStn.isDirection()); issuedPut.setTaskNo(Long.valueOf(taskWrk.getTaskNo())); issuedPut.setTaskStatus(2); issuedPut.setTaskNoDirection(issuedPut.gettaskNoDirection$(issuedPut.getTaskNo(),issuedPut.getTaskStatus())); issuedPut.setTargetPosition(basDevpPositionEnd.getPlcPosition()); issuedPut.setIsRunning(1); issuedPut.setDirection(rgvStnEnd.isDirection()); }catch (Exception e){ log.error("任务生成失败issued1===》异常信息:{}",e.getMessage()); return false; } switch (sign){ case 1: taskProtocolCache.updateTaskProtocol(issuedTake); break; case 2: taskProtocolCache.updateTaskProtocol(issuedPut); break; default: taskProtocolCache.updateTaskProtocol(issuedTake); taskProtocolCache.updateTaskProtocol(issuedPut); break; } } catch (Exception e){ log.error("任务生成失败issued2===》异常信息:{}",e.getMessage()); } return true; } // 遍历入库口 for (RgvSlave.RgvStn inSta : rgvSlave.getRgvInSStn()) { } } } } src/main/java/com/zy/asrs/utils/RouteUtils.java
@@ -1,6 +1,10 @@ package com.zy.asrs.utils; import com.zy.asrs.entity.BasDevpPosition; import com.zy.asrs.entity.TaskWrk; import com.zy.asrs.entity.WrkMast; import com.zy.core.enums.RouteCollectCountType; import com.zy.core.model.RgvSlave; import java.util.ArrayList; import java.util.List; @@ -11,441 +15,33 @@ * Created by Monkey D. Luffy on 2023/7/18 */ public class RouteUtils { public static final List<Integer> MERGE_STA_NO_One = new ArrayList<Integer>() {{ add(171);add(116);add(117); }}; public static final List<Integer> MERGE_STA_NO_TWO = new ArrayList<Integer>() {{ add(113);add(123);add(114);add(1142); }}; public static final List<Integer> MERGE_STA_NO_THREE = new ArrayList<Integer>() {{ add(107);add(118);add(108);add(119); }}; public static final List<Integer> MERGE_STA_NO_FOUR = new ArrayList<Integer>() {{ add(110);add(120);add(111);add(121); }}; public static final List<Integer> MERGE_STA_NO_FIVE = new ArrayList<Integer>() {{ add(104);add(122);add(105); }}; public static final List<Integer> MERGE_STA_NO_SIX = new ArrayList<Integer>() {{ add(108);add(119);add(110);add(120); }}; public static final List<Integer> MERGE_STA_NO_SEVEN = new ArrayList<Integer>() {{ }}; public static final List<Integer> MERGE_STA_NO_EIGHT = new ArrayList<Integer>() {{ }}; public static final List<Integer> MERGE_STA_NO_NINE = new ArrayList<Integer>() {{ }}; // 正序 public static final List<Integer> TRACK_POSITION_POSITIVE_SEQUENCE1 = new ArrayList<Integer>() {{ add(101);add(102);add(104);add(122);add(105);add(107);add(118);add(108); }}; // 反序 public static final List<Integer> TRACK_POSITION_REVERSE_SEQUENCE2 = new ArrayList<Integer>() {{ add(117);add(116);add(171);add(1142);add(114);add(123);add(113);add(121);add(111);add(120);add(110); }}; public static Integer getEndRoute(Integer endRoute,Integer rgvNo){ if (rgvNo == 1){ if (TRACK_POSITION_POSITIVE_SEQUENCE1.contains(endRoute)){ return endRoute; } else { return 108; } } else if (rgvNo == 2){ if (TRACK_POSITION_REVERSE_SEQUENCE2.contains(endRoute)){ return endRoute; } else { return 110; } } return endRoute; } // 正序 public static final List<Integer> TRACK_POSITION_POSITIVE_SEQUENCE = new ArrayList<Integer>() {{ add(101);add(102);add(104);add(122);add(105);add(107);add(118);add(108);add(119);add(110);add(120);add(111);add(121);add(113);add(123);add(114);add(1142);add(171);add(116);add(117); }}; // 反序 public static final List<Integer> TRACK_POSITION_REVERSE_SEQUENCE = new ArrayList<Integer>() {{ add(117);add(116);add(171);add(1142);add(114);add(123);add(113);add(121);add(111);add(120);add(110);add(119);add(108);add(118);add(107);add(105);add(122);add(104);add(102);add(101); }}; public static String zerofill(String msg, Integer count){ if (msg.length() == count){ return msg; } else if (msg.length() > count){ return msg.substring(0, 16); } else { StringBuilder msgBuilder = new StringBuilder(msg); for (int i = 0; i<count-msg.length(); i++){ msgBuilder.insert(0,"0"); } return msgBuilder.toString(); } } // /* // * 获取干涉最远站点 // * */ // public static Integer RouteIndexFarMas(int rgvNo,Integer staNo){ // List<Integer> staFall = new ArrayList<>(); // if (MERGE_STA_NO_SIX.contains(staNo)){ // staFall = MERGE_STA_NO_SIX; // }else if (MERGE_STA_NO_One.contains(staNo)){ // staFall = MERGE_STA_NO_One; // }else if (MERGE_STA_NO_TWO.contains(staNo)){ // staFall = MERGE_STA_NO_TWO; // }else if (MERGE_STA_NO_THREE.contains(staNo)){ // staFall = MERGE_STA_NO_THREE; // }else if (MERGE_STA_NO_FOUR.contains(staNo)){ // staFall = MERGE_STA_NO_FOUR; // }else if (MERGE_STA_NO_FIVE.contains(staNo)){ // staFall = MERGE_STA_NO_FIVE; // }else { // return staNo; // } // // int indexNo = 0; // if (rgvNo==1){ // indexNo=staFall.size()-1; // } // return staFall.get(indexNo); // } /* * 获取干涉最远站点 * */ public static Integer RouteIndexFarMas(int rgvNo,Integer staNo){ if (rgvNo==1){ switch (staNo){ case 101: case 102: return 102; case 104: case 122: return 118; case 105: return 119; case 107: case 118: return 108; case 108: case 119: return 111; case 110: case 120: return 113; case 111: case 121: return 113; case 113: return 114; case 123: case 114: return 1142; default: return 116; } }else { switch (staNo){ case 117: case 116: case 171: return 1142; case 1142: case 114: return 113; case 123: case 113: return 111; case 121: return 110; case 111: return 110; case 120: case 110: return 108; case 119: case 108: return 107; case 118: case 107: return 105; case 105: case 122: case 104: return 104; default: return 102; } } } /* * 获取干涉最远站点 * */ public static Integer RouteIndexFarMasL(int rgvNo,Integer staNo){ if (rgvNo==1){ switch (staNo){ case 101: case 102: case 104: case 122: case 105: case 107: return 118; case 118: return staNo; default: return 108; } }else { switch (staNo){ case 117: case 116: case 171: case 1142: case 114: case 123: case 113: case 121: return 121; case 111: return staNo; default: return 110; } } } // 获取当前小车未行走的路线集合 public static List<Integer> getRoute(Integer groupStart,Integer groupEnd){ boolean sign = TRACK_POSITION_POSITIVE_SEQUENCE.indexOf(groupStart) < TRACK_POSITION_POSITIVE_SEQUENCE.indexOf(groupEnd); List<Integer> result = new ArrayList<>(); List<Integer> groupRoute = new ArrayList<>(); if (sign){ groupRoute = TRACK_POSITION_POSITIVE_SEQUENCE; }else { groupRoute = TRACK_POSITION_REVERSE_SEQUENCE; } if (groupRoute.contains(groupStart) && groupRoute.contains(groupEnd)) { sign = false; for (Integer route : groupRoute) { if (route.equals(groupStart)){ sign=true; } if (route.equals(groupEnd)){ result.add(route); break; } if (sign){ result.add(route); } } }else { return null; } return result; } /* * 获取最远站点 * */ public static Integer RouteIndexFarMas(Integer a,Integer b,Integer c,Integer d){ int ia = TRACK_POSITION_POSITIVE_SEQUENCE.indexOf(a); int ib = TRACK_POSITION_POSITIVE_SEQUENCE.indexOf(b); int ic = TRACK_POSITION_POSITIVE_SEQUENCE.indexOf(c); int id = TRACK_POSITION_POSITIVE_SEQUENCE.indexOf(d); if (id==0){ if (ia>ib){ if (ia>ic){ return a; }else { return c; } }else { if (ib>ic){ return b; }else { return c; } } }else { if (ia<ib){ if (ia<ic){ return a; }else { return c; } }else { if (ib<ic){ return b; }else { return c; } } } } /* * 获取最远站点 * a:当前位置 * b:开始位置 * c:结束位置 * d:锁开始位置 * */ public static Integer RouteIndexFarMasNew(Integer a,Integer b,Integer c,Integer d){ int ia = TRACK_POSITION_POSITIVE_SEQUENCE.indexOf(a); int ib = TRACK_POSITION_POSITIVE_SEQUENCE.indexOf(b); int ic = TRACK_POSITION_POSITIVE_SEQUENCE.indexOf(c); int id = TRACK_POSITION_POSITIVE_SEQUENCE.indexOf(d); if (id==0){ if (ia>ib){ if (ia>ic){ return a; }else { return c; } }else { if (ib>ic){ return b; }else { return c; } } }else { if (ia<ib){ if (ia<ic){ return a; }else { return c; } }else { if (ib<ic){ return b; }else { return c; } } } } public static Integer[] RouteIndexFarArr(Integer a,Integer b,Integer c,Integer d){ int ia = TRACK_POSITION_POSITIVE_SEQUENCE.indexOf(a); int ib = TRACK_POSITION_POSITIVE_SEQUENCE.indexOf(b); int ic = TRACK_POSITION_POSITIVE_SEQUENCE.indexOf(c); int id = TRACK_POSITION_POSITIVE_SEQUENCE.indexOf(d); return new Integer[]{ia,ib,ic,id}; } /* * a 小车当前位置 * b 小车任务开始位置 * c 小车任务结束位置 * d 小车初始位置 * 获取最大路径差值 * */ public static List<Integer> RouteMapCurrentFar(Integer a,Integer b,Integer c,Integer d){ Integer farStn = RouteIndexFarMas(a, b, c, d); return getRouteIntersection(TRACK_POSITION_POSITIVE_SEQUENCE,getRoute(farStn, d), RouteCollectCountType.DIFFERENCESET); } public static List<Integer> RouteMapCurrentFar(Integer farStn,Integer d){ return getRouteIntersection(TRACK_POSITION_POSITIVE_SEQUENCE,getRoute(farStn, d), RouteCollectCountType.DIFFERENCESET); } /* * 另一台小车最远位置 * */ public static Integer RouteMapOtherFarStnNo(List<Integer> routeDIFF,Integer d){ int id = TRACK_POSITION_POSITIVE_SEQUENCE.indexOf(d); if (id==0){ return routeDIFF.get(0); }else { int size = routeDIFF.size(); return routeDIFF.get(size-1); } } //是否有交集 public static boolean getRouteBoolean(List<Integer> groupCurrent,List<Integer> groupOther){ for (Integer positionCurrent : groupCurrent){ for (Integer positionOther : groupOther){ if (positionCurrent.equals(positionOther)){ return true; } } } return false; } //集合运算 public static List<Integer> getRouteIntersection(List<Integer> groupCurrent, List<Integer> groupOther, RouteCollectCountType routeCollectCountType){ switch (routeCollectCountType){ case INTERSECTION: //交集 return groupCurrent.stream().filter(item -> groupOther.contains(item)).collect(toList()); case DIFFERENCESET: //差集 return groupCurrent.stream().filter(item -> !groupOther.contains(item)).collect(toList()); case UNION: //并集 groupCurrent.addAll(groupOther); return groupCurrent; case DEDUPLICATIONUNION: //去重并集 groupCurrent.addAll(groupOther); return groupCurrent.stream().distinct().collect(toList()); default: return null; } } /* * a 小车当前位置 * b 小车任务开始位置 * c 小车任务结束位置 * sign 另一个小车空闲标记 * */ public static boolean RouteAutoBoolean(Integer a,Integer b,Integer c,Integer aa,Integer bb,Integer cc,boolean idleOther){ List<Integer> routeCurrent = getRouteIntersection(getRoute(a, c), getRoute(b, c), RouteCollectCountType.DEDUPLICATIONUNION);//并集 List<Integer> routeOther = getRouteIntersection(getRoute(aa, cc), getRoute(bb, cc), RouteCollectCountType.DEDUPLICATIONUNION);// return !getRouteBoolean(routeCurrent, routeOther); //是否有交集 } public static List<Integer> RouteAutoBoolean(Integer a,Integer b,Integer c){ return getRouteIntersection(getRoute(a, c), getRoute(b, c), RouteCollectCountType.DEDUPLICATIONUNION); } //排序 执行方向(面朝轨道 定位值左小右大) 0:左 小 1:右 大 public static List<Integer>[] avoidRange(List<Integer> staNoList,List<BasDevpPosition> basDevpPositions) { List<Integer>[] avoidRangeArray = new ArrayList[2]; public static void main(String[] arge){ List<Integer> routeCurrent = getRoute(104, 119); //获取当前小车路径 List<Integer> routeOther = getRoute(117, 118); //获取其它小车路径 System.out.println("当前小车路径:\t"+routeCurrent); System.out.println("其它小车路径:\t"+routeOther); boolean routeBoolean = getRouteBoolean(routeCurrent, routeOther); //是否有交集 System.out.println("是否有交集:\t"+routeBoolean); List<Integer> routeIntersection = getRouteIntersection(routeCurrent, routeOther, RouteCollectCountType.INTERSECTION);//交集 System.out.println("路径交集:\t"+routeIntersection); List<Integer> routeIntersection1 = getRouteIntersection(routeCurrent, routeOther, RouteCollectCountType.DIFFERENCESET);//差集 System.out.println("路径差集:\t"+routeIntersection1); List<Integer> routeIntersection2 = getRouteIntersection(routeCurrent, routeOther, RouteCollectCountType.UNION);//并集 System.out.println("路径并集:\t"+routeIntersection2); List<Integer> routeIntersection3 = getRouteIntersection(routeCurrent, routeOther, RouteCollectCountType.DEDUPLICATIONUNION);//去重并集 System.out.println("路径去重并集:\t"+routeIntersection3); System.out.println(RouteAutoBoolean(101,104,119,114,116,120,true)); List<Integer> routeDIFF = RouteMapCurrentFar(114, 104, 119, 117); System.out.println("当前路径最大集合:\t"+ routeDIFF); Integer routeFarOther= RouteMapOtherFarStnNo(routeDIFF,117); System.out.println("另一台小车最远站点:\t"+routeFarOther); Integer[] integers = RouteIndexFarArr(114, 104, 119, 101); for (Integer integer:integers){ System.out.println(integer); return avoidRangeArray; } //提取站点集合 public static List<Integer> BasDevpPositionExtractSites(List<BasDevpPosition> basDevpPositions){ List<Integer> siteList = new ArrayList<>(); for (BasDevpPosition basDevpPosition : basDevpPositions){ if (!siteList.contains(basDevpPosition.getDevNo())){ siteList.add(basDevpPosition.getDevNo()); } } return siteList; } //提取站点集合 public static List<Integer> SortNearby(List<Integer> staNoList,Long rgvNowPos,List<BasDevpPosition> basDevpPositions){ List<Integer> siteList = new ArrayList<>(); return siteList; } } src/main/java/com/zy/asrs/utils/TrackRangeUtils.java
New file @@ -0,0 +1,49 @@ package com.zy.asrs.utils; import com.zy.core.cache.RgvStatusCache; import com.zy.core.model.RgvSlave; import com.zy.core.model.protocol.RgvProtocol; /** * Created by Monkey D. Luffy on 2023/7/18 */ public class TrackRangeUtils { public boolean IsItSmall(RgvSlave slave) { RgvProtocol rgvProtocol = RgvStatusCache.getRgvStatus(slave.getId()); RgvProtocol rgvProtocolOther = RgvStatusCache.getRgvStatus(slave.getOtherId()); if (rgvProtocol.getRgvPos() < rgvProtocolOther.getRgvPos()) { return true; } return false; } public Long[][] avoidRange(RgvSlave slave, Long trackEntireLength, Long trackBenchmark, Long avoidDistance) { RgvProtocol rgvProtocol = RgvStatusCache.getRgvStatus(slave.getId()); RgvProtocol rgvProtocolOther = RgvStatusCache.getRgvStatus(slave.getOtherId()); RgvProtocol rgvProtocolE, rgvProtocolB; if (rgvProtocol.getRgvPos() < rgvProtocolOther.getRgvPos()) { rgvProtocolE = rgvProtocolOther; rgvProtocolB = rgvProtocol; } else { rgvProtocolE = rgvProtocol; rgvProtocolB = rgvProtocolOther; } long entireLengthE = trackEntireLength - rgvProtocolE.getCarBodyKunPeng(); long benchmarkE = trackBenchmark + rgvProtocolB.getCarBodyJiaoMing() + rgvProtocolB.getCarBodyKunPeng() + avoidDistance + rgvProtocolE.getCarBodyJiaoMing(); long entireLengthB = trackEntireLength - rgvProtocolE.getCarBodyKunPeng() - rgvProtocolE.getCarBodyJiaoMing() - avoidDistance - rgvProtocolB.getCarBodyKunPeng(); long benchmarkB = trackBenchmark + rgvProtocolB.getCarBodyJiaoMing(); return new Long[][]{new Long[]{entireLengthE, benchmarkE}, new Long[]{entireLengthB, benchmarkB}}; } public boolean avoidRange(Long avoid, Long[] range) { return avoid < range[0] && avoid > range[1]; } } src/main/java/com/zy/core/MainProcess.java
@@ -51,6 +51,9 @@ // 堆垛机异常信息记录 mainService.recCrnErr(); // 任务下发 mainService.taskStart(); } catch (Exception e) { src/main/java/com/zy/core/cache/TaskProtocolCache.java
@@ -15,7 +15,7 @@ @Slf4j public class TaskProtocolCache { // 本地缓存,键为 taskNo,值为 TaskProtocol private final ConcurrentHashMap<Long, TaskProtocol> cache = new ConcurrentHashMap<>(); private final ConcurrentHashMap<String, TaskProtocol> cache = new ConcurrentHashMap<>(); // 读写锁,确保线程安全 // private final ReentrantReadWriteLock lock = new ReentrantReadWriteLock(); @@ -24,28 +24,16 @@ * 更新设备状态 */ public void updateTaskProtocol(TaskProtocol status) { cache.put(status.getTaskNo(), status); cache.put(status.getTaskNoDirection(), status); } /** * 删除任务缓存 */ public TaskProtocol removeTaskProtocol(String taskNo) { public TaskProtocol removeTaskProtocol(String taskNoDirection) { // lock.readLock().lock(); // 加读锁 try { return cache.remove(taskNo); } finally { // lock.readLock().unlock(); // 释放读锁 } } /** * 获取任务缓存 */ public TaskProtocol getTaskProtocol(String taskNo) { // lock.readLock().lock(); // 加读锁 try { return cache.get(taskNo); return cache.remove(taskNoDirection); } finally { // lock.readLock().unlock(); // 释放读锁 } @@ -54,7 +42,7 @@ /** * 获取所有任务 */ public ConcurrentHashMap<Long, TaskProtocol> getAllTaskProtocol() { public ConcurrentHashMap<String, TaskProtocol> getAllTaskProtocol() { // lock.readLock().lock(); // 加读锁 try { return new ConcurrentHashMap<>(cache); // 返回副本 @@ -74,6 +62,10 @@ } return new ArrayList<>(); } /** * 获取所有取任务 */ public List<TaskProtocol> getAllTakeTaskProtocol() { // lock.readLock().lock(); // 加读锁 try { @@ -90,7 +82,7 @@ } /** * 获取所有取任务 * 获取所有放任务 */ public List<TaskProtocol> getAllPutTaskProtocol() { // lock.readLock().lock(); // 加读锁 @@ -108,7 +100,7 @@ } /** * 获取所有取任务 * 获取所有行走任务 */ public List<TaskProtocol> getAllWalkTaskProtocol() { // lock.readLock().lock(); // 加读锁 src/main/java/com/zy/core/model/RgvSlave.java
@@ -29,7 +29,8 @@ private Long carBodyKunPeng; // RGV入库源站点 private List<RgvStn> rgvInSStn = new ArrayList<>(); private List<RgvStn> rgvInSta = new ArrayList<>(); private List<RgvStn> rgvOutSta = new ArrayList<>(); @Data public static class RgvStn { @@ -40,6 +41,9 @@ // RGV站点编号 private Integer staNo; // RGV站点编号 private boolean direction; // // 排 // private Integer row; // src/main/java/com/zy/core/model/protocol/TaskProtocol.java
@@ -7,27 +7,42 @@ */ @Data public class TaskProtocol { private volatile String taskNoDirection; // 任务号(主属性) private volatile Long taskNo; // 任务号(主属性) private volatile Long targetPosition = 0L; // 目标位置 private volatile Long currentPosition = 0L; // 当前位置 private volatile int isRunning = 0; // 运行状态 0:初始 1:等待执行 2:执行中 3:执行中断 4:完结 private volatile int taskStatus = 0; //作业模式 0:行走 1:取 2:放 private volatile boolean direction; // 执行方向(面朝轨道 定位值左小右大) true:左 false:右 public TaskProtocol(){} public TaskProtocol(Long taskNo, Long targetPosition, Long currentPosition, int isRunning, int taskStatus) { public TaskProtocol(Long taskNo, Long targetPosition, int isRunning, int taskStatus, boolean direction) { this.taskNo = taskNo; this.targetPosition = targetPosition; this.currentPosition = currentPosition; this.isRunning = isRunning; this.taskStatus = taskStatus; this.direction = direction; } public TaskProtocol(TaskProtocol taskProtocol) { this.taskNo = taskProtocol.getTaskNo(); this.targetPosition = taskProtocol.getTargetPosition(); this.taskStatus = taskProtocol.getTaskStatus(); this.direction = taskProtocol.direction; } public String gettaskNoDirection$(Long taskNo,int taskStatus){ String taskStatusStr = "Walk"; switch (taskStatus){ case 1: taskStatusStr = "Tack"; case 2: taskStatusStr = "Put"; } return taskNo+"_"+taskStatusStr; } } src/main/java/com/zy/core/thread/RgvThread.java
@@ -13,6 +13,7 @@ import com.zy.asrs.service.BasRgvOptService; import com.zy.asrs.service.BasRgvService; import com.zy.asrs.utils.RouteUtils; import com.zy.asrs.utils.TrackRangeUtils; import com.zy.core.ThreadHandler; import com.zy.core.cache.*; import com.zy.core.enums.RgvModeType; @@ -169,7 +170,7 @@ continue; } } Thread.sleep(200); Thread.sleep(100); TaskProtocol issued = new TaskProtocol(taskProtocol); write(issued); taskProtocol.setIsRunning(taskProtocol.getIsRunning() +1); @@ -227,8 +228,11 @@ RgvTaskProtocol rgvTaskProtocol = RgvTaskCache.getRgvStatus(slave.getId()); RgvProtocol rgvProtocolOther = RgvStatusCache.getRgvStatus(slave.getOtherId()); RgvTaskProtocol rgvTaskProtocolOther = RgvTaskCache.getRgvStatus(slave.getOtherId()); Long[][] avoidRange = new TrackRangeUtils().avoidRange(slave, trackEntireLength, trackBenchmark, avoidDistance); if (rgvProtocol.getRgvPos()<rgvProtocolOther.getRgvPos()){ if (new TrackRangeUtils().IsItSmall(slave)) { if (rgvProtocolOther.getStatusType().equals(RgvStatusType.IDLE)){ if ((rgvProtocolOther.getRgvPos()-rgvProtocolOther.getCarBodyJiaoMing()) - (targetPosition+rgvProtocol.getCarBodyKunPeng()) @@ -236,13 +240,13 @@ return true; } else { long avoid = targetPosition + rgvProtocol.getCarBodyKunPeng() + avoidDistance + rgvProtocolOther.getCarBodyJiaoMing(); if (avoid > trackEntireLength-rgvProtocolOther.getCarBodyKunPeng()){ log.error("避让超出范围!!!任务异常 联系管理员!!!"); if (!new TrackRangeUtils().avoidRange(avoid, avoidRange[0])) { log.error("行走超出范围!!!任务异常 联系管理员!!!"); return false; } rgvTaskProtocol.setAvoid(1); rgvTaskProtocol.setAvoidingTheDestination(avoid); RgvTaskCache.updateRgvStatus(rgvTaskProtocol); rgvTaskProtocolOther.setAvoid(1); rgvTaskProtocolOther.setAvoidingTheDestination(avoid); RgvTaskCache.updateRgvStatus(rgvTaskProtocolOther); return true; } } else if (rgvProtocolOther.getStatusType().equals(RgvStatusType.ROAM)){ @@ -252,13 +256,13 @@ return true; } else { long avoid = targetPosition + rgvProtocol.getCarBodyKunPeng() + avoidDistance + rgvProtocolOther.getCarBodyJiaoMing(); if (avoid > trackEntireLength-rgvProtocolOther.getCarBodyKunPeng()){ log.error("避让超出范围!!!任务异常 联系管理员!!!"); if (!new TrackRangeUtils().avoidRange(avoid, avoidRange[0])) { log.error("行走超出范围!!!任务异常 联系管理员!!!"); return false; } rgvTaskProtocol.setAvoid(1); rgvTaskProtocol.setAvoidingTheDestination(avoid); RgvTaskCache.updateRgvStatus(rgvTaskProtocol); rgvTaskProtocolOther.setAvoid(1); rgvTaskProtocolOther.setAvoidingTheDestination(avoid); RgvTaskCache.updateRgvStatus(rgvTaskProtocolOther); return true; } } else if (rgvProtocolOther.getStatusType().equals(RgvStatusType.WORKING)){ @@ -267,16 +271,9 @@ > avoidDistance){//无需避让 return true; } else { RgvThread rgvThreadOther = (RgvThread) SlaveConnection.get(SlaveType.Rgv, rgvProtocolOther.getRgvNo()); TaskProtocolCache taskProtocolCacheOther = rgvThreadOther.getTaskProtocolCache(); List<TaskProtocol> allPutTaskProtocol = taskProtocolCacheOther.getAllPutTaskProtocol(); if (allPutTaskProtocol.size() > 1){ return false; } for (TaskProtocol taskProtocol : allPutTaskProtocol){ if (taskProtocol.getTargetPosition()>=rgvProtocolOther.getRgvPos()){ if (rgvProtocolOther.getRgvPosDestination() >= rgvProtocolOther.getRgvPos()) { long avoid = rgvProtocolOther.getRgvPos()-rgvProtocolOther.getCarBodyJiaoMing()-avoidDistance-rgvProtocol.getCarBodyKunPeng(); if (avoid > trackEntireLength-rgvProtocolOther.getCarBodyKunPeng()){ if (!new TrackRangeUtils().avoidRange(avoid, avoidRange[1])) { log.error("行走超出范围!!!任务异常 联系管理员!!!"); return false; } @@ -284,9 +281,6 @@ rgvTaskProtocol.setAvoidingTheDestination(avoid); RgvTaskCache.updateRgvStatus(rgvTaskProtocol); return false; } else { return false; } } return false; } @@ -299,13 +293,13 @@ return true; } else { long avoid = targetPosition -rgvProtocol.getCarBodyJiaoMing() - avoidDistance - rgvProtocolOther.getCarBodyKunPeng(); if (avoid < trackBenchmark + rgvProtocolOther.getCarBodyJiaoMing()){ log.error("避让超出范围!!!任务异常 联系管理员!!!"); if (!new TrackRangeUtils().avoidRange(avoid, avoidRange[1])) { log.error("行走超出范围!!!任务异常 联系管理员!!!"); return false; } rgvTaskProtocol.setAvoid(1); rgvTaskProtocol.setAvoidingTheDestination(avoid); RgvTaskCache.updateRgvStatus(rgvTaskProtocol); rgvTaskProtocolOther.setAvoid(1); rgvTaskProtocolOther.setAvoidingTheDestination(avoid); RgvTaskCache.updateRgvStatus(rgvTaskProtocolOther); return true; } } else if (rgvProtocolOther.getStatusType().equals(RgvStatusType.ROAM)){ @@ -315,31 +309,25 @@ return true; } else { long avoid = targetPosition -rgvProtocol.getCarBodyJiaoMing() - avoidDistance - rgvProtocolOther.getCarBodyKunPeng(); if (avoid < trackBenchmark + rgvProtocolOther.getCarBodyJiaoMing()){ log.error("避让超出范围!!!任务异常 联系管理员!!!"); if (!new TrackRangeUtils().avoidRange(avoid, avoidRange[1])) { log.error("行走超出范围!!!任务异常 联系管理员!!!"); return false; } rgvTaskProtocol.setAvoid(1); rgvTaskProtocol.setAvoidingTheDestination(avoid); RgvTaskCache.updateRgvStatus(rgvTaskProtocol); rgvTaskProtocolOther.setAvoid(1); rgvTaskProtocolOther.setAvoidingTheDestination(avoid); RgvTaskCache.updateRgvStatus(rgvTaskProtocolOther); return true; } } else if (rgvProtocolOther.getStatusType().equals(RgvStatusType.WORKING)){ if ((targetPosition-rgvProtocol.getCarBodyJiaoMing()) - (rgvProtocolOther.getRgvPosDestination()+rgvProtocolOther.getCarBodyKunPeng()) > avoidDistance){//无需避让 return true; } else { RgvThread rgvThreadOther = (RgvThread) SlaveConnection.get(SlaveType.Rgv, rgvProtocolOther.getRgvNo()); TaskProtocolCache taskProtocolCacheOther = rgvThreadOther.getTaskProtocolCache(); List<TaskProtocol> allPutTaskProtocol = taskProtocolCacheOther.getAllPutTaskProtocol(); if (allPutTaskProtocol.size() > 1){ return false; } for (TaskProtocol taskProtocol : allPutTaskProtocol){ if (taskProtocol.getTargetPosition()<=rgvProtocolOther.getRgvPos()){ if (rgvProtocolOther.getRgvPosDestination() <= rgvProtocolOther.getRgvPos()) { long avoid = rgvProtocolOther.getRgvPos()+rgvProtocolOther.getCarBodyKunPeng()+avoidDistance+rgvProtocol.getCarBodyJiaoMing(); if (avoid < trackBenchmark + rgvProtocolOther.getCarBodyJiaoMing()){ if (!new TrackRangeUtils().avoidRange(avoid, avoidRange[0])) { log.error("行走超出范围!!!任务异常 联系管理员!!!"); return false; } @@ -347,9 +335,6 @@ rgvTaskProtocol.setAvoidingTheDestination(avoid); RgvTaskCache.updateRgvStatus(rgvTaskProtocol); return false; } else { return false; } } return false; } @@ -512,6 +497,7 @@ // array[4] = command.getDestinationStaNo(); // array[10] = taskProtocol.getCommand(); OperateResult result = siemensNet.Write("DB100.0", taskProtocol.getTaskNo()); OperateResult result1 = siemensNet.Write("DB100.1", taskProtocol.isDirection()); // 执行方向(面朝轨道 定位值左小右大) true:左 false:右 // if (taskProtocol.getAckFinish1() == 0) { // short commandFinish = 3; //工位1、2任务同时写入 @@ -537,7 +523,8 @@ null ); bean.insert(basRgvOpt); } catch (Exception ignore) {} } catch (Exception ignore) { } if (result != null && result.IsSuccess) { Thread.sleep(200); src/main/resources/application-prod.yml
@@ -43,12 +43,25 @@ carBodyJiaoMing: 100 carBodyKunPeng: 100 #RGV源站点 rgvInSStn[0]: rgvInSta[0]: devpPlcId: ${wcs-slave.devp[0].id} staNo: 100 rgvInSStn[1]: direction: true rgvInSta[1]: devpPlcId: ${wcs-slave.devp[0].id} staNo: 101 #执行方向(面朝轨道 定位值左小右大) true:左 false:右 direction: false #RGV目标站点 rgvOutSta[0]: devpPlcId: ${wcs-slave.devp[0].id} staNo: 100 direction: true rgvOutSta[1]: devpPlcId: ${wcs-slave.devp[0].id} staNo: 101 #执行方向(面朝轨道 定位值左小右大) true:左 false:右 direction: false # RGV穿梭车2 rgv[1]: id: 2 @@ -60,9 +73,22 @@ carBodyJiaoMing: 100 carBodyKunPeng: 100 #RGV源站点 rgvInSStn[0]: rgvInSta[0]: devpPlcId: ${wcs-slave.devp[0].id} staNo: 100 rgvInSStn[1]: direction: true rgvInSta[1]: devpPlcId: ${wcs-slave.devp[0].id} staNo: 101 #执行方向(面朝轨道 定位值左小右大) true:左 false:右 direction: false #RGV目标站点 rgvOutSta[0]: devpPlcId: ${wcs-slave.devp[0].id} staNo: 100 direction: true rgvOutSta[1]: devpPlcId: ${wcs-slave.devp[0].id} staNo: 101 #执行方向(面朝轨道 定位值左小右大) true:左 false:右 direction: false