Skip to content

Commit

Permalink
made x angles to speaker using swerve drive
Browse files Browse the repository at this point in the history
  • Loading branch information
PGgit08 committed Jan 26, 2024
1 parent 288efc6 commit 3a91fdd
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/main/deploy/pathplanner/paths/amp path.path
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,4 @@
"folder": null,
"previewStartingState": null,
"useDefaultConstraints": false
}
}
1 change: 1 addition & 0 deletions src/main/java/frc/robot/RobotContainer.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.pathplanner.lib.auto.AutoBuilder;
import com.pathplanner.lib.auto.NamedCommands;
import edu.wpi.first.math.filter.SlewRateLimiter;
import edu.wpi.first.math.geometry.Translation2d;
import edu.wpi.first.math.kinematics.ChassisSpeeds;
import edu.wpi.first.wpilibj.smartdashboard.SendableChooser;
import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;
Expand Down
28 changes: 24 additions & 4 deletions src/main/java/frc/robot/subsystems/SwerveDriveSubsystem.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import com.pathplanner.lib.auto.AutoBuilder;
import com.pathplanner.lib.util.HolonomicPathFollowerConfig;
import com.pathplanner.lib.util.ReplanningConfig;

import edu.wpi.first.math.MathUtil;
import edu.wpi.first.math.VecBuilder;
import edu.wpi.first.math.estimator.SwerveDrivePoseEstimator;
import edu.wpi.first.math.geometry.Pose2d;
Expand Down Expand Up @@ -395,6 +397,28 @@ public Rotation2d getHeadingRaw() {

/** Get the shooter's angle to the speaker hole using the drive's pose estimator. */
public double[] anglesToSpeaker() {
int tagID = Constants.FIELD_CONSTANTS.SPEAKER_TAG;
Pose3d tagPose = Constants.FIELD_CONSTANTS.APRILTAG_LAYOUT.getTagPose(tagID).get();

Translation2d tagTranslation = new Translation2d(tagPose.getX(), tagPose.getY());
Translation2d botTranslation = _pose.getTranslation();

double desiredHeading = MathUtil.inputModulus(
tagTranslation.minus(botTranslation).getAngle().getDegrees(),
-180,
180
);

double xAngleToSpeaker = desiredHeading - _pose.getRotation().getDegrees();
double yAngleToSpeaker = 0;

double[] angles = {
xAngleToSpeaker,
yAngleToSpeaker
};

return angles;

// int tagID = Constants.FIELD_CONSTANTS.SPEAKER_TAG;
// Pose3d tagPose = Constants.FIELD_CONSTANTS.APRILTAG_LAYOUT.getTagPose(tagID).get();

Expand All @@ -407,10 +431,6 @@ public double[] anglesToSpeaker() {

// SmartDashboard.putNumber("MOVE ANGLE", moveAngle.getDegrees());

double[] a = {1, 2};

return a;

// double xDifference = tagPose.getX() - _pose.getX();
// double yDifference = tagPose.getY() - _pose.getY();

Expand Down

0 comments on commit 3a91fdd

Please sign in to comment.