|  |  |  | 
|---|
|  |  |  | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; | 
|---|
|  |  |  | import com.zy.asrs.framework.common.Cools; | 
|---|
|  |  |  | import com.zy.asrs.framework.exception.CoolException; | 
|---|
|  |  |  | import com.zy.asrs.wcs.common.ExecuteSupport; | 
|---|
|  |  |  | import com.zy.asrs.wcs.core.action.LiftAction; | 
|---|
|  |  |  | import com.zy.asrs.wcs.core.action.ShuttleAction; | 
|---|
|  |  |  | import com.zy.asrs.wcs.core.entity.BasShuttle; | 
|---|
|  |  |  | import com.zy.asrs.wcs.core.entity.Loc; | 
|---|
|  |  |  | import com.zy.asrs.wcs.core.model.NavigateNode; | 
|---|
|  |  |  | import com.zy.asrs.wcs.core.model.command.LiftAssignCommand; | 
|---|
|  |  |  | import com.zy.asrs.wcs.core.model.command.LiftCommand; | 
|---|
|  |  |  | import com.zy.asrs.wcs.core.model.command.ShuttleAssignCommand; | 
|---|
|  |  |  | import com.zy.asrs.wcs.core.model.command.ShuttleCommand; | 
|---|
|  |  |  | import com.zy.asrs.wcs.core.model.enums.*; | 
|---|
|  |  |  | 
|---|
|  |  |  | import com.zy.asrs.wcs.rcs.News; | 
|---|
|  |  |  | import com.zy.asrs.wcs.rcs.cache.SlaveConnection; | 
|---|
|  |  |  | import com.zy.asrs.wcs.core.entity.Motion; | 
|---|
|  |  |  | import com.zy.asrs.wcs.rcs.constant.DeviceRedisConstant; | 
|---|
|  |  |  | import com.zy.asrs.wcs.rcs.model.enums.ShuttleProtocolStatusType; | 
|---|
|  |  |  | import com.zy.asrs.wcs.rcs.model.enums.SlaveType; | 
|---|
|  |  |  | import com.zy.asrs.wcs.rcs.model.protocol.LiftProtocol; | 
|---|
|  |  |  | 
|---|
|  |  |  | private ShuttleAction shuttleAction; | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private LiftAction liftAction; | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private LiftDispatcher liftDispatcher; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // 计算 | 
|---|
|  |  |  | public Boolean accept(Motion motion) { | 
|---|
|  |  |  | 
|---|
|  |  |  | if (null == shuttleProtocol) { | 
|---|
|  |  |  | return false; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (!shuttleThread.isIdle()) {//设备不空闲 | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if (!shuttleThread.isIdle(new ExecuteSupport() { | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public Boolean judgement() { | 
|---|
|  |  |  | if (Objects.equals(MotionCtgType.get(motion.getMotionCtgEl()), MotionCtgType.SHUTTLE_CHARGE_OFF)) {//非关闭充电motion,需要判断设备状态 | 
|---|
|  |  |  | return false;//不需要判断状态 | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return true;//需要判断状态 | 
|---|
|  |  |  | } | 
|---|
|  |  |  | })) {//设备不空闲 | 
|---|
|  |  |  | return false; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if (motionService.count(new LambdaQueryWrapper<Motion>() | 
|---|
|  |  |  | .eq(Motion::getDeviceCtg, DeviceCtgType.SHUTTLE.val()) | 
|---|
|  |  |  | .eq(Motion::getDevice, motion.getDevice()) | 
|---|
|  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // 判断提升机是否空闲 | 
|---|
|  |  |  | if (!liftThread.isIdle()) { | 
|---|
|  |  |  | if (!liftThread.isIdle(MotionCtgType.SHUTTLE_MOVE_FROM_LIFT)) { | 
|---|
|  |  |  | return false; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if (liftProtocol.getLev() != Utils.getLev(motion.getTarget())) {//判断提升机是否达到目标层 | 
|---|
|  |  |  | if (liftProtocol.getLev() != liftDispatcher.getLiftLevOffset(liftThread.getDevice().getId().intValue(), Utils.getLev(motion.getTarget()))) {//判断提升机是否达到目标层 | 
|---|
|  |  |  | return false; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //                //判断提升机是否被锁定 | 
|---|
|  |  |  | //                if (!liftProtocol.getLock()) { | 
|---|
|  |  |  | //                    //锁定提升机 | 
|---|
|  |  |  | //                    LiftCommand lockCommand = liftThread.getLockCommand(motion.getWrkNo(), true);//获取提升机锁定命令 | 
|---|
|  |  |  | // | 
|---|
|  |  |  | //                    LiftAssignCommand liftAssignCommand = new LiftAssignCommand(); | 
|---|
|  |  |  | //                    liftAssignCommand.setLiftNo(liftThread.getStatus().getLiftNo()); | 
|---|
|  |  |  | //                    liftAssignCommand.setTaskNo(motion.getWrkNo()); | 
|---|
|  |  |  | //                    ArrayList<LiftCommand> list = new ArrayList<>(); | 
|---|
|  |  |  | //                    list.add(lockCommand); | 
|---|
|  |  |  | //                    liftAssignCommand.setCommands(list); | 
|---|
|  |  |  | // | 
|---|
|  |  |  | //                    liftAction.assignWork(liftThread.getDevice(), liftAssignCommand); | 
|---|
|  |  |  | //                    return false;//等待下一次轮询 | 
|---|
|  |  |  | //判断提升机是否被锁定 | 
|---|
|  |  |  | if (!liftThread.isLock(new ExecuteSupport() { | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public Boolean judgement() { | 
|---|
|  |  |  | return true; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | })) { | 
|---|
|  |  |  | return false; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //                //判断提升机工作号是否和当前任务相同 | 
|---|
|  |  |  | //                if (liftProtocol.getTaskNo().intValue() != motion.getTaskNo()) { | 
|---|
|  |  |  | //                    return false; | 
|---|
|  |  |  | //                } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //判断提升机工作号是否和当前任务相同 | 
|---|
|  |  |  | if (liftProtocol.getTaskNo().intValue() != motion.getTaskNo()) { | 
|---|
|  |  |  | return false; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | shuttleCommands = this.shuttleAssignCommand(motion.getOrigin(), motion.getTarget(), NavigationMapType.NORMAL.id, assignCommand, shuttleThread); | 
|---|
|  |  |  | shuttleTaskModeType = ShuttleTaskModeType.SHUTTLE_MOVE_LOC_NO; | 
|---|
|  |  |  | 
|---|
|  |  |  | return false; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | // 判断提升机是否空闲 | 
|---|
|  |  |  | if (!liftThread.isIdle()) { | 
|---|
|  |  |  | if (!liftThread.isIdle(MotionCtgType.SHUTTLE_MOVE_TO_LIFT)) { | 
|---|
|  |  |  | return false; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if (liftProtocol.getLev() != Utils.getLev(motion.getTarget())) {//判断提升机是否达到目标层 | 
|---|
|  |  |  | if (liftProtocol.getLev() != liftDispatcher.getLiftLevOffset(liftThread.getDevice().getId().intValue(), Utils.getLev(motion.getTarget()))) {//判断提升机是否达到目标层 | 
|---|
|  |  |  | return false; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //                //判断提升机是否被锁定 | 
|---|
|  |  |  | //                if (!liftProtocol.getLiftLock()) { | 
|---|
|  |  |  | //                    //锁定提升机 | 
|---|
|  |  |  | //                    LiftCommand lockCommand = liftThread.getLockCommand(true);//获取提升机锁定命令 | 
|---|
|  |  |  | //                    lockCommand.setLiftNo(liftProtocol.getLiftNo()); | 
|---|
|  |  |  | //                    lockCommand.setTaskNo(motion.getWrkNo().shortValue());//获取任务号 | 
|---|
|  |  |  | //                    liftThread.assignWork(lockCommand); | 
|---|
|  |  |  | //                    return false;//等待下一次轮询 | 
|---|
|  |  |  | //判断提升机是否被锁定 | 
|---|
|  |  |  | if (!liftThread.isLock(new ExecuteSupport() { | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public Boolean judgement() { | 
|---|
|  |  |  | return true;//牛眼没有提升机锁,直接返回true | 
|---|
|  |  |  | } | 
|---|
|  |  |  | })) { | 
|---|
|  |  |  | return false; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //                //判断提升机工作号是否和当前任务相同 | 
|---|
|  |  |  | //                if (liftProtocol.getTaskNo().intValue() != motion.getTaskNo()) { | 
|---|
|  |  |  | //                    return false; | 
|---|
|  |  |  | //                } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //判断提升机工作号是否和当前任务相同 | 
|---|
|  |  |  | if (liftProtocol.getTaskNo().intValue() != motion.getTaskNo()) { | 
|---|
|  |  |  | return false; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | shuttleCommands = this.shuttleAssignCommand(motion.getOrigin(), motion.getTarget(), NavigationMapType.NORMAL.id, assignCommand, shuttleThread); | 
|---|
|  |  |  | shuttleTaskModeType = ShuttleTaskModeType.SHUTTLE_MOVE_LOC_NO; | 
|---|
|  |  |  | 
|---|
|  |  |  | case SHUTTLE_PALLET_DOWN://托盘下降 | 
|---|
|  |  |  | shuttleTaskModeType = ShuttleTaskModeType.PALLET_DOWN; | 
|---|
|  |  |  | shuttleCommands.add(shuttleThread.getLiftCommand(motion.getTaskNo(), false)); | 
|---|
|  |  |  | break; | 
|---|
|  |  |  | case SHUTTLE_UPDATE_LOCATION://小车坐标更新 | 
|---|
|  |  |  | shuttleTaskModeType = ShuttleTaskModeType.SHUTTLE_UPDATE_LOCATION; | 
|---|
|  |  |  | shuttleCommands.add(shuttleThread.getUpdateLocationCommand(motion.getTaskNo(), motion.getTarget())); | 
|---|
|  |  |  | break; | 
|---|
|  |  |  | default: | 
|---|
|  |  |  | throw new CoolException(motion.getMotionCtgEl() + "没有指定任务作业流程!!!"); | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //充电任务 | 
|---|
|  |  |  | if (Objects.requireNonNull(MotionCtgType.get(motion.getMotionCtgEl())).equals(MotionCtgType.SHUTTLE_CHARGE_ON)) { | 
|---|
|  |  |  | // 复位穿梭车 | 
|---|
|  |  |  | shuttleThread.setSyncTaskNo(0); | 
|---|
|  |  |  | shuttleThread.setProtocolStatus(ShuttleProtocolStatusType.IDLE); | 
|---|
|  |  |  | shuttleThread.setPakMk(true); | 
|---|
|  |  |  | return true; | 
|---|
|  |  |  | if (shuttleProtocol.getHasCharge() || shuttleProtocol.getProtocolStatusType().equals(ShuttleProtocolStatusType.CHARGING_WAITING)) { | 
|---|
|  |  |  | // 复位穿梭车 | 
|---|
|  |  |  | shuttleThread.setSyncTaskNo(0); | 
|---|
|  |  |  | shuttleThread.setProtocolStatus(ShuttleProtocolStatusType.IDLE); | 
|---|
|  |  |  | shuttleThread.setPakMk(true); | 
|---|
|  |  |  | return true; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if (!shuttleProtocol.getProtocolStatusType().equals(ShuttleProtocolStatusType.WAITING) | 
|---|
|  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | break; | 
|---|
|  |  |  | case SHUTTLE_MOVE_TO_LIFT: | 
|---|
|  |  |  | liftThread = (LiftThread) SlaveConnection.get(SlaveType.Lift, Integer.parseInt(motion.getTemp())); | 
|---|
|  |  |  | if (liftThread == null) { | 
|---|
|  |  |  | return false; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | liftProtocol = liftThread.getStatus(); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if (!shuttleProtocol.getCurrentLocNo().equals(motion.getTarget())) { | 
|---|
|  |  |  | return false; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //判断提升机是否被锁定 | 
|---|
|  |  |  | if (!liftThread.isLock(new ExecuteSupport() { | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public Boolean judgement() { | 
|---|
|  |  |  | return false; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | })) { | 
|---|
|  |  |  | return false; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //判断小车是否已到位 | 
|---|
|  |  |  | if (!liftProtocol.getHasCar()) { | 
|---|
|  |  |  | return false; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //                //判断提升机工作号是否和当前任务相同 | 
|---|
|  |  |  | //                if (liftProtocol.getTaskNo().intValue() != motion.getTaskNo()) { | 
|---|
|  |  |  | //                    return false; | 
|---|
|  |  |  | //                } | 
|---|
|  |  |  | break; | 
|---|
|  |  |  | case SHUTTLE_MOVE_FROM_LIFT: | 
|---|
|  |  |  | liftThread = (LiftThread) SlaveConnection.get(SlaveType.Lift, Integer.parseInt(motion.getTemp())); | 
|---|
|  |  |  | if (liftThread == null) { | 
|---|
|  |  |  | return false; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | liftProtocol = liftThread.getStatus(); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if (!shuttleProtocol.getCurrentLocNo().equals(motion.getTarget())) { | 
|---|
|  |  |  | return false; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //判断提升机是否被锁定 | 
|---|
|  |  |  | if (!liftThread.isLock(new ExecuteSupport() { | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public Boolean judgement() { | 
|---|
|  |  |  | return false; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | })) { | 
|---|
|  |  |  | return false; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //判断小车是否已离开 | 
|---|
|  |  |  | if (liftProtocol.getHasCar()) { | 
|---|
|  |  |  | return false; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //                //判断提升机工作号是否和当前任务相同 | 
|---|
|  |  |  | //                if (liftProtocol.getTaskNo().intValue() != motion.getTaskNo()) { | 
|---|
|  |  |  | //                    return false; | 
|---|
|  |  |  | //                } | 
|---|
|  |  |  | break; | 
|---|
|  |  |  | case SHUTTLE_TRANSPORT_FROM_LIFT: | 
|---|
|  |  |  | case SHUTTLE_TRANSPORT_TO_LIFT: | 
|---|
|  |  |  | case SHUTTLE_MOVE_FROM_LIFT_TO_CONVEYOR: | 
|---|
|  |  |  | 
|---|
|  |  |  | return false; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //                //判断提升机是否被锁定 | 
|---|
|  |  |  | //                if (liftProtocol.getLiftLock()) { | 
|---|
|  |  |  | //                    //解锁提升机 | 
|---|
|  |  |  | //                    LiftCommand lockCommand = liftThread.getLockCommand(false);//获取提升机解锁命令 | 
|---|
|  |  |  | //                    lockCommand.setLiftNo(liftProtocol.getLiftNo()); | 
|---|
|  |  |  | //                    lockCommand.setTaskNo(motion.getWrkNo().shortValue());//获取任务号 | 
|---|
|  |  |  | //                    liftThread.assignWork(lockCommand); | 
|---|
|  |  |  | //                    return false; | 
|---|
|  |  |  | //                } | 
|---|
|  |  |  | //判断提升机是否被锁定 | 
|---|
|  |  |  | if (liftThread.isLock(new ExecuteSupport() { | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public Boolean judgement() { | 
|---|
|  |  |  | return false; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | })) { | 
|---|
|  |  |  | return false; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //判断提升机工作号是否和当前任务相同 | 
|---|
|  |  |  | if (liftProtocol.getTaskNo().intValue() != motion.getTaskNo()) { | 
|---|
|  |  |  | return false; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //                if (liftProtocol.getTaskNo() != 0) { | 
|---|
|  |  |  | //                    //清空提升机号 | 
|---|
|  |  |  | //                    liftThread.setTaskNo(0); | 
|---|
|  |  |  | //                } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | break; | 
|---|
|  |  |  | case SHUTTLE_UPDATE_LOCATION://小车坐标更新 | 
|---|
|  |  |  | break; | 
|---|
|  |  |  | case SHUTTLE_PALLET_LIFT://托盘顶升 | 
|---|
|  |  |  | if (!shuttleProtocol.getHasLift()) { | 
|---|
|  |  |  | return false; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | break; | 
|---|
|  |  |  | case SHUTTLE_PALLET_DOWN://托盘下降 | 
|---|
|  |  |  | if (shuttleProtocol.getHasLift()) { | 
|---|
|  |  |  | return false; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | break; | 
|---|
|  |  |  | default: | 
|---|
|  |  |  | break; | 
|---|
|  |  |  | 
|---|
|  |  |  | //通过xy坐标小车二维码 | 
|---|
|  |  |  | String distCodeNum = NavigatePositionConvert.xyToPosition(endPath.getX(), endPath.getY(), endPath.getZ(), hostId); | 
|---|
|  |  |  | //获取移动命令 | 
|---|
|  |  |  | ShuttleCommand command = shuttleThread.getMoveCommand(assignCommand.getDeviceTaskNo(), startCodeNum, distCodeNum, allDistance, ShuttleRunDirection.get(startPath.getDirection()).id.intValue(), runSpeed); | 
|---|
|  |  |  | ShuttleCommand command = shuttleThread.getMoveCommand(assignCommand.getDeviceTaskNo(), startCodeNum, distCodeNum, allDistance, ShuttleRunDirection.get(startPath.getDirection()).id.intValue(), runSpeed, nodes); | 
|---|
|  |  |  | command.setNodes(nodes);//将行走节点添加到每一步命令中 | 
|---|
|  |  |  | commands.add(command); | 
|---|
|  |  |  | } | 
|---|