Skip to content

Commit

Permalink
added driver perspective for field relative chassis speeds
Browse files Browse the repository at this point in the history
  • Loading branch information
PGgit08 committed Jan 18, 2025
1 parent 2e00a2d commit 275327a
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 6 deletions.
5 changes: 0 additions & 5 deletions simgui-ds.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
{
"FMS": {
"window": {
"visible": false
}
},
"System Joysticks": {
"window": {
"visible": false
Expand Down
15 changes: 15 additions & 0 deletions src/main/java/frc/robot/subsystems/Swerve.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
import edu.wpi.first.math.kinematics.SwerveDriveKinematics;
import edu.wpi.first.math.kinematics.SwerveModuleState;
import edu.wpi.first.networktables.NetworkTableInstance;
import edu.wpi.first.wpilibj.DriverStation;
import edu.wpi.first.wpilibj.DriverStation.Alliance;
import edu.wpi.first.wpilibj.Notifier;
import edu.wpi.first.wpilibj.RobotController;
import edu.wpi.first.wpilibj2.command.Command;
Expand Down Expand Up @@ -160,6 +162,8 @@ public class Swerve extends TunerSwerveDrivetrain implements Subsystem, SelfChec

private final VisionSystemSim _visionSystemSim;

private boolean _hasAppliedDriverPerspective;

/**
* Creates a new CommandSwerveDrivetrain.
*
Expand Down Expand Up @@ -476,6 +480,17 @@ private void updateVisionPoseEstimates() {
public void periodic() {
updateVisionPoseEstimates();

if (!_hasAppliedDriverPerspective || DriverStation.isDisabled()) {
DriverStation.getAlliance()
.ifPresent(
allianceColor -> {
setOperatorPerspectiveForward(
allianceColor == Alliance.Red ? Rotation2d.k180deg : Rotation2d.kZero);

_hasAppliedDriverPerspective = true;
});
}

DogLog.log(
"Swerve/Accepted Estimates",
_acceptedEstimates.stream().map(VisionPoseEstimate::pose).toArray(Pose3d[]::new));
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/frc/robot/utils/VisionPoseEstimator.java
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ public VisionPoseEstimator(
if (Robot.isSimulation()) {
var cameraProps = new SimCameraProperties();

_cameraSim = new PhotonCameraSim(_camera, cameraProps);
_cameraSim = new PhotonCameraSim(_camera, cameraProps, fieldLayout);
} else {
_cameraSim = null;
}
Expand Down

0 comments on commit 275327a

Please sign in to comment.