Skip to content

Commit 22a1019

Browse files
committed
fixed vision
1 parent 9f3afd7 commit 22a1019

File tree

8 files changed

+114
-15
lines changed

8 files changed

+114
-15
lines changed

src/main/java/frc/robot/RobotContainer.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -482,7 +482,7 @@ public Command prepShooter() {
482482

483483
public Command shootSpeaker() {
484484
return (
485-
rotateArmSpeaker().deadlineWith(prepShooter())
485+
rotateArmSpeaker().deadlineWith(shooter.runVoltage(0))
486486
.andThen(shootNote().deadlineWith(rotateArmSpeaker().repeatedly())));
487487
}
488488

@@ -529,10 +529,10 @@ public Command shootNote() {
529529
.alongWith(shooter.runVoltage(ShooterConstants.SHOOTER_UNJAM_VOLTAGE))).withTimeout(0.1).andThen(shooter.runVoltageBoth(rightShooterVolts::get, leftShooterVolts::get) // run shooter full speed
530530
.alongWith(
531531
new SequentialCommandGroup(
532-
indexer.manualCommand(IndexerConstants.INDEXER_OUT_VOLTAGE / 10).withTimeout(0.6), // run intake back for 0.1 seconds
533-
indexer.manualCommand(IndexerConstants.INDEXER_IN_VOLTAGE) // run intake in to shoot
532+
indexer.manualCommand(IndexerConstants.INDEXER_OUT_VOLTAGE / 100).withTimeout(1), // run intake back for 0.1 seconds
533+
/*new WaitCommand(0.8).andThen */(indexer.manualCommand(IndexerConstants.INDEXER_IN_VOLTAGE)) // run intake in to shoot
534534
))
535-
.withTimeout(1.5));//.alongWith(new InstantCommand(() -> {NoteVisualizer.shoot().schedule();})); // run the visualizer
535+
.withTimeout(1.9));//.alongWith(new InstantCommand(() -> {NoteVisualizer.shoot().schedule();})); // run the visualizer
536536
}
537537

