Junjie
2023-05-11 44fa920bbcf6cd94c81f3a6d2f3008925a8635ca
四向穿梭车命令封装
2个文件已修改
155 ■■■■■ 已修改文件
src/main/java/com/zy/asrs/service/impl/MainServiceImpl.java 129 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/zy/core/thread/ShuttleThread.java 26 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/zy/asrs/service/impl/MainServiceImpl.java
@@ -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);//将该指令添加到队头
                        //分配目标库位
@@ -2261,7 +2196,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 +2206,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 +2223,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);
@@ -2404,11 +2335,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);
                //指令集分配
src/main/java/com/zy/core/thread/ShuttleThread.java
@@ -918,7 +918,7 @@
     * 获取托盘顶升命令
     * @param lift 1顶升,2下降
     */
    private ShuttleCommand getPalletCommand(Short lift) {
    public ShuttleCommand getPalletCommand(Short lift) {
        ShuttleCommand command = new ShuttleCommand();
        command.setCommandWord((short) 2);
        command.setStartCodeNum((short) 0);
@@ -938,7 +938,7 @@
     * 正常移动命令
     * @return
     */
    private ShuttleCommand getMoveCommand(Short startCodeNum, Short distCodeNum, Integer startToDistDistance, Short runDirection) {
    public ShuttleCommand getMoveCommand(Short startCodeNum, Short distCodeNum, Integer startToDistDistance, Short runDirection) {
        ShuttleCommand command = new ShuttleCommand();
        command.setCommandWord((short) 1);
        command.setStartCodeNum(startCodeNum);
@@ -957,7 +957,7 @@
     * 强制移动命令
     * @param direction 移动方向 1左移,2右移,3前移,4后移
     */
    private ShuttleCommand getForceMoveCommand(Short direction) {
    public ShuttleCommand getForceMoveCommand(Short direction) {
        ShuttleCommand command = new ShuttleCommand();
        command.setCommandWord((short) 3);
        command.setStartCodeNum((short) 0);
@@ -975,7 +975,7 @@
    /**
     * 状态复位命令
     */
    private ShuttleCommand getResetCommand() {
    public ShuttleCommand getResetCommand() {
        ShuttleCommand command = new ShuttleCommand();
        command.setCommandWord((short) 6);
        command.setStartCodeNum((short) 0);
@@ -998,7 +998,7 @@
     * 获取寻库位命令
     * @param direction 1:向正方向(左)寻库位,2:向负方向(右)寻库位,3:向负方向(后)寻库位,4:向正方向(前)寻库位
     */
    private ShuttleCommand getFindLocCommand(Short direction, Integer startToDistance, Short runSpeed) {
    public ShuttleCommand getFindLocCommand(Short direction, Integer startToDistance, Short runSpeed) {
        ShuttleCommand command = new ShuttleCommand();
        command.setCommandWord((short) 4);
        command.setRunDirection(direction);
@@ -1012,14 +1012,14 @@
     * 获取寻库位命令,默认移动距离3000,运行速度1000
     * @param direction 1:向正方向(左)寻库位,2:向负方向(右)寻库位,3:向负方向(后)寻库位,4:向正方向(前)寻库位
     */
    private ShuttleCommand getFindLocCommand(Short direction) {
    public ShuttleCommand getFindLocCommand(Short direction) {
        return getFindLocCommand(direction, 3000, (short) 1000);
    }
    /**
     * 获取充电开关命令
     */
    private ShuttleCommand getChargeSwitchCommand() {
    public ShuttleCommand getChargeSwitchCommand() {
        ShuttleCommand command = new ShuttleCommand();
        command.setCommandWord((short) 8);
        command.setIOControl((short) 4);
@@ -1027,6 +1027,18 @@
        return command;
    }
    /**
     * charge:1=>开始充电,2=>断开充电
     */
    public ShuttleCommand getChargeSwitchCommand(Short charge) {
        ShuttleCommand command = new ShuttleCommand();
        command.setCommandWord((short) 5);//充电
        command.setShuttleNo(shuttleProtocol.getShuttleNo());
        command.setChargeSwitch(charge);//开始充电
        command.setCommandEnd((short) 1);
        return command;
    }
    /******************************************************************************************/
    /**************************************** 测试专用 *****************************************/
    /*****************************************************************************************/