| | |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; |
| | | import com.zy.acs.common.constant.RedisConstant; |
| | | import com.zy.acs.common.domain.AgvAction; |
| | | import com.zy.acs.common.domain.AgvActionItem; |
| | | import com.zy.acs.common.domain.AgvProtocol; |
| | | import com.zy.acs.common.domain.BaseResult; |
| | | import com.zy.acs.common.domain.*; |
| | | import com.zy.acs.common.domain.protocol.*; |
| | | import com.zy.acs.common.domain.protocol.action.*; |
| | | import com.zy.acs.common.enums.*; |
| | | import com.zy.acs.common.utils.Base62; |
| | | import com.zy.acs.common.utils.GsonUtils; |
| | | import com.zy.acs.common.utils.RedisSupport; |
| | | import com.zy.acs.common.utils.Utils; |
| | |
| | | , (task, agvNo, sta) -> { |
| | | Long agvId = agvService.getAgvId(agvNo); |
| | | |
| | | // List<Travel> travelList = travelService.list(new LambdaQueryWrapper<Travel>() |
| | | // .eq(Travel::getAgvId, agvId) |
| | | // .eq(Travel::getState, TravelStateType.RUNNING.toString()) |
| | | // .orderByDesc(Travel::getCreateTime)); |
| | | // if (Cools.isEmpty(travelList)) { |
| | | // throw new BusinessException("[Agv: " + agvNo + "]allocate inbound failed to find travel"); |
| | | Travel travel = travelService.findRunningTravel(agvId); |
| | | if (null == travel) { |
| | | throw new CoolException("[Agv:" + agvNo + "] allocate inbound failed: no roller waiting travel"); |
| | | } |
| | | |
| | | // curr segment |
| | | Segment currSeg = segmentService.getCurrWaitingSeg(travel.getId(), agvId); |
| | | // if (null == currSeg) { |
| | | // currSeg = segmentService.getCurrRunningSeg(travel.getId(), agvId, null); |
| | | // } |
| | | // Travel travel = travelList.get(0); |
| | | // |
| | | // List<Segment> currSegments = segmentService.list(new LambdaQueryWrapper<Segment>() |
| | | // .eq(Segment::getAgvId, agvId) |
| | | // .eq(Segment::getTravelId, travel.getId()) |
| | | // ); |
| | | // load segment |
| | | Segment currSeg = segmentService.getRollerWaiting(agvId, sta.getCode(), TaskPosDto.PosType.ORI_STA); |
| | | if (null == currSeg) { |
| | | throw new BusinessException("[Agv:" + agvNo + "] allocate inbound failed: no roller waiting segment"); |
| | | throw new CoolException("[Agv:" + agvNo + "] allocate inbound failed: no waiting segment"); |
| | | } |
| | | |
| | | // get backpack lev |
| | | int backpackLev = 0; |
| | | int backpack = agvService.getBackpack(agvId); |
| | | int backpackCap = agvService.getBackpack(agvId); |
| | | List<Integer> usedBackpacks = segmentService.selectUsedBackpacks(currSeg.getTravelId(), agvId); |
| | | if (usedBackpacks.size() >= backpack) { |
| | | if (usedBackpacks.size() >= backpackCap) { |
| | | throw new CoolException("[Agv:" + agvNo + "] allocate inbound segment failed: no idle backpack to use"); |
| | | } |
| | | for (int lev = 1; lev <= backpack; lev++) { |
| | | for (int lev = 1; lev <= backpackCap; lev++) { |
| | | if (!usedBackpacks.contains(lev)) { |
| | | backpackLev = lev; |
| | | break; |
| | |
| | | |
| | | // DEST-only sort |
| | | destPosList.sort((a, b) -> { |
| | | |
| | | // 主轴 |
| | | double aFirst = a.getFirstWeight(sameGroupXy); |
| | | double bFirst = b.getFirstWeight(sameGroupXy); |
| | |
| | | |
| | | // get placeSeg serial |
| | | int placeSegSerial; |
| | | // query placeSeg idx |
| | | int idx = -1; |
| | | for (int i = 0; i < destPosList.size(); i++) { |
| | | if (Objects.equals(destPosList.get(i).getCodeId(), newDto.getCodeId()) |
| | | && Objects.equals(destPosList.get(i).getTaskId(), newDto.getTaskId())) { |
| | | if (Objects.equals(destPosList.get(i).getTaskId(), newDto.getTaskId()) |
| | | && Objects.equals(destPosList.get(i).getCodeId(), newDto.getCodeId())) { |
| | | idx = i; |
| | | break; |
| | | } |
| | |
| | | try { |
| | | // valid ----------------------------------------------- |
| | | Agv agv = agvService.getById(agvId); |
| | | if (!agvService.judgeEnable(agv.getId(), false)) { |
| | | if (!agvService.judgeEnable(agv.getId())) { |
| | | return; |
| | | } |
| | | if (!Cools.isEmpty(taskService.selectInSts(agvId, TaskStsType.ASSIGN, TaskStsType.PROGRESS))) { |
| | |
| | | return o2.getPriority() - o1.getPriority(); |
| | | } |
| | | }); |
| | | Integer backpack = agvService.getBackpack(agvId); |
| | | if (taskList.size() > backpack) { |
| | | taskList = taskList.subList(0, backpack); |
| | | Integer backpackCap = agvService.getBackpack(agvId); |
| | | if (taskList.size() > backpackCap) { |
| | | taskList = taskList.subList(0, backpackCap); |
| | | } |
| | | |
| | | AgvDetail agvDetail = agvDetailService.selectByAgvId(agvId); |
| | |
| | | |
| | | } |
| | | |
| | | if (backpackLev > backpack) { |
| | | if (backpackLev > backpackCap) { |
| | | throw new BusinessException("解析Task失败,AGV背篓已满......"); |
| | | } |
| | | |
| | |
| | | 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())); |
| | | // task.setSeqNum(Utils.generateSeqNum(Cools.isEmpty(lastTasks)?null:lastTasks.get(0).getSeqNum())); |
| | | task.setSeqNum(Base62.encode(snowflakeIdWorker.nextId())); |
| | | task.setOriCode(agvDetail.getCode()); |
| | | task.setDestCode(endCode.getId()); |
| | | // lane |
| | |
| | | long actionPrepareSts = ActionStsType.PREPARE.val(); |
| | | // JSONObject storeDirection = configService.getVal("storeDirection", JSONObject.class); |
| | | int angleOffsetVal = configService.getVal("mapAngleOffsetVal", Integer.class); |
| | | // Double defaultShelfDepth = configService.getVal("defaultShelfDepth", Double.class); |
| | | // defaultShelfDepth = Optional.ofNullable(defaultShelfDepth).orElse((double) 0); |
| | | String agvNo = agvService.getAgvNo(agvId); |
| | | // if (!agvService.judgeEnable(agvId)) { |
| | | // throw new CoolException("AGV[" + agvNo + "]当前不可用..."); |
| | |
| | | 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++) { |
| | |
| | | null, // 动作号 |
| | | null, // 优先级 |
| | | ActionTypeType.TurnCorner.desc, // 名称 |
| | | (double) mapService.spinDirection(lastCode).val, // 属性值 |
| | | (double) MapService.calcSpinDirection(lastCode, lastDirection, nextLaneDir).val, // 属性值 |
| | | lastCode.getData(), // 地面码 |
| | | String.valueOf(nextLaneDir), // 动作参数 |
| | | ActionTypeType.TurnCorner.val(), // 动作类型 |
| | |
| | | now // 工作时间 |
| | | )); |
| | | lastDirection = nextLaneDir; |
| | | |
| | | if (nextDirection.equals(oppNextLaneDir)) { |
| | | reverse = true; |
| | | } |
| | | } else { |
| | | if (nextDirection.equals(oppNextLaneDir)) { |
| | | nextDirection = nextLaneDir; |
| | | reverse = true; |
| | | } |
| | | } |
| | | |
| | | nextDirection = nextLaneDir; |
| | | } else if (null != lastLaneDir) { |
| | | final double oppLastLaneDir = (lastLaneDir + 180) % 360; |
| | | if (nextDirection.equals(oppLastLaneDir)) { |
| | | if (nextDirection.equals(oppNextLaneDir)) { |
| | | reverse = true; |
| | | } |
| | | nextDirection = lastLaneDir; |
| | | nextDirection = nextLaneDir; // 防止 第一个动作一定是 turn 出问题 |
| | | } else if (null != lastLaneDir) { // turn 环形直角不应该存在于lane中 |
| | | final double oppLastLaneDir = (lastLaneDir + 180) % 360; |
| | | |
| | | if (!lastDirection.equals(nextDirection)) { |
| | | if (!lastDirection.equals(lastLaneDir)) { |
| | | if (!lastCode.getCornerBool()) { |
| | | throw new CoolException(agvNo + "号小车离开巷道需调整方向为 " + nextDirection + "°,请推至转弯点手动调整"); |
| | | } |
| | | } |
| | | |
| | | if (nextDirection.equals(oppLastLaneDir)) { |
| | | reverse = true; |
| | | } |
| | | nextDirection = lastLaneDir; // 防止 第一个动作一定是 turn 出问题 |
| | | } else { |
| | | |
| | | // 如果下一个方向正好是作业方向的相反方向,则重置下一个方向为作业方向,标记 reverse = true |
| | |
| | | null, // 动作号 |
| | | null, // 优先级 |
| | | ActionTypeType.TurnCorner.desc, // 名称 |
| | | (double) mapService.spinDirection(lastCode).val, // 属性值 |
| | | (double) MapService.calcSpinDirection(lastCode, lastDirection, nextDirection).val, // 属性值 |
| | | lastCode.getData(), // 地面码 |
| | | String.valueOf(nextDirection), // 动作参数 |
| | | ActionTypeType.TurnCorner.val(), // 动作类型 |
| | |
| | | null, // 动作号 |
| | | null, // 优先级 |
| | | ActionTypeType.TurnCorner.desc, // 名称 |
| | | (double) mapService.spinDirection(lastCode).val, // 属性值 |
| | | (double) MapService.calcSpinDirection(lastCode, lastDirection, nextDirection).val, // 属性值 |
| | | lastCode.getData(), // 地面码 |
| | | String.valueOf(nextDirection), // 动作参数 |
| | | ActionTypeType.TurnCorner.val(), // 动作类型 |
| | |
| | | null, // 动作号 |
| | | null, // 优先级 |
| | | ActionTypeType.TurnCorner.desc, // 名称 |
| | | (double) mapService.spinDirection(lastCode).val, // 属性值 |
| | | (double) MapService.calcSpinDirection(lastCode, lastDirection, firstTurnDir).val, // 属性值 |
| | | lastCode.getData(), // 地面码 |
| | | String.valueOf(firstTurnDir), // 动作参数 |
| | | ActionTypeType.TurnCorner.val(), // 动作类型 |
| | |
| | | ActionTypeType.ReadyTakeFromShelvesLoc.desc, // 名称 |
| | | (double) agvDirectionType.val, // 属性值 |
| | | lastCode.getData(), // 地面码 |
| | | String.valueOf(oriLoc.getOffset()), // 动作参数 |
| | | JSON.toJSONString(new HeightDepthDto(oriLoc.getOffset())), // 动作参数 |
| | | ActionTypeType.ReadyTakeFromShelvesLoc.val(), // 动作类型 |
| | | actionPrepareSts, // 动作进度 |
| | | agvId, // AGV |
| | |
| | | ActionTypeType.ReadyReleaseToShelvesLoc.desc, // 名称 |
| | | (double) agvDirectionType.val, // 属性值 |
| | | lastCode.getData(), // 地面码 |
| | | String.valueOf(destLoc.getOffset()), // 动作参数 |
| | | JSON.toJSONString(new HeightDepthDto(destLoc.getOffset())), // 动作参数 |
| | | ActionTypeType.ReadyReleaseToShelvesLoc.val(), // 动作类型 |
| | | actionPrepareSts, // 动作进度 |
| | | agvId, // AGV |
| | |
| | | null, // 动作号 |
| | | null, // 优先级 |
| | | ActionTypeType.TurnCorner.desc, // 名称 |
| | | (double) mapService.spinDirection(lastCode).val, // 属性值 |
| | | (double) MapService.calcSpinDirection(lastCode, lastDirection, oriStaWorkDirection).val, // 属性值 |
| | | lastCode.getData(), // 地面码 |
| | | String.valueOf(oriStaWorkDirection), // 动作参数 |
| | | ActionTypeType.TurnCorner.val(), // 动作类型 |
| | |
| | | ActionTypeType.ReadyTakeFromConveyorSta.desc, // 名称 |
| | | staWorkDirection, // 属性值 |
| | | lastCode.getData(), // 地面码 |
| | | String.valueOf(oriSta.getOffset()), // 动作参数 |
| | | JSON.toJSONString(new HeightDepthDto(oriSta.getHeight(), Optional.ofNullable(oriSta.getDepth()).orElse((double) 0))), // 动作参数 |
| | | ActionTypeType.ReadyTakeFromConveyorSta.val(), // 动作类型 |
| | | actionPrepareSts, // 动作进度 |
| | | agvId, // AGV |
| | |
| | | null, // 动作号 |
| | | null, // 优先级 |
| | | ActionTypeType.TurnCorner.desc, // 名称 |
| | | (double) mapService.spinDirection(lastCode).val, // 属性值 |
| | | (double) MapService.calcSpinDirection(lastCode, lastDirection, destStaWorkDirection).val, // 属性值 |
| | | lastCode.getData(), // 地面码 |
| | | String.valueOf(destStaWorkDirection), // 动作参数 |
| | | ActionTypeType.TurnCorner.val(), // 动作类型 |
| | |
| | | ActionTypeType.ReadyReleaseToConveyorSta.desc, // 名称 |
| | | staWorkDirection, // 属性值 |
| | | lastCode.getData(), // 地面码 |
| | | String.valueOf(destSta.getOffset()), // 动作参数 |
| | | JSON.toJSONString(new HeightDepthDto(destSta.getHeight(), Optional.ofNullable(destSta.getDepth()).orElse((double) 0))), // 动作参数 |
| | | ActionTypeType.ReadyReleaseToConveyorSta.val(), // 动作类型 |
| | | actionPrepareSts, // 动作进度 |
| | | agvId, // AGV |
| | |
| | | null, // 动作号 |
| | | null, // 优先级 |
| | | ActionTypeType.TurnCorner.desc, // 名称 |
| | | (double) mapService.spinDirection(lastCode).val, // 属性值 |
| | | (double) MapService.calcSpinDirection(lastCode, lastDirection, chargeDirection).val, // 属性值 |
| | | lastCode.getData(), // 地面码 |
| | | String.valueOf(chargeDirection), // 动作参数 |
| | | ActionTypeType.TurnCorner.val(), // 动作类型 |
| | |
| | | agvAction.add(new AgvActionItem<>(ReadyTakeFromShelvesLoc.class) |
| | | .setVal(action.getVal().intValue()) |
| | | .setQrCode(action.getCode()) |
| | | .bodySync(body -> body.setHeight((short) Double.parseDouble(action.getParams()))) |
| | | .bodySync((body) -> { |
| | | HeightDepthDto heightDepthDto = JSON.parseObject(action.getParams(), HeightDepthDto.class); |
| | | body.setHeight(heightDepthDto.getHeight()); |
| | | body.setDepth(heightDepthDto.getDepth()); |
| | | }) |
| | | ); |
| | | break; |
| | | case ReadyTakeFromConveyorSta: |
| | | agvAction.add(new AgvActionItem<>(ReadyTakeFromConveyorSta.class) |
| | | .setVal(action.getVal().intValue()) |
| | | .setQrCode(action.getCode()) |
| | | .bodySync(body -> body.setHeight((short) Double.parseDouble(action.getParams()))) |
| | | .bodySync((body) -> { |
| | | HeightDepthDto heightDepthDto = JSON.parseObject(action.getParams(), HeightDepthDto.class); |
| | | body.setHeight(heightDepthDto.getHeight()); |
| | | body.setDepth(heightDepthDto.getDepth()); |
| | | }) |
| | | ); |
| | | break; |
| | | case ReadyTakeFromAgvSite: |
| | |
| | | agvAction.add(new AgvActionItem<>(ReadyReleaseToShelvesLoc.class) |
| | | .setVal(action.getVal().intValue()) |
| | | .setQrCode(action.getCode()) |
| | | .bodySync(body -> body.setHeight((short) Double.parseDouble(action.getParams()))) |
| | | ); |
| | | break; |
| | | case LoadPlatformLift: |
| | | agvAction.add(new AgvActionItem<>(LoadPlatformLift.class) |
| | | .setVal(action.getVal().intValue()) |
| | | .setQrCode(action.getCode()) |
| | | .bodySync(body -> body.setHeight((short) Double.parseDouble(action.getParams()))) |
| | | .bodySync((body) -> { |
| | | HeightDepthDto heightDepthDto = JSON.parseObject(action.getParams(), HeightDepthDto.class); |
| | | body.setHeight(heightDepthDto.getHeight()); |
| | | body.setDepth(heightDepthDto.getDepth()); |
| | | }) |
| | | ); |
| | | break; |
| | | case ReadyReleaseToConveyorSta: |
| | | agvAction.add(new AgvActionItem<>(ReadyReleaseToConveyorSta.class) |
| | | .setVal(action.getVal().intValue()) |
| | | .setQrCode(action.getCode()) |
| | | .bodySync(body -> body.setHeight((short) Double.parseDouble(action.getParams()))) |
| | | .bodySync((body) -> { |
| | | HeightDepthDto heightDepthDto = JSON.parseObject(action.getParams(), HeightDepthDto.class); |
| | | body.setHeight(heightDepthDto.getHeight()); |
| | | body.setDepth(heightDepthDto.getDepth()); |
| | | }) |
| | | ); |
| | | break; |
| | | case ReadyReleaseToAgvSite: |
| | |
| | | .setVal(action.getVal().intValue()) |
| | | .setQrCode(action.getCode()) |
| | | .bodySync(body -> body.setDepth((short) Double.parseDouble(action.getParams()))) |
| | | ); |
| | | break; |
| | | case LoadPlatformLift: |
| | | agvAction.add(new AgvActionItem<>(LoadPlatformLift.class) |
| | | .setVal(action.getVal().intValue()) |
| | | .setQrCode(action.getCode()) |
| | | .bodySync(body -> body.setHeight((short) Double.parseDouble(action.getParams()))) |
| | | ); |
| | | break; |
| | | case FinishPath: |
| | |
| | | Code code = codeService.getCacheByData(agv_06_up.getQrCode()); |
| | | |
| | | // query current segment |
| | | Segment currSeg = segmentService.getCurrRunningSeg(agv.getId(), code.getId()); |
| | | Segment currSeg = segmentService.getCurrRunningSeg(null, agv.getId(), code.getId()); |
| | | if (null == currSeg) { |
| | | log.error("failed to find curr segment [{}]", agv.getUuid()); |
| | | } else { |
| | |
| | | // load from sta |
| | | sta = staService.getById(currTask.getOriSta()); |
| | | // reserve to be waiting |
| | | if (!staReserveService.waitingStaReserve(sta, currTask, 1, StaReserveType.OUT)) { |
| | | if (!staReserveService.waitingStaReserve(sta, currTask, currSeg, 1, StaReserveType.OUT)) { |
| | | break; |
| | | } |
| | | // convey plc valid |
| | |
| | | staReserveService.rollbackWaitingToReserved(sta, currTask, StaReserveType.OUT); |
| | | break; |
| | | } |
| | | log.info("AGV [{}] load permitted at conveyor station [{}]", protocol.getAgvNo(), sta.getStaNo()); |
| | | success = true; |
| | | break; |
| | | case DEST_STA: |
| | | // place to sta |
| | | sta = staService.getById(currTask.getDestSta()); |
| | | // reserve to be waiting |
| | | if (!staReserveService.waitingStaReserve(sta, currTask, 1, StaReserveType.IN)) { |
| | | if (!staReserveService.waitingStaReserve(sta, currTask, currSeg, 1, StaReserveType.IN)) { |
| | | break; |
| | | } |
| | | // convey plc valid |
| | |
| | | staReserveService.rollbackWaitingToReserved(sta, currTask, StaReserveType.IN); |
| | | break; |
| | | } |
| | | log.info("AGV [{}] unload permitted at conveyor station [{}]", protocol.getAgvNo(), sta.getStaNo()); |
| | | success = true; |
| | | break; |
| | | default: |
| | | log.error("agv[{}] has wrong posType [{}], segment [{}]", protocol.getAgvNo(), posType.toString(), currSeg.getId()); |
| | | log.error("AGV [{}] has wrong posType [{}], segment [{}]", protocol.getAgvNo(), posType.toString(), currSeg.getId()); |
| | | break; |
| | | } |
| | | } |
| | |
| | | AGV_06_DOWN agv_06_down = new AGV_06_DOWN(); |
| | | agv_06_down.setSerialNo(agv_06_up.getSerialNo()); |
| | | agv_06_down.setActionCode(agv_06_up.getActionCode()); |
| | | //agv_06_down.setResult(success ? 1 : 0); |
| | | agv_06_down.setResult(1); |
| | | agv_06_down.setResult(success ? 1 : 0); |
| | | redis.push(RedisConstant.AGV_PATH_DOWN_FLAG, AgvProtocol.build(protocol.getAgvNo()).setMessageBody(agv_06_down)); |
| | | } |
| | | |