538538
/* // Brings the note forward and back for 0.5 seconds each to center it

src/main/java/frc/robot/subsystems/drive/Drive.java

+12-1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
import com.pathplanner.lib.util.PathPlannerLogging;
3838
import com.pathplanner.lib.util.ReplanningConfig;
3939

40+
import edu.wpi.first.math.Matrix;
4041
import edu.wpi.first.math.estimator.SwerveDrivePoseEstimator;
4142
import edu.wpi.first.math.geometry.Pose2d;
4243
import edu.wpi.first.math.geometry.Rotation2d;
@@ -46,6 +47,8 @@
4647
import edu.wpi.first.math.kinematics.SwerveDriveOdometry;
4748
import edu.wpi.first.math.kinematics.SwerveModulePosition;
4849
import edu.wpi.first.math.kinematics.SwerveModuleState;
50+
import edu.wpi.first.math.numbers.N1;
51+
import edu.wpi.first.math.numbers.N3;
4952
import edu.wpi.first.wpilibj.DriverStation;
5053
import edu.wpi.first.wpilibj.DriverStation.Alliance;
5154
import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;
@@ -54,6 +57,7 @@
5457
import edu.wpi.first.wpilibj2.command.SubsystemBase;
5558
import edu.wpi.first.wpilibj2.command.sysid.SysIdRoutine;
5659
import frc.robot.Constants;
60+
import frc.robot.subsystems.vision.VisionConstants;
5761
import frc.robot.subsystems.vision.VisionIO;
5862
import frc.robot.subsystems.vision.VisionIOInputsAutoLogged;
5963
import frc.robot.util.autonomous.DeadzoneChooser;
@@ -186,8 +190,15 @@ public void periodic() {
186190
visionIO.updateInputs(visionInputs, getPose());
187191
Logger.processInputs("Vision", visionInputs);
188192
if (visionInputs.hasEstimate) {
193+
List<Matrix<N3, N1>> stdDeviations = visionIO.getStdArray(getPose());
194+
189195
for (int i = 0; i < visionInputs.estimate.length; i++) {
190-
poseEstimator.addVisionMeasurement(visionInputs.estimate[i], Timer.getFPGATimestamp());
196+
if (stdDeviations.size() <= i) {
197+
poseEstimator.addVisionMeasurement(visionInputs.estimate[i], Timer.getFPGATimestamp(), VisionConstants.kSingleTagStdDevs);
198+
} else {
199+
poseEstimator.addVisionMeasurement(visionInputs.estimate[i], Timer.getFPGATimestamp(), stdDeviations.get(i));
200+
}
201+
191202
}
192203
}
193204
}

src/main/java/frc/robot/subsystems/groundIntake/GroundIntakeConstants.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public static class GroundIntakePhysicalConstants {
2222
public static final double kGroundIntakeD = 0.0;
2323
}
2424

25-
public static final double GROUND_INTAKE_IN_VOLTAGE = 9;
25+
public static final double GROUND_INTAKE_IN_VOLTAGE = 9.2;
2626
public static final double GROUND_INTAKE_WEAK_IN_VOLTAGE = 4.5;
2727
public static final double GROUND_INTAKE_OUT_VOLTAGE = -9;
2828
}

src/main/java/frc/robot/subsystems/indexer/IndexerConstants.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public static class IndexerPhysicalConstants {
3838
}
3939

4040
public static final double INDEXER_IN_VOLTAGE = 8;
41-
public static final double INDEXER_IN_VOLTAGE_WEAK = 3.95;
41+
public static final double INDEXER_IN_VOLTAGE_WEAK = 4.2;
4242
public static final double INDEXER_OUT_VOLTAGE = -2;
4343

4444
public static final double SHOOTER_UNJAM_TIME = 0.2;

src/main/java/frc/robot/subsystems/vision/VisionIO.java

+60
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,35 @@ public default Pose2d[] getEstimatesArray(PhotonPipelineResult[] results, Photon
133133
return finalEstimates;
134134
}
135135

136+
public default List<Matrix<N3, N1>> getStdArray(Pose2d currentPose) {
137+
PhotonPipelineResult[] results = getResults();
138+
PhotonPoseEstimator[] photonEstimator = getEstimators();
139+
PhotonCamera[] cams = getCameras();
140+
141+
List<Matrix<N3, N1>> stdsArray = new ArrayList<Matrix<N3, N1>>();
142+
Optional<Pose2d>[] estimates = getEstimates(results, photonEstimator);
143+
144+
for (int i = 0; i < estimates.length; i++) {
145+
if (estimates[i].isPresent() && estimates[i].get() != null) {
146+
stdsArray.add(getEstimationStdDevs(currentPose, cams[i], photonEstimator[i]));
147+
}
148+
}
149+
150+
return stdsArray;
151+
}
152+
153+
public default PhotonPipelineResult[] getResults() {
154+
return null;
155+
}
156+
157+
public default PhotonPoseEstimator[] getEstimators() {
158+
return null;
159+
}
160+
161+
public default PhotonCamera[] getCameras() {
162+
return null;
163+
}
164+
136165
public default double estimateLatestTimestamp(PhotonPipelineResult[] results) {
137166
double latestTimestamp = 0;
138167
int count = 0;
@@ -218,6 +247,37 @@ public default Matrix<N3, N1> getEstimationStdDevs(Pose2d estimatedPose, PhotonP
218247
return estStdDevs;
219248
}
220249

250+
/**
251+
* The standard deviations of the estimated pose from {@link #getEstimatedGlobalPose()}, for use
252+
* with {@link edu.wpi.first.math.estimator.SwerveDrivePoseEstimator SwerveDrivePoseEstimator}.
253+
* This should only be used when there are targets visible.
254+
*
255+
* @param estimatedPose The estimated pose to guess standard deviations for.
256+
*/
257+
public default Matrix<N3, N1> getEstimationStdDevs(Pose2d estimatedPose, PhotonCamera camera, PhotonPoseEstimator orangeEstimator) {
258+
var estStdDevs = kSingleTagStdDevs;
259+
var targets = getLatestResult(camera).getTargets();
260+
int numTags = 0;
261+
double avgDist = 0;
262+
for (var tgt : targets) {
263+
var tagPose = orangeEstimator.getFieldTags().getTagPose(tgt.getFiducialId());
264+
if (tagPose.isEmpty()) continue;
265+
numTags++;
266+
avgDist +=
267+
tagPose.get().toPose2d().getTranslation().getDistance(estimatedPose.getTranslation());
268+
}
269+
if (numTags == 0) return estStdDevs;
270+
avgDist /= numTags;
271+
// Decrease std devs if multiple targets are visible
272+
if (numTags > 1) estStdDevs = kMultiTagStdDevs;
273+
// Increase std devs based on (average) distance
274+
if (numTags == 1 && avgDist > 4)
275+
estStdDevs = VecBuilder.fill(Double.MAX_VALUE, Double.MAX_VALUE, Double.MAX_VALUE);
276+
else estStdDevs = estStdDevs.times(1 + (avgDist * avgDist / 30));
277+
278+
return estStdDevs;
279+
}
280+
221281
// Override this
222282
public default Matrix<N3, N1> getEstimationStdDevs(Pose2d estimatedPose) {
223283
return kSingleTagStdDevs;

src/main/java/frc/robot/subsystems/vision/VisionIOPhoton.java

+11
Original file line numberDiff line numberDiff line change
@@ -131,4 +131,15 @@ public boolean goodResult(PhotonPipelineResult result) {
131131
*/;
132132
}
133133

134+
public PhotonPipelineResult[] getResults() {
135+
return getAprilTagResults();
136+
}
137+
138+
public PhotonPoseEstimator[] getEstimators() {
139+
return new PhotonPoseEstimator[] { camera1Estimator, camera2Estimator, camera3Estimator };
140+
}
141+
142+
public PhotonCamera[] getCameras() {
143+
return new PhotonCamera[] { camera1, camera2, camera3 };
144+
}
134145
}

