| | |
| | | throw new BusinessException("Internal Server Error!"); |
| | | } |
| | | Boolean locStaStatusCheck = configService.getVal("LOC_STA_STATUS_CHECK", Boolean.class, true); |
| | | Integer locStaTaskNum = configService.getVal("LOC_STA_TASK_NUM", Integer.class, 2); |
| | | |
| | | |
| | | // 保存任务 |
| | |
| | | if (locStaStatusCheck && !destSta.getStaSts().equals(StaStsType.IDLE.val())) { |
| | | throw new BusinessException("destSta:" + task.getDestSta$() + " is not in IDLE status"); |
| | | } |
| | | } else { |
| | | List<Task> list = taskService.list(new LambdaQueryWrapper<Task>().eq(Task::getDestSta, destSta.getId()).in(Task::getTaskSts, TaskStsType.INIT.val(), TaskStsType.WAITING.val(), TaskStsType.ASSIGN.val(), TaskStsType.PROGRESS.val())); |
| | | if (!Cools.isEmpty(list) && list.size() >= locStaTaskNum) { |
| | | throw new BusinessException("destSta:" + task.getDestSta$() + " task more"); |
| | | } |
| | | } |
| | | destSta.setStaSts(StaStsType.READY_RELEASE.val()); |
| | | destSta.setUpdateTime(now); |
| | |
| | | break; |
| | | case STA_TO_LOC: |
| | | oriSta = staService.getById(task.getOriSta()); |
| | | if (oriSta.getStaTypeIsCheck() != 1) { |
| | | if (locStaStatusCheck && !oriSta.getStaSts().equals(StaStsType.STOCK.val())) { |
| | | throw new BusinessException("oriSta:" + task.getOriSta$() + " is not in STOCK status"); |
| | | } |
| | | } |
| | | // if (oriSta.getStaTypeIsCheck() != 1) { |
| | | // if (locStaStatusCheck && !oriSta.getStaSts().equals(StaStsType.STOCK.val())) { |
| | | // throw new BusinessException("oriSta:" + task.getOriSta$() + " is not in STOCK status"); |
| | | // } |
| | | // } |
| | | oriSta.setStaSts(StaStsType.READY_TAKE.val()); |
| | | oriSta.setUpdateTime(now); |
| | | if (!staService.updateById(oriSta)) { |
| | |
| | | if (destSta.getStaTypeIsCheck() != 1) { |
| | | if (locStaStatusCheck && !destSta.getStaSts().equals(StaStsType.IDLE.val())) { |
| | | throw new BusinessException("destSta:" + task.getDestSta$() + " is not in IDLE status"); |
| | | } |
| | | } else { |
| | | List<Task> list = taskService.list(new LambdaQueryWrapper<Task>().eq(Task::getDestSta, destSta.getId()).in(Task::getTaskSts, TaskStsType.INIT.val(), TaskStsType.WAITING.val(), TaskStsType.ASSIGN.val(), TaskStsType.PROGRESS.val())); |
| | | if (!Cools.isEmpty(list) && list.size() >= locStaTaskNum) { |
| | | throw new BusinessException("destSta:" + task.getDestSta$() + " task more"); |
| | | } |
| | | } |
| | | destSta.setStaSts(StaStsType.READY_RELEASE.val()); |
| | |
| | | |
| | | // 需要走行 |
| | | if (!lastCode.getData().equals(code.getData())) { |
| | | |
| | | // 走行路径节点 |
| | | // List<String> pathList = mapService.checkoutPath(agv.getUuid(), lastCode, code); |
| | | List<String> pathListPart = pathList.subList(pathList.indexOf(lastCode.getData()), pathList.indexOf(code.getData()) + 1); |
| | |
| | | // 第一步:如果下一个方向正好是作业方向的相反方向,则重置下一个方向为作业方向,标记 reverse = true |
| | | boolean reverse = false; |
| | | if (nextDirection.equals((workDirection + 180) % 360)) { |
| | | nextDirection = workDirection; |
| | | reverse = true; |
| | | List<String> list = Arrays.asList("00000050", "00000051", "00000052", "00000053", "00000054"); |
| | | if ((Objects.requireNonNull(TaskPosDto.queryPosType(segment.getPosType())).equals(TaskPosDto.PosType.ORI_STA) |
| | | || Objects.requireNonNull(TaskPosDto.queryPosType(segment.getPosType())) |
| | | .equals(TaskPosDto.PosType.DEST_STA)) && list.contains(lastCode.getData())) { |
| | | reverse = false; |
| | | lastDirection = nextDirection; |
| | | } else { |
| | | nextDirection = workDirection; |
| | | reverse = true; |
| | | } |
| | | } |
| | | |
| | | // 第二步:判断当前节点是否可以旋转 |
| | |
| | | nextDirection = lastDirection; |
| | | reverse = true; |
| | | } else { |
| | | if ((Objects.requireNonNull(TaskPosDto.queryPosType(segment.getPosType())) |
| | | .equals(TaskPosDto.PosType.ORI_STA) || Objects.requireNonNull(TaskPosDto.queryPosType(segment.getPosType())) |
| | | .equals(TaskPosDto.PosType.DEST_STA)) && lastCode.getData().equals("00000050")) { |
| | | // turn |
| | | reverse = false; |
| | | actionList.add(new Action( |
| | | null, // 编号s |
| | | task.getBusId(), // 总线 |
| | | task.getId(), // 任务 |
| | | null, // 动作号 |
| | | null, // 优先级 |
| | | ActionTypeType.TurnCorner.desc, // 名称 |
| | | mapService.isTurnCorner(lastCode.getData()) ? 1D : 0D, // 属性值 |
| | | lastCode.getData(), // 地面码 |
| | | String.valueOf(180), // 动作参数 |
| | | ActionTypeType.TurnCorner.val(), // 动作类型 |
| | | actionPrepareSts, // 动作进度 |
| | | agvId, // AGV |
| | | now // 工作时间 |
| | | )); |
| | | } else { |
| | | // turn |
| | | actionList.add(new Action( |
| | | null, // 编号s |
| | | task.getBusId(), // 总线 |
| | | task.getId(), // 任务 |
| | | null, // 动作号 |
| | | null, // 优先级 |
| | | ActionTypeType.TurnCorner.desc, // 名称 |
| | | mapService.isTurnCorner(lastCode.getData()) ? 1D : 0D, // 属性值 |
| | | lastCode.getData(), // 地面码 |
| | | String.valueOf(nextDirection), // 动作参数 |
| | | ActionTypeType.TurnCorner.val(), // 动作类型 |
| | | actionPrepareSts, // 动作进度 |
| | | agvId, // AGV |
| | | now // 工作时间 |
| | | )); |
| | | } |
| | | lastDirection = nextDirection; |
| | | } |
| | | } else { |
| | | if ((Objects.requireNonNull(TaskPosDto.queryPosType(segment.getPosType())) |
| | | .equals(TaskPosDto.PosType.ORI_STA) || Objects.requireNonNull(TaskPosDto.queryPosType(segment.getPosType())) |
| | | .equals(TaskPosDto.PosType.DEST_STA)) && lastCode.getData().equals("00000050")) { |
| | | // turn |
| | | reverse = false; |
| | | actionList.add(new Action( |
| | | null, // 编号s |
| | | task.getBusId(), // 总线 |
| | |
| | | ActionTypeType.TurnCorner.desc, // 名称 |
| | | mapService.isTurnCorner(lastCode.getData()) ? 1D : 0D, // 属性值 |
| | | lastCode.getData(), // 地面码 |
| | | String.valueOf(nextDirection), // 动作参数 |
| | | String.valueOf(180), // 动作参数 |
| | | ActionTypeType.TurnCorner.val(), // 动作类型 |
| | | actionPrepareSts, // 动作进度 |
| | | agvId, // AGV |
| | | now // 工作时间 |
| | | )); |
| | | |
| | | lastDirection = nextDirection; |
| | | } |
| | | } |
| | | } |
| | | |
| | | // 第一个动作一定是 turn |
| | | if (actionList.isEmpty() && lastCode.getCornerBool()) { |
| | | // turn |
| | | actionList.add(new Action( |
| | | null, // 编号 |
| | | task.getBusId(), // 总线 |
| | | task.getId(), // 任务 |
| | | null, // 动作号 |
| | | null, // 优先级 |
| | | ActionTypeType.TurnCorner.desc, // 名称 |
| | | mapService.isTurnCorner(lastCode.getData()) ? 1D : 0D, // 属性值 |
| | | lastCode.getData(), // 地面码 |
| | | String.valueOf(nextDirection), // 动作参数 |
| | | ActionTypeType.TurnCorner.val(), // 动作类型 |
| | | actionPrepareSts, // 动作进度 |
| | | agvId, // AGV |
| | | now // 工作时间 |
| | | )); |
| | | |
| | | lastDirection = nextDirection; |
| | | } |
| | | |
| | | // run |
| | | ActionTypeType actionType = ActionTypeType.StraightAheadTurnable; |
| | | if (reverse) { |
| | | actionType = ActionTypeType.StraightBackTurnable; |
| | | } |
| | | CodeGap gap = codeGapService.findByCodeOfBoth(lastCode.getId(), nextCode.getId()); |
| | | actionList.add(new Action( |
| | | null, // 编号 |
| | | task.getBusId(), // 总线 |
| | | task.getId(), // 任务 |
| | | null, // 动作号 |
| | | null, // 优先级 |
| | | actionType.desc, // 名称 |
| | | (double) agvSpeedType.val, // 属性值 |
| | | lastCode.getData(), // 地面码 |
| | | String.valueOf(gap.getDistance()), // 动作参数 |
| | | actionType.val(), // 动作类型 |
| | | actionPrepareSts, // 动作进度 |
| | | agvId, // AGV |
| | | now // 工作时间 |
| | | )); |
| | | |
| | | lastCode = nextCode; |
| | | |
| | | } |
| | | } |
| | | |
| | | // 初始方向值补丁 |
| | | if (first) { |
| | | if (Cools.isEmpty(actionList) || !actionList.get(0).getActionType().equals(ActionTypeType.TurnCorner.val())) { |
| | | Double turnDirection = workDirection; |
| | | List<String> list = Arrays.asList("00000051", "00000052", "00000053", "00000054"); |
| | | if ((Objects.requireNonNull(TaskPosDto.queryPosType(segment.getPosType())).equals(TaskPosDto.PosType.ORI_STA) |
| | | || Objects.requireNonNull(TaskPosDto.queryPosType(segment.getPosType())) |
| | | .equals(TaskPosDto.PosType.DEST_STA)) && list.contains(lastCode.getData())) { |
| | | turnDirection = workDirection + 180.0; |
| | | } |
| | | if (lastCode.getCornerBool()) { |
| | | // turn |
| | | actionList.add(new Action( |
| | | null, // 编号 |
| | | task.getBusId(), // 总线 |
| | | task.getId(), // 任务 |
| | | null, // 动作号 |
| | | null, // 优先级 |
| | | ActionTypeType.TurnCorner.desc, // 名称 |
| | | mapService.isTurnCorner(lastCode.getData()) ? 1D : 0D, // 属性值 |
| | | lastCode.getData(), // 地面码 |
| | | String.valueOf(turnDirection), // 动作参数 |
| | | ActionTypeType.TurnCorner.val(), // 动作类型 |
| | | actionPrepareSts, // 动作进度 |
| | | agvId, // AGV |
| | | now // 工作时间 |
| | | )); |
| | | lastDirection = workDirection; |
| | | } |
| | | } |
| | | first = false; |
| | | } |
| | | |
| | | // 作业点动作 |
| | | AgvDirectionType agvDirectionType; |
| | | Double staWorkDirection; |
| | | AgvBackpackType backpackType = AgvBackpackType.query(segment.getBackpack()); |
| | | switch (Objects.requireNonNull(TaskPosDto.queryPosType(segment.getPosType()))) { |
| | | case ORI_LOC: |
| | | assert backpackType != null; |
| | | // 检验方向 |
| | | if (!lastDirection.equals(workDirection)) { |
| | | throw new CoolException(agvNo + "号小车方向错误,请推至转弯点手动调整"); |
| | | } |
| | | // 货架取货 |
| | | Loc oriLoc = locService.getById(task.getOriLoc()); |
| | | // 计算左右方向 |
| | | agvDirectionType = mapService.calculateAgvWorkDirectionByShelf(oriLoc, lastCode); |
| | | actionList.add(new Action( |
| | | null, // 编号 |
| | | task.getBusId(), // 总线 |
| | | task.getId(), // 任务 |
| | | null, // 动作号 |
| | | null, // 优先级 |
| | | ActionTypeType.ReadyTakeFromShelvesLoc.desc, // 名称 |
| | | (double) agvDirectionType.val, // 属性值 |
| | | lastCode.getData(), // 地面码 |
| | | String.valueOf(oriLoc.getOffset()), // 动作参数 |
| | | ActionTypeType.ReadyTakeFromShelvesLoc.val(), // 动作类型 |
| | | actionPrepareSts, // 动作进度 |
| | | agvId, // AGV |
| | | now // 工作时间 |
| | | )); |
| | | // 暂存点放货 |
| | | actionList.add(new Action( |
| | | null, // 编号 |
| | | task.getBusId(), // 总线 |
| | | task.getId(), // 任务 |
| | | null, // 动作号 |
| | | null, // 优先级 |
| | | ActionTypeType.ReadyReleaseToAgvSite.desc, // 名称 |
| | | (double) backpackType.lev, // 属性值 |
| | | lastCode.getData(), // 地面码 |
| | | String.valueOf(backpackType.height), // 动作参数 |
| | | ActionTypeType.ReadyReleaseToAgvSite.val(), // 动作类型 |
| | | actionPrepareSts, // 动作进度 |
| | | agvId, // AGV |
| | | now // 工作时间 |
| | | )); |
| | | break; |
| | | case DEST_LOC: |
| | | assert backpackType != null; |
| | | // 检验方向 |
| | | if (!lastDirection.equals(workDirection)) { |
| | | throw new CoolException(agvNo + "号小车方向错误,请推至转弯点手动调整"); |
| | | } |
| | | // 暂存点取货货 |
| | | actionList.add(new Action( |
| | | null, // 编号 |
| | | task.getBusId(), // 总线 |
| | | task.getId(), // 任务 |
| | | null, // 动作号 |
| | | null, // 优先级 |
| | | ActionTypeType.ReadyTakeFromAgvSite.desc, // 名称 |
| | | (double) backpackType.lev, // 属性值 |
| | | lastCode.getData(), // 地面码 |
| | | String.valueOf(backpackType.height), // 动作参数 |
| | | ActionTypeType.ReadyTakeFromAgvSite.val(), // 动作类型 |
| | | actionPrepareSts, // 动作进度 |
| | | agvId, // AGV |
| | | now // 工作时间 |
| | | )); |
| | | |
| | | // 货架放货 |
| | | Loc destLoc = locService.getById(task.getDestLoc()); |
| | | // 计算左右方向 |
| | | agvDirectionType = mapService.calculateAgvWorkDirectionByShelf(destLoc, lastCode); |
| | | actionList.add(new Action( |
| | | null, // 编号 |
| | | task.getBusId(), // 总线 |
| | | task.getId(), // 任务 |
| | | null, // 动作号 |
| | | null, // 优先级 |
| | | ActionTypeType.ReadyReleaseToShelvesLoc.desc, // 名称 |
| | | (double) agvDirectionType.val, // 属性值 |
| | | lastCode.getData(), // 地面码 |
| | | String.valueOf(destLoc.getOffset()), // 动作参数 |
| | | ActionTypeType.ReadyReleaseToShelvesLoc.val(), // 动作类型 |
| | | actionPrepareSts, // 动作进度 |
| | | agvId, // AGV |
| | | now // 工作时间 |
| | | )); |
| | | break; |
| | | case ORI_STA: |
| | | // 站点取货 |
| | | Sta oriSta = staService.getById(task.getOriSta()); |
| | | Double oriStaWorkDirection = mapService.getStaAngle(oriSta, workDirection); |
| | | // 检验方向 |
| | | // if (!lastDirection.equals(oriStaWorkDirection)) { |
| | | // if (!lastCode.getCornerBool()) { |
| | | // throw new CoolException(agvNo + "号小车方向错误,请推至转弯点手动调整"); |
| | | // } |
| | | // // turn |
| | | // actionList.add(new Action( |
| | | // null, // 编号 |
| | | // task.getBusId(), // 总线 |
| | | // task.getId(), // 任务 |
| | | // null, // 动作号 |
| | | // null, // 优先级 |
| | | // ActionTypeType.TurnCorner.desc, // 名称 |
| | | // mapService.isTurnCorner(lastCode.getData()) ? 1D : 0D, // 属性값 |
| | | // lastCode.getData(), // 地面码 |
| | | // String.valueOf(oriStaWorkDirection), // 动作参数 |
| | | // ActionTypeType.TurnCorner.val(), // 动作类型 |
| | | // actionPrepareSts, // 动作进度 |
| | | // agvId, // AGV |
| | | // now // 工作时间 |
| | | // )); |
| | | // lastDirection = oriStaWorkDirection; |
| | | // } |
| | | // 计算货叉工作方向 |
| | | staWorkDirection = mapService.calculateAgvWorkDirectionByStation(oriStaWorkDirection, lastDirection); |
| | | actionList.add(new Action( |
| | | null, // 编号 |
| | | task.getBusId(), // 总线 |
| | | task.getId(), // 任务 |
| | | null, // 动作号 |
| | | null, // 优先级 |
| | | ActionTypeType.ReadyTakeFromShelvesLoc.desc, // 名称 |
| | | Double.parseDouble("0"), // 属性值 |
| | | lastCode.getData(), // 地面码 |
| | | String.valueOf(oriSta.getOffset()), // 动作参数 |
| | | ActionTypeType.ReadyTakeFromShelvesLoc.val(), // 动作类型 |
| | | actionPrepareSts, // 动作进度 |
| | | agvId, // AGV |
| | | now, // 工作时间 |
| | | oriSta.getStaTypeIsCheck() == 1 ? 1 : 0, |
| | | oriSta.getStaNo() |
| | | )); |
| | | // 暂存点放货 |
| | | assert backpackType != null; |
| | | actionList.add(new Action( |
| | | null, // 编号 |
| | | task.getBusId(), // 总线 |
| | | task.getId(), // 任务 |
| | | null, // 动作号 |
| | | null, // 优先级 |
| | | ActionTypeType.ReadyReleaseToAgvSite.desc, // 名称 |
| | | (double) backpackType.lev, // 属性값 |
| | | lastCode.getData(), // 地面码 |
| | | String.valueOf(backpackType.height), // 动作参数 |
| | | ActionTypeType.ReadyReleaseToAgvSite.val(), // 动作类型 |
| | | actionPrepareSts, // 动作进度 |
| | | agvId, // AGV |
| | | now // 工作时间 |
| | | )); |
| | | break; |
| | | case DEST_STA: |
| | | // 站点放货 |
| | | Sta destSta = staService.getById(task.getDestSta()); |
| | | Double destStaWorkDirection = mapService.getStaAngle(destSta, workDirection); |
| | | // CodeGap gap = codeGapService.findByCodeOfBoth(lastCode.getId(), nextCode.getId()); |
| | | |
| | | // 检验方向 |
| | | // if (!lastDirection.equals(destStaWorkDirection)) { |
| | | // if (!lastCode.getCornerBool()) { |
| | | // throw new CoolException(agvNo + "号小车方向错误,请推至转弯点手动调整"); |
| | | // } |
| | | // |
| | | // actionList.add(new Action( |
| | | // null, // 编号 |
| | | // task.getBusId(), // 总线 |
| | | // task.getId(), // 任务 |
| | | // null, // 动作号 |
| | | // null, // 优先级 |
| | | // actionType.desc, // 名称 |
| | | // (double) agvSpeedType.val, // 属性值 |
| | | // lastCode.getData(), // 地面码 |
| | | // String.valueOf(gap.getDistance()), // 动作参数 |
| | | // actionType.val(), // 动作类型 |
| | | // actionPrepareSts, // 动作进度 |
| | | // agvId, // AGV |
| | | // now // 工作时间 |
| | | // )); |
| | | // // turn |
| | | // actionList.add(new Action( |
| | | // null, // 编号 |
| | | // task.getBusId(), // 总线 |
| | | // task.getId(), // 任务 |
| | | // null, // 动作号 |
| | | // null, // 优先级 |
| | | // ActionTypeType.TurnCorner.desc, // 名称 |
| | | // mapService.isTurnCorner(lastCode.getData()) ? 1D : 0D, // 属性값 |
| | | // lastCode.getData(), // 地面码 |
| | | // String.valueOf(destStaWorkDirection), // 动作参数 |
| | | // ActionTypeType.TurnCorner.val(), // 动作类型 |
| | | // actionPrepareSts, // 动作进度 |
| | | // agvId, // AGV |
| | | // now // 工作时间 |
| | | // )); |
| | | // lastDirection = destStaWorkDirection; |
| | | // } |
| | | // 暂存点取货 |
| | | assert backpackType != null; |
| | | actionList.add(new Action( |
| | | null, // 编号 |
| | | task.getBusId(), // 总线 |
| | | task.getId(), // 任务 |
| | | null, // 动作号 |
| | | null, // 优先级 |
| | | ActionTypeType.ReadyTakeFromAgvSite.desc, // 名称 |
| | | (double) backpackType.lev, // 属性값 |
| | | lastCode.getData(), // 地面码 |
| | | String.valueOf(backpackType.height), // 动作参数 |
| | | ActionTypeType.ReadyTakeFromAgvSite.val(), // 动作类型 |
| | | actionPrepareSts, // 动作进度 |
| | | agvId, // AGV |
| | | now // 工作时间 |
| | | |
| | | )); |
| | | // 计算货叉工作方向 |
| | | staWorkDirection = mapService.calculateAgvWorkDirectionByStation(destStaWorkDirection, lastDirection); |
| | | actionList.add(new Action( |
| | | null, // 编号 |
| | | task.getBusId(), // 总线 |
| | | task.getId(), // 任务 |
| | | null, // 动作号 |
| | | null, // 优先级 |
| | | ActionTypeType.ReadyReleaseToShelvesLoc.desc, // 名称 |
| | | Double.parseDouble("0"), // 属性值 |
| | | lastCode.getData(), // 地面码 |
| | | String.valueOf(destSta.getOffset()), // 动作参数 |
| | | ActionTypeType.ReadyReleaseToShelvesLoc.val(), // 动作类型 |
| | | actionPrepareSts, // 动作进度 |
| | | agvId, // AGV |
| | | now, // 工作时间 |
| | | destSta.getStaTypeIsCheck() == 1 ? 2 : 0, |
| | | destSta.getStaNo() |
| | | )); |
| | | break; |
| | | case TO_CHARGE: |
| | | // 检验方向 |
| | | FuncSta chargeFuncSta = funcStaService.query(lastCode.getId(), FuncStaType.CHARGE.toString()); |
| | | Double chargeDirection = Double.parseDouble(chargeFuncSta.getAngle()); |
| | | if (!lastDirection.equals(chargeDirection) && lastCode.getCornerBool()) { |
| | | actionList.add(new Action( |
| | | null, // 编号 |
| | | null, // 总线 |
| | | task.getId(), // 任务 |
| | | null, // 动作号 |
| | | null, // 优先级 |
| | | ActionTypeType.TurnCorner.desc, // 名称 |
| | | mapService.isTurnCorner(lastCode.getData()) ? 1D : 0D, // 属性값 |
| | | lastCode.getData(), // 地面码 |
| | | String.valueOf(chargeDirection), // 动作参数 |
| | | ActionTypeType.TurnCorner.val(), // 动作类型 |
| | | actionPrepareSts, // 动作进度 |
| | | agvId, // AGV |
| | | now // 工作时间 |
| | | )); |
| | | lastDirection = chargeDirection; |
| | | } |
| | | |
| | | // charge |
| | | actionList.add(new Action( |
| | | null, // 编号 |
| | | null, // 总线 |
| | | task.getId(), // 任务 |
| | | null, // 动作号 |
| | | null, // 优先级 |
| | | ActionTypeType.DockingCharge.desc, // 名称 |
| | | null, // 属性값 |
| | | lastCode.getData(), // 地面码 |
| | | null, // 动作参数 |
| | | ActionTypeType.DockingCharge.val(), // 动作类型 |
| | | actionPrepareSts, // 动作进度 |
| | | agvId, // AGV |
| | | now // 工作时间 |
| | | )); |
| | | break; |
| | | case TO_STANDBY: |
| | | // FuncSta standByFuncSta = funcStaService.query(agvId, lastCode.getId(), 2); |
| | | // Double standByDirection = Double.parseDouble(standByFuncSta.getAngle()); |
| | | // if (!lastDirection.equals(standByDirection)) { |
| | | // actionList.add(new Action( |
| | | // null, // 编号 |
| | | // null, // 总线 |
| | | // task.getId(), // 任务 |
| | | // null, // 动作号 |
| | | // null, // 优先级 |
| | | // ActionTypeType.TurnCorner.desc, // 名称 |
| | | // null, // 属性값 |
| | | // lastCode.getData(), // 地面码 |
| | | // String.valueOf(standByDirection), // 动作参数 |
| | | // ActionTypeType.TurnCorner.val(), // 动作类型 |
| | | // actionPrepareSts, // 动作进度 |
| | | // agvId, // AGV |
| | | // now // 工作时间 |
| | | // )); |
| | | // lastDirection = standByDirection; |
| | | // } |
| | | String runToWaitHeightFlag = configService.getVal("RunToWaitHeightFlag", String.class); |
| | | if (!Cools.isEmpty(runToWaitHeightFlag) && runToWaitHeightFlag.contains(agvId.toString())) { |
| | | String runToWaitHeight = configService.getVal("RunToWaitHeight", String.class); |
| | | if (Cools.isEmpty(runToWaitHeight)) { |
| | | runToWaitHeight = "800"; |
| | | } |
| | | Double runToWaitHeightValue = configService.getVal("RunToWaitHeightValue", Double.class); |
| | | if (runToWaitHeightValue == 0) { |
| | | runToWaitHeightValue = 1D; |
| | | } |
| | | // 修复空指针异常:检查lastCode是否为null |
| | | if (lastCode == null) { |
| | | throw new BusinessException("AGV定位信息异常,无法生成待机动作"); |
| | | } |
| | | actionList.add(new Action( |
| | | null, // 编号 |
| | | task.getBusId(), // 总线 |
| | | task.getId(), // 任务 |
| | | null, // 动作号 |
| | | null, // 优先级 |
| | | ActionTypeType.RunToWaitHeight.desc, // 名称 |
| | | runToWaitHeightValue, // 属性값 |
| | | lastCode.getData(), // 地面码 |
| | | runToWaitHeight, // 动作参数 |
| | | ActionTypeType.RunToWaitHeight.val(), // 动作类型 |
| | | actionPrepareSts, // 动作进度 |
| | | agvId, // AGV |
| | | now // 工作时间 |
| | | )); |
| | | } |
| | | break; |
| | | case MOVE: |
| | | break; |
| | | default: |
| | | break; |
| | | } |
| | | |
| | | } |
| | | |
| | | // finish |
| | | actionList.add(new Action( |
| | | null, // 编号 |
| | | null, // 总线 |
| | | null, // 任务 |
| | | null, // 动作号 |
| | | null, // 优先级 |
| | | ActionTypeType.FinishPath.desc, // 名称 |
| | | null, // 属性值 |
| | | lastCode.getData(), // 地面码 |
| | | null, // 动作参数 |
| | | ActionTypeType.FinishPath.val(), // 动作类型 |
| | | actionPrepareSts, // 动作进度 |
| | | agvId, // AGV |
| | | now // 工作时间 |
| | | )); |
| | | |
| | | List<Action> newActionList = actionSorter.optimizeSort(actionList); |
| | | String groupId = String.valueOf(snowflakeIdWorker.nextId()).substring(3); |
| | | |
| | | // save action |
| | | int i = newActionList.size(); |
| | | for (Action action : newActionList) { |
| | | // action.setUuid(String.valueOf(snowflakeIdWorker.nextId()).substring(3)); |
| | | action.setGroupId(groupId); |
| | | action.setPriority(i); |
| | | i -= 1; |
| | | } |
| | | if (!actionService.saveBatch(newActionList)) { |
| | | throw new BusinessException("group[" + groupId + "] 动作保存失败"); |
| | | } |
| | | |
| | | // update segment |
| | | for (Segment item : segmentList) { |
| | | item.setGroupId(groupId); |
| | | item.setState(SegmentStateType.RUNNING.toString()); |
| | | item.setUpdateTime(now); |
| | | if (null != algoStartTime) { |
| | | item.setAlgoTime((int) (now.getTime() - algoStartTime.getTime())); |
| | | } |
| | | if (!segmentService.updateById(item)) { |
| | | throw new CoolException("更新Segment失败"); |
| | | } |
| | | } |
| | | |
| | | log.info("{}号Agv动作组装完成,指令数量:{}", agvNo, newActionList.size()); |
| | | } catch (Exception e) { |
| | | log.error("mainService.generateAction", e); |
| | | TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); |
| | | |
| | | if (!Cools.isEmpty(pathList)) { |
| | | pathList.remove(0); |
| | | List<int[]> codeMatrixIdxList = mapDataDispatcher.getCodeMatrixIdxList(null, pathList); |
| | | mapDataDispatcher.clearDynamicMatrixByCodeList(null, codeMatrixIdxList); |
| | | } |
| | | |
| | | throw new RuntimeException("generateAction method caught an exception, rolling back transaction.", e); |
| | | } |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 根据分片生成动作 ( 车辆可能已经做过一些任务了,正在等待下一段任务 ) |
| | | */ |
| | | @Transactional |
| | | public synchronized void generateActionV2(Long agvId, List<Segment> segmentList, List<String> pathList, Date algoStartTime) { |
| | | try { |
| | | if (Cools.isEmpty(agvId, segmentList)) { |
| | | return; |
| | | } |
| | | Date now = new Date(); |
| | | long actionPrepareSts = ActionStsType.PREPARE.val(); |
| | | // JSONObject storeDirection = configService.getVal("storeDirection", JSONObject.class); |
| | | int angleOffsetVal = configService.getVal("mapAngleOffsetVal", Integer.class); |
| | | String agvNo = agvService.getAgvNo(agvId); |
| | | // if (!agvService.judgeEnable(agvId)) { |
| | | // throw new CoolException("AGV[" + agvNo + "]当前不可用..."); |
| | | // } |
| | | |
| | | AgvModel agvModel = agvModelService.getByAgvId(agvId); |
| | | Double workDirection = agvModel.getWorkDirection(); |
| | | AgvSpeedType agvSpeedType = AgvSpeedType.query(agvModel.getTravelSpeed()); |
| | | assert agvSpeedType != null; |
| | | |
| | | AgvDetail agvDetail = agvDetailService.selectMajorByAgvId(agvId); |
| | | |
| | | List<Action> actionList = new ArrayList<>(); |
| | | // start node |
| | | Code lastCode = codeService.getCacheById(agvDetail.getRecentCode()); |
| | | Double lastDirection = MapService.mapToNearest(agvDetail.getAgvAngle()); |
| | | if (!lastCode.getData().equals(pathList.get(0))) { |
| | | throw new CoolException("AGV[" + agvNo + "]定位偏移..."); |
| | | } |
| | | |
| | | //String lastCorner = null; |
| | | Integer index = -1; |
| | | boolean corner = false; |
| | | for (int i = pathList.size(); i < 0; i++) { |
| | | Code nextCode = codeService.getCacheByData(pathList.get(i)); |
| | | if (nextCode != null && nextCode.getCornerBool()) { |
| | | //lastCorner = pathList.get(i); |
| | | index = i; |
| | | } |
| | | } |
| | | |
| | | boolean first = true; |
| | | for (Segment segment : segmentList) { |
| | | |
| | | // 分段所属的Task |
| | | Task task = taskService.getById(segment.getTaskId()); |
| | | |
| | | // 节点条码 |
| | | Code code = codeService.getCacheById(segment.getEndNode()); |
| | | |
| | | // 需要走行 |
| | | if (!lastCode.getData().equals(code.getData())) { |
| | | |
| | | // 走行路径节点 |
| | | // List<String> pathList = mapService.checkoutPath(agv.getUuid(), lastCode, code); |
| | | List<String> pathListPart = pathList.subList(pathList.indexOf(lastCode.getData()), pathList.indexOf(code.getData()) + 1); |
| | | |
| | | for (int i = 0; i < pathListPart.size(); i++) { |
| | | if (i == 0) { |
| | | continue; |
| | | } |
| | | String next = pathListPart.get(i); |
| | | Code nextCode = codeService.getCacheByData(next); |
| | | Double nextDirection; |
| | | |
| | | boolean reverse = false; |
| | | if (index >= i) { |
| | | // DOTO 添加转弯 |
| | | Code endCode = codeService.getCacheByData(pathList.get(pathList.size() - 1)); |
| | | nextDirection = mapService.calculateDirection(lastCode, endCode, angleOffsetVal); |
| | | reverse = true; |
| | | } else { |
| | | nextDirection = mapService.calculateDirection(lastCode, nextCode, angleOffsetVal); |
| | | |
| | | // 第一步:如果下一个方向正好是作业方向的相反方向,则重置下一个方向为作业方向,标记 reverse = true |
| | | if (!nextDirection.equals((workDirection + 180) % 360)) { |
| | | nextDirection = workDirection; |
| | | reverse = true; |
| | | } |
| | | |
| | | // 第二步:判断当前节点是否可以旋转 |
| | | if (!lastCode.getCornerBool()) { |
| | | // 如果是作业方向,但是小车在巷道内方向错误,则停止 |
| | | if (reverse && !lastDirection.equals(nextDirection)) { |
| | | // throw new CoolException(agvNo + "号小车方向错误,请推至转弯点手动调整"); |
| | | } |
| | | // 如果不是作业方向,判断是否相反方向,如果反方向则倒退行走 |
| | | if (nextDirection.equals((lastDirection + 180) % 360)) { |
| | | nextDirection = lastDirection; |
| | | reverse = true; |
| | | } |
| | | } else { |
| | | if (!lastDirection.equals(nextDirection)) { |
| | | // 如果下个节点方向与当前agv方向相反,则倒退行走,但是如果当前agv方向正好与工作方向相反,则旋转至工作方向 |
| | | if (nextDirection.equals((lastDirection + 180) % 360) && !workDirection.equals((lastDirection + 180) % 360)) { |
| | | nextDirection = lastDirection; |
| | | reverse = true; |
| | | } else { |
| | | // turn |
| | | actionList.add(new Action( |
| | | null, // 编号s |
| | | task.getBusId(), // 总线 |
| | | task.getId(), // 任务 |
| | | null, // 动作号 |
| | | null, // 优先级 |
| | | ActionTypeType.TurnCorner.desc, // 名称 |
| | | mapService.isTurnCorner(lastCode.getData()) ? 1D : 0D, // 属性值 |
| | | lastCode.getData(), // 地面码 |
| | | String.valueOf(nextDirection), // 动作参数 |
| | | ActionTypeType.TurnCorner.val(), // 动作类型 |
| | | actionPrepareSts, // 动作进度 |
| | | agvId, // AGV |
| | | now // 工作时间 |
| | | )); |
| | | |
| | | lastDirection = nextDirection; |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | |
| | | // 第一个动作一定是 turn |
| | | if (actionList.isEmpty()) { |
| | |
| | | ActionTypeType.ReadyTakeFromAgvSite.val(), // 动作类型 |
| | | actionPrepareSts, // 动作进度 |
| | | agvId, // AGV |
| | | now, // 工作时间 |
| | | destSta.getStaTypeIsCheck() == 1 ? 2 : 0, |
| | | destSta.getStaNo() |
| | | now // 工作时间 |
| | | |
| | | )); |
| | | // 计算货叉工作方向 |
| | | staWorkDirection = mapService.calculateAgvWorkDirectionByStation(destStaWorkDirection, lastDirection); |
| | |
| | | ActionTypeType.ReadyReleaseToConveyorSta.val(), // 动作类型 |
| | | actionPrepareSts, // 动作进度 |
| | | agvId, // AGV |
| | | now // 工作时间 |
| | | now, // 工作时间 |
| | | destSta.getStaTypeIsCheck() == 1 ? 2 : 0, |
| | | destSta.getStaNo() |
| | | )); |
| | | break; |
| | | case TO_CHARGE: |
| | | // 检验方向 |
| | | FuncSta chargeFuncSta = funcStaService.query(lastCode.getId(), FuncStaType.CHARGE.toString()); |
| | | Double chargeDirection = Double.parseDouble(chargeFuncSta.getAngle()); |
| | | if (!lastDirection.equals(chargeDirection)) { |
| | | if (!lastDirection.equals(chargeDirection) && lastCode.getCornerBool()) { |
| | | actionList.add(new Action( |
| | | null, // 编号 |
| | | null, // 总线 |
| | |
| | | |
| | | log.info("{}号Agv动作组装完成,指令数量:{}", agvNo, newActionList.size()); |
| | | } catch (Exception e) { |
| | | log.error("mainService.generateAction", e); |
| | | log.error("mainService.generateActionV2", e); |
| | | TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); |
| | | |
| | | if (!Cools.isEmpty(pathList)) { |
| | |
| | | mapDataDispatcher.clearDynamicMatrixByCodeList(null, codeMatrixIdxList); |
| | | } |
| | | |
| | | throw new RuntimeException("generateAction method caught an exception, rolling back transaction.", e); |
| | | throw new RuntimeException("generateActionV2 method caught an exception, rolling back transaction.", e); |
| | | } |
| | | } |
| | | |
| | |
| | | // } |
| | | // } |
| | | |
| | | List<Long> taskIds = actionService.selectTaskIdsByGroupId(serialNo); |
| | | for (Long taskId : taskIds) { |
| | | Task task = taskService.getById(taskId); |
| | | report(task, agv_11_up.getQrCode(), TaskReportStsType.END); |
| | | } |
| | | // List<Long> taskIds = actionService.selectTaskIdsByGroupId(serialNo); |
| | | // for (Long taskId : taskIds) { |
| | | // Task task = taskService.getById(taskId); |
| | | // report(task, agv_11_up.getQrCode(), TaskReportStsType.END); |
| | | // } |
| | | } |
| | | |
| | | // 出库取货 |
| | |
| | | // } |
| | | // } |
| | | // } |
| | | List<Long> taskIds = actionService.selectTaskIdsByGroupId(serialNo); |
| | | for (Long taskId : taskIds) { |
| | | Task task = taskService.getById(taskId); |
| | | report(task, agv_11_up.getQrCode(), TaskReportStsType.OTBIN); |
| | | } |
| | | // List<Long> taskIds = actionService.selectTaskIdsByGroupId(serialNo); |
| | | // for (Long taskId : taskIds) { |
| | | // Task task = taskService.getById(taskId); |
| | | // report(task, agv_11_up.getQrCode(), TaskReportStsType.OTBIN); |
| | | // } |
| | | |
| | | } |
| | | //从输送线取货完成 |
| | | if (agv_11_up.getCompleteType().equals(AgvCompleteType.TAKE_FROM_STA_COMPLETE)) { |
| | | WebsocketServiceImpl.taskShelfBarcode = agv_11_up.getLocCode(); |
| | | List<Long> taskIds = actionService.selectTaskIdsByGroupId(serialNo); |
| | | for (Long taskId : taskIds) { |
| | | Task task = taskService.getById(taskId); |
| | | report(task, agv_11_up.getQrCode(), TaskReportStsType.OTBIN); |
| | | } |
| | | } |
| | | // if (agv_11_up.getCompleteType().equals(AgvCompleteType.TAKE_FROM_STA_COMPLETE)) { |
| | | // WebsocketServiceImpl.taskShelfBarcode = agv_11_up.getLocCode(); |
| | | // List<Long> taskIds = actionService.selectTaskIdsByGroupId(serialNo); |
| | | // for (Long taskId : taskIds) { |
| | | // Task task = taskService.getById(taskId); |
| | | // report(task, agv_11_up.getQrCode(), TaskReportStsType.OTBIN); |
| | | // } |
| | | // } |
| | | //往输送线放货完成 |
| | | if (agv_11_up.getCompleteType().equals(AgvCompleteType.RELEASE_FROM_STA_COMPLETE)) { |
| | | WebsocketServiceImpl.taskShelfBarcode = agv_11_up.getLocCode(); |
| | | List<Long> taskIds = actionService.selectTaskIdsByGroupId(serialNo); |
| | | for (Long taskId : taskIds) { |
| | | Task task = taskService.getById(taskId); |
| | | report(task, agv_11_up.getQrCode(), TaskReportStsType.END); |
| | | } |
| | | } |
| | | // if (agv_11_up.getCompleteType().equals(AgvCompleteType.RELEASE_FROM_STA_COMPLETE)) { |
| | | // WebsocketServiceImpl.taskShelfBarcode = agv_11_up.getLocCode(); |
| | | // List<Long> taskIds = actionService.selectTaskIdsByGroupId(serialNo); |
| | | // for (Long taskId : taskIds) { |
| | | // Task task = taskService.getById(taskId); |
| | | // report(task, agv_11_up.getQrCode(), TaskReportStsType.END); |
| | | // } |
| | | // } |
| | | |
| | | // 路径完成 || 充电完成 |
| | | if (agv_11_up.getCompleteType().equals(AgvCompleteType.ENTIRE_PATH_COMPLETE) |
| | |
| | | // task |
| | | for (Segment segment : segmentList) { |
| | | boolean taskComplete = false; |
| | | boolean otbin = false; |
| | | |
| | | |
| | | Task task = taskService.getById(segment.getTaskId()); |
| | | assert null != task; |
| | |
| | | switch (Objects.requireNonNull(posType)) { |
| | | case ORI_STA: |
| | | case ORI_LOC: |
| | | otbin = true; |
| | | break; |
| | | case DEST_STA: |
| | | case DEST_LOC: |
| | |
| | | break; |
| | | } |
| | | |
| | | if (otbin) { |
| | | locService.taskCallBackOtbin(task); |
| | | report(task, null, TaskReportStsType.OTBIN); |
| | | } |
| | | |
| | | |
| | | if (taskComplete) { |
| | | locService.taskCallBack(task); |
| | | locService.taskCallBackEnd(task); |
| | | |
| | | task.setTaskSts(TaskStsType.COMPLETE.val()); |
| | | task.setEndTime(now); |
| | | task.setUpdateTime(now); |
| | | if (!taskService.updateById(task)) { |
| | | log.error("Task [{}] 更新失败 !!!", task.getSeqNum()); |
| | | } else { |
| | | report(task, null, TaskReportStsType.END); |
| | | } |
| | | report(task, null, TaskReportStsType.END); |
| | | if (task.getSeqNum() != null && task.getSeqNum().contains("SSX-CK")) { |
| | | report(task, "1001", TaskReportStsType.COMPLETED); |
| | | } |
| | | } |
| | | } |
| | |
| | | } |
| | | List<TaskReport> list = taskReportService.list(new LambdaQueryWrapper<TaskReport>().eq(TaskReport::getSeqNum, task.getSeqNum()).eq(TaskReport::getBusNo, task.getBusId$()).eq(TaskReport::getTaskSts, taskReportStsType.status)); |
| | | if (!Cools.isEmpty(list)) { |
| | | log.info("TaskReport [{}] 已重复,不再插入 ==========>> ", JSON.toJSONString(task)); |
| | | log.info("TaskReport [{},{}] 已重复,不再插入 ==========>> ", taskReportStsType, JSON.toJSONString(task)); |
| | | return; |
| | | } |
| | | TaskReport taskReport = new TaskReport(); |
| | | taskReport.setAgvId(task.getAgvId()); |
| | | taskReport.setAgvNo(task.getAgvId$()); |
| | | taskReport.setBusNo(task.getBusId$()); |
| | | taskReport.setCreateTime(new Date()); |
| | | taskReport.setCompleted(0); |
| | |
| | | taskReport.setEventType(taskReportStsType.name); |
| | | taskReport.setSeqNum(task.getSeqNum()); |
| | | taskReport.setZpallet(task.getZpallet()); |
| | | |
| | | if (!taskReportService.save(taskReport)) { |
| | | log.info("TaskReport [{}] 插入失败 ==========>> ", JSON.toJSONString(taskReport)); |
| | | } else { |
| | |
| | | |
| | | private boolean askSta(Integer askType, String askSta) { |
| | | log.info("来询问输送线了,{},{}", askType, askSta); |
| | | String wmsUrl = configService.getVal("WMS_URL", String.class); |
| | | String wmsUrl = configService.getVal("WCS_URL", String.class); |
| | | String wmsPath = configService.getVal("WMS_STA", String.class); |
| | | if (Cools.isEmpty(wmsPath) || Cools.isEmpty(wmsUrl)) { |
| | | return true; |
| | | return false; |
| | | } |
| | | Integer time = configService.getVal("TIMEOUT", Integer.class, 5); |
| | | //Integer times = configService.getVal("REPORT_TIMES", Integer.class, 2); |