Skip to content

Commit

Permalink
tune interpolationUtil
Browse files Browse the repository at this point in the history
  • Loading branch information
Owen756 committed May 22, 2024
1 parent 23ae571 commit 31cf683
Showing 1 changed file with 22 additions and 3 deletions.
25 changes: 22 additions & 3 deletions src/main/java/frc/robot/localization/InterpolationUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,30 @@ public class InterpolationUtil {
List.of(SUBWOOFER, STAGE_FRONT, STAGE_RIGHT, STAGE_MIDDLE);

public static Pose2d interpolatePose(Pose2d visionInput) {
double distanceSum = 0;

for (var dataPoint : DATA_POINTS) {
var distancePoint =
dataPoint.measuredPose().getTranslation().getDistance(visionInput.getTranslation());

distanceSum += distancePoint;
}

Pose2d weightedSum = new Pose2d();

for (var dataPoint : DATA_POINTS) {
double distancePoint =
dataPoint.visionPose().getTranslation().getDistance(visionInput.getTranslation());
var distancePoint =
dataPoint.measuredPose().getTranslation().getDistance(visionInput.getTranslation());

var result = dataPoint.visionPose().times(distanceSum - distancePoint);

weightedSum =
new Pose2d(
weightedSum.getX() + result.getX(),
weightedSum.getY() + result.getY(),
weightedSum.getRotation().plus(result.getRotation()));
}

return new Pose2d();
return weightedSum.div(distanceSum);
}
}

0 comments on commit 31cf683

Please sign in to comment.