#
vincentlu
12 小时以前 6cbb420754e6e29fa134a6afca4514b8dfd62918
zy-acs-manager/src/main/java/com/zy/acs/manager/core/service/MainService.java
@@ -90,7 +90,7 @@
    @Autowired
    private SegmentService segmentService;
    @Autowired
    private TrafficService trafficService;
    private LaneService laneService;
    @Autowired
    private AgvModelService agvModelService;
    @Autowired
@@ -945,59 +945,108 @@
                        String next = pathListPart.get(i);
                        Code nextCode = codeService.getCacheByData(next);
                        // 车头朝前的下一个行走方向
                        Double nextDirection = mapService.calculateDirection(lastCode, nextCode, angleOffsetVal);
                        // 反向角
                        final double oppLastDir = (lastDirection + 180) % 360;
                        // 如果下一个方向正好是作业方向的相反方向,则重置下一个方向为作业方向,标记 reverse = true
                        // 是否倒退行走
                        boolean reverse = false;
                        if (nextDirection.equals(oppWorkDir)) {
                            nextDirection = workDirection;
                            reverse = true;
                        }
                        // 判断当前节点是否可以旋转
                        if (!lastCode.getCornerBool()) {
                            // 如果是作业方向,但是小车在巷道内方向错误,则停止
                            if (reverse && !lastDirection.equals(nextDirection)) {
                                throw new CoolException(agvNo + "号小车方向错误,请推至转弯点手动调整");
                        // 巷道逻辑
                        if (!laneBuilder.isInitialized()) {
                            throw new CoolException("lanes are not initialized");
                        }
                        LaneDto lastLaneDto = laneBuilder.search(lastCode.getData());
                        LaneDto nextLaneDto = laneBuilder.search(nextCode.getData());
                        // 进入巷道角度
                        Double lastLaneDir = laneService.getLaneDirection(lastLaneDto);
                        Double nextLaneDir = laneService.getLaneDirection(nextLaneDto);
                        // 巷道强制转弯,优先级 > workDirection
                        if (null != nextLaneDir) {
                            nextDirection = nextLaneDir;
                            if (!lastDirection.equals(nextDirection)) {
                                if (!lastCode.getCornerBool()) {
                                    throw new CoolException(agvNo + "号小车进入巷道需调整方向为 " + nextDirection + "°,请推至转弯点手动调整");
                                }
                                // turn
                                actionList.add(new Action(
                                        null,    // 编号s
                                        task.getBusId(),    // 总线
                                        task.getId(),    // 任务
                                        null,    // 动作号
                                        null,    // 优先级
                                        ActionTypeType.TurnCorner.desc,    // 名称
                                        (double) mapService.spinDirection(lastCode).val,     // 属性值
                                        lastCode.getData(),    // 地面码
                                        String.valueOf(nextDirection),   // 动作参数
                                        ActionTypeType.TurnCorner.val(),    // 动作类型
                                        actionPrepareSts,    // 动作进度
                                        agvId,    // AGV
                                        now    // 工作时间
                                ));
                                lastDirection = nextDirection;
                            }
                            // 如果不是作业方向(另一组相反方向),判断是否相反方向,如果反方向则倒退行走
                            if (nextDirection.equals(oppLastDir)) {
                                // 倒退时,因为agv方向没变,所以下一个方向还是agv方向,故nextDirection = lastDirection;
                                nextDirection = lastDirection;
                        } else if (null != lastLaneDir) {
                            nextDirection = lastLaneDir;
                            if (!lastDirection.equals(nextDirection)) {
                                if (!lastCode.getCornerBool()) {
                                    throw new CoolException(agvNo + "号小车离开巷道需调整方向为 " + nextDirection + "°,请推至转弯点手动调整");
                                }
                            }
                        } else {
                            // 如果下一个方向正好是作业方向的相反方向,则重置下一个方向为作业方向,标记 reverse = true
                            if (nextDirection.equals(oppWorkDir)) {
                                nextDirection = workDirection;
                                reverse = true;
                            }
                            // 总结:1.如果是作业组(差180°)方向,那么agv方向必须是作业方向,如果 reverse 则说明倒退,这时候nextDirection肯定会等于作业方向(前面赋值了),如果不相同,则报错
                            //      2.如果不是作业组方向(另一组相反方向差180°),因为此函数不能旋转,所以差180°时只能倒退,倒退的时候因为agv不会旋转,所以nextDirection要变成agv方向
                        } else {
                            if (!lastDirection.equals(nextDirection)) {
                                // 如果下一个方向与agv方向相反,则倒退行走,避免进行毫无意义的转弯动作。
                                // 但是要注意:如果agv方向与工作方向正好相反,则需要旋转至工作方向,也就是为什么要加!workDirection.equals(oppLastDir)判断
                                if (nextDirection.equals(oppLastDir) && !workDirection.equals(oppLastDir)) {
                            // 判断当前节点是否可以旋转
                            if (!lastCode.getCornerBool()) {
                                // 如果是作业方向,但是小车在巷道内方向错误,则停止
                                if (reverse && !lastDirection.equals(nextDirection)) {
                                    throw new CoolException(agvNo + "号小车方向错误,请推至转弯点手动调整");
                                }
                                // 如果不是作业方向(另一组相反方向),判断是否相反方向,如果反方向则倒退行走
                                if (nextDirection.equals(oppLastDir)) {
                                    // 倒退时,因为agv方向没变,所以下一个方向还是agv方向,故nextDirection = lastDirection;
                                    nextDirection = lastDirection;
                                    reverse = true;
                                } else {
                                    // turn
                                    actionList.add(new Action(
                                            null,    // 编号s
                                            task.getBusId(),    // 总线
                                            task.getId(),    // 任务
                                            null,    // 动作号
                                            null,    // 优先级
                                            ActionTypeType.TurnCorner.desc,    // 名称
                                            (double) mapService.spinDirection(lastCode).val,     // 属性值
                                            lastCode.getData(),    // 地面码
                                            String.valueOf(nextDirection),   // 动作参数
                                            ActionTypeType.TurnCorner.val(),    // 动作类型
                                            actionPrepareSts,    // 动作进度
                                            agvId,    // AGV
                                            now    // 工作时间
                                    ));
                                }
                                // 总结:1.如果是作业组(差180°)方向,那么agv方向必须是作业方向,如果 reverse 则说明倒退,这时候nextDirection肯定会等于作业方向(前面赋值了),如果不相同,则报错
                                //      2.如果不是作业组方向(另一组相反方向差180°),因为此函数不能旋转,所以差180°时只能倒退,倒退的时候因为agv不会旋转,所以nextDirection要变成agv方向
                            } else {
                                if (!lastDirection.equals(nextDirection)) {
                                    // 如果下一个方向与agv方向相反,则倒退行走,避免进行毫无意义的转弯动作。
                                    // 但是要注意:如果agv方向与工作方向正好相反,则需要旋转至工作方向,也就是为什么要加!workDirection.equals(oppLastDir)判断
                                    if (nextDirection.equals(oppLastDir) && !workDirection.equals(oppLastDir)) {
                                        // 倒退时,因为agv方向没变,所以下一个方向还是agv方向,故nextDirection = lastDirection;
                                        nextDirection = lastDirection;
                                        reverse = true;
                                    } else {
                                        // turn
                                        actionList.add(new Action(
                                                null,    // 编号s
                                                task.getBusId(),    // 总线
                                                task.getId(),    // 任务
                                                null,    // 动作号
                                                null,    // 优先级
                                                ActionTypeType.TurnCorner.desc,    // 名称
                                                (double) mapService.spinDirection(lastCode).val,     // 属性值
                                                lastCode.getData(),    // 地面码
                                                String.valueOf(nextDirection),   // 动作参数
                                                ActionTypeType.TurnCorner.val(),    // 动作类型
                                                actionPrepareSts,    // 动作进度
                                                agvId,    // AGV
                                                now    // 工作时间
                                        ));
                                    lastDirection = nextDirection;
                                        lastDirection = nextDirection;
                                    }
                                }
                            }
                        }
@@ -1052,6 +1101,25 @@
                // 初始方向值补丁
                if (first) {
                    if (Cools.isEmpty(actionList) || !actionList.get(0).getActionType().equals(ActionTypeType.TurnCorner.val())) {
                        Double firstTurnDir = workDirection;
                        // 巷道逻辑
                        if (!laneBuilder.isInitialized()) {
                            throw new CoolException("lanes are not initialized");
                        }
                        LaneDto lastLaneDto = laneBuilder.search(lastCode.getData());
                        // 进入巷道角度
                        Double lastLaneDir = laneService.getLaneDirection(lastLaneDto);
                        if (lastLaneDir != null) {
                            firstTurnDir = lastLaneDir;
                        }
                        if (!lastDirection.equals(firstTurnDir)) {
                            if (!lastCode.getCornerBool()) {
                                throw new CoolException(agvNo + "号小车方向错误,请推至转弯点手动调整");
                            }
                        }
                        // turn
                        actionList.add(new Action(
                                null,    // 编号
@@ -1062,14 +1130,14 @@
                                ActionTypeType.TurnCorner.desc,    // 名称
                                (double) mapService.spinDirection(lastCode).val,    // 属性值
                                lastCode.getData(),    // 地面码
                                String.valueOf(workDirection),   // 动作参数
                                String.valueOf(firstTurnDir),   // 动作参数
                                ActionTypeType.TurnCorner.val(),    // 动作类型
                                actionPrepareSts,    // 动作进度
                                agvId,    // AGV
                                now    // 工作时间
                        ));
                        lastDirection = workDirection;
                        lastDirection = firstTurnDir;
                    }
                    first = false;
@@ -1822,8 +1890,8 @@
            AGV_06_DOWN agv_06_down = new AGV_06_DOWN();
            agv_06_down.setSerialNo(agv_06_up.getSerialNo());
            agv_06_down.setActionCode(agv_06_up.getActionCode());
            agv_06_down.setResult(success ? 1 : 0);
            //agv_06_down.setResult(success ? 1 : 0);
            agv_06_down.setResult(1);
            redis.push(RedisConstant.AGV_PATH_DOWN_FLAG, AgvProtocol.build(protocol.getAgvNo()).setMessageBody(agv_06_down));
        }