| | |
| | | package com.zy.acs.manager.core.service; |
| | | |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.zy.acs.common.domain.AgvAction; |
| | | import com.zy.acs.common.domain.AgvActionItem; |
| | |
| | | import com.zy.acs.manager.manager.enums.*; |
| | | import com.zy.acs.manager.manager.service.*; |
| | | import com.zy.acs.manager.manager.service.impl.WebsocketServiceImpl; |
| | | import com.zy.acs.manager.manager.utils.ActionSorter; |
| | | import com.zy.acs.manager.system.service.ConfigService; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Component; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Propagation; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.springframework.transaction.interceptor.TransactionAspectSupport; |
| | |
| | | * Created by vincent on 2023/6/14 |
| | | */ |
| | | @Slf4j |
| | | @Component("mainService") |
| | | @Service("mainService") |
| | | public class MainService { |
| | | |
| | | @Autowired |
| | |
| | | private AgvModelService agvModelService; |
| | | @Autowired |
| | | private LaneService laneService; |
| | | |
| | | @Autowired |
| | | private ActionSorter actionSorter; |
| | | |
| | | @SuppressWarnings("all") |
| | | @Transactional |
| | |
| | | if (!locService.updateById(oriLoc)) { |
| | | throw new BusinessException("oriLoc:" + task.getOriLoc$() + " failed to update"); |
| | | } |
| | | |
| | | destSta = staService.getById(task.getDestSta()); |
| | | if (!destSta.getStaSts().equals(StaStsType.IDLE.val())) { |
| | | throw new BusinessException("destSta:" + task.getDestSta$() + " is not in IDLE status"); |
| | | } |
| | | destSta.setStaSts(StaStsType.READY_RELEASE.val()); |
| | | destSta.setUpdateTime(now); |
| | | if (!staService.updateById(destSta)) { |
| | | throw new BusinessException("destSta:" + task.getDestSta$() + " failed to update"); |
| | | } |
| | | break; |
| | | case STA_TO_LOC: |
| | | oriSta = staService.getById(task.getOriSta()); |
| | | if (!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)) { |
| | | throw new BusinessException("oriSta:" + task.getOriSta$() + " failed to update"); |
| | | } |
| | | |
| | | destLoc = locService.getById(task.getDestLoc()); |
| | | if (!destLoc.getLocSts().equals(LocStsType.IDLE.val())) { |
| | | throw new BusinessException("destLoc:" + task.getDestLoc$() + " is not in IDLE status"); |
| | |
| | | } |
| | | break; |
| | | case STA_TO_STA: |
| | | oriSta = staService.getById(task.getOriSta()); |
| | | if (!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)) { |
| | | throw new BusinessException("oriSta:" + task.getOriSta$() + " failed to update"); |
| | | } |
| | | |
| | | destSta = staService.getById(task.getDestSta()); |
| | | if (!destSta.getStaSts().equals(StaStsType.IDLE.val())) { |
| | | throw new BusinessException("destSta:" + task.getDestSta$() + " is not in IDLE status"); |
| | | } |
| | | destSta.setStaSts(StaStsType.READY_RELEASE.val()); |
| | | destSta.setUpdateTime(now); |
| | | if (!staService.updateById(destSta)) { |
| | | throw new BusinessException("destSta:" + task.getDestSta$() + " failed to update"); |
| | | } |
| | | break; |
| | | default: |
| | | break; |
| | |
| | | for (Task task : taskList) { |
| | | Agv agv = allocateService.execute(task); |
| | | if (null == agv) { |
| | | // log.warn("Task[{}] has an issue, because it failed to checkout agv which is idle...", task.getSeqNum()); |
| | | // log.warn("Task[{}] has an issue, because it failed to check out agv which is idle...", task.getSeqNum()); |
| | | continue; |
| | | } |
| | | task.setAgvId(agv.getId()); |
| | |
| | | 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))) { |
| | |
| | | oriLoc = locService.getById(task.getOriLoc()); |
| | | destLoc = locService.getById(task.getDestLoc()); |
| | | |
| | | startCode = codeService.getById(oriLoc.getCode()); |
| | | endCode = codeService.getById(destLoc.getCode()); |
| | | startCode = codeService.getCacheById(oriLoc.getCode()); |
| | | endCode = codeService.getCacheById(destLoc.getCode()); |
| | | |
| | | TaskPosDto.packagePosGroup(groups, task, startCode, TaskPosDto.PosType.ORI_LOC, sameGroupXy); |
| | | TaskPosDto.packagePosGroup(groups, task, endCode, TaskPosDto.PosType.DEST_LOC, sameGroupXy); |
| | |
| | | oriLoc = locService.getById(task.getOriLoc()); |
| | | destSta = staService.getById(task.getDestSta()); |
| | | |
| | | startCode = codeService.getById(oriLoc.getCode()); |
| | | endCode = codeService.getById(destSta.getCode()); |
| | | startCode = codeService.getCacheById(oriLoc.getCode()); |
| | | endCode = codeService.getCacheById(destSta.getCode()); |
| | | |
| | | TaskPosDto.packagePosGroup(groups, task, startCode, TaskPosDto.PosType.ORI_LOC, sameGroupXy); |
| | | TaskPosDto.packagePosGroup(groups, task, endCode, TaskPosDto.PosType.DEST_STA, sameGroupXy); |
| | |
| | | oriSta = staService.getById(task.getOriSta()); |
| | | destLoc = locService.getById(task.getDestLoc()); |
| | | |
| | | startCode = codeService.getById(oriSta.getCode()); |
| | | endCode = codeService.getById(destLoc.getCode()); |
| | | startCode = codeService.getCacheById(oriSta.getCode()); |
| | | endCode = codeService.getCacheById(destLoc.getCode()); |
| | | |
| | | TaskPosDto.packagePosGroup(groups, task, startCode, TaskPosDto.PosType.ORI_STA, sameGroupXy); |
| | | TaskPosDto.packagePosGroup(groups, task, endCode, TaskPosDto.PosType.DEST_LOC, sameGroupXy); |
| | |
| | | oriSta = staService.getById(task.getOriSta()); |
| | | destSta = staService.getById(task.getDestSta()); |
| | | |
| | | startCode = codeService.getById(oriSta.getCode()); |
| | | endCode = codeService.getById(destSta.getCode()); |
| | | startCode = codeService.getCacheById(oriSta.getCode()); |
| | | endCode = codeService.getCacheById(destSta.getCode()); |
| | | |
| | | TaskPosDto.packagePosGroup(groups, task, startCode, TaskPosDto.PosType.ORI_STA, sameGroupXy); |
| | | TaskPosDto.packagePosGroup(groups, task, endCode, TaskPosDto.PosType.DEST_STA, sameGroupXy); |
| | |
| | | } |
| | | |
| | | // re-order by agv current position |
| | | Code currCode = codeService.getById(agvDetail.getRecentCode()); |
| | | Code currCode = codeService.getCacheById(agvDetail.getRecentCode()); |
| | | Double[] currPosition = new Double[] {currCode.getX(), currCode.getY()}; |
| | | |
| | | List<List<TaskPosDto>> pickGroups = new ArrayList<>(); |
| | |
| | | * 充电 回待机位任务 |
| | | */ |
| | | @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); |
| | | 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(); |
| | | AgvDetail agvDetail = agvDetailService.selectMajorByAgvId(agvId); |
| | | Code endCode = null; |
| | | 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()); |
| | | endCode = codeService.getCacheById(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: |
| | | endCode = codeService.selectByData(destination); |
| | | endCode = codeService.getCacheByData(destination); |
| | | break; |
| | | default: |
| | | return false; |
| | |
| | | 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()); |
| | |
| | | try { |
| | | if (Cools.isEmpty(agvId, segmentList)) { return; } |
| | | Date now = new Date(); |
| | | JSONObject storeDirection = configService.getVal("storeDirection", JSONObject.class); |
| | | Agv agv = agvService.getById(agvId); |
| | | if (!agvService.judgeEnable(agv.getId())) { |
| | | throw new CoolException("AGV[" + agv.getUuid() + "]当前不可用..."); |
| | | } |
| | | 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.getById(agv.getAgvModel()); |
| | | AgvModel agvModel = agvModelService.getByAgvId(agvId); |
| | | Double workDirection = agvModel.getWorkDirection(); |
| | | AgvSpeedType agvSpeedType = AgvSpeedType.query(agvModel.getTravelSpeed()); |
| | | assert agvSpeedType != null; |
| | | |
| | | AgvDetail agvDetail = agvDetailService.selectByAgvId(agvId); |
| | | AgvDetail agvDetail = agvDetailService.selectMajorByAgvId(agvId); |
| | | |
| | | List<Action> actionList = new ArrayList<>(); |
| | | // start node |
| | | Code lastCode = codeService.getById(agvDetail.getRecentCode()); |
| | | Double lastDirection = agvDetail.getAgvAngle(); |
| | | Code lastCode = codeService.getCacheById(agvDetail.getRecentCode()); |
| | | Double lastDirection = MapService.mapToNearest(agvDetail.getAgvAngle()); |
| | | if (!lastCode.getData().equals(pathList.get(0))) { |
| | | throw new CoolException("AGV[" + agv.getUuid() + "]定位偏移..."); |
| | | throw new CoolException("AGV[" + agvNo + "]定位偏移..."); |
| | | } |
| | | |
| | | boolean first = true; |
| | |
| | | Task task = taskService.getById(segment.getTaskId()); |
| | | |
| | | // 节点条码 |
| | | Code code = codeService.getById(segment.getEndNode()); |
| | | Code code = codeService.getCacheById(segment.getEndNode()); |
| | | |
| | | // 需要走行 |
| | | if (!lastCode.getData().equals(code.getData())) { |
| | |
| | | |
| | | String next = pathListPart.get(i); |
| | | |
| | | Code nextCode = codeService.selectByData(next); |
| | | Double nextDirection = mapService.calculateDirection(lastCode, nextCode); |
| | | Code nextCode = codeService.getCacheByData(next); |
| | | Double nextDirection = mapService.calculateDirection(lastCode, nextCode, angleOffsetVal); |
| | | |
| | | // 第一步:如果下一个方向正好是作业方向的相反方向,则重置下一个方向为作业方向,标记 reverse = true |
| | | boolean reverse = false; |
| | | if (nextDirection.equals((workDirection + 180) % 360)) { |
| | | nextDirection = workDirection; |
| | | reverse = true; |
| | | } |
| | | if (!lastDirection.equals(nextDirection) || actionList.isEmpty()) { |
| | | |
| | | // 第二步:判断当前节点是否可以旋转 |
| | | 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()) { |
| | | // turn |
| | | actionList.add(new Action( |
| | | null, // 编号 |
| | |
| | | lastCode.getData(), // 地面码 |
| | | String.valueOf(nextDirection), // 动作参数 |
| | | ActionTypeType.TurnCorner.val(), // 动作类型 |
| | | ActionStsType.PREPARE.val(), // 动作进度 |
| | | actionPrepareSts, // 动作进度 |
| | | agvId, // AGV |
| | | now // 工作时间 |
| | | )); |
| | | |
| | | lastDirection = nextDirection; |
| | | |
| | | } |
| | | |
| | | // run |
| | |
| | | lastCode.getData(), // 地面码 |
| | | String.valueOf(gap.getDistance()), // 动作参数 |
| | | actionType.val(), // 动作类型 |
| | | ActionStsType.PREPARE.val(), // 动作进度 |
| | | actionPrepareSts, // 动作进度 |
| | | agvId, // AGV |
| | | now // 工作时间 |
| | | )); |
| | |
| | | lastCode.getData(), // 地面码 |
| | | String.valueOf(workDirection), // 动作参数 |
| | | ActionTypeType.TurnCorner.val(), // 动作类型 |
| | | ActionStsType.PREPARE.val(), // 动作进度 |
| | | actionPrepareSts, // 动作进度 |
| | | agvId, // AGV |
| | | now // 工作时间 |
| | | )); |
| | |
| | | |
| | | // 作业点动作 |
| | | 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)) { |
| | | // 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(workDirection), // 动作参数 |
| | | ActionTypeType.TurnCorner.val(), // 动作类型 |
| | | ActionStsType.PREPARE.val(), // 动作进度 |
| | | agvId, // AGV |
| | | now // 工作时间 |
| | | )); |
| | | lastDirection = workDirection; |
| | | throw new CoolException(agvNo + "号小车方向错误,请推至转弯点手动调整"); |
| | | } |
| | | // 货架取货 |
| | | Loc oriLoc = locService.getById(task.getOriLoc()); |
| | | // 计算左右方向 |
| | | agvDirectionType = mapService.calculateAgvWorkDirection(storeDirection, oriLoc, lastCode); |
| | | agvDirectionType = mapService.calculateAgvWorkDirectionByShelf(oriLoc, lastCode); |
| | | actionList.add(new Action( |
| | | null, // 编号 |
| | | task.getBusId(), // 总线 |
| | |
| | | lastCode.getData(), // 地面码 |
| | | String.valueOf(oriLoc.getOffset()), // 动作参数 |
| | | ActionTypeType.ReadyTakeFromShelvesLoc.val(), // 动作类型 |
| | | ActionStsType.PREPARE.val(), // 动作进度 |
| | | actionPrepareSts, // 动作进度 |
| | | agvId, // AGV |
| | | now // 工作时间 |
| | | )); |
| | |
| | | lastCode.getData(), // 地面码 |
| | | String.valueOf(backpackType.height), // 动作参数 |
| | | ActionTypeType.ReadyReleaseToAgvSite.val(), // 动作类型 |
| | | ActionStsType.PREPARE.val(), // 动作进度 |
| | | actionPrepareSts, // 动作进度 |
| | | agvId, // AGV |
| | | now // 工作时间 |
| | | )); |
| | |
| | | assert backpackType != null; |
| | | // 检验方向 |
| | | if (!lastDirection.equals(workDirection)) { |
| | | // 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(workDirection), // 动作参数 |
| | | ActionTypeType.TurnCorner.val(), // 动作类型 |
| | | ActionStsType.PREPARE.val(), // 动作进度 |
| | | agvId, // AGV |
| | | now // 工作时间 |
| | | )); |
| | | lastDirection = workDirection; |
| | | throw new CoolException(agvNo + "号小车方向错误,请推至转弯点手动调整"); |
| | | } |
| | | // 暂存点取货货 |
| | | actionList.add(new Action( |
| | |
| | | lastCode.getData(), // 地面码 |
| | | String.valueOf(backpackType.height), // 动作参数 |
| | | ActionTypeType.ReadyTakeFromAgvSite.val(), // 动作类型 |
| | | ActionStsType.PREPARE.val(), // 动作进度 |
| | | actionPrepareSts, // 动作进度 |
| | | agvId, // AGV |
| | | now // 工作时间 |
| | | )); |
| | |
| | | // 货架放货 |
| | | Loc destLoc = locService.getById(task.getDestLoc()); |
| | | // 计算左右方向 |
| | | agvDirectionType = mapService.calculateAgvWorkDirection(storeDirection, destLoc, lastCode); |
| | | agvDirectionType = mapService.calculateAgvWorkDirectionByShelf(destLoc, lastCode); |
| | | actionList.add(new Action( |
| | | null, // 编号 |
| | | task.getBusId(), // 总线 |
| | |
| | | lastCode.getData(), // 地面码 |
| | | String.valueOf(destLoc.getOffset()), // 动作参数 |
| | | ActionTypeType.ReadyReleaseToShelvesLoc.val(), // 动作类型 |
| | | ActionStsType.PREPARE.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.ReadyTakeFromConveyorSta.desc, // 名称 |
| | | staWorkDirection, // 属性值 |
| | | lastCode.getData(), // 地面码 |
| | | String.valueOf(oriSta.getOffset()), // 动作参数 |
| | | ActionTypeType.ReadyTakeFromConveyorSta.val(), // 动作类型 |
| | | actionPrepareSts, // 动作进度 |
| | | agvId, // AGV |
| | | now // 工作时间 |
| | | )); |
| | | // 暂存点放货 |
| | | 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); |
| | | // 检验方向 |
| | | if (!lastDirection.equals(destStaWorkDirection)) { |
| | | 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(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.ReadyReleaseToConveyorSta.desc, // 名称 |
| | | staWorkDirection, // 属性值 |
| | | lastCode.getData(), // 地面码 |
| | | String.valueOf(destSta.getOffset()), // 动作参数 |
| | | ActionTypeType.ReadyReleaseToConveyorSta.val(), // 动作类型 |
| | | actionPrepareSts, // 动作进度 |
| | | agvId, // AGV |
| | | now // 工作时间 |
| | | )); |
| | | break; |
| | | case TO_CHARGE: |
| | | // 检验方向 |
| | |
| | | lastCode.getData(), // 地面码 |
| | | String.valueOf(chargeDirection), // 动作参数 |
| | | ActionTypeType.TurnCorner.val(), // 动作类型 |
| | | ActionStsType.PREPARE.val(), // 动作进度 |
| | | actionPrepareSts, // 动作进度 |
| | | agvId, // AGV |
| | | now // 工作时间 |
| | | )); |
| | |
| | | lastCode.getData(), // 地面码 |
| | | null, // 动作参数 |
| | | ActionTypeType.DockingCharge.val(), // 动作类型 |
| | | ActionStsType.PREPARE.val(), // 动作进度 |
| | | actionPrepareSts, // 动作进度 |
| | | agvId, // AGV |
| | | now // 工作时间 |
| | | )); |
| | |
| | | // lastCode.getData(), // 地面码 |
| | | // String.valueOf(standByDirection), // 动作参数 |
| | | // ActionTypeType.TurnCorner.val(), // 动作类型 |
| | | // ActionStsType.PREPARE.val(), // 动作进度 |
| | | // actionPrepareSts, // 动作进度 |
| | | // agvId, // AGV |
| | | // now // 工作时间 |
| | | // )); |
| | |
| | | lastCode.getData(), // 地面码 |
| | | null, // 动作参数 |
| | | ActionTypeType.FinishPath.val(), // 动作类型 |
| | | ActionStsType.PREPARE.val(), // 动作进度 |
| | | actionPrepareSts, // 动作进度 |
| | | agvId, // AGV |
| | | now // 工作时间 |
| | | )); |
| | | |
| | | List<Action> newActionList = new ArrayList<>(actionList); |
| | | |
| | | // List<Action> optimizeList = actionService.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 |
| | |
| | | } |
| | | } |
| | | |
| | | log.info(agv.getUuid() + "号Agv动作组装完成,指令数量:" + newActionList.size()); |
| | | log.info("{}号Agv动作组装完成,指令数量:{}", agvNo, newActionList.size()); |
| | | } catch (Exception e) { |
| | | log.error("mainService.generateAction", e); |
| | | TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); |
| | | |
| | | if (!Cools.isEmpty(pathList)) { |
| | | pathList.remove(0); |
| | | mapDataDispatcher.clearDynamicMatrixByCodeList(null, pathList); |
| | | List<int[]> codeMatrixIdxList = mapDataDispatcher.getCodeMatrixIdxList(null, pathList); |
| | | mapDataDispatcher.clearDynamicMatrixByCodeList(null, codeMatrixIdxList); |
| | | } |
| | | |
| | | throw new RuntimeException("generateAction method caught an exception, rolling back transaction.", e); |
| | |
| | | if (Cools.isEmpty(actionList)) { |
| | | return; |
| | | } |
| | | |
| | | Long agvId = actionList.get(0).getAgvId(); |
| | | String agvNo = agvService.getAgvNo(agvId); |
| | | if (!agvService.judgeOnline(agvId)) { |
| | | return; |
| | | } |
| | | |
| | | long actionIssuedSts = ActionStsType.ISSUED.val(); |
| | | for (Action action : actionList) { |
| | | action.setActionSts(actionIssuedSts); |
| | | 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 |
| | |
| | | } |
| | | } |
| | | |
| | | Agv agv = agvService.getById(actionList.get(0).getAgvId()); |
| | | AgvAction agvAction = new AgvAction(agv.getUuid(), actionGroupId); |
| | | AgvAction agvAction = new AgvAction(agvNo, actionGroupId); |
| | | for (Action action : actionList) { |
| | | |
| | | switch (Objects.requireNonNull(ActionTypeType.get(action.getActionTypeEl()))) { |
| | | case TurnCorner: |
| | | agvAction.add(new AgvActionItem<>(TurnCornerAction.class) |
| | |
| | | .bodySync(body -> body.setHeight((short) Double.parseDouble(action.getParams()))) |
| | | ); |
| | | 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()))) |
| | | ); |
| | | break; |
| | | case ReadyTakeFromAgvSite: |
| | | agvAction.add(new AgvActionItem<>(ReadyTakeFromAgvSite.class) |
| | | .setVal(action.getVal().intValue()) |
| | |
| | | .bodySync(body -> body.setHeight((short) Double.parseDouble(action.getParams()))) |
| | | ); |
| | | 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()))) |
| | | ); |
| | | break; |
| | | case ReadyReleaseToAgvSite: |
| | | agvAction.add(new AgvActionItem<>(ReadyReleaseToAgvSite.class) |
| | | .setVal(action.getVal().intValue()) |