-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
79 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package frc.robot.localization; | ||
|
||
public enum LocalizationState { | ||
DEFAULT_STATE; | ||
} |
60 changes: 60 additions & 0 deletions
60
src/main/java/frc/robot/localization/LocalizationSubsystem.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package frc.robot.localization; | ||
|
||
import edu.wpi.first.math.VecBuilder; | ||
import edu.wpi.first.math.estimator.SwerveDrivePoseEstimator; | ||
import edu.wpi.first.math.geometry.Pose2d; | ||
import edu.wpi.first.math.geometry.Rotation2d; | ||
import edu.wpi.first.math.kinematics.SwerveModulePosition; | ||
import frc.robot.config.RobotConfig; | ||
import frc.robot.imu.ImuSubsystem; | ||
import frc.robot.util.scheduling.SubsystemPriority; | ||
import frc.robot.util.state_machines.StateMachine; | ||
import frc.robot.vision.VisionSubsystem; | ||
import frc.robot.vision.LimelightHelpers.PoseEstimate; | ||
|
||
public class LocalizationSubsystem extends StateMachine<LocalizationState>{ | ||
private final ImuSubsystem imu; | ||
private final VisionSubsystem vision; | ||
private final SwerveDrivePoseEstimator poseEstimator; | ||
private PoseEstimate estimatepose; | ||
private double lastAddedVisionTimestamp = 0; | ||
|
||
|
||
|
||
public LocalizationSubsystem(ImuSubsystem imu, VisionSubsystem vision) { | ||
super(SubsystemPriority.LOCALIZATION,LocalizationState.DEFAULT_STATE); | ||
this.imu = imu; | ||
this.vision = vision; | ||
poseEstimator = | ||
new SwerveDrivePoseEstimator( | ||
null, | ||
imu.getRobotHeading(), | ||
null, | ||
new Pose2d()); | ||
} | ||
@Override | ||
protected void collectInputs(){ | ||
var maybeResults = vision.getVisionResult(); | ||
if (maybeResults.isPresent()) { | ||
var results = maybeResults.get(); | ||
Pose2d visionPose = results.pose(); | ||
|
||
double visionTimestamp = results.timestamp(); | ||
|
||
if (visionTimestamp == lastAddedVisionTimestamp) { | ||
// Don't add the same vision pose over and over | ||
} else { | ||
poseEstimator.addVisionMeasurement( | ||
visionPose, | ||
visionTimestamp, | ||
VecBuilder.fill( | ||
RobotConfig.get().vision().xyStdDev(), | ||
RobotConfig.get().vision().xyStdDev(), | ||
RobotConfig.get().vision().thetaStdDev())); | ||
lastAddedVisionTimestamp = visionTimestamp; | ||
} | ||
|
||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -55,4 +55,5 @@ public Optional<VisionResult> getVisionResult() { | |
public void robotPeriodic() { | ||
super.robotPeriodic(); | ||
} | ||
|
||
} |