自动化立体仓库 - WCS系统
Junjie
2023-06-10 e1783e196a4ada918268b9f81bfb3a19641e0626
src/main/java/com/zy/asrs/service/impl/MainServiceImpl.java
@@ -640,13 +640,13 @@
                DevpThread devpThread = (DevpThread) SlaveConnection.get(SlaveType.Devp, devp.getId());
                StaProtocol staProtocol = devpThread.getStation().get(rackInStn.getStaNo());
                StaProtocol staProtocol105 = devpThread.getStation().get(105);
                staProtocol105.setWorkNo((short) 752);
                staProtocol105.setStaNo((short) 100);
                StaProtocol staProtocol106 = devpThread.getStation().get(106);
                staProtocol106.setWorkNo((short) 753);
                staProtocol106.setStaNo((short) 100);
//                StaProtocol staProtocol105 = devpThread.getStation().get(105);
//                staProtocol105.setWorkNo((short) 752);
//                staProtocol105.setStaNo((short) 100);
//
//                StaProtocol staProtocol106 = devpThread.getStation().get(106);
//                staProtocol106.setWorkNo((short) 753);
//                staProtocol106.setStaNo((short) 100);
                if (staProtocol == null) {
                    continue;
@@ -708,18 +708,15 @@
                            if (wrkMast.getWrkSts() == 8 || Boolean.parseBoolean(searchIdleShuttle.get("sameLay").toString())) {
                                //同一层直接取货无需经过提升机
                                //直接计算车到提升机取货再到库位路径指令
                                List<ShuttleCommand> commands = this.shuttleAssignCommand(currentLocNo, liftLocNo, locNo, assignCommand);
                                List<ShuttleCommand> commands = this.shuttleAssignCommand(currentLocNo, liftLocNo, locNo, assignCommand,shuttleThread);
                                if (wrkMast.getWrkSts() == 8) {
                                    //此时车在提升机内部,需要多下达一步指令让车移动到提升机口
                                    BasDevp basDevp = basDevpService.selectById(109);//获取提升机信息
                                    ShuttleCommand moveCommand = new ShuttleCommand();
                                    moveCommand.setCommandWord((short) 1);
                                    moveCommand.setStartCodeNum(Short.parseShort(basDevp.getQrCodeValue()));//提升机内部二维码
                                    moveCommand.setDistCodeNum(commands.get(0).getStartCodeNum());//提升机口二维码
                                    moveCommand.setStartToDistDistance(1300);
                                    moveCommand.setMiddleToDistDistance(0);
                                    moveCommand.setRunDirection(commands.get(0).getRunDirection());
                                    moveCommand.setCommandEnd((short) 1);
                                    short startCode = Short.parseShort(basDevp.getQrCodeValue());//提升机内部二维码
                                    Short distCode = commands.get(0).getStartCodeNum();//提升机口二维码
                                    Short runDirection = commands.get(0).getRunDirection();//运行方向
                                    //获取命令
                                    ShuttleCommand moveCommand = shuttleThread.getMoveCommand(startCode, distCode, 1300, runDirection);
                                    commands.add(0, moveCommand);//将该指令添加到队头
                                }
                                assignCommand.setCommands(commands);
@@ -732,7 +729,7 @@
                                //不同层,将目标库位分配成提升机库位号
                                //小车移动到提升机口,计算路径
                                List<ShuttleCommand> commands = this.shuttleAssignCommand(currentLocNo, liftLocNo, ShuttleTaskModeType.PAK_IN.id, assignCommand);
                                List<ShuttleCommand> commands = this.shuttleAssignCommand(currentLocNo, liftLocNo, ShuttleTaskModeType.PAK_IN.id, assignCommand, shuttleThread);
                                //分配目标库位
                                shuttleProtocol.setLocNo(liftLocNo);
                                //目标库位
@@ -756,7 +753,7 @@
    }
    //获取起点-终点指令。mapType:1=》无货地图,2=》有货地图
    public synchronized List<ShuttleCommand> shuttleAssignCommand(String startLocNo, String locNo, Integer mapType, ShuttleAssignCommand assignCommand) {
    public synchronized List<ShuttleCommand> shuttleAssignCommand(String startLocNo, String locNo, Integer mapType, ShuttleAssignCommand assignCommand, ShuttleThread shuttleThread) {
        //计算小车起点到中点所需命令
        List<NavigateNode> calc = NavigateUtils.calc(startLocNo, locNo, mapType);
        List<ShuttleCommand> commands = new ArrayList<>();
@@ -776,29 +773,12 @@
            //目标路径
            NavigateNode endPath = nodes.get(nodes.size() - 1);
            Integer allDistance = NavigateUtils.getCurrentPathAllDistance(nodes);//计算当前路径行走总距离
            ShuttleCommand command = new ShuttleCommand();
            command.setCommandWord((short) 1);
            //通过xy坐标小车二维码
            Short startCodeNum = NavigatePositionConvert.xyToPosition(startPath.getX(), startPath.getY(), startPath.getZ());
            command.setStartCodeNum(startCodeNum);
            command.setMiddleCodeNum((short) 1);
            //通过xy坐标小车二维码
            Short distCodeNum = NavigatePositionConvert.xyToPosition(endPath.getX(), endPath.getY(), endPath.getZ());
            command.setDistCodeNum(distCodeNum);
            command.setStartToDistDistance(allDistance);
            command.setMiddleToDistDistance(0);
            command.setRunDirection(ShuttleRunDirection.get(startPath.getDirection()).id);
            command.setPalletLift((short) 1);
            command.setForceMoveDistance(0);
            command.setChargeSwitch((short) 2);
            command.setIOControl((short) 0);
            command.setRadarTmp((short) 0);
            command.setCommandEnd((short) 1);
            //获取移动命令
            ShuttleCommand command = shuttleThread.getMoveCommand(startCodeNum, distCodeNum, allDistance, ShuttleRunDirection.get(startPath.getDirection()).id);
            commands.add(command);
        }
@@ -811,7 +791,7 @@
    }
    //获取起点-中点-终点指令
    public synchronized List<ShuttleCommand> shuttleAssignCommand(String startLocNo, String middleLocNo, String locNo, ShuttleAssignCommand assignCommand) {
    public synchronized List<ShuttleCommand> shuttleAssignCommand(String startLocNo, String middleLocNo, String locNo, ShuttleAssignCommand assignCommand, ShuttleThread shuttleThread) {
        //计算小车起点到中点所需命令
        List<NavigateNode> calc = NavigateUtils.calc(startLocNo, middleLocNo, 1);//小车无货,走入库地图
        List<ShuttleCommand> commands = new ArrayList<>();
@@ -832,37 +812,17 @@
            NavigateNode endPath = nodes.get(nodes.size() - 1);
            Integer allDistance = NavigateUtils.getCurrentPathAllDistance(nodes);//计算当前路径行走总距离
            ShuttleCommand command = new ShuttleCommand();
            command.setCommandWord((short) 1);
            //通过xy坐标小车二维码
            Short startCodeNum = NavigatePositionConvert.xyToPosition(startPath.getX(), startPath.getY(), startPath.getZ());
            command.setStartCodeNum(startCodeNum);
            command.setMiddleCodeNum((short) 1);
            //通过xy坐标小车二维码
            Short distCodeNum = NavigatePositionConvert.xyToPosition(endPath.getX(), endPath.getY(), endPath.getZ());
            command.setDistCodeNum(distCodeNum);
            command.setStartToDistDistance(allDistance);
            command.setMiddleToDistDistance(0);
            command.setRunDirection(ShuttleRunDirection.get(startPath.getDirection()).id);
            command.setPalletLift((short) 1);
            command.setForceMoveDistance(0);
            command.setChargeSwitch((short) 2);
            command.setIOControl((short) 0);
            command.setRadarTmp((short) 0);
            command.setCommandEnd((short) 1);
            //获取移动命令
            ShuttleCommand command = shuttleThread.getMoveCommand(startCodeNum, distCodeNum, allDistance, ShuttleRunDirection.get(startPath.getDirection()).id);
            commands.add(command);
        }
        //小车指令到达目标位置后,再发出一条顶升指令
        ShuttleCommand command = new ShuttleCommand();
        command.setCommandWord((short) 2);
        command.setPalletLift((short) 1);
        command.setCommandEnd((short) 1);
        commands.add(command);
        commands.add(shuttleThread.getPalletCommand((short) 1));
        //计算小车中点到终点所需命令
        List<NavigateNode> calc2 = NavigateUtils.calc(middleLocNo, locNo, 2);//小车有货,走出库地图(出库地图有专用货道)
@@ -881,37 +841,16 @@
            NavigateNode endPath = nodes.get(nodes.size() - 1);
            Integer allDistance = NavigateUtils.getCurrentPathAllDistance(nodes);//计算当前路径行走总距离
            command = new ShuttleCommand();
            command.setCommandWord((short) 1);
            //通过xy坐标小车二维码
            Short startCodeNum = NavigatePositionConvert.xyToPosition(startPath.getX(), startPath.getY(), startPath.getZ());
            command.setStartCodeNum(startCodeNum);
            command.setMiddleCodeNum((short) 1);
            //通过xy坐标小车二维码
            Short distCodeNum = NavigatePositionConvert.xyToPosition(endPath.getX(), endPath.getY(), endPath.getZ());
            command.setDistCodeNum(distCodeNum);
            command.setStartToDistDistance(allDistance);
            command.setMiddleToDistDistance(0);
            command.setRunDirection(ShuttleRunDirection.get(startPath.getDirection()).id);
            command.setPalletLift((short) 1);
            command.setForceMoveDistance(0);
            command.setChargeSwitch((short) 2);
            command.setIOControl((short) 0);
            command.setRadarTmp((short) 0);
            command.setCommandEnd((short) 1);
            commands.add(command);
            ShuttleCommand moveCommand = shuttleThread.getMoveCommand(startCodeNum, distCodeNum, allDistance, ShuttleRunDirection.get(startPath.getDirection()).id);
            commands.add(moveCommand);
        }
        //小车指令到达目标位置后,再发出一条托盘下降指令
        command = new ShuttleCommand();
        command.setCommandWord((short) 2);
        command.setPalletLift((short) 2);
        command.setCommandEnd((short) 1);
        commands.add(command);
        commands.add(shuttleThread.getPalletCommand((short) 2));
        assignCommand.setNodes(allNode);//当前任务所占用的节点list
        //所使用的路径进行锁定禁用
@@ -1001,7 +940,7 @@
                        if (Boolean.parseBoolean(searchIdleShuttle.get("sameLay").toString())) {
                            //同一层(将小车移动到货物位置)
                            List<ShuttleCommand> commands = this.shuttleAssignCommand(currentLocNo, wrkMast.getSourceLocNo(), liftLocNo, assignCommand);
                            List<ShuttleCommand> commands = this.shuttleAssignCommand(currentLocNo, wrkMast.getSourceLocNo(), liftLocNo, assignCommand, shuttleThread);
                            //分配目标库位
                            shuttleProtocol.setLocNo(wrkMast.getSourceLocNo());
                            //目标库位
@@ -1012,7 +951,7 @@
                            //不同层,将目标库位分配成提升机库位号(将小车移动到提升机位置)
                            //小车到提升机口指令
                            List<ShuttleCommand> commands = this.shuttleAssignCommand(currentLocNo, liftLocNo, ShuttleTaskModeType.PAK_IN.id, assignCommand);
                            List<ShuttleCommand> commands = this.shuttleAssignCommand(currentLocNo, liftLocNo, ShuttleTaskModeType.PAK_IN.id, assignCommand, shuttleThread);
                            shuttleProtocol.setLocNo(liftLocNo);
                            //目标库位
                            assignCommand.setLocNo(liftLocNo);
@@ -1020,17 +959,13 @@
                            wrkMast.setWrkSts(22L);//小车迁移状态
                        }
                    } else if (wrkMast.getWrkSts() == 25) {
                        List<ShuttleCommand> commands = this.shuttleAssignCommand(currentLocNo, wrkMast.getSourceLocNo(), liftLocNo, assignCommand);
                        List<ShuttleCommand> commands = this.shuttleAssignCommand(currentLocNo, wrkMast.getSourceLocNo(), liftLocNo, assignCommand, shuttleThread);
                        //此时车在提升机内部,需要多下达一步指令让车移动到提升机口
                        BasDevp basDevp = basDevpService.selectById(109);//获取提升机信息
                        ShuttleCommand moveCommand = new ShuttleCommand();
                        moveCommand.setCommandWord((short) 1);//小车移动指令字
                        moveCommand.setStartCodeNum(Short.parseShort(basDevp.getQrCodeValue()));//提升机二维码
                        moveCommand.setDistCodeNum(commands.get(0).getStartCodeNum());
                        moveCommand.setStartToDistDistance(1300);
                        moveCommand.setMiddleToDistDistance(0);
                        moveCommand.setRunDirection(commands.get(0).getRunDirection());
                        moveCommand.setCommandEnd((short) 1);
                        short startCode = Short.parseShort(basDevp.getQrCodeValue());//提升机二维码
                        Short distCode = commands.get(0).getStartCodeNum();//目标二维码
                        //获取移动命令
                        ShuttleCommand moveCommand = shuttleThread.getMoveCommand(startCode, distCode, 1300, commands.get(0).getRunDirection());
                        commands.add(0, moveCommand);//将该指令添加到队头
                        //分配目标库位
@@ -1272,44 +1207,22 @@
                //提升机当前楼层
                int liftLev = liftProtocol.getLev().intValue();
                if (liftLev != 1) {
                    //提升机不在1层
                    LiftCommand command1 = new LiftCommand();
                    command1.setLiftNo(liftProtocol.getLiftNo());//提升机号
                    command1.setTaskNo(liftProtocol.getTaskNo());//任务号
                    command1.setRun((short) 1);//升降
                    command1.setDistPosition((short) 1);//目标楼层1层
                    command1.setLiftLock(true);//锁定提升机
                    //提升机不在1层,获取到1层的提升机命令
                    LiftCommand command1 = liftThread.getLiftUpDownCommand(liftProtocol.getLiftNo(), liftProtocol.getTaskNo(), (short) 1);
                    commands.add(command1);//将命令添加进list
                }
                //输送线将货物运进来
                LiftCommand command2 = new LiftCommand();
                command2.setLiftNo(liftProtocol.getLiftNo());//提升机号
                command2.setTaskNo(liftProtocol.getTaskNo());//任务号
                command2.setRun((short) 6);//输送线运作
                command2.setLiftLock(true);//锁定提升机
                //输送线将货物运进来(正转)
                LiftCommand command2 = liftThread.getLiftTurnCommand(liftProtocol.getLiftNo(), liftProtocol.getTaskNo(), 1);
                commands.add(command2);//将命令添加进list
                //提升机前往目标楼层
                LiftCommand command3 = new LiftCommand();
                command3.setLiftNo(liftProtocol.getLiftNo());//提升机号
                command3.setTaskNo(liftProtocol.getTaskNo());//任务号
                command3.setRun((short) 1);//升降
                command3.setDistPosition((short) wrkMastLocNoLey);//工作档目标楼层
                command3.setLiftLock(true);//锁定提升机
                //提升机前往目标楼层(工作档目标楼层)
                LiftCommand command3 = liftThread.getLiftUpDownCommand(liftProtocol.getLiftNo(), liftProtocol.getTaskNo(), (short) wrkMastLocNoLey);
                commands.add(command3);//将命令添加进list
                //提升机到达指定楼层,输送线将货物移出去
                //提升机到达指定楼层,输送线将货物移出去(反转)
                //输送线将货物移出去
                LiftCommand command4 = new LiftCommand();
                command4.setLiftNo(liftProtocol.getLiftNo());//提升机号
                command4.setTaskNo(liftProtocol.getTaskNo());//任务号
                command4.setRun((short) 3);//输送线运作
                command4.setLiftLock(true);//锁定提升机
                LiftCommand command4 = liftThread.getLiftTurnCommand(liftProtocol.getLiftNo(), liftProtocol.getTaskNo(), 2);
                commands.add(command4);//将命令添加进list
            }else {
                liftProtocol.setShuttleNo(wrkMast.getShuttleNo().shortValue());//设置四向穿梭车号
@@ -1338,45 +1251,24 @@
                int liftLev = liftProtocol.getLev().intValue();
                if (liftLev != currentLocNoLey) {
                    //不同楼层
                    LiftCommand command1 = new LiftCommand();
                    command1.setLiftNo(liftProtocol.getLiftNo());//提升机号
                    command1.setTaskNo(liftProtocol.getTaskNo());//任务号
                    command1.setRun((short) 1);//升降
                    command1.setDistPosition((short) currentLocNoLey);//目标楼层(穿梭车所在楼层)
                    command1.setLiftLock(true);//锁定提升机
                    //获取目标楼层(穿梭车所在楼层)命令
                    LiftCommand command1 = liftThread.getLiftUpDownCommand(liftProtocol.getLiftNo(), liftProtocol.getTaskNo(), (short) currentLocNoLey);
                    commands.add(command1);//将命令添加进list
                }
                //输送线将四向穿梭车移动进来
                LiftCommand command2 = new LiftCommand();
                command2.setLiftNo(liftProtocol.getLiftNo());//提升机号
                command2.setTaskNo(liftProtocol.getTaskNo());//任务号
                command2.setRun((short) 6);//输送线运作
                command2.setLiftLock(true);//锁定提升机
                //输送线将四向穿梭车移动进来(正转)
                LiftCommand command2 = liftThread.getLiftTurnCommand(liftProtocol.getLiftNo(), liftProtocol.getTaskNo(), 1);
                commands.add(command2);//将命令添加进list
                if (liftLev != currentLocNoLey) {
                    //提升机前往目标楼层
                    LiftCommand command3 = new LiftCommand();
                    command3.setLiftNo(liftProtocol.getLiftNo());//提升机号
                    command3.setTaskNo(liftProtocol.getTaskNo());//任务号
                    command3.setRun((short) 1);//升降
                    command3.setDistPosition((short) wrkMastLocNoLey);//工作档目标楼层
                    command3.setLiftLock(true);//锁定提升机
                    //提升机前往目标楼层(工作档目标楼层)
                    LiftCommand command3 = liftThread.getLiftUpDownCommand(liftProtocol.getLiftNo(), liftProtocol.getTaskNo(), (short) wrkMastLocNoLey);
                    commands.add(command3);//将命令添加进list
                }
                //提升机到达指定楼层,输送线将四向穿梭车移出去
                //输送线将四向穿梭车移动出去
                LiftCommand command4 = new LiftCommand();
                command4.setLiftNo(liftProtocol.getLiftNo());//提升机号
                command4.setTaskNo(liftProtocol.getTaskNo());//任务号
                command4.setRun((short) 3);//输送线运作
                command4.setLiftLock(true);//锁定提升机
                //输送线将四向穿梭车移动出去(反转)
                LiftCommand command4 = liftThread.getLiftTurnCommand(liftProtocol.getLiftNo(), liftProtocol.getTaskNo(), 2);
                commands.add(command4);//将命令添加进list
            }
