#
luxiaotao1123
昨天 9b79c0073a7108cd05ed49806a4affb45e9f1629
#
1个文件已添加
3个文件已修改
1个文件已删除
175 ■■■■ 已修改文件
zy-acs-manager/src/main/java/com/zy/acs/manager/core/domain/DirectionDto.java 32 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
zy-acs-manager/src/main/java/com/zy/acs/manager/core/domain/type/CodeDirectionType.java 20 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
zy-acs-manager/src/main/java/com/zy/acs/manager/core/domain/type/DirectionType.java 15 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
zy-acs-manager/src/main/java/com/zy/acs/manager/core/service/MainService.java 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
zy-acs-manager/src/main/java/com/zy/acs/manager/core/service/MapService.java 106 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
zy-acs-manager/src/main/java/com/zy/acs/manager/core/domain/DirectionDto.java
@@ -1,8 +1,11 @@
package com.zy.acs.manager.core.domain;
import com.zy.acs.manager.core.domain.type.DirectionType;
import com.zy.acs.manager.core.domain.type.CodeDirectionType;
import lombok.Data;
import java.util.ArrayList;
import java.util.List;
/**
 * Created by vincent on 2026/1/14
@@ -10,8 +13,33 @@
@Data
public class DirectionDto {
    private DirectionType direction;
    private Double angle;
    private Boolean enabled;
    public static List<DirectionDto> initCodeDirections() {
        List<DirectionDto> list = new ArrayList<>();
        DirectionDto northDto = new DirectionDto();
        northDto.setAngle(CodeDirectionType.NORTH.angle);
        northDto.setEnabled(true);
        list.add(northDto);
        DirectionDto eastDto = new DirectionDto();
        eastDto.setAngle(CodeDirectionType.EAST.angle);
        eastDto.setEnabled(true);
        list.add(eastDto);
        DirectionDto southDto = new DirectionDto();
        southDto.setAngle(CodeDirectionType.SOUTH.angle);
        southDto.setEnabled(true);
        list.add(southDto);
        DirectionDto westDto = new DirectionDto();
        westDto.setAngle(CodeDirectionType.WEST.angle);
        westDto.setEnabled(true);
        list.add(westDto);
        return list;
    }
}
zy-acs-manager/src/main/java/com/zy/acs/manager/core/domain/type/CodeDirectionType.java
New file
@@ -0,0 +1,20 @@
package com.zy.acs.manager.core.domain.type;
public enum CodeDirectionType {
    NONE(null, "NONE"),
    NORTH(0.0, "NORTH"),
    EAST(90.0, "EAST"),
    SOUTH(180.0, "SOUTH"),
    WEST(270.0, "WEST"),
    ;
    public Double angle;
    public String desc;
    CodeDirectionType(Double angle, String desc) {
        this.angle = angle;
        this.desc = desc;
    }
}
zy-acs-manager/src/main/java/com/zy/acs/manager/core/domain/type/DirectionType.java
File was deleted
zy-acs-manager/src/main/java/com/zy/acs/manager/core/service/MainService.java
@@ -993,7 +993,7 @@
                                reverse = true;
                            }
                            nextDirection = nextLaneDir; // 防止 第一个动作一定是 turn 出问题
                        } else if (null != lastLaneDir) {
                        } else if (null != lastLaneDir) { // todo turn 环形直角
                            final double oppLastLaneDir = (lastLaneDir + 180) % 360;
                            if (!lastDirection.equals(nextDirection)) { // lastLaneDir
zy-acs-manager/src/main/java/com/zy/acs/manager/core/service/MapService.java
@@ -1,10 +1,13 @@
package com.zy.acs.manager.core.service;
import com.alibaba.fastjson.JSON;
import com.zy.acs.common.enums.AgvDirectionType;
import com.zy.acs.framework.common.Cools;
import com.zy.acs.manager.core.constant.MapDataConstant;
import com.zy.acs.manager.core.domain.DirectionDto;
import com.zy.acs.manager.core.domain.SortCodeDto;
import com.zy.acs.manager.core.domain.UnlockPathTask;
import com.zy.acs.manager.core.domain.type.CodeDirectionType;
import com.zy.acs.manager.core.service.astart.*;
import com.zy.acs.manager.core.service.astart.domain.AStarNavigateNode;
import com.zy.acs.manager.core.service.astart.domain.DynamicNode;
@@ -36,6 +39,7 @@
@Component("mapService")
public class MapService {
    private static final double EPS = 1e-7;
    private final static int[][] DIRECTIONS = {{0,1},{0,-1},{-1,0},{1,0}};
    @Value("${floyd.enable}")
@@ -422,6 +426,108 @@
        return CodeSpinType.of(code.getSpin());
    }
    public static void main(String[] args) {
        List<DirectionDto> directionDtoList = DirectionDto.initCodeDirections();
        System.out.println(JSON.toJSONString(directionDtoList));
    }
    public CodeSpinType calcSpinDirection(Code code, Double currDir, Double nextDir) {
        if (Cools.isEmpty(code, currDir, nextDir)) {
            return CodeSpinType.NA;
        }
        List<Double> disableAngleList = new ArrayList<>();
        List<DirectionDto> directionDtoList = DirectionDto.initCodeDirections();
        for (DirectionDto dto : directionDtoList) {
            if (null != dto.getEnabled() && !dto.getEnabled()) {
                disableAngleList.add(dto.getAngle());
            }
        }
        if (Cools.isEmpty(disableAngleList)) {
            return CodeSpinType.NA;
        }
        double curr = norm360(currDir);
        double next = norm360(nextDir);
        // 如果几乎相等,认为不需要旋转
        if (almostEqual(curr, next)) {
            return CodeSpinType.NA;
        }
        double cwDelta = cwDelta(curr, next);     // (0, 360)
        double ccwDelta = 360.0 - cwDelta;  // (0, 360)
        boolean cwBlocked = false;
        boolean ccwBlocked = false;
        for (Double disableAngle : disableAngleList) {
            if (disableAngle == null) continue;
            double disable = norm360(disableAngle);
            if (isOnArcCW(curr, next, disable)) {
                cwBlocked = true;
            }
            if (isOnArcCCW(curr, next, disable)) {
                ccwBlocked = true;
            }
        }
        if (cwBlocked && !ccwBlocked) {
            return CodeSpinType.CCW;
        }
        if (!cwBlocked && ccwBlocked) {
            return CodeSpinType.CW;
        }
        return CodeSpinType.NA;
    }
    private static double norm360(double a) {
        double x = a % 360.0;
        if (x < 0) x += 360.0;
        // 360 归一化为 0
        if (almostEqual(x, 360.0)) return 0.0;
        return x;
    }
    private static boolean almostEqual(double a, double b) {
        return Math.abs(a - b) <= EPS;
    }
    /**
     * 顺时针距离:从 start 到 end,沿 CW 方向走多少度,范围 (0, 360],这里不会返回 0(除非你 curr==next 已提前处理)
     */
    private static double cwDelta(double start, double end) {
        double d = end - start;
        if (d < 0) d += 360.0;
        if (almostEqual(d, 0.0)) return 0.0;
        return d;
    }
    /**
     * 判断 angle 是否落在从 start -> end 的顺时针弧段上(不含端点)。
     * 即:沿 CW 从 start 走 cwDelta(start,end) 的路径上是否“经过”angle。
     */
    private static boolean isOnArcCW(double start, double end, double angle) {
        double total = cwDelta(start, end);
        // 弧长为 0 表示无旋转(已提前处理),这里直接 false
        if (almostEqual(total, 0.0)) return false;
        double a = cwDelta(start, angle);
        // 不包含端点:a 在 (0, total) 之间才算经过
        return a > EPS && a < total - EPS;
    }
    /**
     * 判断 angle 是否落在从 start -> end 的逆时针弧段上(不含端点)。
     * 逆时针等价于:顺时针从 end -> start 的弧段。
     */
    private static boolean isOnArcCCW(double start, double end, double angle) {
        // 逆时针 start->end == 顺时针 end->start
        return isOnArcCW(end, start, angle);
    }
    /**
     * That vehicle is walking if the dynamic node count > 1
     */