| | |
| | | if (null == endCode) { |
| | | return R.error(); |
| | | } |
| | | if (!mainLockWrapService.buildMinorTask(agv, param.getTaskMode(), endCode.getData(), null)) { |
| | | if (!mainLockWrapService.buildMinorTask(agv.getId(), param.getTaskMode(), endCode.getData(), null)) { |
| | | return R.error(); |
| | | } |
| | | break; |
| | | case TO_CHARGE: |
| | | case TO_STANDBY: |
| | | if (!mainLockWrapService.buildMinorTask(agv, param.getTaskMode(), null, null)) { |
| | | if (!mainLockWrapService.buildMinorTask(agv.getId(), param.getTaskMode(), null, null)) { |
| | | return R.error(); |
| | | } |
| | | break; |
| | |
| | | @Component |
| | | public class KernelScheduler { |
| | | |
| | | public static int CORE_SCAN_FREQUENCY_MILLISECOND = 30; |
| | | public static int CORE_SCAN_FREQUENCY_MILLISECOND = 15; |
| | | |
| | | private static final int LOCK_TIMEOUT = 5; |
| | | |
| | |
| | | continue; |
| | | } |
| | | |
| | | mainLockWrapService.buildMinorTask(agv, TaskTypeType.TO_CHARGE, null, null); |
| | | mainLockWrapService.buildMinorTask(agv.getId(), TaskTypeType.TO_CHARGE, null, null); |
| | | } |
| | | } |
| | | } |
| | |
| | | } |
| | | // } |
| | | |
| | | mainLockWrapService.buildMinorTask(agv, TaskTypeType.TO_STANDBY, null, null); |
| | | mainLockWrapService.buildMinorTask(agv.getId(), TaskTypeType.TO_STANDBY, null, null); |
| | | } |
| | | } |
| | | |
| | |
| | | return -weight; |
| | | } |
| | | |
| | | public Boolean validCapacityOfLane(Agv agv, Code code) { |
| | | public Boolean validCapacityOfLane(String agvNo, Code code) { |
| | | Lane lane = laneService.search(code.getData()); |
| | | if (null != lane) { |
| | | Integer maxAgvCountInLane = configService.getVal("maxAgvCountInLane", Integer.class); |
| | | |
| | | List<String> agvNosByLane = this.findAgvNosByLane(lane); |
| | | agvNosByLane.remove(agv.getUuid()); |
| | | agvNosByLane.remove(agvNo); |
| | | if (agvNosByLane.size() >= maxAgvCountInLane) { |
| | | return false; |
| | | } |
| | |
| | | } |
| | | } |
| | | |
| | | public boolean buildMinorTask(Agv agv, TaskTypeType taskType, String destination, Jam jam) { |
| | | public boolean buildMinorTask(Long agvId, TaskTypeType taskType, String destination, Jam jam) { |
| | | boolean lockAcquired = false; |
| | | try { |
| | | if (!(lockAcquired = this.lock.tryLock(LOCK_TIMEOUT, TimeUnit.SECONDS))) { |
| | |
| | | } |
| | | // log.info("buildMinorTask AGV[{}] lock time: {}", agv.getUuid(), System.currentTimeMillis()); |
| | | |
| | | return mainService.buildMinorTask(agv, taskType, destination, jam); |
| | | return mainService.buildMinorTask(agvId, taskType, destination, jam); |
| | | } catch (Exception e) { |
| | | log.error("MainLockWrapService.buildMinorTask[task]", e); |
| | | TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); |
| | |
| | | * 充电 回待机位任务 |
| | | */ |
| | | @Transactional(propagation = Propagation.REQUIRES_NEW) // although there is a Transactional here that the lock is isolated, but we can't join the caller's Transactional |
| | | public boolean buildMinorTask(Agv agv, TaskTypeType taskType, String destination, Jam jam) { |
| | | if (Cools.isEmpty(agv, taskType)) { return false; } |
| | | public boolean buildMinorTask(Long agvId, TaskTypeType taskType, String destination, Jam jam) { |
| | | if (Cools.isEmpty(agvId, taskType)) { return false; } |
| | | try { |
| | | AgvDetail agvDetail = agvDetailService.selectByAgvId(agv.getId()); |
| | | if (!agvService.judgeEnable(agv.getId())) { |
| | | String agvNo = agvService.getAgvNo(agvId); |
| | | AgvDetail agvDetail = agvDetailService.selectByAgvId(agvId); |
| | | if (!agvService.judgeEnable(agvId)) { |
| | | return false; |
| | | } |
| | | if (!Cools.isEmpty(taskService.selectInSts(agv.getId(), TaskStsType.ASSIGN, TaskStsType.PROGRESS))) { |
| | | throw new CoolException("AGV[" + agv.getUuid() + "] failed to assign,because already has the task in running..."); |
| | | if (!Cools.isEmpty(taskService.selectInSts(agvId, TaskStsType.ASSIGN, TaskStsType.PROGRESS))) { |
| | | throw new CoolException("AGV[" + agvNo + "] failed to assign,because already has the task in running..."); |
| | | } |
| | | if (!Cools.isEmpty(segmentService.getByAgvAndState(agv.getId(), SegmentStateType.WAITING.toString())) |
| | | || !Cools.isEmpty(segmentService.getByAgvAndState(agv.getId(), SegmentStateType.RUNNING.toString()))) { |
| | | throw new CoolException("AGV[" + agv.getUuid() + "] failed to assign,because already has the segment in running..."); |
| | | if (!Cools.isEmpty(segmentService.getByAgvAndState(agvId, SegmentStateType.WAITING.toString())) |
| | | || !Cools.isEmpty(segmentService.getByAgvAndState(agvId, SegmentStateType.RUNNING.toString()))) { |
| | | throw new CoolException("AGV[" + agvNo + "] failed to assign,because already has the segment in running..."); |
| | | } |
| | | |
| | | Date now = new Date(); |
| | |
| | | switch (taskType) { |
| | | case TO_CHARGE: |
| | | case TO_STANDBY: |
| | | List<FuncSta> idleFunStaList = funcStaService.findInIdleStatus(FuncStaType.query(taskType), agv.getId()); |
| | | List<FuncSta> idleFunStaList = funcStaService.findInIdleStatus(FuncStaType.query(taskType), agvId); |
| | | if (!Cools.isEmpty(idleFunStaList)) { |
| | | FuncSta funcSta = funcStaService.checkoutClosestFunSta(agvDetail.getRecentCode(), idleFunStaList); |
| | | endCode = codeService.getById(funcSta.getCode()); |
| | | } |
| | | if (null == endCode) { |
| | | log.warn("AGV[{}] failed to search destination,there hadn't any idle funSta,TaskTypeType:{}", agv.getUuid(), taskType.toString()); |
| | | log.warn("AGV[{}] failed to search destination,there hadn't any idle funSta,TaskTypeType:{}", agvNo, taskType.toString()); |
| | | } |
| | | break; |
| | | case MOVE: |
| | |
| | | if (null == endCode) { |
| | | return false; |
| | | } |
| | | if (!allocateService.validCapacityOfLane(agv, endCode)) { |
| | | throw new BusinessException("the lane with code:" + endCode.getData() + " is full of AGV[" + agv.getUuid() + "]!!!"); |
| | | if (!allocateService.validCapacityOfLane(agvNo, endCode)) { |
| | | throw new BusinessException("the lane with code:" + endCode.getData() + " is full of AGV[" + agvNo + "]!!!"); |
| | | } |
| | | |
| | | Task task = new Task(); |
| | | task.setAgvId(agv.getId()); |
| | | task.setAgvId(agvId); |
| | | task.setUuid(String.valueOf(snowflakeIdWorker.nextId()).substring(3)); |
| | | List<Task> lastTasks = taskService.list(new LambdaQueryWrapper<Task>().orderByDesc(Task::getId)); |
| | | task.setSeqNum(Utils.generateSeqNum(Cools.isEmpty(lastTasks)?null:lastTasks.get(0).getSeqNum())); |
| | |
| | | Travel travel = new Travel(); |
| | | travel.setUuid(String.valueOf(snowflakeIdWorker.nextId()).substring(3)); |
| | | travel.setTravelId(String.valueOf(snowflakeIdWorker.nextId()).substring(3)); |
| | | travel.setAgvId(agv.getId()); |
| | | travel.setAgvId(agvId); |
| | | // travel.setTaskContent(JSON.toJSONString(list)); |
| | | travel.setTaskIds(GsonUtils.toJson(Utils.singletonList(task.getId()))); |
| | | travel.setState(TravelStateType.RUNNING.toString()); |
| | |
| | | Segment segment = new Segment(); |
| | | segment.setUuid(String.valueOf(snowflakeIdWorker.nextId()).substring(3)); |
| | | segment.setTravelId(travel.getId()); |
| | | segment.setAgvId(agv.getId()); |
| | | segment.setAgvId(agvId); |
| | | segment.setTaskId(task.getId()); |
| | | segment.setSerial(segSerial); |
| | | segment.setEndNode(endCode.getId()); |
| | |
| | | if (!agvService.judgeEnable(agvId)) { |
| | | return; |
| | | } |
| | | Agv agv = agvService.getById(agvId); |
| | | Code destinationCode = this.getDestinationCode(agv, agvDetail); |
| | | Code destinationCode = this.getDestinationCode(agvNo, agvDetail); |
| | | if (null == destinationCode) { |
| | | return; |
| | | } |
| | | if (mainLockWrapService.buildMinorTask(agv, TaskTypeType.MOVE, destinationCode.getData(), null)) { |
| | | log.info(agv.getUuid() + "开始走行演示..."); |
| | | if (mainLockWrapService.buildMinorTask(agvId, TaskTypeType.MOVE, destinationCode.getData(), null)) { |
| | | log.info(agvNo + "开始走行演示..."); |
| | | } |
| | | } |
| | | |
| | |
| | | * 评估HandlerController没有调用buildMajorTask,手动创建task的可行性 |
| | | * agv地图图标变化 |
| | | */ |
| | | public Code getDestinationCode(Agv agv, AgvDetail agvDetail) { |
| | | public Code getDestinationCode(String agvNo, AgvDetail agvDetail) { |
| | | Integer maxAgvCountInLane = configService.getVal("maxAgvCountInLane", Integer.class); |
| | | |
| | | Code startCode = codeService.getById(agvDetail.getRecentCode()); |
| | |
| | | |
| | | for (Code endCode : list) { |
| | | // valid lane |
| | | if (!allocateService.validCapacityOfLane(agv, endCode)) { |
| | | if (!allocateService.validCapacityOfLane(agvNo, endCode)) { |
| | | continue; |
| | | } |
| | | |
| | |
| | | * avoidPathList include wave node and dynamic node |
| | | */ |
| | | private boolean notifyVehicleAvoid(String agvNo, String agvPosCode, List<String> avoidPathList, String sponsor, Jam jam) { |
| | | Agv agv = agvService.selectByUuid(agvNo); |
| | | if (!Cools.isEmpty(segmentService.getByAgvAndState(agv.getId(), SegmentStateType.RUNNING.toString()))) { |
| | | Long agvId = agvService.getAgvId(agvNo); |
| | | if (!Cools.isEmpty(segmentService.getByAgvAndState(agvId, SegmentStateType.RUNNING.toString()))) { |
| | | log.warn("{}号车辆避让失败,存在进行中任务!!!", agvNo); |
| | | return false; |
| | | } |
| | |
| | | String endCodeData = finalNode.getCodeData(); |
| | | Code endCode = codeService.getCacheByData(endCodeData); |
| | | |
| | | List<Segment> waitingSegList = segmentService.getByAgvAndState(agv.getId(), SegmentStateType.WAITING.toString()); |
| | | List<Segment> waitingSegList = segmentService.getByAgvAndState(agvId, SegmentStateType.WAITING.toString()); |
| | | if (!Cools.isEmpty(waitingSegList)) { |
| | | |
| | | if (waitingSegList.size() > 1) { |
| | |
| | | Segment insertSeg = new Segment(); |
| | | insertSeg.setUuid(String.valueOf(snowflakeIdWorker.nextId()).substring(3)); |
| | | insertSeg.setTravelId(segment.getTravelId()); |
| | | insertSeg.setAgvId(agv.getId()); |
| | | insertSeg.setAgvId(agvId); |
| | | insertSeg.setTaskId(segment.getTaskId()); |
| | | insertSeg.setSerial(segment.getSerial() - 1); |
| | | insertSeg.setEndNode(endCode.getId()); |
| | |
| | | |
| | | } else { |
| | | |
| | | return mainLockWrapService.buildMinorTask(agv, TaskTypeType.MOVE, endCodeData, jam); |
| | | return mainLockWrapService.buildMinorTask(agvId, TaskTypeType.MOVE, endCodeData, jam); |
| | | } |
| | | |
| | | return true; |