@@ -2261,7 +2153,7 @@
                ShuttleAssignCommand assignCommand = new ShuttleAssignCommand();
                //获取小车到充电库位路径指令
                List<ShuttleCommand> commands = this.shuttleAssignCommand(currentLocNo, chargeLocNo, ShuttleTaskModeType.PAK_IN.id, assignCommand);
                List<ShuttleCommand> commands = this.shuttleAssignCommand(currentLocNo, chargeLocNo, ShuttleTaskModeType.PAK_IN.id, assignCommand, shuttleThread);
                //进行充电中
                shuttleProtocol.setProtocolStatus(ShuttleProtocolStatusType.CHARGING);
@@ -2271,11 +2163,7 @@
                assignCommand.setCharge(true);//充电任务
                //创建充电指令
                ShuttleCommand command = new ShuttleCommand();
                command.setCommandWord((short) 5);//充电
                command.setShuttleNo(shuttleProtocol.getShuttleNo());
                command.setChargeSwitch((short) 1);//开始充电
                command.setCommandEnd((short) 1);
                ShuttleCommand command = shuttleThread.getChargeSwitchCommand((short) 1);//开始充电
                commands.add(command);
                //指令集分配
@@ -2292,7 +2180,7 @@
                ShuttleAssignCommand assignCommand = new ShuttleAssignCommand();
                //小车移动到提升机口,计算路径
                List<ShuttleCommand> commands = this.shuttleAssignCommand(currentLocNo, liftLocNo, ShuttleTaskModeType.PAK_IN.id, assignCommand);
                List<ShuttleCommand> commands = this.shuttleAssignCommand(currentLocNo, liftLocNo, ShuttleTaskModeType.PAK_IN.id, assignCommand, shuttleThread);
                //分配目标库位
                shuttleProtocol.setLocNo(liftLocNo);
