Skip to content

Commit

Permalink
worked on implementing interpolatedUtil
Browse files Browse the repository at this point in the history
  • Loading branch information
Owen756 committed Jun 8, 2024
1 parent 31cf683 commit cba8c80
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 13 deletions.
24 changes: 12 additions & 12 deletions src/main/java/frc/robot/localization/InterpolationUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
package frc.robot.localization;

import edu.wpi.first.math.geometry.Pose2d;
import edu.wpi.first.math.geometry.Rotation2d;
import java.util.List;

public class InterpolationUtil {
Expand All @@ -24,25 +25,24 @@ public static Pose2d interpolatePose(Pose2d visionInput) {

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

distanceSum += distancePoint;
}

Pose2d weightedSum = new Pose2d();

double weightedX = 0;
double weightedY = 0;
Rotation2d weightedRotation = new Rotation2d();
for (var dataPoint : DATA_POINTS) {
var distancePoint =
dataPoint.measuredPose().getTranslation().getDistance(visionInput.getTranslation());

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

weightedSum =
new Pose2d(
weightedSum.getX() + result.getX(),
weightedSum.getY() + result.getY(),
weightedSum.getRotation().plus(result.getRotation()));
var result =
dataPoint.visionPose().minus(dataPoint.measuredPose()).times(distanceSum - distancePoint);
weightedX += result.getX();
weightedY += result.getY();
weightedRotation = weightedRotation.plus(result.getRotation());
}
Pose2d weightedSum = new Pose2d(weightedX, weightedY, weightedRotation);

return weightedSum.div(distanceSum);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import frc.robot.util.scheduling.SubsystemPriority;
import frc.robot.vision.LimelightHelpers;
import frc.robot.vision.VisionSubsystem;
import frc.robot.localization.InterpolationUtil;

public class LocalizationSubsystem extends LifecycleSubsystem {
private static final double SHOOT_WHILE_MOVE_LOOKAHEAD = 0.2;
Expand Down Expand Up @@ -62,7 +63,7 @@ public LocalizationSubsystem(SwerveSubsystem swerve, ImuSubsystem imu, VisionSub
SwerveSubsystem.KINEMATICS,
imu.getRobotHeading(),
swerve.getModulePositions().toArray(new SwerveModulePosition[4]),
new Pose2d());
InterpolationUtil.interpolatePose(new Pose2d()));
odometry =
new SwerveDriveOdometry(
SwerveSubsystem.KINEMATICS,
Expand Down

0 comments on commit cba8c80

Please sign in to comment.