Skip to content
This repository has been archived by the owner on Jan 10, 2025. It is now read-only.

Commit

Permalink
Ignore vision measurements if less than two tags are detected
Browse files Browse the repository at this point in the history
Resolves #18
  • Loading branch information
spacey-sooty committed Jul 4, 2024
1 parent 96bc93e commit 02c670e
Showing 1 changed file with 10 additions and 22 deletions.
32 changes: 10 additions & 22 deletions src/main/java/frc/robot/subsystems/CommandSwerveDrivetrain.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
*/
@SuppressWarnings("PMD.SingularField")
public class CommandSwerveDrivetrain extends SwerveDrivetrain implements Subsystem {
private NetworkTable m_limelight = NetworkTableInstance.getDefault().getTable("limelight");
private final NetworkTable m_limelight = NetworkTableInstance.getDefault().getTable("limelight");
private Pose3d m_botpose;
private static final double kSimLoopPeriod = 0.005; // 5 ms
private Notifier m_simNotifier;
Expand Down Expand Up @@ -147,34 +147,22 @@ public void periodic() {
new Translation3d(data[0], data[1], data[2]),
new Rotation3d(data[4], data[5], data[6]));

if ((int) data[7] < 2) {
return;
}

if (reasonablePose(m_botpose)) {
addVisionMeasurement(m_botpose.toPose2d(), frc.robot.Utils.now());
}
}
}

private boolean reasonablePose(Pose3d pose) {
if (Math.abs(pose.getZ()) > 0.1) {
return false;
}

if (pose.getY() < 0) {
return false;
}

if (pose.getY() > Constants.fieldY) {
return false;
}

if (pose.getX() < 0) {
return false;
}

if (pose.getX() > Constants.fieldX) {
return false;
}

return true;
return !((Math.abs(pose.getZ()) > 0.1)
&& (pose.getX() > Constants.fieldX)
&& (pose.getX() < 0)
&& (pose.getY() > Constants.fieldY)
&& (pose.getY() < 0));
}

public Command followTrajectory(String name, boolean isRed) {
Expand Down

0 comments on commit 02c670e

Please sign in to comment.