| | |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.baomidou.mybatisplus.mapper.EntityWrapper; |
| | | import com.baomidou.mybatisplus.mapper.Wrapper; |
| | | import com.core.common.Cools; |
| | | import com.core.common.DateUtils; |
| | | import com.core.common.R; |
| | | import com.core.exception.CoolException; |
| | | import com.zy.asrs.domain.enums.WorkNoType; |
| | | import com.zy.asrs.entity.*; |
| | | import com.zy.asrs.mapper.*; |
| | | import com.zy.asrs.service.*; |
| | | import com.zy.asrs.utils.*; |
| | | import com.zy.common.model.LocTypeDto; |
| | | import com.zy.common.model.MatDto; |
| | | import com.zy.common.model.SearchLocParam; |
| | | import com.zy.common.model.StartupDto; |
| | | import com.zy.asrs.service.BasCircularShuttleService; |
| | | import com.zy.asrs.service.BasDevpPositionService; |
| | | import com.zy.asrs.service.WrkMastService; |
| | | import com.zy.asrs.task.core.ReturnT; |
| | | import com.zy.asrs.task.escalationParam.RgvTaskReportingParam; |
| | | import com.zy.asrs.utils.PostMesDataUtils; |
| | | import com.zy.asrs.utils.SortTheExecutionOfTheCarUtil; |
| | | import com.zy.asrs.utils.TimeCalculatorUtils; |
| | | import com.zy.common.CodeRes; |
| | | import com.zy.common.service.CommonService; |
| | | import com.zy.common.utils.CollectionUtils; |
| | | import com.zy.common.utils.HttpHandler; |
| | | import com.zy.common.utils.RedisUtil; |
| | | import com.zy.common.utils.RgvUtils; |
| | | import com.zy.core.CrnThread; |
| | | import com.zy.core.DevpThread; |
| | | import com.zy.core.Slave; |
| | | import com.zy.core.cache.MessageQueue; |
| | | import com.zy.core.cache.SlaveConnection; |
| | | import com.zy.core.enums.*; |
| | | import com.zy.core.model.*; |
| | | import com.zy.core.model.command.*; |
| | | import com.zy.core.model.cpmmandParam.CrnCommandParam; |
| | | import com.zy.core.model.protocol.*; |
| | | import com.zy.core.model.RgvSlave; |
| | | import com.zy.core.model.Task; |
| | | import com.zy.core.model.command.RgvCommand; |
| | | import com.zy.core.model.protocol.RgvProtocol; |
| | | import com.zy.core.properties.SlaveProperties; |
| | | import com.zy.core.thread.*; |
| | | import com.zy.core.thread.RgvThread; |
| | | import com.zy.system.entity.license.LicenseVerify; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.springframework.transaction.interceptor.TransactionAspectSupport; |
| | | import springfox.documentation.spring.web.json.Json; |
| | | |
| | | import java.util.*; |
| | | import java.util.concurrent.TimeUnit; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | | * 立体仓库WCS系统主流程业务 |
| | | * Created by vincent on 2020/8/6 |
| | | * Created by IX on 2024/10/01 |
| | | */ |
| | | @Slf4j |
| | | @Service("mainService") |
| | | @Transactional |
| | | public class MainServiceImpl { |
| | | |
| | | public static final long COMMAND_TIMEOUT = 5 * 1000; |
| | | // private static final int[][] execute = new int[][]{{1,4},{2,4},{3,4},{4,4},{5,6},{6,6},{7,4},{8,4},{9,3},{10,4},{11,4}}; |
| | | private static final int[][] execute = new int[][]{{1,4},{2,4},{3,4},{4,4},{5,6},{6,6},{7,4},{8,4},{9,3},{10,4},{11,4}}; |
| | | |
| | | private static final Integer jarMaxLoc = 7; |
| | | private static final Float jarTemperature = 50F; |
| | | @Autowired |
| | | private CommonService commonService; |
| | | @Autowired |
| | | private SlaveProperties slaveProperties; |
| | | @Autowired |
| | | private WrkMastMapper wrkMastMapper; |
| | | private BasRgvServiceImpl basRgvService; |
| | | @Autowired |
| | | private WrkDetlService wrkDetlService; |
| | | private BasDevpPositionService basDevpPositionService; |
| | | @Autowired |
| | | private WaitPakinMapper waitPakinMapper; |
| | | private BasCircularShuttleService basCircularShuttleService; |
| | | @Autowired |
| | | private LocMastService locMastService; |
| | | private WrkMastService wrkMastService; |
| | | @Autowired |
| | | private StaDescService staDescService; |
| | | @Autowired |
| | | private BasCrnpService basCrnpService; |
| | | @Autowired |
| | | private BasRgvService basRgvService; |
| | | @Autowired |
| | | private BasDevpService basDevpService; |
| | | @Autowired |
| | | private LocDetlService locDetlService; |
| | | @Autowired |
| | | private BasErrLogService basErrLogService; |
| | | @Autowired |
| | | private BasCrnErrorMapper basCrnErrorMapper; |
| | | @Autowired |
| | | private BasRgvErrMapper basRgvErrMapper; |
| | | @Autowired |
| | | private BasRgvErrLogService basRgvErrLogService; |
| | | @Autowired |
| | | private BasRgvPathService basRgvPathService; |
| | | @Autowired |
| | | private RedisUtil redisUtil; |
| | | @Autowired |
| | | private WrkMastStaMapper wrkMastStaMapper; |
| | | @Autowired |
| | | private BasRgvMapMapper basRgvMapMapper; |
| | | @Autowired |
| | | private RgvOneSignMapper rgvOneSignMapper; |
| | | @Autowired |
| | | private WrkMastCrnMapper wrkMastCrnMapper; |
| | | @Autowired |
| | | private WrkMastSplitTwinMapper wrkMastSplitTwinMapper; |
| | | @Autowired |
| | | private WrkMastSplitTwinService wrkMastSplitTwinService; |
| | | @Autowired |
| | | private BasJarMastService basJarMastService; |
| | | @Autowired |
| | | private WrkMastExecuteService wrkMastExecuteService; |
| | | @Autowired |
| | | private BasJarService basJarService; |
| | | @Autowired |
| | | private BasJarMapper basJarMapper; |
| | | private CommonService commonService; |
| | | |
| | | @Value("${constant-parameters.taskRunPerimeter}") |
| | | private Long taskRunPerimeter; |
| | | @Value("${constant-parameters.perimeter}") |
| | | private Long perimeter; |
| | | @Value("${constant-parameters.proportion}") |
| | | private Long proportion; |
| | | @Value("${constant-parameters.acceleration}") |
| | | private Long acceleration; |
| | | @Value("${constant-parameters.rgvCount}") |
| | | private Long rgvCount; |
| | | @Value("${constant-parameters.rgvDate}") |
| | | private Double rgvDate; |
| | | @Value("${wms.url}") |
| | | private String wmsUrl; |
| | | @Value("${wms.reportOutPath}") |
| | | private String wmsOutPath; |
| | | @Value("${wms.reportSwitch}") |
| | | private boolean reportSwitch; |
| | | @Value("${wms.reportSwitchAuto}") |
| | | private boolean reportSwitchAuto; |
| | | |
| | | /* |
| | | * 验证许可证是否有效 |
| | | * */ |
| | | public synchronized boolean licenseVerify() { |
| | | try{ |
| | | // if (true) { |
| | | // return true; |
| | | // } |
| | | return new LicenseVerify().verify(); |
| | | } catch (Exception e){ |
| | | log.info("许可证验证失败!!异常:{}",e.getMessage()); |
| | | } |
| | | return false; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 站点任务检测 更新小车位置信息 |
| | | */ |
| | | public synchronized void updateStePositionNearby() { |
| | | try { |
| | | List<WrkMast> wrkMasts = wrkMastService.selectList(new EntityWrapper<WrkMast>().eq("wrk_sts", 1L)); |
| | | if (wrkMasts.isEmpty()) { |
| | | return; |
| | | } |
| | | List<BasDevpPosition> basDevpPositions = basDevpPositionService.selectList(new EntityWrapper<BasDevpPosition>().orderBy("plc_position", true)); |
| | | if (basDevpPositions.isEmpty()) { |
| | | log.error("获取所有站点信息异常"); |
| | | return; |
| | | } |
| | | // List<Integer> siteList = SortTheExecutionOfTheCarUtil.WrkMastExtractSites(wrkMasts); |
| | | // List<Integer> devpList = SortTheExecutionOfTheCarUtil.BasDevpPositionExtractSites(basDevpPositions); |
| | | // Integer siteNo = SortTheExecutionOfTheCarUtil.ObtainDenseAreasFirstPlace(siteList, devpList); |
| | | // if (siteNo == null) { |
| | | // log.error("就近密集原则获取站点失败"); |
| | | // return; |
| | | // } |
| | | Integer siteNo = 110; |
| | | Long sitePosition = 0L; |
| | | for (BasDevpPosition basDevpPosition : basDevpPositions) { |
| | | if (basDevpPosition.getDevNo().equals(siteNo)) { |
| | | sitePosition = basDevpPosition.getPlcPosition(); |
| | | break; |
| | | } |
| | | } |
| | | List<List<Long>> rgvPositionList = new ArrayList<>(); |
| | | for (RgvSlave rgvSlave : slaveProperties.getRgv()) { |
| | | RgvThread rgvThread = (RgvThread) SlaveConnection.get(SlaveType.Rgv, rgvSlave.getId()); |
| | | RgvProtocol rgvProtocol = rgvThread.getRgvProtocol(); |
| | | if (rgvProtocol == null) { |
| | | continue; |
| | | } |
| | | List<Long> rgvPosition = new ArrayList<>(); |
| | | rgvPosition.add(rgvProtocol.getRgvNo().longValue()); |
| | | rgvPosition.add(rgvProtocol.getRgvPos()); |
| | | rgvPositionList.add(rgvPosition); |
| | | } |
| | | Integer rgvNo = SortTheExecutionOfTheCarUtil.LatelyAndGreaterThan(rgvPositionList, sitePosition, perimeter); |
| | | if (rgvNo == -1) { |
| | | log.info("更新小车排序信息异常={}", rgvNo); |
| | | return; |
| | | } |
| | | List<BasCircularShuttle> basCircularShuttleList = basCircularShuttleService.selectList(new EntityWrapper<BasCircularShuttle>().eq("status", 0).orderBy("rgv_id", true)); |
| | | if (basCircularShuttleList.get(0).getRgvNo().equals(rgvNo)) { |
| | | return; |
| | | } |
| | | |
| | | int[][] ints = new int[basCircularShuttleList.size()][2]; |
| | | for (BasCircularShuttle basCircularShuttle : basCircularShuttleList) { |
| | | ints[basCircularShuttle.getRgvNo() - 1] = new int[]{basCircularShuttle.getRgvNo(), basCircularShuttle.getRgvId()}; |
| | | } |
| | | // String[] oldList = new String[ints.length]; |
| | | // for (int[] rgv : ints){ |
| | | // oldList[rgv[0]-1] = Arrays.toString(rgv); |
| | | // } |
| | | int[][] rgvList = SortTheExecutionOfTheCarUtil.ReorderSteId(ints, rgvNo); |
| | | // String[] newList = new String[rgvList.length]; |
| | | // for (int[] rgv : rgvList){ |
| | | // newList[rgv[0]-1] = Arrays.toString(rgv); |
| | | // } |
| | | |
| | | // log.info("更新小车排序信息:原始小车号rgvNo={},小车重新排序信息={},小车原始排序信息={}",rgvNo,Arrays.toString(newList),Arrays.toString(oldList)); |
| | | for (BasCircularShuttle basCircularShuttle : basCircularShuttleList) { |
| | | int[] rgv = rgvList[basCircularShuttle.getRgvNo() - 1]; |
| | | basCircularShuttle.setRgvId(rgv[1]); |
| | | basCircularShuttleService.updateById(basCircularShuttle); |
| | | } |
| | | |
| | | } catch (Exception e) { |
| | | log.error("自动更新小车排序信息失败,异常:" + e); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 站点任务检测 更新小车位置信息 |
| | | */ |
| | | public synchronized void updateStePosition() { |
| | | try { |
| | | boolean sign = false; |
| | | Integer rgvNo = 0; |
| | | List<BasCircularShuttle> basCircularShuttleList = basCircularShuttleService.selectList(new EntityWrapper<BasCircularShuttle>().orderBy("rgv_id", true)); |
| | | for (BasCircularShuttle basCircularShuttle : basCircularShuttleList) { |
| | | if (basCircularShuttle.getStatus() != 0){ |
| | | sign = true; |
| | | continue; |
| | | } |
| | | RgvThread rgvThread = (RgvThread) SlaveConnection.get(SlaveType.Rgv, basCircularShuttle.getRgvNo()); |
| | | RgvProtocol rgvProtocol = rgvThread.getRgvProtocol(); |
| | | if (rgvProtocol == null) { |
| | | sign = true; |
| | | } else if (rgvProtocol.modeType != RgvModeType.AUTO || (rgvProtocol.getStatusType() != RgvStatusType.IDLE && rgvProtocol.getStatusType() != RgvStatusType.ROAM && rgvProtocol.getStatusType() != RgvStatusType.WALK)) { |
| | | sign = true; |
| | | } else { |
| | | rgvNo = basCircularShuttle.getRgvNo(); |
| | | break; |
| | | } |
| | | } |
| | | if (sign && rgvNo != 0) { |
| | | int[][] ints = new int[basCircularShuttleList.size()][2]; |
| | | for (BasCircularShuttle basCircularShuttle : basCircularShuttleList) { |
| | | ints[basCircularShuttle.getRgvNo() - 1] = new int[]{basCircularShuttle.getRgvNo(), basCircularShuttle.getRgvId()}; |
| | | } |
| | | // String[] oldList = new String[ints.length]; |
| | | // for (int[] rgv : ints){ |
| | | // oldList[rgv[0]-1] = Arrays.toString(rgv); |
| | | // } |
| | | int[][] rgvList = SortTheExecutionOfTheCarUtil.ReorderSteId(ints, rgvNo); |
| | | // String[] newList = new String[rgvList.length]; |
| | | // for (int[] rgv : rgvList){ |
| | | // newList[rgv[0]-1] = Arrays.toString(rgv); |
| | | // } |
| | | |
| | | // log.info("更新小车排序信息:原始小车号rgvNo={},小车重新排序信息={},小车原始排序信息={}",rgvNo,Arrays.toString(newList),Arrays.toString(oldList)); |
| | | for (BasCircularShuttle basCircularShuttle : basCircularShuttleList) { |
| | | int[] rgv = rgvList[basCircularShuttle.getRgvNo() - 1]; |
| | | basCircularShuttle.setRgvId(rgv[1]); |
| | | basCircularShuttleService.updateById(basCircularShuttle); |
| | | } |
| | | } |
| | | |
| | | } catch (Exception e) { |
| | | log.error("自动更新小车排序信息失败,异常:" + e); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 站点任务检测 下发小车取放任务 |
| | | */ |
| | | public synchronized void DevpTaskNoRun() { |
| | | try { |
| | | List<WrkMast> wrkMasts = wrkMastService.selectList(new EntityWrapper<WrkMast>().eq("wrk_sts", 1L).orderBy("modi_time", true)); |
| | | if (wrkMasts.isEmpty()) { |
| | | return; |
| | | } |
| | | long differenceInSeconds = TimeCalculatorUtils.differenceInMilliseconds(wrkMasts.get(0).getModiTime(), new Date()); |
| | | if (differenceInSeconds <= 100) { |
| | | return; |
| | | } |
| | | |
| | | BasCircularShuttle basCircularShuttle = basCircularShuttleService.selectOne(new EntityWrapper<BasCircularShuttle>().eq("rgv_id", 1)); |
| | | RgvThread rgvThread = (RgvThread) SlaveConnection.get(SlaveType.Rgv, basCircularShuttle.getRgvNo()); |
| | | RgvProtocol rgvProtocol = rgvThread.getRgvProtocol(); |
| | | if (rgvProtocol == null) { |
| | | return; |
| | | } |
| | | List<BasDevpPosition> basDevpPositions = basDevpPositionService.selectList(new EntityWrapper<BasDevpPosition>().orderBy("plc_position", true)); |
| | | List<BasDevpPosition> basDevpPositionDevRegion = basDevpPositionService.selectList(new EntityWrapper<BasDevpPosition>().orderBy("dev_region", true)); |
| | | Integer devNo = SortTheExecutionOfTheCarUtil.LatelyAndLessThan(basDevpPositions, rgvProtocol.getRgvPos(), perimeter); |
| | | BasDevpPosition[] basDevpPositionsList = SortTheExecutionOfTheCarUtil.devpNoSort(basDevpPositions, devNo); |
| | | BasDevpPosition[] basDevpPositionsListUN = SortTheExecutionOfTheCarUtil.devpNoSortUN(basDevpPositionsList); |
| | | List<List<Integer>> siteListAll = SortTheExecutionOfTheCarUtil.siteListAll(basDevpPositionDevRegion); |
| | | // List<List<WrkMast>> wrkMastLists = getWrkMastLists(basDevpPositionsListUN); |
| | | List<List<List<WrkMast>>> wrkMastListAll = getWrkMastListAll(siteListAll,basDevpPositionsListUN); |
| | | //下发任务 |
| | | // taskDown(wrkMastLists); |
| | | taskDown(wrkMastListAll); |
| | | } catch (Exception e) { |
| | | log.error("自动下发小车取放任务失败,异常:" + e); |
| | | } |
| | | } |
| | | |
| | | //获取小车取放任务列表失败 |
| | | public synchronized List<List<List<WrkMast>>> getWrkMastListAll(List<List<Integer>> siteListAll ,BasDevpPosition[] basDevpPositionsListUN) { |
| | | List<List<List<WrkMast>>> wrkMastListAll = new ArrayList<>(); |
| | | for (List<Integer> siteList : siteListAll){ |
| | | List<List<WrkMast>> wrkMastLists = new ArrayList<>(); |
| | | try { |
| | | List<WrkMast> wrkMastlistA = new ArrayList<>(); |
| | | List<WrkMast> wrkMastlistB = new ArrayList<>(); |
| | | for (BasDevpPosition basDevpPosition : basDevpPositionsListUN) { |
| | | List<WrkMast> wrkMastList = wrkMastService.selectList(new EntityWrapper<WrkMast>().eq("sta_no", basDevpPosition.getDevNo()).eq("wrk_sts", 1L).orderBy("modi_time", true)); |
| | | for (WrkMast wrkMast : wrkMastList) { |
| | | if (!Cools.isEmpty(wrkMast)) { |
| | | if (siteList.contains(wrkMast.getSourceStaNo())){ |
| | | if (SortTheExecutionOfTheCarUtil.devpNoSortbj(basDevpPositionsListUN, wrkMast.getSourceStaNo(), wrkMast.getStaNo())) { |
| | | wrkMastlistA.add(wrkMast); |
| | | } else { |
| | | wrkMastlistB.add(wrkMast); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | wrkMastLists.add(wrkMastlistA); |
| | | wrkMastLists.add(wrkMastlistB); |
| | | // return wrkMastLists; |
| | | wrkMastListAll.add(wrkMastLists); |
| | | } catch (Exception e) { |
| | | log.error("获取小车取放任务列表失败,异常:" + e); |
| | | } |
| | | } |
| | | return wrkMastListAll; |
| | | } |
| | | |
| | | //获取小车取放任务列表失败 |
| | | public synchronized List<List<WrkMast>> getWrkMastLists(BasDevpPosition[] basDevpPositionsListUN) { |
| | | List<List<WrkMast>> wrkMastLists = new ArrayList<>(); |
| | | try { |
| | | List<WrkMast> wrkMastlistA = new ArrayList<>(); |
| | | List<WrkMast> wrkMastlistB = new ArrayList<>(); |
| | | for (BasDevpPosition basDevpPosition : basDevpPositionsListUN) { |
| | | List<WrkMast> wrkMastList = wrkMastService.selectList(new EntityWrapper<WrkMast>().eq("sta_no", basDevpPosition.getDevNo()).eq("wrk_sts", 1L).orderBy("modi_time", true)); |
| | | for (WrkMast wrkMast : wrkMastList) { |
| | | if (!Cools.isEmpty(wrkMast)) { |
| | | if (SortTheExecutionOfTheCarUtil.devpNoSortbj(basDevpPositionsListUN, wrkMast.getSourceStaNo(), wrkMast.getStaNo())) { |
| | | wrkMastlistA.add(wrkMast); |
| | | } else { |
| | | wrkMastlistB.add(wrkMast); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | wrkMastLists.add(wrkMastlistA); |
| | | wrkMastLists.add(wrkMastlistB); |
| | | return wrkMastLists; |
| | | } catch (Exception e) { |
| | | log.error("获取小车取放任务列表失败,异常:" + e); |
| | | return wrkMastLists; |
| | | } |
| | | } |
| | | |
| | | // public synchronized void taskDown(List<List<WrkMast>> wrkMastLists) { |
| | | // long rgvId = 0; |
| | | // runRgv: |
| | | // for (List<WrkMast> wrkMastList : wrkMastLists) { |
| | | // for (WrkMast wrkMast : wrkMastList) { |
| | | // while (rgvId <= rgvCount) { |
| | | // rgvId++; |
| | | //// log.info("存在任务,RGV号={},任务数据={}", rgvId, JSON.toJSON(wrkMast)); |
| | | // if (rgvId > rgvCount) { |
| | | // break runRgv; |
| | | // } |
| | | // BasCircularShuttle basCircularShuttle = basCircularShuttleService.selectOne(new EntityWrapper<BasCircularShuttle>().eq("rgv_id", rgvId)); |
| | | // if (basCircularShuttle.getStatus() != 0){ |
| | | // continue ; |
| | | // } |
| | | // RgvThread rgvThread = (RgvThread) SlaveConnection.get(SlaveType.Rgv, basCircularShuttle.getRgvNo()); |
| | | // RgvProtocol rgvProtocol = rgvThread.getRgvProtocol(); |
| | | // if (rgvProtocol == null) { |
| | | // continue; |
| | | // } |
| | | // |
| | | // List<WrkMast> wrkMasts = wrkMastService.selectList(new EntityWrapper<WrkMast>().eq("rgv_no", rgvProtocol.getRgvNo()).eq("wrk_sts", 2L)); |
| | | // if (!wrkMasts.isEmpty()) { |
| | | // continue; |
| | | // } |
| | | // if (rgvProtocol != null |
| | | // && rgvProtocol.modeType == RgvModeType.AUTO |
| | | // && (rgvProtocol.getStatusType() == RgvStatusType.IDLE || rgvProtocol.getStatusType() == RgvStatusType.ROAM) |
| | | // && rgvProtocol.getTaskNo1() == 0 |
| | | // && rgvProtocol.getAlarm() == 0) { |
| | | // if (rgvProtocol.getStatusType() == RgvStatusType.ROAM) { |
| | | // double finalVelocity = 0.0; // 最终速度 (m/s) |
| | | // double distance = (Math.pow(finalVelocity, 2) - Math.pow(rgvProtocol.instantaneousSpeed / 60, 2)) / (2 * acceleration); |
| | | // BasDevpPosition basDevpPosition = basDevpPositionService.selectOne(new EntityWrapper<BasDevpPosition>().eq("dev_no", wrkMast.getSourceStaNo())); |
| | | // if ((distance * proportion + (rgvProtocol.instantaneousSpeed / 60) * proportion * rgvDate) > (SortTheExecutionOfTheCarUtil.LatelyAndLessThan(basDevpPosition.getPlcPosition(), rgvProtocol.getRgvPos(), perimeter) )) { |
| | | //// List<BasDevpPosition> basDevpPositions = basDevpPositionService.selectList(new EntityWrapper<BasDevpPosition>().orderBy("plc_position", true)); |
| | | //// if (basDevpPositions.isEmpty()) { |
| | | //// log.error("获取所有站点信息异常,RGV任务下发失败,请联系管理员!!!"); |
| | | //// break runRgv; |
| | | //// } |
| | | //// List<Integer> devpList = SortTheExecutionOfTheCarUtil.BasDevpPositionExtractSites(basDevpPositions); |
| | | //// |
| | | //// if (!SortTheExecutionOfTheCarUtil.calculateShortestDistanceDirection(devpList,rgvProtocol.getEndStaM(),wrkMast.getSourceStaNo())){ |
| | | // continue; |
| | | //// } |
| | | // } |
| | | // } |
| | | // RgvCommand rgvCommand = new RgvCommand(); |
| | | // rgvCommand.setRgvNo(rgvProtocol.getRgvNo()); |
| | | // rgvCommand.setAckFinish1((short) 0); // 工位1任务完成确认位 |
| | | // rgvCommand.setTaskNo1(wrkMast.getWrkNo().shortValue()); |
| | | // rgvCommand.setTaskMode1(RgvTaskModeType.FETCH_PUT); // 工位1任务模式: 取放货 |
| | | // rgvCommand.setSourceStaNo1(wrkMast.getSourceStaNo().shortValue()); //工位1起点 |
| | | // rgvCommand.setDestinationStaNo1(wrkMast.getStaNo().shortValue()); //工位1目标站点 |
| | | // rgvCommand.setCommand((short) 1); //工位1任务确认 |
| | | // rgvCommand.setRgvSome(basCircularShuttle.getRgvSome()==1 ? (short) 1 : (short) 0); |
| | | // if (!MessageQueue.offer(SlaveType.Rgv, rgvProtocol.getRgvNo(), new Task(2, rgvCommand))) { |
| | | // // |
| | | // log.error("RGV命令下发失败,RGV号={},任务数据={}", rgvId, JSON.toJSON(rgvCommand)); |
| | | // break runRgv; |
| | | // } |
| | | // log.info("RGV命令下发成功,RGV号={},任务数据={}", rgvId, JSON.toJSON(rgvCommand)); |
| | | // |
| | | // wrkMast.setWrkSts(2L); |
| | | // wrkMast.setRgvNo(rgvProtocol.getRgvNo()); |
| | | // Date now = new Date(); |
| | | // wrkMast.setAppeTime(now); |
| | | // wrkMast.setCrnStrTime(now); |
| | | // try { |
| | | // wrkMastService.updateById(wrkMast); |
| | | // break; |
| | | // } catch (Exception e) { |
| | | // log.error("更新小车任务失败,任务号:" + wrkMast.getWrkNo()); |
| | | // } |
| | | // break runRgv; |
| | | // } else if (rgvProtocol != null |
| | | // && rgvProtocol.modeType == RgvModeType.AUTO |
| | | // && rgvProtocol.getStatusType() == RgvStatusType.WALK |
| | | // && rgvProtocol.getTaskNo1() == 0 |
| | | // && rgvProtocol.getAlarm() == 0) { |
| | | // if (rgvProtocol.getStatusType() == RgvStatusType.WALK) { |
| | | // double finalVelocity = 0.0; // 最终速度 (m/s) |
| | | // double distance = (Math.pow(finalVelocity, 2) - Math.pow(rgvProtocol.instantaneousSpeed / 60, 2)) / (2 * acceleration); |
| | | // BasDevpPosition basDevpPosition = basDevpPositionService.selectOne(new EntityWrapper<BasDevpPosition>().eq("dev_no", wrkMast.getSourceStaNo())); |
| | | // if ((distance * proportion + (rgvProtocol.instantaneousSpeed / 60) * proportion * rgvDate) > (SortTheExecutionOfTheCarUtil.LatelyAndLessThan(basDevpPosition.getPlcPosition(), rgvProtocol.getRgvPos(), perimeter) )) { |
| | | //// List<BasDevpPosition> basDevpPositions = basDevpPositionService.selectList(new EntityWrapper<BasDevpPosition>().orderBy("plc_position", true)); |
| | | //// if (basDevpPositions.isEmpty()) { |
| | | //// log.error("获取所有站点信息异常,RGV任务下发失败,请联系管理员!!!"); |
| | | //// break runRgv; |
| | | //// } |
| | | //// List<Integer> devpList = SortTheExecutionOfTheCarUtil.BasDevpPositionExtractSites(basDevpPositions); |
| | | //// |
| | | //// if (!SortTheExecutionOfTheCarUtil.calculateShortestDistanceDirection(devpList,rgvProtocol.getEndStaM(),wrkMast.getSourceStaNo())){ |
| | | // continue; |
| | | //// } |
| | | // } |
| | | // } |
| | | // RgvCommand rgvCommand = new RgvCommand(); |
| | | // rgvCommand.setRgvNo(rgvProtocol.getRgvNo()); |
| | | // rgvCommand.setAckFinish1((short) 0); // 工位1任务完成确认位 |
| | | // rgvCommand.setTaskNo1(wrkMast.getWrkNo().shortValue()); |
| | | // rgvCommand.setTaskMode1(RgvTaskModeType.X_MOVE); // 工位1任务模式: 取放货 |
| | | // rgvCommand.setSourceStaNo1(wrkMast.getSourceStaNo().shortValue()); //工位1起点 |
| | | // rgvCommand.setDestinationStaNo1(wrkMast.getStaNo().shortValue()); //工位1目标站点 |
| | | // rgvCommand.setCommand((short) 1); //工位1任务确认 |
| | | // rgvCommand.setRgvSome(basCircularShuttle.getRgvSome()==1 ? (short) 1 : (short) 0); |
| | | // if (!MessageQueue.offer(SlaveType.Rgv, rgvProtocol.getRgvNo(), new Task(3, rgvCommand))) { |
| | | // // |
| | | // log.error("RGV命令下发失败,RGV号={},任务数据={}", rgvId, JSON.toJSON(rgvCommand)); |
| | | // break runRgv; |
| | | // } |
| | | // log.info("RGV命令下发成功,RGV号={},任务数据={}", rgvId, JSON.toJSON(rgvCommand)); |
| | | // |
| | | // wrkMast.setWrkSts(2L); |
| | | // wrkMast.setRgvNo(rgvProtocol.getRgvNo()); |
| | | // Date now = new Date(); |
| | | // wrkMast.setAppeTime(now); |
| | | // wrkMast.setCrnStrTime(now); |
| | | // try { |
| | | // wrkMastService.updateById(wrkMast); |
| | | // break; |
| | | // } catch (Exception e) { |
| | | // log.error("更新小车任务失败,任务号:" + wrkMast.getWrkNo()); |
| | | // } |
| | | // break runRgv; |
| | | // } else { |
| | | // break runRgv; |
| | | // } |
| | | // } |
| | | // } |
| | | // } |
| | | // } |
| | | public synchronized void taskDown(List<List<List<WrkMast>>> wrkMastListAll) { |
| | | |
| | | List<Integer> rgvNoM = new ArrayList<>(); |
| | | List<Integer> rgvNoR = new ArrayList<>(); |
| | | Integer wrkMastRunCount = 0; |
| | | Long devperimeter = 0L; |
| | | for (List<List<WrkMast>> wrkMastLists : wrkMastListAll) { |
| | | long rgvId = 0; |
| | | runRgv: |
| | | for (List<WrkMast> wrkMastList : wrkMastLists) { |
| | | for (WrkMast wrkMast : wrkMastList) { |
| | | while (rgvId <= rgvCount) { |
| | | rgvId++; |
| | | // log.info("存在任务,RGV号={},任务数据={}", rgvId, JSON.toJSON(wrkMast)); |
| | | if (rgvId > rgvCount) { |
| | | break runRgv; |
| | | } |
| | | BasCircularShuttle basCircularShuttle = basCircularShuttleService.selectOne(new EntityWrapper<BasCircularShuttle>().eq("rgv_id", rgvId)); |
| | | if (basCircularShuttle.getStatus() != 0){ |
| | | continue ; |
| | | } |
| | | RgvThread rgvThread = (RgvThread) SlaveConnection.get(SlaveType.Rgv, basCircularShuttle.getRgvNo()); |
| | | RgvProtocol rgvProtocol = rgvThread.getRgvProtocol(); |
| | | if (rgvProtocol == null) { |
| | | continue; |
| | | } |
| | | |
| | | List<WrkMast> wrkMasts = wrkMastService.selectList(new EntityWrapper<WrkMast>().eq("rgv_no", rgvProtocol.getRgvNo()).eq("wrk_sts", 2L)); |
| | | if (!wrkMasts.isEmpty()) { |
| | | continue; |
| | | } |
| | | if (rgvProtocol != null |
| | | && rgvProtocol.modeType == RgvModeType.AUTO |
| | | && (rgvProtocol.getStatusType() == RgvStatusType.IDLE || rgvProtocol.getStatusType() == RgvStatusType.ROAM) |
| | | && rgvProtocol.getTaskNo1() == 0 |
| | | && rgvProtocol.getAlarm() == 0) { |
| | | BasDevpPosition basDevpPosition = basDevpPositionService.selectOne(new EntityWrapper<BasDevpPosition>().eq("dev_no", wrkMast.getSourceStaNo())); |
| | | if (basDevpPosition.getPlcPosition()>rgvProtocol.getRgvPos()){ |
| | | if (basDevpPosition.getPlcPosition()-rgvProtocol.getRgvPos()>taskRunPerimeter){ |
| | | if (!rgvNoM.contains(rgvProtocol.getRgvNo())){ |
| | | rgvNoM.add(rgvProtocol.getRgvNo()); |
| | | wrkMastRunCount++; |
| | | break; |
| | | } |
| | | continue ; |
| | | } |
| | | } else { |
| | | if (rgvProtocol.getRgvPos()+ perimeter -basDevpPosition.getPlcPosition()>taskRunPerimeter){ |
| | | if (!rgvNoM.contains(rgvProtocol.getRgvNo())){ |
| | | rgvNoM.add(rgvProtocol.getRgvNo()); |
| | | wrkMastRunCount++; |
| | | break; |
| | | } |
| | | continue ; |
| | | } |
| | | } |
| | | |
| | | if (rgvProtocol.getStatusType() == RgvStatusType.ROAM) { |
| | | double finalVelocity = 0.0; // 最终速度 (m/s) |
| | | double distance = (Math.pow(finalVelocity, 2) - Math.pow(rgvProtocol.instantaneousSpeed / 60, 2)) / (2 * acceleration); |
| | | if ((distance * proportion + (rgvProtocol.instantaneousSpeed / 60) * proportion * rgvDate) > (SortTheExecutionOfTheCarUtil.LatelyAndLessThan(basDevpPosition.getPlcPosition(), rgvProtocol.getRgvPos(), perimeter) )) { |
| | | // List<BasDevpPosition> basDevpPositions = basDevpPositionService.selectList(new EntityWrapper<BasDevpPosition>().orderBy("plc_position", true)); |
| | | // if (basDevpPositions.isEmpty()) { |
| | | // log.error("获取所有站点信息异常,RGV任务下发失败,请联系管理员!!!"); |
| | | // break runRgv; |
| | | // } |
| | | // List<Integer> devpList = SortTheExecutionOfTheCarUtil.BasDevpPositionExtractSites(basDevpPositions); |
| | | // |
| | | // if (!SortTheExecutionOfTheCarUtil.calculateShortestDistanceDirection(devpList,rgvProtocol.getEndStaM(),wrkMast.getSourceStaNo())){ |
| | | continue; |
| | | // } |
| | | } |
| | | } |
| | | |
| | | if (!rgvNoR.contains(rgvProtocol.getRgvNo())){ |
| | | rgvNoR.add(rgvProtocol.getRgvNo()); |
| | | } else { |
| | | continue ; |
| | | } |
| | | |
| | | RgvCommand rgvCommand = new RgvCommand(); |
| | | rgvCommand.setRgvNo(rgvProtocol.getRgvNo()); |
| | | rgvCommand.setAckFinish1((short) 0); // 工位1任务完成确认位 |
| | | rgvCommand.setTaskNo1(wrkMast.getWrkNo().shortValue()); |
| | | rgvCommand.setTaskMode1(RgvTaskModeType.FETCH_PUT); // 工位1任务模式: 取放货 |
| | | rgvCommand.setSourceStaNo1(wrkMast.getSourceStaNo().shortValue()); //工位1起点 |
| | | rgvCommand.setDestinationStaNo1(wrkMast.getStaNo().shortValue()); //工位1目标站点 |
| | | rgvCommand.setCommand((short) 1); //工位1任务确认 |
| | | rgvCommand.setRgvSome(basCircularShuttle.getRgvSome()==1 ? (short) 1 : (short) 0); |
| | | if (!MessageQueue.offer(SlaveType.Rgv, rgvProtocol.getRgvNo(), new Task(2, rgvCommand))) { |
| | | // |
| | | log.error("RGV命令下发失败,RGV号={},任务数据={}", rgvId, JSON.toJSON(rgvCommand)); |
| | | break runRgv; |
| | | } |
| | | log.info("RGV命令下发成功,RGV号={},任务数据={}", rgvId, JSON.toJSON(rgvCommand)); |
| | | |
| | | wrkMast.setWrkSts(2L); |
| | | wrkMast.setRgvNo(rgvProtocol.getRgvNo()); |
| | | Date now = new Date(); |
| | | wrkMast.setAppeTime(now); |
| | | wrkMast.setCrnStrTime(now); |
| | | try { |
| | | wrkMastService.updateById(wrkMast); |
| | | break; |
| | | } catch (Exception e) { |
| | | log.error("更新小车任务失败,任务号:" + wrkMast.getWrkNo()); |
| | | } |
| | | break runRgv; |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | try{ |
| | | for (Integer rgvNo : rgvNoM){ |
| | | if (wrkMastRunCount==0){ |
| | | break; |
| | | } |
| | | if (rgvNoR.contains(rgvNo)){ |
| | | continue; |
| | | } |
| | | RgvThread rgvThread = (RgvThread) SlaveConnection.get(SlaveType.Rgv, rgvNo); |
| | | RgvProtocol rgvProtocol = rgvThread.getRgvProtocol(); |
| | | if (rgvProtocol == null) { |
| | | continue; |
| | | } |
| | | wrkMastRunCount--; |
| | | if (rgvProtocol != null |
| | | && rgvProtocol.modeType == RgvModeType.AUTO |
| | | && rgvProtocol.getStatusType() == RgvStatusType.IDLE |
| | | && rgvProtocol.getTaskNo1() == 0 |
| | | && rgvProtocol.getAlarm() == 0) { |
| | | if (!MessageQueue.offer(SlaveType.Rgv, rgvProtocol.getRgvNo(), new Task(4,devperimeter))) { |
| | | log.error("RGV漫游启动命令下发失败,RGV号={},任务数据={}", rgvNo, "漫游指令"); |
| | | break; |
| | | } |
| | | } |
| | | } |
| | | } catch (Exception e){ |
| | | |
| | | } |
| | | } |
| | | |
| | | //任务完成 |
| | | public synchronized void rgvCompleteWrkMastSta(int[] autoZ) { |
| | | try { |
| | | for (RgvSlave rgvSlave : slaveProperties.getRgv()) { |
| | | RgvThread rgvThread = (RgvThread) SlaveConnection.get(SlaveType.Rgv, rgvSlave.getId()); |
| | | RgvProtocol rgvProtocol = rgvThread.getRgvProtocol(); |
| | | if (rgvProtocol == null) { |
| | | continue; |
| | | } |
| | | BasRgv basRgv = basRgvService.selectById(rgvSlave.getId()); |
| | | if (basRgv == null) { |
| | | log.error("{}号RGV尚未在数据库进行维护!", rgvSlave.getId()); |
| | | continue; |
| | | } |
| | | if (rgvProtocol.getStatusType() == RgvStatusType.WAITING) { |
| | | log.info("{}号小车等待wcs确认,状态{},参数{}", rgvProtocol.getRgvNo(), rgvProtocol.getStatusType(), rgvProtocol); |
| | | } |
| | | // 只有当RGV等待WCS确认、自动 |
| | | if (rgvProtocol.getStatusType() == RgvStatusType.WAITING |
| | | && rgvProtocol.getModeType() == RgvModeType.AUTO |
| | | && rgvProtocol.getTaskNo1() != 0 |
| | | ) { |
| | | // log.info("{}号小车等待wcs确认,状态{},参数{}",rgvProtocol.getRgvNo(),rgvProtocol.getStatusType(),rgvProtocol); |
| | | WrkMast wrkMast = wrkMastService.selectOne(new EntityWrapper<WrkMast>().eq("wrk_no", rgvProtocol.getTaskNo1().longValue())); |
| | | if (Cools.isEmpty(wrkMast) || !wrkMast.getWrkSts().equals(2L)) { |
| | | log.error("未查到小车执行任务或者执行任务状态不符合!" + wrkMast); |
| | | continue; |
| | | } |
| | | boolean rgvComplete = rgvComplete(rgvProtocol.getRgvNo()); |
| | | if (!rgvComplete) { |
| | | log.error("小车复位失败,小车号{}!", rgvProtocol.getRgvNo()); |
| | | break; |
| | | } |
| | | wrkMast.setWrkSts(3L); |
| | | Date now = new Date(); |
| | | wrkMast.setAppeTime(now); |
| | | wrkMast.setCrnEndTime(now); |
| | | try{ |
| | | try{ |
| | | if (reportSwitch){ |
| | | RgvTaskReportingParam rgvTaskReportingParam = new RgvTaskReportingParam(wrkMast); |
| | | ReturnT<String> result = new PostMesDataUtils().postMesDataWcs(wmsUrl, wmsOutPath, rgvTaskReportingParam); |
| | | if (result.getCode()==200){ |
| | | wrkMast.setWrkSts(4L); |
| | | wrkMast.setAppeTime(now); |
| | | wrkMastService.updateById(wrkMast); |
| | | continue; |
| | | }else { |
| | | log.error("工作号"+wrkMast.getWrkNo()+"任务完成信息上传处理失败"); |
| | | } |
| | | } else { |
| | | //测试用 |
| | | wrkMast.setWrkSts(4L); |
| | | wrkMast.setAppeTime(now); |
| | | wrkMastService.updateById(wrkMast); |
| | | if (reportSwitchAuto) { |
| | | WrkMast wrkMast1 = new WrkMast(); |
| | | int workNo = commonService.getWorkNo(0); |
| | | wrkMast1.setWrkNo((long) workNo); |
| | | wrkMast1.setSourceStaNo(wrkMast.getSourceNoCs(autoZ)); |
| | | wrkMast1.setStaNo(wrkMast.getStaNoCs(autoZ)); |
| | | wrkMast1.setWrkSts(1L); |
| | | wrkMast1.setIoType(1); |
| | | wrkMast1.setModiTime(now); |
| | | wrkMast1.setAppeTime(now); |
| | | wrkMast1.setMemo("测试数据"); |
| | | wrkMastService.insert(wrkMast1); |
| | | } |
| | | continue; |
| | | } |
| | | } catch (Exception e){ |
| | | log.error("工作号"+wrkMast.getWrkNo()+"任务完成信息上传处理失败,异常信息:"+e); |
| | | } |
| | | } catch (Exception e){} |
| | | wrkMastService.updateById(wrkMast); |
| | | } |
| | | } |
| | | } catch (Exception e) { |
| | | log.error("小车复位线程报错!" + e); |
| | | } |
| | | } |
| | | |
| | | /* |
| | | * 小车复位 |
| | | * */ |
| | | public synchronized boolean rgvComplete(Integer rgvNo) { |
| | | try { |
| | | // 命令下发区 -------------------------------------------------------------------------- |
| | | if (!MessageQueue.offer(SlaveType.Rgv, rgvNo, new Task(3, new RgvCommand()))) { |
| | | log.error("RGV命令下发失败,RGV号={}", rgvNo); |
| | | return false; |
| | | } else { |
| | | log.info("RGV命令下发成功,RGV号={}", rgvNo); |
| | | return true; |
| | | } |
| | | } catch (Exception e) { |
| | | log.error("RGV命令下发失败,RGV号={}。异常:" + e, rgvNo); |
| | | return false; |
| | | } |
| | | } |
| | | } |