This commit is contained in:
Michael Mikovsky
2025-01-09 19:40:37 -07:00
parent d81c4b381d
commit 76b53c95a7
4 changed files with 31 additions and 7 deletions
+3 -3
View File
@@ -276,11 +276,11 @@ public final class Constants {
}
public static final class VisionConstants {
public static final String CAMERA_NAME = "photonvision";
public static final String CAMERA_NAME = "Camera_Module_v1";
public static final Transform3d CAMERA_POS = new Transform3d(new Translation3d(), new Rotation3d());
public static final AprilTagFieldLayout kTagLayout = AprilTagFields.kDefaultField.loadAprilTagLayoutField();
public static final AprilTagFieldLayout kTagLayout = AprilTagFields.k2024Crescendo.loadAprilTagLayoutField();
// The standard deviations of our vision estimated poses, which affect correction rate
// (Fake values. Experiment and determine estimation noise on an actual robot.)
@@ -305,4 +305,4 @@ public final class Constants {
public static final double LEFT_AXIS_DEADBAND = 0.1;
}
}
}
@@ -57,6 +57,7 @@ public class RobotContainer {
public final Vision m_vision = new Vision(m_robotMap.camera);
public final SwerveDrive m_robotSwerveDrive = new SwerveDrive(m_robotMap.swerveDrivetrain, m_vision);
// public final SwerveDrive m_robotSwerveDrive = new SwerveDrive(m_robotMap.swerveDrivetrain);
/* Controllers */
@@ -49,6 +49,7 @@ public class SwerveDrive extends Subsystem {
/** Creates a new SwerveDrive. */
public SwerveDrive(SwerveDrivetrain<TalonFX, TalonFX, CANcoder> swerveDriveTrain, Vision vision) {
// public SwerveDrive(SwerveDrivetrain<TalonFX, TalonFX, CANcoder> swerveDriveTrain) {
super();
this.swerveDriveTrain = swerveDriveTrain;
@@ -172,7 +173,13 @@ public class SwerveDrive extends Subsystem {
SmartDashboard.putNumber("Gyro", getGyroAngle());
SmartDashboard.putNumber("RotTartget", rotTarget);
vision.setLastOdomPose(swerveDriveTrain.samplePoseAt(Vision.getTime()));
double time = Vision.getTime();
vision.setLastOdomPose(swerveDriveTrain.samplePoseAt(time));
if(vision.isTag()){
swerveDriveTrain.addVisionMeasurement(vision.getPose2d(), time);
}
// if(e.isPresent())
}
@@ -56,9 +56,15 @@ public class Vision extends Subsystem {
public void periodic() {
var result = camera.getLatestResult();
isTag = result.hasTargets();
field.setRobotPose(lastPhysOdomPose);
// sbCamConnected.setBoolean(camera);
// System.out.println(isTag);
if(!isTag){
field.setRobotPose(lastPhysOdomPose);
sbTag.setBoolean(isTag);
return;
}
@@ -66,12 +72,11 @@ public class Vision extends Subsystem {
// In case the pose estimator fails to estimate the pose, fallback to physical odometry.
if(EstimatedRobotPose.isEmpty()){
sbTag.setBoolean(isTag);
field.setRobotPose(lastPhysOdomPose);
isTag = false;
return;
}
field.setRobotPose(lastVisionPose);
}
@@ -196,6 +201,11 @@ public class Vision extends Subsystem {
return Utils.getCurrentTimeSeconds();
}
public boolean isTag(){
return isTag;
}
@@ -219,6 +229,11 @@ public class Vision extends Subsystem {
.add("Tag Detected", false)
.withWidget(BuiltInWidgets.kBooleanBox)
.getEntry();
GenericEntry sbCamConnected = subsystemLayout
.add("Camera Connnected", false)
.withWidget(BuiltInWidgets.kBooleanBox)
.getEntry();
// GenericEntry sbShiftState = subsystemLayout
// .add("Shift State", 0)
@@ -229,6 +244,7 @@ public class Vision extends Subsystem {
@Override
public void queryStatus() {
sbTag.setBoolean(isTag);
sbCamConnected.setBoolean(camera.isConnected());
field.setRobotPose(getPose2d());
}