Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ def getProjectBooleanProperty(String name, boolean defaultValue = false) {
}

def ROBOT_MAIN_CLASS = getProjectBooleanProperty('automatedTest') ? "frc.robot.test.AutomatedTestMain" : "frc.robot.Main"
def HIGH_FIDELITY_VISION = getProjectBooleanProperty('highFidelityVision')

// Define my targets (RoboRIO) and artifacts (deployable files)
// This is added by GradleRIO's backing project DeployUtils.
Expand Down Expand Up @@ -131,6 +132,7 @@ tasks.withType(JavaCompile) {
tasks.withType(JavaExec).configureEach {
if (name.toLowerCase().contains("simulate")) {
jvmArgs "-Xmx2G", "-Xms2G"
systemProperty 'highFidelityVision', HIGH_FIDELITY_VISION
}
}

Expand Down
17 changes: 15 additions & 2 deletions src/main/java/frc/robot/sim/visionproducers/VisionSim.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,20 @@

package frc.robot.sim.visionproducers;

import static frc.robot.sim.visionproducers.VisionSimConstants.*;
import static frc.robot.sim.visionproducers.VisionSimConstants.kAvgDistTolerance;
import static frc.robot.sim.visionproducers.VisionSimConstants.kAvgLatencyMs;
import static frc.robot.sim.visionproducers.VisionSimConstants.kCalibErrorAvg;
import static frc.robot.sim.visionproducers.VisionSimConstants.kCalibErrorStdDev;
import static frc.robot.sim.visionproducers.VisionSimConstants.kCameraFOVDegrees;
import static frc.robot.sim.visionproducers.VisionSimConstants.kCameraFPS;
import static frc.robot.sim.visionproducers.VisionSimConstants.kCameraResHeight;
import static frc.robot.sim.visionproducers.VisionSimConstants.kCameraResWidth;
import static frc.robot.sim.visionproducers.VisionSimConstants.kLatencyStdDevMs;
import static frc.robot.sim.visionproducers.VisionSimConstants.kMaxSightRangeMeters;
import static frc.robot.sim.visionproducers.VisionSimConstants.kMinTargetAreaPixels;
import static frc.robot.sim.visionproducers.VisionSimConstants.kMultiTagStdDevs;
import static frc.robot.sim.visionproducers.VisionSimConstants.kSingleTagStdDevs;
import static frc.robot.sim.visionproducers.VisionSimConstants.kTagLayout;

import edu.wpi.first.math.Matrix;
import edu.wpi.first.math.VecBuilder;
Expand Down Expand Up @@ -178,7 +191,7 @@ private void updateEstimationStdDevs(
}

// Increase std devs based on (average) distance
if (numTags == 1 && avgDist > 1.3) {
if (numTags == 1 && avgDist > kAvgDistTolerance) {
estStdDevs = VecBuilder.fill(Double.MAX_VALUE, Double.MAX_VALUE, Double.MAX_VALUE);
} else {
estStdDevs = estStdDevs.times(1 + (avgDist * avgDist / 3.33));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,27 @@ public class VisionSimConstants {
public static final Matrix<N3, N1> kSingleTagStdDevs = VecBuilder.fill(4, 4, 8);
public static final Matrix<N3, N1> kMultiTagStdDevs = VecBuilder.fill(0.5, 0.5, 1);

// High-fidelity vision simulation flag (set via -PhighFidelityVision=true in build.gradle)
private static final boolean kHighFidelityVision =
Boolean.parseBoolean(System.getProperty("highFidelityVision", "false"));

// Camera simulation properties (shared by all cameras — all cameras are identical)
public static final int kCameraResWidth = 320;
public static final int kCameraResHeight = 240;
// Low-fidelity (default): 320x240, high-fidelity (LimeLight-like): 1280x800
public static final int kCameraResWidth = kHighFidelityVision ? 1280 : 320;
public static final int kCameraResHeight = kHighFidelityVision ? 800 : 240;
public static final double kCameraFOVDegrees = 90.0;
public static final double kCalibErrorAvg = 0.12;
public static final double kCalibErrorStdDev = 0.035;
// Since camera res width and height are not exactly scaled the same
// we take the geometric mean of the both of the scalars then multiply by the old numbers
public static final double kCalibErrorAvg = kHighFidelityVision ? 0.44 : 0.12;
public static final double kCalibErrorStdDev = kHighFidelityVision ? 0.13 : 0.035;
public static final double kCameraFPS = 15;
public static final double kAvgLatencyMs = 50;
public static final double kLatencyStdDevMs = 15;
public static final double kMinTargetAreaPixels = 10.0;
// except for this line below due to pixels being a square
public static final double kMinTargetAreaPixels = kHighFidelityVision ? 133.0 : 10.0;
public static final double kMaxSightRangeMeters = 3.0;
public static final double kAvgDistTolerance = kHighFidelityVision ? 4.78 : 1.3;
public static final double kAvgDistVarianceScale = kHighFidelityVision ? 12.2 : 3.33;

/** Per-camera configuration for vision simulation. */
public record VisionConfig(
Expand Down
Loading