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