Skip to content

Commit 9d548df

Browse files
committed
Updated LimelightHelper, added CamPose, deleted VisionSubsystem
1 parent 9623b77 commit 9d548df

File tree

4 files changed

+325
-439
lines changed

4 files changed

+325
-439
lines changed

src/main/java/frc/robot/Constants.java

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import edu.wpi.first.math.geometry.Pose3d;
1010
import edu.wpi.first.math.geometry.Rotation3d;
1111
import edu.wpi.first.math.geometry.Translation2d;
12+
import edu.wpi.first.math.geometry.Translation3d;
1213
import edu.wpi.first.math.kinematics.SwerveDriveKinematics;
1314
import edu.wpi.first.math.numbers.N3;
1415

@@ -77,7 +78,7 @@ public static final class DriveConstants {
7778
public static final double kDrivingGearRatio = 8.14; // SDS MK4i's in L1 configuration
7879

7980
// TODO: Tune this PID before running on a robot on the ground
80-
public static final double kPModuleTurningController = -0.3;
81+
public static final double kPModuleTurningController = 0.3;
8182

8283
public static final SwerveDriveKinematics kDriveKinematics = new SwerveDriveKinematics(
8384
new Translation2d(kWheelBase / 2, kTrackWidth / 2),
@@ -98,23 +99,20 @@ public static final class DriveConstants {
9899

99100
public static final class VisionConstants {
100101
// TODO: Update cam pose relative to center of bot
101-
public static final Pose3d kCamPose = new Pose3d(0, 0, 0, new Rotation3d(0, 0, 0));
102-
public static final double[] kLimelightCamPose = {
103-
kCamPose.getX(),
104-
kCamPose.getY(),
105-
kCamPose.getZ(),
106-
kCamPose.getRotation().getX(),
107-
kCamPose.getRotation().getY(),
108-
kCamPose.getRotation().getZ() };
102+
public static final Pose3d kCamPos = new Pose3d(
103+
new Translation3d(0.3048,0.254,0),
104+
new Rotation3d(0,0,0)
105+
);
106+
107+
public static final String kLimelightName = "limelight-sr";
108+
109+
// https://docs.limelightvision.io/docs/docs-limelight/pipeline-apriltag/apriltag-robot-localization-megatag2
110+
public static final int kIMUMode = 0;
109111

110112
// TODO: Experiment with different std devs in the pose estimator
111113
public static final Vector<N3> kOdometrySTDDevs = VecBuilder.fill(0.1, 0.1, 0.1);
112114
public static final Vector<N3> kVisionSTDDevs = VecBuilder.fill(0.5, 0.5, 999999);
113115

114-
// Field size in meters
115-
public static final double kFieldWidth = 8.21055;
116-
public static final double kFieldLength = 16.54175;
117-
118116
public static final boolean kUseVision = true;
119117
}
120118

src/main/java/frc/robot/subsystems/DriveSubsystem.java

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,21 @@ public DriveSubsystem() {
8181
m_headingCorrectionPID.enableContinuousInput(-Math.PI, Math.PI);
8282

8383
// TODO: Name the Limelight "LL1899" and set the camera orientation
84-
// TODO: Set a custom crop window for improved performance (the bot only needs to see april tags on the reef)
84+
// TODO: Set a custom crop window for improved performance (the bot only needs
85+
// to see april tags on the reef)
8586
m_poseEstimator.setVisionMeasurementStdDevs(VecBuilder.fill(0.5, 0.5, 9999999));
87+
88+
if (VisionConstants.kUseVision && Robot.isReal()) {
89+
LimelightHelpers.setCameraPose_RobotSpace(
90+
VisionConstants.kLimelightName,
91+
VisionConstants.kCamPos.getX(),
92+
VisionConstants.kCamPos.getY(),
93+
VisionConstants.kCamPos.getZ(),
94+
VisionConstants.kCamPos.getRotation().getX(),
95+
VisionConstants.kCamPos.getRotation().getY(),
96+
VisionConstants.kCamPos.getRotation().getZ());
97+
LimelightHelpers.SetIMUMode(VisionConstants.kLimelightName, VisionConstants.kIMUMode);
98+
}
8699
}
87100

88101
@Override
@@ -101,10 +114,11 @@ public void periodic() {
101114

102115
if (VisionConstants.kUseVision && Robot.isReal()) {
103116
// Update LimeLight with current robot orientation
104-
LimelightHelpers.SetRobotOrientation("LL1899", m_gyro.getAngle(), 0.0, 0.0, 0.0, 0.0, 0.0);
117+
LimelightHelpers.SetRobotOrientation(VisionConstants.kLimelightName, m_gyro.getAngle(), 0.0, 0.0, 0.0, 0.0, 0.0);
105118

106119
// Get the pose estimate
107-
LimelightHelpers.PoseEstimate limelightMeasurement = LimelightHelpers.getBotPoseEstimate_wpiBlue_MegaTag2("LL1899");
120+
LimelightHelpers.PoseEstimate limelightMeasurement = LimelightHelpers
121+
.getBotPoseEstimate_wpiBlue_MegaTag2(VisionConstants.kLimelightName);
108122

109123
// Add it to your pose estimator if it is a valid measurement
110124
if (limelightMeasurement != null && limelightMeasurement.tagCount != 0 && m_gyro.getRate() < 720) {
@@ -113,7 +127,6 @@ public void periodic() {
113127
limelightMeasurement.timestampSeconds);
114128
}
115129
}
116-
117130

118131
m_field.setRobotPose(m_poseEstimator.getEstimatedPosition());
119132

@@ -246,7 +259,8 @@ public void setModuleStates(SwerveModuleState[] desiredStates) {
246259
};
247260
SmartDashboard.putNumberArray("AdvantageScope Swerve Desired States", logData);
248261

249-
// Takes the integral of the rotation speed to find the current angle for the simulator
262+
// Takes the integral of the rotation speed to find the current angle for the
263+
// simulator
250264
m_gyroAngle += DriveConstants.kDriveKinematics.toChassisSpeeds(desiredStates).omegaRadiansPerSecond
251265
* Robot.kDefaultPeriod;
252266
}

src/main/java/frc/robot/subsystems/VisionSubsystem.java

Lines changed: 0 additions & 129 deletions
This file was deleted.

0 commit comments

Comments
 (0)