Add probe interpolation to improve accuracy

This commit is contained in:
Redstone1024 2024-08-28 14:13:18 +08:00
parent 4d16c1f7a1
commit 4885d3fef8

View File

@ -648,7 +648,7 @@ public class Prediction extends Module {
boolean findPitch = false;
// Basic physics prediction
if (predictionLevel.get() >= 1) {
{
// Solve for the highest pitch
{
double minPitch = -90.0;
@ -715,8 +715,8 @@ public class Prediction extends Module {
for (int i = 0; i < numProbe * 2 + 1; ++i) {
for (int j = 0; j < numProbe * 2 + 1; ++j) {
targetYaw = centerYaw - (i - numProbe) * delta;
targetPitch = centerPitch - (j - numProbe) * delta;
targetYaw = centerYaw + (i - numProbe) * delta;
targetPitch = centerPitch + (j - numProbe) * delta;
calculatePath();
arrayProbe[i][j] = isHitTarget;
}
@ -743,20 +743,30 @@ public class Prediction extends Module {
}
int maxProbe = 0;
targetYaw = centerYaw;
targetPitch = centerPitch;
int maxI = numProbe;
int maxJ = numProbe;
for (int i = numProbe * 2; i >= 0; --i) {
for (int j = numProbe * 2; j >= 0; --j) {
int x = Math.max(Math.min(validProbe[i][j][0], validProbe[i][j][1]), Math.min(validProbe[i][j][2], validProbe[i][j][3]));
if (x > maxProbe) {
maxProbe = x;
targetYaw = centerYaw - (i - numProbe) * delta;
targetPitch = centerPitch - (j - numProbe) * delta;
maxI = i;
maxJ = j;
}
}
}
targetYaw = centerYaw;
targetPitch = centerPitch;
targetYaw += (maxI - numProbe) * delta;
targetPitch += (maxJ - numProbe) * delta;
if (maxI != 0 && arrayProbe[maxI - 1][maxJ]) targetYaw -= delta / 2.0;
if (maxJ != 0 && arrayProbe[maxI][maxJ - 1]) targetPitch -= delta / 2.0;
if (maxI != numProbe * 2 && arrayProbe[maxI + 1][maxJ]) targetYaw += delta / 2.0;
if (maxJ != numProbe * 2 && arrayProbe[maxI][maxJ + 1]) targetPitch += delta / 2.0;
calculatePath();
}