Skip to content

Commit 8e2e2d6

Browse files
authored
Merge pull request #1 from Prospect-Robotics/stefan/change_variables
Stefan/change variables
2 parents 9533434 + 5b02cbe commit 8e2e2d6

3 files changed

Lines changed: 70 additions & 71 deletions

File tree

.idea/codeStyles/Project.xml

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/vcs.xml

Lines changed: 0 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/main/java/com/team2813/subsystems/Drive.java

Lines changed: 68 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,22 @@
11
package com.team2813.subsystems;
22

3-
import static com.team2813.Constants.*;
3+
import static com.team2813.Constants.BACK_LEFT_DRIVE_ID;
4+
import static com.team2813.Constants.BACK_LEFT_ENCODER_ID;
5+
import static com.team2813.Constants.BACK_LEFT_STEER_ID;
6+
import static com.team2813.Constants.BACK_RIGHT_DRIVE_ID;
7+
import static com.team2813.Constants.BACK_RIGHT_ENCODER_ID;
8+
import static com.team2813.Constants.BACK_RIGHT_STEER_ID;
49
import static com.team2813.Constants.DriverConstants.DRIVER_CONTROLLER;
10+
import static com.team2813.Constants.FRONT_LEFT_DRIVE_ID;
11+
import static com.team2813.Constants.FRONT_LEFT_ENCODER_ID;
12+
import static com.team2813.Constants.FRONT_LEFT_STEER_ID;
13+
import static com.team2813.Constants.FRONT_RIGHT_DRIVE_ID;
14+
import static com.team2813.Constants.FRONT_RIGHT_ENCODER_ID;
15+
import static com.team2813.Constants.FRONT_RIGHT_STEER_ID;
16+
import static com.team2813.Constants.PIGEON_ID;
517
import static com.team2813.lib2813.util.ControlUtils.deadband;
18+
import static edu.wpi.first.units.Units.Centimeters;
19+
import static edu.wpi.first.units.Units.Degrees;
620
import static edu.wpi.first.units.Units.Rotations;
721

822
import com.ctre.phoenix6.Utils;
@@ -25,20 +39,28 @@
2539
import com.google.auto.value.AutoBuilder;
2640
import com.team2813.commands.DefaultDriveCommand;
2741
import com.team2813.commands.RobotLocalization;
28-
import com.team2813.lib2813.limelight.BotPoseEstimate;
2942
import com.team2813.lib2813.preferences.PreferencesInjector;
3043
import com.team2813.sysid.SwerveSysidRequest;
3144
import com.team2813.vision.MultiPhotonPoseEstimator;
3245
import edu.wpi.first.apriltag.AprilTagFieldLayout;
3346
import edu.wpi.first.apriltag.AprilTagFields;
3447
import edu.wpi.first.math.Matrix;
3548
import edu.wpi.first.math.Nat;
36-
import edu.wpi.first.math.geometry.*;
49+
import edu.wpi.first.math.geometry.Pose2d;
50+
import edu.wpi.first.math.geometry.Rotation2d;
51+
import edu.wpi.first.math.geometry.Rotation3d;
52+
import edu.wpi.first.math.geometry.Transform3d;
53+
import edu.wpi.first.math.geometry.Translation3d;
3754
import edu.wpi.first.math.kinematics.ChassisSpeeds;
3855
import edu.wpi.first.math.kinematics.SwerveModuleState;
3956
import edu.wpi.first.math.numbers.N1;
4057
import edu.wpi.first.math.numbers.N3;
41-
import edu.wpi.first.networktables.*;
58+
import edu.wpi.first.networktables.DoubleArrayPublisher;
59+
import edu.wpi.first.networktables.DoublePublisher;
60+
import edu.wpi.first.networktables.NetworkTable;
61+
import edu.wpi.first.networktables.NetworkTableInstance;
62+
import edu.wpi.first.networktables.StructArrayPublisher;
63+
import edu.wpi.first.networktables.StructPublisher;
4264
import edu.wpi.first.units.Units;
4365
import edu.wpi.first.units.measure.AngularVelocity;
4466
import edu.wpi.first.wpilibj.DriverStation;
@@ -47,7 +69,6 @@
4769
import edu.wpi.first.wpilibj2.command.Command;
4870
import edu.wpi.first.wpilibj2.command.SubsystemBase;
4971
import java.util.List;
50-
import java.util.Optional;
5172
import java.util.function.DoubleSupplier;
5273
import java.util.stream.IntStream;
5374
import org.photonvision.EstimatedRobotPose;
@@ -57,9 +78,19 @@
5778
import org.photonvision.targeting.PhotonTrackedTarget;
5879

