张世豪
4 天以前 6700283f9103a45bc087838ebf3eeeeb9022dd98
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
package gecaoji;
 
import java.text.DecimalFormat;
 
/**
 * 割草机安全距离计算器
 * 根据割草机尺寸和RTK定位精度计算作业时的安全距离
 */
public class MowerSafetyDistanceCalculator {
    
    // RTK定位精度(单位:米)
    private static final double RTK_ACCURACY = 0.03;
    
    /**
     * 计算综合安全距离
     * @param length 割草机长度(米)
     * @param width 割草机宽度(米)
     * @return 综合安全距离(米),保留两位小数
     */
    public static double calculateSafetyDistance(double length, double width) {
        // 验证输入参数
        if (length <= 0 || width <= 0) {
            throw new IllegalArgumentException("割草机长度和宽度必须为正数");
        }
        
        // 计算直线行驶时的侧向安全距离(不含误差补偿)
        double lateralSafety = width / 2;
        
        // 计算原地掉头时的旋转半径
        double diagonal = Math.sqrt(length * length + width * width);
        double turnRadius = diagonal / 2;
        
        // 计算综合安全距离(取最大值 + RTK误差补偿)
        double safetyDistance = Math.max(lateralSafety, turnRadius) + 2 * RTK_ACCURACY;
        
        // 保留两位小数
        DecimalFormat df = new DecimalFormat("#.##");
        return Double.parseDouble(df.format(safetyDistance));
    }
    
    /**
     * 计算直线行驶时的最小侧向安全距离
     * @param width 割草机宽度(米)
     * @return 侧向安全距离(米),保留两位小数
     */
    public static double calculateLateralSafetyDistance(double width) {
        if (width <= 0) {
            throw new IllegalArgumentException("割草机宽度必须为正数");
        }
        
        double lateralSafety = width / 2 + 2 * RTK_ACCURACY;
        
        DecimalFormat df = new DecimalFormat("#.##");
        return Double.parseDouble(df.format(lateralSafety));
    }
    
    /**
     * 计算原地掉头所需的安全半径
     * @param length 割草机长度(米)
     * @param width 割草机宽度(米)
     * @return 掉头安全半径(米),保留两位小数
     */
    public static double calculateTurnSafetyRadius(double length, double width) {
        if (length <= 0 || width <= 0) {
            throw new IllegalArgumentException("割草机长度和宽度必须为正数");
        }
        
        double diagonal = Math.sqrt(length * length + width * width);
        double turnRadius = diagonal / 2 + 2 * RTK_ACCURACY;
        
        DecimalFormat df = new DecimalFormat("#.##");
        return Double.parseDouble(df.format(turnRadius));
    }
    
    /**
     * 计算两行之间的推荐间距(用于平行线路径规划)
     * @param cuttingWidth 割草宽度(米)
     * @return 行间距(米),保留两位小数
     */
    public static double calculateRowSpacing(double cuttingWidth) {
        if (cuttingWidth <= 0) {
            throw new IllegalArgumentException("割草宽度必须为正数");
        }
        
        // 考虑双向误差叠加
        double rowSpacing = cuttingWidth - 2 * RTK_ACCURACY;
        
        // 确保行间距为正数
        if (rowSpacing <= 0) {
            System.out.println("警告:割草宽度过小,无法保证全覆盖");
            rowSpacing = cuttingWidth; // 返回原始值
        }
        
        DecimalFormat df = new DecimalFormat("#.##");
        return Double.parseDouble(df.format(rowSpacing));
    }    
    
}