Skip to content

Commit 973683a

Browse files
committed
PhotonCameraSimulator removed
1 parent 0f64cf9 commit 973683a

2 files changed

Lines changed: 41 additions & 192 deletions

File tree

src/main/java/frc/robot/Robot.java

Lines changed: 41 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,13 @@
1616

1717
import org.littletonrobotics.urcl.URCL;
1818
import org.photonvision.PhotonCamera;
19+
import org.photonvision.simulation.PhotonCameraSim;
20+
import org.photonvision.simulation.SimCameraProperties;
1921

2022
import edu.wpi.first.math.geometry.Pose2d;
23+
import edu.wpi.first.math.geometry.Rotation2d;
2124
import edu.wpi.first.math.geometry.Transform2d;
25+
import edu.wpi.first.math.geometry.Transform3d;
2226
import edu.wpi.first.math.kinematics.ChassisSpeeds;
2327
import edu.wpi.first.math.util.Units;
2428
import edu.wpi.first.wpilibj.DataLogManager;
@@ -35,7 +39,6 @@
3539
import frc.robot.commands.DriveCommand;
3640
import frc.robot.commands.PathDriveCommand;
3741
import frc.robot.subsystems.DriveSubsystem;
38-
import frc.robot.subsystems.PhotonCameraSimulator;
3942
import frc.robot.subsystems.PoseEstimationSubsystem;
4043
import frc.robot.subsystems.VisionSimulator;
4144

@@ -51,11 +54,26 @@ public class Robot extends TimedRobot {
5154
private final PowerDistribution m_pdh = new PowerDistribution();
5255
private final VisionSimulator m_visionSimulator = new VisionSimulator(m_driveSubsystem,
5356
pose(kFieldLayout.getFieldLength() / 2 + 2.5, 1.91 + .3, 180), 0.01);
57+
SimCameraProperties cameraProp = new SimCameraProperties() {
58+
{
59+
setCalibration(640, 480, Rotation2d.fromDegrees(100));
60+
// Approximate detection noise with average and standard deviation error in
61+
// pixels.
62+
setCalibError(0.25, 0.08);
63+
// Set the camera image capture framerate (Note: this is limited by robot loop
64+
// rate).
65+
setFPS(20);
66+
// The average and standard deviation in milliseconds of image data latency.
67+
setAvgLatencyMs(35);
68+
setLatencyStdDevMs(5);
69+
70+
}
71+
};
5472
private final PhotonCamera m_camera1 = RobotBase.isSimulation()
55-
? new PhotonCameraSimulator("Camera1", kRobotToCamera1, m_visionSimulator, 3, 0.1)
73+
? cameraSim("Camera1", kRobotToCamera1, m_visionSimulator, cameraProp)
5674
: new PhotonCamera("Cool camera");
5775
private final PhotonCamera m_camera2 = RobotBase.isSimulation()
58-
? new PhotonCameraSimulator("Camera2", kRobotToCamera2, m_visionSimulator, 3, 0.1)
76+
? cameraSim("Camera2", kRobotToCamera2, m_visionSimulator, cameraProp)
5977
: new PhotonCamera("Cool camera2");
6078
private final PoseEstimationSubsystem m_poseEstimationSubsystem = new PoseEstimationSubsystem(m_driveSubsystem)
6179
.addCamera(m_camera1, kRobotToCamera1)
@@ -110,6 +128,26 @@ public Robot() {
110128
bindDriveControls();
111129
}
112130

131+
/**
132+
* Constructs a {@code PhotonCamera} that provides simulation.
133+
*
134+
* @param cameraName the name of the {@code PhotonCamera}
135+
* @param robotToCamera the {@code Pose2d} of the {@code PhotonCamera} relative
136+
* to the center of the robot
137+
* @param m_visionSimulator the {@code VisionSimulator} to use
138+
* @param cameraProp the {@code SimCameraProperties} to use
139+
* @return the constructed {@code PhotonCamera}
140+
*/
141+
PhotonCamera cameraSim(String cameraName, Transform3d robotToCamera, VisionSimulator m_visionSimulator,
142+
SimCameraProperties cameraProp) {
143+
PhotonCamera camera = new PhotonCamera(cameraName);
144+
PhotonCameraSim cameraSim = new PhotonCameraSim(camera, cameraProp);
145+
cameraSim.enableProcessedStream(true);
146+
cameraSim.enableDrawWireframe(true);
147+
m_visionSimulator.addCamera(cameraSim, robotToCamera);
148+
return camera;
149+
}
150+
113151
public void bindDriveControls() {
114152
m_driveSubsystem.setDefaultCommand(
115153
m_driveSubsystem.driveCommand(

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

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

0 commit comments

Comments
 (0)