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/RgvProtocol.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){ @@ -1134,42 +1177,257 @@ } if (rgvProtocolOther.statusEnable){ // if (!rgvProtocolOther.getModeType().equals(RgvModeType.AUTO) || rgvProtocolOther.getRgvPos().equals(0L)) { return true; return true; // } } return false; } private void sc(){ // 根据输送线plc遍历 public synchronized void taskStart() { for (RgvSlave rgvSlave : slaveProperties.getRgv()) { if (!deviceDetection(rgvSlave)){ continue; } RgvProtocol rgvProtocol = RgvStatusCache.getRgvStatus(rgvSlave.getId()); 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()); } } RgvProtocol rgvProtocolOther = RgvStatusCache.getRgvStatus(rgvSlave.getOtherId()); if (taskWrkList.isEmpty() || staList.isEmpty()) continue; //求出当前车可运行范围 Long[] farthestPoint = new Long[]{0L,0L}; if (!rgvProtocolOther.statusEnable){ farthestPoint = new Long[]{0L,0L}; } else { if (rgvProtocolOther.getStatusType().equals(RgvStatusType.IDLE)){ boolean sign = false; if (rgvOtherStatusEnable(rgvSlave)){ //分成上下两部分任务 List<Integer>[] avoidRange = RouteUtils.gradeRange(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); //所属部分就进取货 //筛选范围内任务 //就近排序 RgvProtocol rgvProtocolOther = RgvStatusCache.getRgvStatus(rgvSlave.getOtherId()); //筛选在范围任务 List<Integer> belongToRange = RouteUtils.belongToRange(rangeList, rgvProtocolOther.getRgvPosDestination(), basDevpPositions); for (Integer staNoNow : belongToRange){ for (RgvSlave.RgvStn rgvStn : rgvSlave.getRgvInSta()){ if (rgvStn.getStaNo().equals(staNoNow)){ TaskWrk taskWrk = deviceDetection(rgvStn); if (taskWrk!=null){ if (RouteUtils.CheckIfItIsWithinTheRange(rangeList,taskWrk.getTargetPointConvert(),basDevpPositions)){ sign = taskGenerate(rgvSlave,rgvStn,0); } } break; } } if (sign){ break; } } if (!sign){ // 筛选范围内取货任务 for (Integer staNoNow : belongToRange){ 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 : rangeList){ for (RgvSlave.RgvStn rgvStn : rgvSlave.getRgvInSta()){ if (rgvStn.getStaNo().equals(staNoNow)){ TaskWrk taskWrk = deviceDetection(rgvStn); if (taskWrk!=null){ if (RouteUtils.CheckIfItIsWithinTheRange(rangeList,taskWrk.getTargetPointConvert(),basDevpPositions)){ sign = taskGenerate(rgvSlave,rgvStn,0); } } break; } } if (sign){ break; } } } 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)){ TaskWrk taskWrk = deviceDetection(rgvStn); if (taskWrk!=null){ if (RouteUtils.CheckIfItIsWithinTheRange(rangeList,taskWrk.getTargetPointConvert(),basDevpPositions)){ sign = taskGenerate(rgvSlave,rgvStn,0); } } break; } } if (sign){ break; } } } } else { //可用区域就近取货 //就近排序 RgvProtocol rgvProtocol = RgvStatusCache.getRgvStatus(rgvSlave.getId()); List<Integer> rangeList = RouteUtils.SortNearby(staList, rgvProtocol.RgvPos, basDevpPositions); // 半边区域内取货任务 for (Integer staNoNow : rangeList){ for (RgvSlave.RgvStn rgvStn : rgvSlave.getRgvInSta()){ if (rgvStn.getStaNo().equals(staNoNow)){ sign = taskGenerate(rgvSlave,rgvStn,0); break; } } if (sign){ break; } } } } } // 遍历入库口 for (RgvSlave.RgvStn inSta : rgvSlave.getRgvInSStn()) { } 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; } } 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,56 @@ * Created by Monkey D. Luffy on 2023/7/18 */ public class RouteUtils { //排序 执行方向(面朝轨道 定位值左小右大) 0:左 小 1:右 大 public static List<Integer>[] gradeRange(List<Integer> staNoList,List<BasDevpPosition> basDevpPositions) { List<Integer>[] avoidRangeArray = new ArrayList[2]; 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); }}; return avoidRangeArray; } 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 List<Integer> belongToRange(List<Integer> staNoList,Long position,List<BasDevpPosition> basDevpPositions){ List<Integer> siteList = new ArrayList<>(); public static final List<Integer> MERGE_STA_NO_NINE = new ArrayList<Integer>() {{ return siteList; } }}; // 正序 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; //提取站点集合 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 endRoute; return siteList; } // 正序 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 List<Integer> SortNearby(List<Integer> staNoList,Long rgvNowPos,List<BasDevpPosition> basDevpPositions){ List<Integer> siteList = new ArrayList<>(); 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(); return siteList; } //检测是否在范围 public static boolean CheckIfItIsWithinTheRange(List<Integer> staNoList,Integer staNo,List<BasDevpPosition> basDevpPositions){ List<Integer> siteList = new ArrayList<>(); if (staNoList.isEmpty()){ return true; } } // /* // * 获取干涉最远站点 // * */ // 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); } 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); } } } 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/RgvProtocol.java
@@ -49,6 +49,10 @@ * RGV当前位置 */ public Long RgvPos = 0L; /** * RGV目的位置 */ public Long RgvPosDestination = 0L; /** 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; @@ -44,7 +45,7 @@ private SiemensS7Net siemensNet; private RgvSlave slave; // private RgvProtocol rgvProtocol; // private RgvProtocol rgvProtocol; private TaskProtocolCache taskProtocolCache = new TaskProtocolCache(); // # 轨道总长 private Long trackEntireLength = 100L; @@ -70,7 +71,7 @@ @SuppressWarnings("InfiniteLoopStatement") public void run() { boolean connect = this.connect(); if (connect){ if (connect) { // 启动读数据线程 new Thread(this::readStatusRgv).start(); @@ -83,7 +84,7 @@ } } private void readStatusRgv(){ private void readStatusRgv() { while (true) { try { Thread.sleep(100); @@ -91,7 +92,7 @@ readStatus(); } catch (Exception e) { log.error("RGV数据读取线程异常!!!"+e.getMessage()); log.error("RGV数据读取线程异常!!!" + e.getMessage()); initRgv(); // e.printStackTrace(); } @@ -109,7 +110,7 @@ // 休眠 1 秒 Thread.sleep(100); if (!deviceDetection()){ if (!deviceDetection()) { continue; } RgvTaskProtocol rgvTaskProtocol = RgvTaskCache.getRgvStatus(slave.getId()); @@ -130,7 +131,7 @@ RgvTaskCache.updateRgvStatus(rgvTaskProtocol); } catch (Exception e) { log.error("RGV行走任务下发线程异常!!!"+e.getMessage()); log.error("RGV行走任务下发线程异常!!!" + e.getMessage()); // e.printStackTrace(); } } @@ -144,7 +145,7 @@ try { // 休眠 1 秒 Thread.sleep(100); if (!deviceDetection()){ if (!deviceDetection()) { continue; } RgvProtocol rgvProtocol = RgvStatusCache.getRgvStatus(slave.getId()); @@ -159,36 +160,36 @@ } List<TaskProtocol> allTakeTaskProtocol = taskProtocolCache.getTakeOrPutTaskProtocol(rgvProtocol.getLoaded()); for(TaskProtocol taskProtocol: allTakeTaskProtocol){ if (taskProtocol.getIsRunning() == 1){//准备下发 for (TaskProtocol taskProtocol : allTakeTaskProtocol) { if (taskProtocol.getIsRunning() == 1) {//准备下发 RgvProtocol rgvProtocolOther = RgvStatusCache.getRgvStatus(slave.getOtherId()); //双车 if (rgvOtherStatusEnable()){ if (rgvOtherStatusEnable()) { //另一台车是否允许此台车执行 if (!otherRgvAvoid(taskProtocol.getTargetPosition())){ if (!otherRgvAvoid(taskProtocol.getTargetPosition())) { continue; } } Thread.sleep(200); Thread.sleep(100); TaskProtocol issued = new TaskProtocol(taskProtocol); write(issued); taskProtocol.setIsRunning(taskProtocol.getIsRunning() +1); taskProtocol.setIsRunning(taskProtocol.getIsRunning() + 1); taskProtocolCache.updateTaskProtocol(taskProtocol); break; } } } catch (Exception e) { log.error("RGV取货任务下发线程异常!!!"+e.getMessage()); log.error("RGV取货任务下发线程异常!!!" + e.getMessage()); // e.printStackTrace(); } } } public boolean deviceDetection(){ public boolean deviceDetection() { RgvProtocol rgvProtocol = RgvStatusCache.getRgvStatus(slave.getId()); RgvTaskProtocol rgvTaskProtocol = RgvTaskCache.getRgvStatus(slave.getId()); if (rgvProtocol == null || rgvTaskProtocol ==null) { if (rgvProtocol == null || rgvTaskProtocol == null) { return false; } if (!rgvProtocol.getModeType().equals(RgvModeType.AUTO) || rgvProtocol.getRgvPos().equals(0L) || rgvTaskProtocol.getAvoid() == -1 || rgvProtocol.getRgvPosDestination() == 0L @@ -201,20 +202,20 @@ if (rgvProtocolOther == null) { return false; } if (rgvProtocolOther.statusEnable){ if (!rgvProtocolOther.getModeType().equals(RgvModeType.AUTO) || rgvProtocolOther.getRgvPos().equals(0L) || rgvTaskProtocolOther.getAvoid() == -1 || rgvProtocolOther.getRgvPosDestination() == 0L) { if (rgvProtocolOther.statusEnable) { if (!rgvProtocolOther.getModeType().equals(RgvModeType.AUTO) || rgvProtocolOther.getRgvPos().equals(0L) || rgvTaskProtocolOther.getAvoid() == -1 || rgvProtocolOther.getRgvPosDestination() == 0L) { return false; } } return true; } public boolean rgvOtherStatusEnable(){ public boolean rgvOtherStatusEnable() { RgvProtocol rgvProtocolOther = RgvStatusCache.getRgvStatus(slave.getOtherId()); if (rgvProtocolOther == null) { return true; } if (rgvProtocolOther.statusEnable){ if (rgvProtocolOther.statusEnable) { // if (!rgvProtocolOther.getModeType().equals(RgvModeType.AUTO) || rgvProtocolOther.getRgvPos().equals(0L)) { return true; // } @@ -222,134 +223,118 @@ return false; } public boolean otherRgvAvoid(Long targetPosition){ public boolean otherRgvAvoid(Long targetPosition) { RgvProtocol rgvProtocol = RgvStatusCache.getRgvStatus(slave.getId()); 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 (rgvProtocolOther.getStatusType().equals(RgvStatusType.IDLE)){ if ((rgvProtocolOther.getRgvPos()-rgvProtocolOther.getCarBodyJiaoMing()) - (targetPosition+rgvProtocol.getCarBodyKunPeng()) > avoidDistance){//无需避让 if (new TrackRangeUtils().IsItSmall(slave)) { if (rgvProtocolOther.getStatusType().equals(RgvStatusType.IDLE)) { if ((rgvProtocolOther.getRgvPos() - rgvProtocolOther.getCarBodyJiaoMing()) - (targetPosition + rgvProtocol.getCarBodyKunPeng()) > avoidDistance) {//无需避让 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)){ if ((rgvProtocolOther.getRgvPosDestination()-rgvProtocolOther.getCarBodyJiaoMing()) - (targetPosition+rgvProtocol.getCarBodyKunPeng()) > avoidDistance){//无需避让 } else if (rgvProtocolOther.getStatusType().equals(RgvStatusType.ROAM)) { if ((rgvProtocolOther.getRgvPosDestination() - rgvProtocolOther.getCarBodyJiaoMing()) - (targetPosition + rgvProtocol.getCarBodyKunPeng()) > avoidDistance) {//无需避让 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)){ if ((rgvProtocolOther.getRgvPosDestination()-rgvProtocolOther.getCarBodyJiaoMing()) - (targetPosition+rgvProtocol.getCarBodyKunPeng()) > avoidDistance){//无需避让 } else if (rgvProtocolOther.getStatusType().equals(RgvStatusType.WORKING)) { if ((rgvProtocolOther.getRgvPosDestination() - rgvProtocolOther.getCarBodyJiaoMing()) - (targetPosition + rgvProtocol.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()){ long avoid = rgvProtocolOther.getRgvPos()-rgvProtocolOther.getCarBodyJiaoMing()-avoidDistance-rgvProtocol.getCarBodyKunPeng(); if (avoid > trackEntireLength-rgvProtocolOther.getCarBodyKunPeng()){ log.error("行走超出范围!!!任务异常 联系管理员!!!"); return false; } rgvTaskProtocol.setAvoid(1); rgvTaskProtocol.setAvoidingTheDestination(avoid); RgvTaskCache.updateRgvStatus(rgvTaskProtocol); return false; } else { if (rgvProtocolOther.getRgvPosDestination() >= rgvProtocolOther.getRgvPos()) { long avoid = rgvProtocolOther.getRgvPos() - rgvProtocolOther.getCarBodyJiaoMing() - avoidDistance - rgvProtocol.getCarBodyKunPeng(); if (!new TrackRangeUtils().avoidRange(avoid, avoidRange[1])) { log.error("行走超出范围!!!任务异常 联系管理员!!!"); return false; } rgvTaskProtocol.setAvoid(1); rgvTaskProtocol.setAvoidingTheDestination(avoid); RgvTaskCache.updateRgvStatus(rgvTaskProtocol); return false; } return false; } } } else { if (rgvProtocolOther.getStatusType().equals(RgvStatusType.IDLE)){ if ((targetPosition-rgvProtocol.getCarBodyJiaoMing()) - (rgvProtocolOther.getRgvPos()+rgvProtocolOther.getCarBodyKunPeng()) > avoidDistance){//无需避让 if (rgvProtocolOther.getStatusType().equals(RgvStatusType.IDLE)) { if ((targetPosition - rgvProtocol.getCarBodyJiaoMing()) - (rgvProtocolOther.getRgvPos() + rgvProtocolOther.getCarBodyKunPeng()) > avoidDistance) {//无需避让 return true; } else { long avoid = targetPosition -rgvProtocol.getCarBodyJiaoMing() - avoidDistance - rgvProtocolOther.getCarBodyKunPeng(); if (avoid < trackBenchmark + rgvProtocolOther.getCarBodyJiaoMing()){ log.error("避让超出范围!!!任务异常 联系管理员!!!"); long avoid = targetPosition - rgvProtocol.getCarBodyJiaoMing() - avoidDistance - rgvProtocolOther.getCarBodyKunPeng(); 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)){ if ((targetPosition-rgvProtocol.getCarBodyJiaoMing()) - (rgvProtocolOther.getRgvPosDestination()+rgvProtocolOther.getCarBodyKunPeng()) > avoidDistance){//无需避让 } else if (rgvProtocolOther.getStatusType().equals(RgvStatusType.ROAM)) { if ((targetPosition - rgvProtocol.getCarBodyJiaoMing()) - (rgvProtocolOther.getRgvPosDestination() + rgvProtocolOther.getCarBodyKunPeng()) > avoidDistance) {//无需避让 return true; } else { long avoid = targetPosition -rgvProtocol.getCarBodyJiaoMing() - avoidDistance - rgvProtocolOther.getCarBodyKunPeng(); if (avoid < trackBenchmark + rgvProtocolOther.getCarBodyJiaoMing()){ log.error("避让超出范围!!!任务异常 联系管理员!!!"); long avoid = targetPosition - rgvProtocol.getCarBodyJiaoMing() - avoidDistance - rgvProtocolOther.getCarBodyKunPeng(); 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){//无需避让 } 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()){ long avoid = rgvProtocolOther.getRgvPos()+rgvProtocolOther.getCarBodyKunPeng()+avoidDistance+rgvProtocol.getCarBodyJiaoMing(); if (avoid < trackBenchmark + rgvProtocolOther.getCarBodyJiaoMing()){ log.error("行走超出范围!!!任务异常 联系管理员!!!"); return false; } rgvTaskProtocol.setAvoid(1); rgvTaskProtocol.setAvoidingTheDestination(avoid); RgvTaskCache.updateRgvStatus(rgvTaskProtocol); return false; } else { if (rgvProtocolOther.getRgvPosDestination() <= rgvProtocolOther.getRgvPos()) { long avoid = rgvProtocolOther.getRgvPos() + rgvProtocolOther.getCarBodyKunPeng() + avoidDistance + rgvProtocol.getCarBodyJiaoMing(); if (!new TrackRangeUtils().avoidRange(avoid, avoidRange[0])) { log.error("行走超出范围!!!任务异常 联系管理员!!!"); return false; } rgvTaskProtocol.setAvoid(1); rgvTaskProtocol.setAvoidingTheDestination(avoid); RgvTaskCache.updateRgvStatus(rgvTaskProtocol); return false; } return false; } @@ -368,25 +353,25 @@ rgvProtocol.setRgvNo(slave.getId()); } rgvProtocol.setMode((short) -1); rgvProtocol.setStatus((short)-1); rgvProtocol.setWalkPos((short)0); rgvProtocol.setStatus((short) -1); rgvProtocol.setWalkPos((short) 0); rgvProtocol.setRgvPos(0L); rgvProtocol.setAlarm((short)0); rgvProtocol.setAlarm((short) 0); rgvProtocol.setxSpeed((short) 0); rgvProtocol.setxDistance((short) 0); rgvProtocol.setxDuration((short) 0); rgvProtocol.setCarBodyJiaoMing(0L); rgvProtocol.setCarBodyKunPeng(0L); try{ try { BasRgvService basRgvService = SpringUtils.getBean(BasRgvService.class); BasRgv rgv = basRgvService.selectById(slave.getId()); if (!Cools.isEmpty(rgv)){ if (!Cools.isEmpty(rgv)) { rgvProtocol.setStatusEnable(rgv.getStatus() == 1); } else { rgvProtocol.setStatusEnable(false); } } catch (Exception e){ log.error("RGV异常!!!"+e.getMessage()); } catch (Exception e) { log.error("RGV异常!!!" + e.getMessage()); rgvProtocol.setStatusEnable(true); } @@ -411,7 +396,7 @@ siemensNet.setRack(slave.getRack().byteValue()); siemensNet.setSlot(slave.getSlot().byteValue()); OperateResult connect = siemensNet.ConnectServer(); if(connect.IsSuccess){ if (connect.IsSuccess) { result = true; // OutputQueue.RGV.offer(MessageFormat.format( "【{0}】RGV plc连接成功 ===>> [id:{1}] [ip:{2}] [port:{3}] [rack:{4}] [slot:{5}]", DateUtils.convert(new Date()), slave.getId(), slave.getIp(), slave.getPort(), slave.getRack(), slave.getSlot())); log.info("RGV plc连接成功 ===>> [id:{}] [ip:{}] [port:{}] [rack:{}] [slot:{}]", slave.getId(), slave.getIp(), slave.getPort(), slave.getRack(), slave.getSlot()); @@ -428,7 +413,7 @@ /** * 读取状态 */ private void readStatus(){ private void readStatus() { try { OperateResultExOne<byte[]> result = siemensNet.Read("DB101.0", (short) 34); if (result.IsSuccess) { @@ -446,7 +431,7 @@ // rgvProtocol.setxDistance(siemensNet.getByteTransform().TransInt16(result.Content, 40)); // rgvProtocol.setxDuration(siemensNet.getByteTransform().TransInt16(result.Content, 48)); OutputQueue.RGV.offer(MessageFormat.format("【{0}】[id:{1}] <<<<< 实时数据更新成功",DateUtils.convert(new Date()), slave.getId())); OutputQueue.RGV.offer(MessageFormat.format("【{0}】[id:{1}] <<<<< 实时数据更新成功", DateUtils.convert(new Date()), slave.getId())); // // 工位1复位信号 // if (rgvProtocol.getStatusType().equals(RgvStatusType.WAITING) // || rgvProtocol.getStatusType().equals(RgvStatusType.FETCHWAITING)) { @@ -463,18 +448,18 @@ // 根据实时信息更新数据库 BasRgvService basRgvService = SpringUtils.getBean(BasRgvService.class); BasRgv basRgv = basRgvService.selectById(slave.getId()); if (!Cools.isEmpty(basRgv)){ if (!Cools.isEmpty(basRgv)) { rgvProtocol.setStatusEnable(basRgv.getStatus() == 1); } else { rgvProtocol.setStatusEnable(false); } // BasRgv basRgv = new BasRgv(); basRgv.setRgvNo(slave.getId()); basRgv.setRgvSts((int)rgvProtocol.getMode()); if (!basRgvService.updateById(rgvProtocol.toSqlModel(basRgv))){ basRgv.setRgvSts((int) rgvProtocol.getMode()); if (!basRgvService.updateById(rgvProtocol.toSqlModel(basRgv))) { log.error("RGV plc数据库更新失败 ===>> [id:{}] [ip:{}] [port:{}] [rack:{}] [slot:{}]", slave.getId(), slave.getIp(), slave.getPort(), slave.getRack(), slave.getSlot()); } } catch (Exception ignore){ } catch (Exception ignore) { } @@ -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任务同时写入 @@ -531,13 +517,14 @@ null, null, null, result.IsSuccess? 1 : 0, result.IsSuccess ? 1 : 0, null, new Date(), 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 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