Skip to content

Commit

Permalink
Drive Pose is not used as back if no vision reported
Browse files Browse the repository at this point in the history
  • Loading branch information
StewardHail3433 committed Apr 5, 2024
1 parent 882223a commit 36ca114
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/main/java/frc/robot/config/RobotConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ public static class DriveConstants {
public static double slewRateLimiterX = 3;
public static double slewRateLimiterY = 3;
public static double slewRateLimiterAngle = 3;

public static double blueSpeakerX = 0.14;
public static double speakerY = 5.53;
public static double redSpeakerX = 16.54-0.14;
}

public static class ArmConstants {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/frc/robot/config/RobotConfigPhoenix.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public RobotConfigPhoenix() {
new Translation3d(-Units.inchesToMeters(10.75), 0, Units.inchesToMeters(8)),
new Rotation3d(0, Units.degreesToRadians(-33), Units.degreesToRadians(180)))));

VisionConstants.visionDistanceOffsetInMeters = -0.2;
VisionConstants.visionDistanceOffsetInMeters = 0;
vision = new VisionSubsystem(cameras, AprilTagFields.k2024Crescendo.loadAprilTagLayoutField());

if (Robot.isSimulation()) {
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/frc/robot/subsystems/drive/Drive.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package frc.robot.subsystems.drive;

import java.util.Optional;

import edu.wpi.first.math.Matrix;
import edu.wpi.first.math.geometry.Pose2d;
import edu.wpi.first.math.kinematics.ChassisSpeeds;
Expand Down Expand Up @@ -72,4 +74,8 @@ public default void lockPose() {}

public default void addVisionMeasurement(
Pose2d robotPose, double timestamp, Matrix<N3, N1> visionMeasurementStdDevs) {}

public default Optional<Double> getDistanceFromSpeaker() {
return Optional.empty();
}
}
9 changes: 9 additions & 0 deletions src/main/java/frc/robot/subsystems/drive/DriveIO.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package frc.robot.subsystems.drive;

import edu.wpi.first.math.geometry.Pose2d;
import frc.robot.config.RobotConfig.DriveConstants;
import frc.robot.util.DevilBotState;

import org.littletonrobotics.junction.AutoLog;
import swervelib.SwerveDrive;

Expand All @@ -11,6 +14,7 @@ public static class DriveIOInputs {
public double poseX = 0.0;
public double poseY = 0.0;
public double poseRotInDegrees = 0.0;
public double distanceFromSpeaker = 0;
}

/** Updates the set of loggable inputs. */
Expand All @@ -19,6 +23,11 @@ public void updateInputs(DriveIOInputs inputs, SwerveDrive swerveDrive) {
inputs.poseX = inputs.pose.getTranslation().getX();
inputs.poseY = inputs.pose.getTranslation().getY();
inputs.poseRotInDegrees = inputs.pose.getRotation().getDegrees();
if(!DevilBotState.isRedAlliance()){
inputs.distanceFromSpeaker = Math.sqrt(Math.pow(inputs.poseX - DriveConstants.blueSpeakerX,2)+Math.pow(inputs.poseY - DriveConstants.speakerY,2));
} else{
inputs.distanceFromSpeaker = Math.sqrt(Math.pow(inputs.poseX - DriveConstants.redSpeakerX,2)+Math.pow(inputs.poseY - DriveConstants.speakerY,2));
} ;
}

// Other methods for controlling the drive subsystem...
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
import frc.robot.config.RobotConfig.DriveConstants;
import frc.robot.util.DevilBotState;
import java.io.File;
import java.util.Optional;

import org.littletonrobotics.junction.AutoLogOutput;
import org.littletonrobotics.junction.Logger;
import swervelib.SwerveDrive;
Expand Down Expand Up @@ -157,4 +159,8 @@ public void addVisionMeasurement(

swerveDrive.addVisionMeasurement(robotPose, timestamp, visionMeasurementStdDevs);
}

public Optional<Double> getDistanceFromSpeaker() {
return Optional.of(inputs.distanceFromSpeaker);
}
}
8 changes: 8 additions & 0 deletions src/main/java/frc/robot/util/DevilBotState.java
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,14 @@ public static Optional<Double> getArmAngleToTarget() {
RobotConfig.instance.getArmAngleFromDistance(distanceToTarget.get());

return armAngle;
} else {
distanceToTarget =RobotConfig.drive.getDistanceFromSpeaker();
if (distanceToTarget.isPresent()) {
Optional<Double> armAngle =
RobotConfig.instance.getArmAngleFromDistance(distanceToTarget.get());

return armAngle;
}
}
return Optional.empty();

Expand Down

0 comments on commit 36ca114

Please sign in to comment.