5980
/** This is the Drive. His name is Gary. Please be kind to him and say hi. Have a nice day! */
81+
82+
/*
83+
TODO: The compiled list of lines that MIGHT need changing.
84+
Max velocity. - later
85+
Max rotations per second. -later
86+
Change steer PID values.
87+
Change drive PID values.
88+
*/
89+
6090
public class Drive extends SubsystemBase implements AutoCloseable {
61-
private static final double DEFAULT_MAX_VELOCITY_METERS_PER_SECOND = 6;
62-
private static final double DEFAULT_MAX_ROTATIONS_PER_SECOND = 1.2;
91+
private static final double DEFAULT_MAX_VELOCITY_METERS_PER_SECOND =
92+
6; // TODO: Get max velocity now since we have the camera cage.
93+
private static final double DEFAULT_MAX_ROTATIONS_PER_SECOND = 1.2; // TODO: Same here.
6394
private static final Matrix<N3, N1> PHOTON_MULTIPLE_TAG_STD_DEVS =
6495
new Matrix<>(Nat.N3(), Nat.N1(), new double[] {0.1, 0.1, 0.1});
6596
private final RobotLocalization localization;
@@ -77,34 +108,23 @@ public class Drive extends SubsystemBase implements AutoCloseable {
77108
NetworkTableInstance.getDefault().getDoubleTopic("Ambiguity").publish();
78109

79110
/** This measurement is <em>IN INCHES</em> */
80-
private static final double WHEEL_RADIUS_IN = 1.875;
111+
private static final double WHEEL_RADIUS_IN = 1.537;
81112

82113
private double multiplier = 1;
83114
private double lastVisionEstimateTime = -1;
84115

85-
static final double FRONT_DIST = 0.330200;
86-
static final double LEFT_DIST = 0.330200;
116+
static final double FRONT_DIST = 0.4064;
117+
static final double LEFT_DIST = 0.3302;
87118

88-
/**
89-
* The transformation for the {@code captain-barnacles} PhotonVision camera. This camera faces the
90-
* front
91-
*/
92-
private static final Transform3d captBarnaclesTransform =
119+
private static final Transform3d leftColorTransform =
93120
new Transform3d(
94-
0.1688157406,
95-
0.2939800826,
96-
0.1708140348,
97-
new Rotation3d(0, -0.1745329252, -0.5235987756));
121+
new Translation3d(Centimeters.of(31), Centimeters.of(21), Centimeters.of(20)),
122+
new Rotation3d(Degrees.of(0), Degrees.of(-30), Degrees.of(-30)));
98123

99-
/**
100-
* The transformation for the {@code professor-inking} PhotonVision camera. This camera faces the
101-
* back
102-
*/
103-
private static final Transform3d professorInklingTransform =
124+
private static final Transform3d rightColorTransform =
104125
new Transform3d(
105-
0.0584240386, 0.2979761884, 0.1668812004, new Rotation3d(0, 0, 0.1745329252 + Math.PI));
106-
107-
// See above comment, do not delete past this line.
126+
new Translation3d(Centimeters.of(29), Centimeters.of(-23), Centimeters.of(13)),
127+
new Rotation3d(Degrees.of(0), Degrees.of(-20), Degrees.of(30)));
108128

