张世豪
昨天 0803b041d32a284ee8585914618219ecae82b21f
src/gecaoji/Gecaoji.java
@@ -49,6 +49,11 @@
    }
    public void refreshFromDevice() {
        // 检查是否正在导航预览模式,如果是则不更新位置
        if (isNavigating()) {
            return;
        }
        Device device = Device.getGecaoji();
        if (device == null) {
            positionValid = false;
@@ -57,7 +62,7 @@
        double x = parseCoordinate(device.getRealtimeX());
        double y = parseCoordinate(device.getRealtimeY());
        double heading = parseHeading(device.getHeading());
        double heading = parseHeading(device.getYaw());
        if (Double.isNaN(x) || Double.isNaN(y)) {
            // Keep showing the last known mower position when temporary sensor glitches occur.
            return;
@@ -69,6 +74,22 @@
        positionValid = true;
        headingDegrees = heading;
    }
    /**
     * 检查是否正在导航预览模式
     * @return 如果正在导航预览返回true,否则返回false
     */
    private boolean isNavigating() {
        try {
            dikuai.daohangyulan nav = dikuai.daohangyulan.getInstance();
            if (nav != null) {
                return nav.isNavigating();
            }
        } catch (Exception e) {
            // 如果获取导航实例失败,返回false(不影响主要功能)
        }
        return false;
    }
    private void ensurePosition() {
        if (position == null) {
@@ -130,7 +151,8 @@
        double iconHeight = icon.getHeight(null);
        double maxSide = Math.max(iconWidth, iconHeight);
        double scaleFactor = worldSize / Math.max(maxSide, MIN_SCALE);
        double rotationRadians = Math.toRadians(-headingDegrees);
        // 割草机图标默认朝南,Yaw=0表示正北,需要旋转180度
        double rotationRadians = Math.toRadians(headingDegrees + 180);
        AffineTransform original = g2d.getTransform();
        AffineTransform transformed = new AffineTransform(original);
@@ -155,9 +177,11 @@
        g2d.fill(fallbackShape);
        g2d.setColor(Color.WHITE);
        g2d.draw(fallbackShape);
    double rotationRadians = Math.toRadians(-headingDegrees);
    double lineLength = radius;
    double dx = lineLength * Math.sin(rotationRadians);
        // Yaw=0表示正北(0, -1),使用sin/cos计算坐标
        // sin(180)=0, cos(180)=-1 -> 正北
        double rotationRadians = Math.toRadians(180 - headingDegrees);
        double lineLength = radius;
        double dx = lineLength * Math.sin(rotationRadians);
    double dy = lineLength * Math.cos(rotationRadians);
    g2d.drawLine(
        (int) Math.round(position.x),