src/main/java/frc/robot/subsystems/vision/VisionIOSim.java

+17
Original file line numberDiff line numberDiff line change
@@ -132,5 +132,22 @@ public boolean goodResult(PhotonPipelineResult result) {
132132
&& kTagLayout.getTagPose(result.getBestTarget().getFiducialId()).get().toPose2d().getTranslation()
133133
.getDistance(lastEstimate.getTranslation()) < MAX_DISTANCE;
134134
}
135+
136+
public PhotonPipelineResult[] getResults() {
137+
PhotonPipelineResult front_result = getLatestResult(cam1);
138+
PhotonPipelineResult back_result = getLatestResult(cam2);
139+
PhotonPipelineResult front_result2 = getLatestResult(cam3);
140+
141+
PhotonPipelineResult[] results = { front_result, back_result, front_result2 };
142+
return results;
143+
}
144+
145+
public PhotonPoseEstimator[] getEstimators() {
146+
return new PhotonPoseEstimator[] { cam1Estimator, cam2Estimator, cam3Estimator };
147+
}
148+
149+
public PhotonCamera[] getCameras() {
150+
return new PhotonCamera[] { cam1, cam2, cam3 };
151+
}
135152

136153
}

src/main/java/frc/robot/util/drive/DriveControls.java

+8-8
Original file line numberDiff line numberDiff line change
@@ -118,17 +118,17 @@ public static void configureControls() {
118118
PIVOT_ROTATE = () -> (operator.getRightTriggerAxis() - operator.getLeftTriggerAxis());
119119

120120
// Pivot things
121-
PIVOT_AMP = operator.getDPad(DPad.RIGHT);
122-
PIVOT_ZERO = operator.getDPad(DPad.DOWN);
123-
PIVOT_TO_SPEAKER = operator.getDPad(DPad.LEFT);
121+
PIVOT_AMP = operator.getB();
122+
PIVOT_ZERO = operator.getA();
123+
PIVOT_TO_SPEAKER = operator.getX();
124124
PIVOT_PODIUM = EMPTY_TRIGGER;
125-
PIVOT_ANYWHERE = operator.getDPad(DPad.UP); // uses vision
125+
PIVOT_ANYWHERE = operator.getY(); // uses vision
126126

127127
// intaking things
128128
INTAKE_ROTATE = () -> operator.getLeftYD();
129129
INTAKE_IN = operator.rightBumper();
130130
INTAKE_OUT = operator.leftBumper();
131-
INTAKE_UNTIL_INTAKED = operator.getY();
131+
INTAKE_UNTIL_INTAKED = operator.getDPad(DPad.UP);
132132

133133
// ground intake things
134134
GROUND_INTAKE_ROTATE = () -> -2*operator.getLeftXD();
@@ -137,9 +137,9 @@ public static void configureControls() {
137137

138138
// Shooter things
139139
SHOOTER_SPEED = () -> operator.getRightXD();
140-
SHOOTER_FULL_SEND_INTAKE = operator.getX();
141-
SHOOTER_FULL_SEND = operator.getA();
142-
SHOOTER_UNJAM = operator.getB();
140+
SHOOTER_FULL_SEND_INTAKE = operator.getDPad(DPad.LEFT);
141+
SHOOTER_FULL_SEND = operator.getDPad(DPad.DOWN);
142+
SHOOTER_UNJAM = operator.getDPad(DPad.RIGHT);
143143
break;
144144
case PROGRAMMERS:
145145
default:

0 commit comments

Comments
 (0)