@@ -2342,42 +2230,23 @@
            int liftLev = liftProtocol.getLev().intValue();
            if (liftLev != currentLev) {
                //穿梭车和提升机处于不同楼层
                LiftCommand command1 = new LiftCommand();
                command1.setLiftNo(liftProtocol.getLiftNo());//提升机号
                command1.setTaskNo(liftProtocol.getTaskNo());//任务号
                command1.setRun((short) 1);//升降
                command1.setDistPosition(currentLev.shortValue());//目标楼层(穿梭车所在楼层)
                command1.setLiftLock(true);//锁定提升机
                //获取目标楼层(穿梭车所在楼层)命令
                LiftCommand command1 = liftThread.getLiftUpDownCommand(liftProtocol.getLiftNo(), liftProtocol.getTaskNo(), currentLev.shortValue());
                commands.add(command1);//将命令添加进list
            }
            //输送线将四向穿梭车移动进来
            LiftCommand command2 = new LiftCommand();
            command2.setLiftNo(liftProtocol.getLiftNo());//提升机号
            command2.setTaskNo(liftProtocol.getTaskNo());//任务号
            command2.setRun((short) 6);//输送线运作
            command2.setLiftLock(true);//锁定提升机
            //输送线将四向穿梭车移动进来(正转)
            LiftCommand command2 = liftThread.getLiftTurnCommand(liftProtocol.getLiftNo(), liftProtocol.getTaskNo(), 1);
            commands.add(command2);//将命令添加进list
            //提升机前往目标楼层
            LiftCommand command3 = new LiftCommand();
            command3.setLiftNo(liftProtocol.getLiftNo());//提升机号
            command3.setTaskNo(liftProtocol.getTaskNo());//任务号
            command3.setRun((short) 1);//升降
            command3.setDistPosition(chargeLocNoLev.shortValue());//充电库位目标楼层
            command3.setLiftLock(true);//锁定提升机
            //获取充电库位目标楼层命令
            LiftCommand command3 = liftThread.getLiftUpDownCommand(liftProtocol.getLiftNo(), liftProtocol.getTaskNo(), chargeLocNoLev.shortValue());
            commands.add(command3);//将命令添加进list
            //提升机到达指定楼层,输送线将四向穿梭车移出去
            //输送线将四向穿梭车移动出去
            LiftCommand command4 = new LiftCommand();
            command4.setLiftNo(liftProtocol.getLiftNo());//提升机号
            command4.setTaskNo(liftProtocol.getTaskNo());//任务号
            command4.setRun((short) 3);//输送线运作
            command4.setLiftLock(true);//锁定提升机
            //输送线将四向穿梭车移动出去(反转)
            LiftCommand command4 = liftThread.getLiftTurnCommand(liftProtocol.getLiftNo(), liftProtocol.getTaskNo(), 2);
            commands.add(command4);//将命令添加进list
            wrkCharge.setWrkSts(54L);//提升机搬运中
@@ -2404,11 +2273,7 @@
                assignCommand.setCharge(true);
                //创建充电指令
                ShuttleCommand command = new ShuttleCommand();
                command.setCommandWord((short) 5);//充电
                command.setShuttleNo(shuttleProtocol.getShuttleNo());
                command.setChargeSwitch((short) 2);//断开充电
                command.setCommandEnd((short) 1);
                ShuttleCommand command = shuttleThread.getChargeSwitchCommand((short) 2);//断开充电
                commands.add(command);
                //指令集分配