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));
|
}
|
|
}
|