109129
/**
110130
* Configurable values for the {@code Drive} subsystem
@@ -197,17 +217,17 @@ public Drive(
197217
photonPoseEstimator =
198218
new MultiPhotonPoseEstimator.Builder(
199219
networkTableInstance, aprilTagFieldLayout, config.poseStrategy())
200-
// should have named our batteries after Octonauts characters >:(
201-
.addCamera("capt-barnacles", captBarnaclesTransform, "Front PhotonVision camera")
202-
.addCamera("professor-inkling", professorInklingTransform, "Back PhotonVision camera")
220+
.addCamera("left_color", leftColorTransform, "Left PhotonVision camera")
221+
.addCamera("right_color", rightColorTransform, "Right PhotonVision camera")
203222
.build();
204223
this.config = config;
205224

206-
double FLSteerOffset = 0.22021484375;
207-
double FRSteerOffset = 1.917236;
208-
double BLSteerOffset = -0.367919921875;
209-
double BRSteerOffset = -0.258544921875;
225+
double FLSteerOffset = -0.240234;
226+
double FRSteerOffset = -0.011475;
227+
double BLSteerOffset = -0.108887;
228+
double BRSteerOffset = -0.148438;
210229

230+
// TODO: consider retuning PID if we want to.
211231
Slot0Configs steerGains =
212232
new Slot0Configs()
213233
.withKP(50)
@@ -218,6 +238,7 @@ public Drive(
218238
.withKA(0.084645); // Tune this.
219239

220240
// l: 0 h: 10
241+
// TODO: consider retuning PID if we want to.
221242
Slot0Configs driveGains =
222243
new Slot0Configs()
223244
.withKP(2.5)
@@ -228,15 +249,12 @@ public Drive(
228249
.withKA(0); // Tune this.
229250

230251
SwerveDrivetrainConstants drivetrainConstants =
231-
new SwerveDrivetrainConstants()
232-
.withPigeon2Id(PIGEON_ID)
233-
.withCANBusName("swerve"); // README: tweak to actual pigeon and CanBusName
252+
new SwerveDrivetrainConstants().withPigeon2Id(PIGEON_ID).withCANBusName("swerve");
234253

235254
SwerveModuleConstantsFactory<TalonFXConfiguration, TalonFXConfiguration, CANcoderConfiguration>
236255
constantCreator =
237256
new SwerveModuleConstantsFactory<
238257
TalonFXConfiguration, TalonFXConfiguration, CANcoderConfiguration>()
239-
// WARNING: TUNE ALL OF THESE THINGS!!!!!!
240258
.withDriveMotorGearRatio(6.75)
241259
.withSteerMotorGearRatio(150.0 / 7)
242260
.withWheelRadius(Units.Inches.of(WHEEL_RADIUS_IN))
@@ -260,9 +278,9 @@ public Drive(
260278
FLSteerOffset,
261279
FRONT_DIST,
262280
LEFT_DIST,
263-
true, // May need to change later.
264-
true, // May need to change later.
265-
false); // May need to change later.
281+
false,
282+
true,
283+
false);
266284
SwerveModuleConstants<TalonFXConfiguration, TalonFXConfiguration, CANcoderConfiguration>
267285
frontRight =
268286
constantCreator.createModuleConstants(
@@ -272,9 +290,9 @@ public Drive(
272290
FRSteerOffset,
273291
FRONT_DIST,
274292
-LEFT_DIST,
275-
true, // May need to change later.
276-
true, // May need to change later.
277-
false); // May need to change later.
293+
false,
294+
true,
295+
false);
278296
SwerveModuleConstants<TalonFXConfiguration, TalonFXConfiguration, CANcoderConfiguration>
279297
backLeft =
280298
constantCreator.createModuleConstants(
@@ -284,9 +302,9 @@ public Drive(
284302
BLSteerOffset,
285303
-FRONT_DIST,
286304
LEFT_DIST,
287-
true, // May need to change later.
288-
true, // May need to change later.
289-
false); // May need to change later.
305+
false,
306+
true,
307+
false);
290308
SwerveModuleConstants<TalonFXConfiguration, TalonFXConfiguration, CANcoderConfiguration>
291309
backRight =
292310
constantCreator.createModuleConstants(
@@ -296,9 +314,9 @@ public Drive(
296314
BRSteerOffset,
297315
-FRONT_DIST,
298316
-LEFT_DIST,
299-
true, // May need to change later.
300-
true, // May need to change later.
301-
false); // May need to change later.
317+
false,
318+
true,
319+
false);
302320
SwerveModuleConstants<?, ?, ?>[] modules = {frontLeft, frontRight, backLeft, backRight};
303321
drivetrain =
304322
new SwerveDrivetrain<>(
@@ -479,20 +497,6 @@ public ChassisSpeeds getRobotRelativeSpeeds() {
479497
private static final Matrix<N3, N1> LIMELIGHT_STD_DEVS =
480498
new Matrix<>(Nat.N3(), Nat.N1(), new double[] {0.9, 0.9, 0.9});
481499

482-
public void addVisionMeasurement(BotPoseEstimate estimate) {
483-
double estimateTimestamp = estimate.timestampSeconds();
484-
if (estimateTimestamp > lastVisionEstimateTime) {
485-
// Per the JavaDoc for addVisionMeasurement(), only add vision measurements that are already
486-
// within one meter or so of the current odometry pose estimate.
487-
Pose2d drivePose = getPose();
488-
var distance = drivePose.getTranslation().getDistance(estimate.pose().getTranslation());
489-
if (Math.abs(distance) <= config.maxLimelightDifferenceMeters()) {
490-
drivetrain.addVisionMeasurement(estimate.pose(), estimateTimestamp, LIMELIGHT_STD_DEVS);
491-
lastVisionEstimateTime = estimateTimestamp;
492-
}
493-
}
494-
}
495-
496500
private void handlePhotonPose(EstimatedRobotPose estimate) {
497501
if (!config.usePhotonVisionLocation) {
498502
return;
@@ -526,10 +530,6 @@ public void periodic() {
526530
// Note: we call limelightLocation() even if config.addLimelightMeasurement is false so
527531
// the position is published to network tables, which allows us to view the limelight's
528532
// pose estimate in AdvantageScope.
529-
Optional<BotPoseEstimate> limelightEstimate = localization.limelightLocation();
530-
if (config.addLimelightMeasurement) {
531-
limelightEstimate.ifPresent(this::addVisionMeasurement);
532-
}
533533

534534
// Publish data to NetworkTables
535535
expectedStatePublisher.set(drivetrain.getState().ModuleTargets);

0 commit comments

Comments
 (0)