fix
Junjie
2023-06-20 6c6a1178f2e5900d56a381e12f9c9f998cf9b270
fix
4个文件已修改
222 ■■■■■ 已修改文件
src/main/java/com/zy/asrs/controller/SiteController.java 5 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/zy/asrs/service/impl/MainServiceImpl.java 165 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/zy/core/thread/ShuttleThread.java 49 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/zy/core/thread/SiemensDevpThread.java 3 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/zy/asrs/controller/SiteController.java
@@ -71,11 +71,6 @@
            map2.put("modeVal", devpThread.charge1);
            map2.put("modeDesc", devpThread.charge1?"充电中":"关闭");
            res.add(map2);
            Map<String, Object> map3 = new HashMap<>();
            map3.put("floor", 3);
            map3.put("modeVal", devpThread.charge2);
            map3.put("modeDesc", devpThread.charge2?"充电中":"关闭");
            res.add(map3);
        }
        return R.ok().add(res);
    }
src/main/java/com/zy/asrs/service/impl/MainServiceImpl.java
@@ -685,6 +685,11 @@
                                //判断提升机是否空闲
                                if (!liftProtocol.isIdle()) {
                                    try {
                                        Thread.sleep(1000);//休眠1s
                                    } catch (InterruptedException e) {
                                        throw new RuntimeException(e);
                                    }
                                    continue;//提升机忙
                                }
@@ -982,6 +987,11 @@
                        //判断提升机是否空闲
                        if (!liftProtocol.isIdle()) {
                            try {
                                Thread.sleep(1000);//休眠1s
                            } catch (InterruptedException e) {
                                throw new RuntimeException(e);
                            }
                            continue;//提升机忙
                        }
@@ -993,7 +1003,7 @@
                            continue;//提升机不在目标楼层跳过
                        }
                        Integer staNo = Utils.levToOutInStaNo(lev);
                        Integer staNo = Utils.levToOutInStaNo(lev >= 2 ? lev + 1 : lev);
                        DevpThread devpThread = (DevpThread) SlaveConnection.get(SlaveType.Devp, 1);
                        //获取目标站信息
                        StaProtocol staProtocol1 = devpThread.getStation().get(staNo);
