zjj
7 天以前 e29a9f245ff4e57a40bbab1c0acc3cbc31d3ac2b
zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/core/kernel/command/ShuttleCommandService.java
@@ -10,10 +10,7 @@
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.command.*;
import com.zy.asrs.wcs.core.model.enums.*;
import com.zy.asrs.wcs.core.service.BasShuttleService;
import com.zy.asrs.wcs.core.service.LocService;
@@ -22,7 +19,7 @@
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.entity.Device;
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;
@@ -63,6 +60,8 @@
    private LiftAction liftAction;
    @Autowired
    private LiftDispatcher liftDispatcher;
    @Autowired
    private ShuttleDispatcher shuttleDispatcher;
    // 计算
    public Boolean accept(Motion motion) {
@@ -75,7 +74,7 @@
        if (null == shuttleProtocol) {
            return false;
        }
        Device shuttleDevice = shuttleThread.getDevice();
        if (!shuttleThread.isIdle(new ExecuteSupport() {
            @Override
            public Boolean judgement() {
@@ -166,7 +165,7 @@
//                    return false;
//                }
                shuttleCommands = this.shuttleAssignCommand(motion.getOrigin(), motion.getTarget(), NavigationMapType.NORMAL.id, assignCommand, shuttleThread);
                shuttleCommands = this.shuttleInOutLiftCommand(motion.getOrigin(), motion.getTarget(), NavigationMapType.NORMAL.id, assignCommand, shuttleThread);
                shuttleTaskModeType = ShuttleTaskModeType.SHUTTLE_MOVE_LOC_NO;
                break;
            case SHUTTLE_MOVE_TO_LIFT://进提升机
@@ -228,6 +227,21 @@
                shuttleTaskModeType = ShuttleTaskModeType.SHUTTLE_UPDATE_LOCATION;
                shuttleCommands.add(shuttleThread.getUpdateLocationCommand(motion.getTaskNo(), motion.getTarget()));
                break;
            case SHUTTLE_MOVE_STANDBY://穿梭车移动到待机位
                shuttleTaskModeType = ShuttleTaskModeType.SHUTTLE_MOVE_LOC_NO;
                //获取全部待机位
                List<String> standbyLocs = JSON.parseArray(motion.getTemp(), String.class);
                //获取可用待机位
                String shuttleFromLiftStandbyLoc = shuttleDispatcher.searchAvailableLocNo(Integer.valueOf(shuttleDevice.getDeviceNo()), shuttleDevice.getHostId(), shuttleThread.getStatus().getCurrentLocNo(), standbyLocs);
                shuttleCommands = this.shuttleAssignCommand(motion.getOrigin(), shuttleFromLiftStandbyLoc, NavigationMapType.NORMAL.id, assignCommand, shuttleThread);
                //更新动作可用待机位
                motion.setTarget(shuttleFromLiftStandbyLoc);
                motion.setUpdateTime(new Date());
                motionService.updateById(motion);
                break;
            default:
                throw new CoolException(motion.getMotionCtgEl() + "没有指定任务作业流程!!!");
        }
@@ -242,7 +256,7 @@
        if (motion.getOrigin() != null && motion.getTarget() != null) {
            //所使用的路径进行锁定禁用
            boolean lockResult = navigateMapUtils.writeNavigateNodeToRedisMap(Utils.getLev(motion.getTarget()), shuttleProtocol.getShuttleNo(), assignCommand.getNodes(), true);//所使用的路径进行锁定禁用
            boolean lockResult = navigateMapUtils.writeNavigateNodeToRedisMap(Utils.getLev(motion.getTarget()), shuttleProtocol.getShuttleNo(), assignCommand.getNodesDeepCopy(), true);//所使用的路径进行锁定禁用
            if (!lockResult) {
                return false;//锁定失败
            }
@@ -400,6 +414,10 @@
                if (shuttleProtocol.getHasLift()) {
                    return false;
                }
            case SHUTTLE_MOVE_STANDBY://穿梭车移动到待机位
                if (!shuttleProtocol.getCurrentLocNo().equals(motion.getTarget())) {
                    return false;
                }
                break;
            default:
                break;
@@ -454,5 +472,62 @@
        return commands;
    }
    public synchronized List<ShuttleCommand> shuttleInOutLiftCommand(String startLocNo, String endLocNo, Integer mapType, ShuttleAssignCommand assignCommand, ShuttleThread shuttleThread) {
        NavigateNode startNode = NavigatePositionConvert.locNoToNode(startLocNo);
        NavigateNode endNode = NavigatePositionConvert.locNoToNode(endLocNo);
        List<NavigateNode> unlockPath = new ArrayList<>();
        unlockPath.add(startNode);
        unlockPath.add(endNode);
        ShuttleProtocol shuttleProtocol = shuttleThread.getStatus();
        //所使用的路径进行锁定/解锁
        boolean lockResult = navigateMapUtils.writeNavigateNodeToRedisMap(Utils.getLev(endLocNo), shuttleProtocol.getShuttleNo(), unlockPath, false);//所使用的路径进行解锁
        if (!lockResult) {
            News.error("{} dash {} can't find unlock path!", startLocNo, endLocNo);
            return null;//解锁失败
        }
        //获取小车移动速度
        Integer runSpeed = Optional.ofNullable(basShuttleService.getOne(new LambdaQueryWrapper<BasShuttle>().eq(BasShuttle::getDeviceId, assignCommand.getDeviceId())).getRunSpeed()).orElse(1000);
        Long hostId = shuttleThread.getDevice().getHostId();
        List<NavigateNode> nodeList = NavigateUtils.calc(startLocNo, endLocNo, mapType, Utils.getShuttlePoints(Integer.parseInt(shuttleThread.getDevice().getDeviceNo()), Utils.getLev(startLocNo)));
        if (nodeList == null) {
            News.error("{} dash {} can't find navigate path!", startLocNo, endLocNo);
            return null;
        }
        List<NavigateNode> allNode = new ArrayList<>();
        for (NavigateNode node : nodeList) {
            allNode.add(node.clone());
        }
        List<ShuttleCommand> commands = new ArrayList<>();
        //获取分段路径
        ArrayList<ArrayList<NavigateNode>> data = NavigateUtils.getSectionPath(nodeList);
        //将每一段路径分成command指令
        for (ArrayList<NavigateNode> nodes : data) {
            //开始路径
            NavigateNode startPath = nodes.get(0);
            //目标路径
            NavigateNode endPath = nodes.get(nodes.size() - 1);
            Integer allDistance = NavigateUtils.getCurrentPathAllDistance(nodes);//计算当前路径行走总距离
            //通过xy坐标小车二维码
            String startCodeNum = NavigatePositionConvert.xyToPosition(startPath.getX(), startPath.getY(), startPath.getZ(), hostId);
            //通过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, nodes);
            command.setNodes(nodes);//将行走节点添加到每一步命令中
            commands.add(command);
        }
        assignCommand.setNodes(allNode);//当前任务所占用的节点list
        return commands;
    }
}