| | |
| | | try { |
| | | // valid ----------------------------------------------- |
| | | Agv agv = agvService.getById(agvId); |
| | | if (!agvService.judgeEnable(agv.getId(), true)) { |
| | | if (!agvService.judgeEnable(agv.getId(), false)) { |
| | | return; |
| | | } |
| | | if (!Cools.isEmpty(taskService.selectInSts(agvId, TaskStsType.ASSIGN, TaskStsType.PROGRESS))) { |
| | |
| | | if (Cools.isEmpty(agvId, taskType)) { return false; } |
| | | try { |
| | | String agvNo = agvService.getAgvNo(agvId); |
| | | AgvDetail agvDetail = agvDetailService.selectByAgvId(agvId); |
| | | if (!agvService.judgeEnable(agvId)) { |
| | | return false; |
| | | } |
| | |
| | | } |
| | | |
| | | Date now = new Date(); |
| | | AgvDetail agvDetail = agvDetailService.selectMajorByAgvId(agvId); |
| | | Code endCode = null; |
| | | switch (taskType) { |
| | | case TO_CHARGE: |
| | |
| | | // 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 + "]当前不可用..."); |
| | | } |
| | | // if (!agvService.judgeEnable(agvId)) { |
| | | // throw new CoolException("AGV[" + agvNo + "]当前不可用..."); |
| | | // } |
| | | |
| | | AgvModel agvModel = agvModelService.getByAgvId(agvId); |
| | | Double workDirection = agvModel.getWorkDirection(); |
| | |
| | | Code nextCode = codeService.getCacheByData(next); |
| | | Double nextDirection = mapService.calculateDirection(lastCode, nextCode, angleOffsetVal); |
| | | |
| | | // 如果去下个节点的方向与当前方向差180度,则不需要旋转,改为反方向行走,nextDirection继续赋值是为了避免 ‘第一个动作一定是 turn’ 的判断 |
| | | boolean reverse = false; |
| | | if (nextDirection.equals((workDirection + 180) % 360)) { |
| | | nextDirection = workDirection; |
| | | reverse = true; |
| | | } |
| | | if (!lastDirection.equals(nextDirection) || actionList.isEmpty()) { |
| | | |
| | | if (!lastCode.getCornerBool()) { |
| | | if (nextDirection.equals((lastDirection + 180) % 360)) { |
| | | nextDirection = lastDirection; |
| | | reverse = true; |
| | | } |
| | | } else { |
| | | if (!lastDirection.equals(nextDirection)) { |
| | | if (lastDirection.equals((nextDirection + 180) % 360)) { |
| | | nextDirection = lastDirection; |
| | | reverse = true; |
| | | } else { |
| | | // 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; |
| | | } |
| | | } |
| | | } |
| | | |
| | | // 第一个动作一定是 turn |
| | | if (actionList.isEmpty()) { |
| | | // turn |
| | | actionList.add(new Action( |
| | | null, // 编号 |
| | |
| | | )); |
| | | |
| | | lastDirection = nextDirection; |
| | | |
| | | } |
| | | |
| | | // run |
| | |
| | | now // 工作时间 |
| | | )); |
| | | |
| | | // List<Action> newActionList = new ArrayList<>(actionList); |
| | | |
| | | // List<Action> optimizeList = actionService.optimizeSort(actionList); |
| | | |
| | | List<Action> optimizeList = actionSorter.optimizeSort(actionList); |
| | | List<Action> newActionList = new ArrayList<>(optimizeList); |
| | | |
| | | |
| | | 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.setUuid(String.valueOf(snowflakeIdWorker.nextId()).substring(3)); |
| | | action.setGroupId(groupId); |
| | | action.setPriority(i); |
| | | if (!actionService.save(action)) { |
| | | throw new BusinessException(action.getName() + "动作保存失败"); |
| | | } |
| | | i -= 1; |
| | | } |
| | | if (!actionService.saveBatch(newActionList)) { |
| | | throw new BusinessException("group[" + groupId + "] 动作保存失败"); |
| | | } |
| | | |
| | | // update segment |
| | |
| | | action.setStartTime(now); |
| | | action.setIoTime(now); |
| | | action.setUpdateTime(now); |
| | | if (!actionService.updateById(action)) { |
| | | throw new BusinessException(action.getPriority() + " - " + action.getName() + "动作更新失败"); |
| | | } |
| | | } |
| | | if (!actionService.updateBatchById(actionList)) { |
| | | throw new BusinessException("failed to update action batch !!!"); |
| | | } |
| | | |
| | | // task |