@@ -1028,32 +1038,26 @@
                        continue;
                    }
                    wrkMast.setShuttleNo(shuttleProtocol.getShuttleNo().intValue());//给工作档分配四向穿梭车号
                    //源库位(小车当前位置)
                    String currentLocNo = shuttleProtocol.getCurrentLocNo();
                    //小车当前层高
                    Integer currentLev = Utils.getLev(currentLocNo);
                    //获取提升机
                    LiftSlave liftSlave = slaveProperties.getLift().get(0);
                    //当前楼层提升机输送站点库位号
                    String liftSiteLocNo = Utils.levToOutInStaLocNo(currentLev);
                    //分配任务号
                    shuttleProtocol.setTaskNo(wrkMast.getWrkNo().shortValue());
                    //分配源库位
                    shuttleProtocol.setSourceLocNo(currentLocNo);
                    ShuttleAssignCommand assignCommand = new ShuttleAssignCommand();
                    //四向穿梭车号
                    assignCommand.setShuttleNo(shuttleProtocol.getShuttleNo());
                    //任务号
                    assignCommand.setTaskNo(wrkMast.getWrkNo().shortValue());
                    //入出库模式
                    assignCommand.setTaskMode(ShuttleTaskModeType.PAK_OUT.id.shortValue());
                    assignCommand.setSourceLocNo(currentLocNo);
                    if (wrkMast.getWrkSts() == 21) {
                        wrkMast.setShuttleNo(shuttleProtocol.getShuttleNo().intValue());//给工作档分配四向穿梭车号
                        //源库位(小车当前位置)
                        String currentLocNo = shuttleProtocol.getCurrentLocNo();
                        //小车当前层高
                        Integer currentLev = Utils.getLev(currentLocNo);
                        //当前楼层提升机输送站点库位号
                        String liftSiteLocNo = Utils.levToOutInStaLocNo(currentLev);
                        ShuttleAssignCommand assignCommand = new ShuttleAssignCommand();
                        //四向穿梭车号
                        assignCommand.setShuttleNo(shuttleProtocol.getShuttleNo());
                        //任务号
                        assignCommand.setTaskNo(wrkMast.getWrkNo().shortValue());
                        //入出库模式
                        assignCommand.setTaskMode(ShuttleTaskModeType.PAK_OUT.id.shortValue());
                        assignCommand.setSourceLocNo(currentLocNo);
                        //判断小车和库位是否在同一层
                        if (Boolean.parseBoolean(searchIdleShuttle.get("sameLay").toString())) {
                            //同一层(将小车移动到货物位置)
@@ -1064,19 +1068,35 @@
                            }
                            //分配目标库位
                            shuttleProtocol.setLocNo(wrkMast.getSourceLocNo());
                            //分配任务号
                            shuttleProtocol.setTaskNo(wrkMast.getWrkNo().shortValue());
                            //分配源库位
                            shuttleProtocol.setSourceLocNo(currentLocNo);
                            //目标库位
                            assignCommand.setLocNo(wrkMast.getSourceLocNo());
                            assignCommand.setCommands(commands);
                            wrkMast.setWrkSts(26L);//小车搬运中
                            if (wrkMastMapper.updateById(wrkMast) > 0) {
                                //下发任务
                                MessageQueue.offer(SlaveType.Shuttle, assignCommand.getShuttleNo().intValue(), new Task(3, assignCommand));
                            }
                        }else {
                            //不同层,将目标库位分配成提升机库位号(将小车移动到提升机位置)
                            //小车到提升机口指令
                            List<ShuttleCommand> commands = this.shuttleAssignCommand(currentLocNo, liftSiteLocNo, ShuttleTaskModeType.PAK_IN.id, assignCommand, shuttleThread);
                            if (commands == null) {
                                continue;//未找到路径
                                if (!currentLocNo.equals(liftSiteLocNo)) {//当前位置也不在提升机口
                                    continue;//未找到路径
                                }
                                commands = new ArrayList<>();
                            }
                            shuttleProtocol.setLocNo(liftSiteLocNo);
                            //分配任务号
                            shuttleProtocol.setTaskNo(wrkMast.getWrkNo().shortValue());
                            //分配源库位
                            shuttleProtocol.setSourceLocNo(currentLocNo);
                            //获取当前小车所在楼层的站点信息
                            BasDevp basDevp = basDevpService.queryByLocNo(liftSiteLocNo);
@@ -1090,32 +1110,56 @@
                            assignCommand.setLocNo(liftSiteLocNo);
                            assignCommand.setCommands(commands);
                            wrkMast.setWrkSts(22L);//小车迁移状态
                            if (wrkMastMapper.updateById(wrkMast) > 0) {
                                //下发任务
                                MessageQueue.offer(SlaveType.Shuttle, assignCommand.getShuttleNo().intValue(), new Task(3, assignCommand));
                            }
                        }
                    } else if (wrkMast.getWrkSts() == 25) {
                        List<ShuttleCommand> commands = this.shuttleAssignCommand(currentLocNo, wrkMast.getSourceLocNo(), liftSiteLocNo, assignCommand, shuttleThread);
                        wrkMast.setShuttleNo(shuttleProtocol.getShuttleNo().intValue());//给工作档分配四向穿梭车号
                        //当前楼层提升机输送站点库位号
                        String liftSiteLocNo = Utils.levToOutInStaLocNo(liftProtocol.getLev().intValue());
                        ShuttleAssignCommand assignCommand = new ShuttleAssignCommand();
                        //四向穿梭车号
                        assignCommand.setShuttleNo(shuttleProtocol.getShuttleNo());
                        //任务号
                        assignCommand.setTaskNo(wrkMast.getWrkNo().shortValue());
                        //入出库模式
                        assignCommand.setTaskMode(ShuttleTaskModeType.PAK_OUT.id.shortValue());
                        assignCommand.setSourceLocNo(liftSiteLocNo);
                        List<ShuttleCommand> commands = this.shuttleAssignCommand(liftSiteLocNo, wrkMast.getSourceLocNo(), liftSiteLocNo, assignCommand, shuttleThread);
                        if (commands == null) {
                            continue;//未找到路径
                        }
                        //此时车在提升机内部,需要多下达一步指令让车移动到提升机口
                        BasDevp basDevp = basDevpService.selectById(109);//获取提升机信息
                        short startCode = Short.parseShort(basDevp.getQrCodeValue());//提升机二维码
                        short startCode = liftProtocol.getBarcode();//提升机内部二维码
                        Short distCode = commands.get(0).getStartCodeNum();//目标二维码
                        //获取移动命令
                        ShuttleCommand moveCommand = shuttleThread.getMoveCommand(startCode, distCode, 1300, commands.get(0).getRunDirection(), (short) 1, 0);
                        ShuttleCommand moveCommand = shuttleThread.getMoveCommand(startCode, distCode, 1400, commands.get(0).getRunDirection(), startCode, 1400, 500);
                        commands.add(0, moveCommand);//将该指令添加到队头
                        //分配目标库位
                        shuttleProtocol.setLocNo(wrkMast.getSourceLocNo());
                        //分配任务号
                        shuttleProtocol.setTaskNo(wrkMast.getWrkNo().shortValue());
                        //分配源库位
                        shuttleProtocol.setSourceLocNo(liftSiteLocNo);
                        //目标库位
                        assignCommand.setLocNo(wrkMast.getSourceLocNo());
                        assignCommand.setCommands(commands);
                        wrkMast.setWrkSts(26L);//小车搬运中
                        if (wrkMastMapper.updateById(wrkMast) > 0) {
                            //下发任务
                            MessageQueue.offer(SlaveType.Shuttle, assignCommand.getShuttleNo().intValue(), new Task(3, assignCommand));
                        }
                    }
                    if (wrkMastMapper.updateById(wrkMast) > 0) {
                        //下发任务
                        MessageQueue.offer(SlaveType.Shuttle, assignCommand.getShuttleNo().intValue(), new Task(3, assignCommand));
                    }
                }
            }
        }
@@ -1360,11 +1404,6 @@
                continue;
            }
            //给提升机分配任务
            liftProtocol.setLiftLock(true);//锁定提升机
            liftProtocol.setTaskNo(wrkMast.getWrkNo().shortValue());//设置任务号
            liftProtocol.setProtocolStatus(LiftProtocolStatusType.WORKING);//设置提升机状态为工作中
            //命令list
            ArrayList<LiftCommand> commands = new ArrayList<>();
@@ -1382,14 +1421,13 @@
                //工作档目标库位楼层
                int wrkMastLocNoLey = Utils.getLev(wrkMastLocNo);
                //提升机当前楼层
                int liftLev = liftProtocol.getLev().intValue();
                if (liftLev == 0) {//提升机当前楼层为0,提升机失去位置信息,让提升机前往一楼
                    LiftCommand command = liftThread.getLiftUpDownCommand(liftProtocol.getLiftNo(), liftProtocol.getTaskNo(), LiftLevType.ONE.lev);
                    commands.add(command);//将命令添加进list
                Integer levTmp = wrkMastLocNoLey;
                if (wrkMastLocNoLey >= 2) {
                    levTmp += 1;
                }
                Integer distStaNo = Utils.levToOutInStaNo(levTmp);
                if (liftLev != LiftLevType.TWO.realLev) {
                if (liftProtocol.getPositionArrivalFeedback().intValue() != LiftLevType.TWO.realLev.intValue()) {
                    //提升机不在输送线楼层,获取到输送线层的提升机命令
                    LiftCommand command1 = liftThread.getLiftUpDownCommand(liftProtocol.getLiftNo(), liftProtocol.getTaskNo(), LiftLevType.TWO.lev);
                    commands.add(command1);//将命令添加进list
@@ -1400,12 +1438,8 @@
                command2.setOperaStaNo((short) 102);//操作102站
                command2.setRotationDire(1);//给输送线下发链条转动信号,正转
                command2.setDevpId(devpId);
                command2.setStaNo(distStaNo.shortValue());//设置目标站
                commands.add(command2);//将命令添加进list
                Integer levTmp = wrkMastLocNoLey;
                if (wrkMastLocNoLey >= 2) {
                    levTmp += 1;
                }
                //提升机前往目标楼层(工作档目标楼层)
                LiftCommand command3 = liftThread.getLiftUpDownCommand(liftProtocol.getLiftNo(), liftProtocol.getTaskNo(), levTmp);
@@ -1414,12 +1448,15 @@
                //提升机到达指定楼层,输送线将货物移出去(正转)
                //输送线将货物移出去
                LiftCommand command4 = liftThread.getLiftTurnCommand(liftProtocol.getLiftNo(), liftProtocol.getTaskNo(), 1);
                Integer distStaNo = Utils.levToOutInStaNo(levTmp);
                command4.setOperaStaNo(distStaNo.shortValue());//操作目标楼层站点
                command4.setRotationDire(1);//给输送线下发链条转动信号,正转
                command4.setDevpId(devpId);
                command4.setStaNo(distStaNo.shortValue());//设置目标站
                commands.add(command4);//将命令添加进list
                //给提升机分配任务
                liftProtocol.setTaskNo(wrkMast.getWrkNo().shortValue());//设置任务号
                liftProtocol.setProtocolStatus(LiftProtocolStatusType.WORKING);//设置提升机状态为工作中
                wrkMast.setWrkSts(3L);//3.提升机搬运中
            } else if (wrkMast.getWrkSts() == 6) {//6.迁移小车至提升机口完成 => 7.提升机迁移小车中
@@ -1442,7 +1479,7 @@
                }
                //工作档目标库位号
                String wrkMastLocNo = wrkMast.getIoType() == 101 ? wrkMast.getSourceLocNo() : wrkMast.getLocNo();
                String wrkMastLocNo = wrkMast.getLocNo();
                //工作档目标库位楼层
                int wrkMastLocNoLey = Utils.getLev(wrkMastLocNo);
                if (wrkMastLocNoLey >= 2) {
@@ -1452,6 +1489,10 @@
                //提升机前往目标楼层(工作档目标楼层)
                LiftCommand command1 = liftThread.getLiftUpDownCommand(liftProtocol.getLiftNo(), liftProtocol.getTaskNo(), wrkMastLocNoLey);
                commands.add(command1);//将命令添加进list
                //给提升机分配任务
                liftProtocol.setTaskNo(wrkMast.getWrkNo().shortValue());//设置任务号
                liftProtocol.setProtocolStatus(LiftProtocolStatusType.WORKING);//设置提升机状态为工作中
                wrkMast.setWrkSts(7L);//6.迁移小车至提升机口完成 => 7.提升机迁移小车中
            } else if(wrkMast.getWrkSts() == 23) {//23.迁移小车至提升机口完成 => 24.提升机迁移小车中
@@ -1475,7 +1516,7 @@
                }
                //工作档目标库位号
                String wrkMastLocNo = wrkMast.getIoType() == 101 ? wrkMast.getSourceLocNo() : wrkMast.getLocNo();
                String wrkMastLocNo = wrkMast.getSourceLocNo();
                //工作档目标库位楼层
                int wrkMastLocNoLey = Utils.getLev(wrkMastLocNo);
                if (wrkMastLocNoLey >= 2) {
@@ -1486,6 +1527,10 @@
                LiftCommand command1 = liftThread.getLiftUpDownCommand(liftProtocol.getLiftNo(), liftProtocol.getTaskNo(), wrkMastLocNoLey);
                commands.add(command1);//将命令添加进list
                //给提升机分配任务
                liftProtocol.setTaskNo(wrkMast.getWrkNo().shortValue());//设置任务号
                liftProtocol.setProtocolStatus(LiftProtocolStatusType.WORKING);//设置提升机状态为工作中
                wrkMast.setWrkSts(24L);//23.迁移小车至提升机口完成 => 24.提升机迁移小车中
            } else if (wrkMast.getWrkSts() == 27) {//27.小车出库搬运完成
                //工作档源库位号
@@ -1495,14 +1540,10 @@
                //提升机当前楼层
                int liftLev = liftProtocol.getLev().intValue();
                if (liftLev == 0) {//提升机当前楼层为0,提升机失去位置信息,让提升机前往一楼
                    LiftCommand command = liftThread.getLiftUpDownCommand(liftProtocol.getLiftNo(), liftProtocol.getTaskNo(), LiftLevType.ONE.lev);
                    commands.add(command);//将命令添加进list
                }
                //判断提升机是否到位
                StaProtocol staProtocol = devpThread.getStation().get(Utils.levToOutInStaNo(wrkMastLocNoLey));//起始站点
                if (liftLev != wrkMastLocNoLey && wrkMastLocNoLey != 1 || !staProtocol.isLiftArrival()) {
                StaProtocol staProtocol = devpThread.getStation().get(Utils.levToOutInStaNo(wrkMastLocNoLey >= 2 ? wrkMastLocNoLey + 1 : wrkMastLocNoLey));//起始站点
                if (liftLev != wrkMastLocNoLey && !staProtocol.isLiftArrival()) {
                    //提升机不在工作档源库位楼层,调度提升机
                    LiftCommand command1 = liftThread.getLiftUpDownCommand(liftProtocol.getLiftNo(), liftProtocol.getTaskNo(), wrkMastLocNoLey);
                    commands.add(command1);//将命令添加进list
@@ -1536,6 +1577,10 @@
                command5.setRotationDire(0);//链条转动停止
                commands.add(command5);
                //给提升机分配任务
                liftProtocol.setTaskNo(wrkMast.getWrkNo().shortValue());//设置任务号
                liftProtocol.setProtocolStatus(LiftProtocolStatusType.WORKING);//设置提升机状态为工作中
                wrkMast.setWrkSts(28L);//28.提升机搬运中
            }
src/main/java/com/zy/core/thread/ShuttleThread.java
@@ -915,14 +915,15 @@
            qrCodeValues.add(Short.parseShort(basDevp.getQrCodeValue()));
        }
        //遍历所有指令,判断是否有到提升机口的指令,并获取到达该提升机口所需步序
        //遍历所有指令,判断是否有到提升机口的指令或从提升机口前往提升机内的指令,并获取到达该提升机口所需步序
        int step = 0;
        Integer siteNo = null;//站点号
        ShuttleCommand command = null;
        for (int i = 0; i < commands.size(); i++) {
            command = commands.get(i);
            for (Short qrCodeValue : qrCodeValues) {
                if (qrCodeValue.intValue() == command.getDistCodeNum().intValue()) {
                //目标位置是提升机口,或起点位置是提升机口且目标是去提升机内
                if (qrCodeValue.intValue() == command.getDistCodeNum().intValue() || (qrCodeValue.intValue() == command.getStartCodeNum().intValue() && command.getDistCodeNum().intValue() == liftProtocol.getBarcode().intValue())) {
                    //存在
                    step = i + 1;
                    BasDevp basDevp = basDevpService.queryByQrCode(qrCodeValue.intValue());
@@ -937,11 +938,21 @@
            return true;
        }
        //判断下一步是否为提升机口
        if (commandStep + 1 != step) {
            //下一步不是提升机口,跳过后续流程
            return true;
        //判断下一步是否为提升机口或提升机内
        if (commandStep < commands.size()) {
            ShuttleCommand command1 = commands.get(commandStep);
            Short distCodeNum = command1.getDistCodeNum();
            if (distCodeNum != null) {
                BasDevp basDevp = basDevpService.queryByQrCode(Integer.valueOf(distCodeNum));
                if (basDevp == null && distCodeNum.intValue() != liftProtocol.getBarcode().intValue()) {
                    return true;//下一步不是提升机口,跳过后续流程
                }
            }
        }
//        if (commandStep + 1 != step) {
//            //下一步不是提升机口,跳过后续流程
//            return true;
//        }
        //获取四向穿梭车当前楼层
        String shuttleLocNo = shuttleProtocol.getCurrentLocNo();//二维码对应库位号
@@ -956,13 +967,28 @@
        if (siteNo != null) {
            SiemensDevpThread siemensDevpThread = (SiemensDevpThread) SlaveConnection.get(SlaveType.Devp, 1);
            StaProtocol staProtocol = siemensDevpThread.getStation().get(siteNo);
            if (staProtocol.isLiftArrival()
                && liftProtocol.getPositionArrivalFeedback$() == shuttleLocNoLev) {
                //输送线反馈提升机到位且提升机楼层反馈为同一层,直接放行
            if (!staProtocol.isLiftArrival()) {
                //输送线反馈提升机没有到位
                executeLift(liftThread, liftProtocol, redisCommand, shuttleLocNoLev);//调度提升机
                return false;
            }
            if (shuttleProtocol.getCurrentCode().intValue() == liftProtocol.getBarcode().intValue()) {
                //小车处于提升机内
                return true;
            }else {
                if (liftProtocol.getPositionArrivalFeedback$() == shuttleLocNoLev) {
                    return true;//提升机到位
                }
                executeLift(liftThread, liftProtocol, redisCommand, shuttleLocNoLev);//调度提升机
                return false;//提升机没有到位
            }
        }
        return false;
    }
    private boolean executeLift(LiftThread liftThread, LiftProtocol liftProtocol, ShuttleRedisCommand redisCommand, Integer shuttleLocNoLev) {//调度提升机
        if (liftProtocol.getRunning()) {
            //提升机运行中,禁止下发
            return false;
@@ -980,7 +1006,7 @@
        liftProtocol.setSecurityMk(true);//标记置为true,防止其他任务占用当前提升机
        redisCommand.setLiftSecurityMk(true);//标记置为true,防止其他任务占用当前提升机
        //任务数据保存到redis
        redisUtil.set("shuttle_wrk_no_" + wrkNo, JSON.toJSONString(redisCommand));
        redisUtil.set("shuttle_wrk_no_" + redisCommand.getWrkNo(), JSON.toJSONString(redisCommand));
        //命令list
        ArrayList<LiftCommand> liftCommands = new ArrayList<>();
@@ -993,8 +1019,7 @@
        liftAssignCommand.setTaskNo(liftProtocol.getTaskNo());
        //下发任务
        MessageQueue.offer(SlaveType.Lift, liftProtocol.getLiftNo().intValue(), new Task(3, liftAssignCommand));
        return false;
        return true;
    }
    /**
src/main/java/com/zy/core/thread/SiemensDevpThread.java
@@ -53,6 +53,9 @@
        add(107);add(108);
    }};
    public boolean charge0;
    public boolean charge1;
    public SiemensDevpThread(DevpSlave slave) {
        this.slave = slave;
    }