generated from wpilibsuite/vendor-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WIP - Begin adding vision sim support
- Loading branch information
Showing
5 changed files
with
103 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,58 @@ | ||
package coppercore.vision; | ||
|
||
import edu.wpi.first.math.geometry.Rotation2d; | ||
import edu.wpi.first.math.geometry.Transform3d; | ||
import org.photonvision.PhotonCamera; | ||
import org.photonvision.simulation.SimCameraProperties; | ||
|
||
public record CameraParams(PhotonCamera camera, Transform3d robotToCamera) {} | ||
public record CameraParams( | ||
PhotonCamera camera, Transform3d robotToCamera, SimCameraProperties simCameraProp) { | ||
public static class CameraParamBuilder { | ||
String cameraName; | ||
Transform3d robotToCamera; | ||
|
||
SimCameraProperties simCameraProp = new SimCameraProperties(); | ||
|
||
public CameraParamBuilder withCameraName(String cameraName) { | ||
this.cameraName = cameraName; | ||
|
||
return this; | ||
} | ||
|
||
public CameraParamBuilder withRobotToCamera(Transform3d robotToCamera) { | ||
this.robotToCamera = robotToCamera; | ||
|
||
return this; | ||
} | ||
|
||
public CameraParamBuilder withCalibration(int resX, int resY, Rotation2d diagFOV) { | ||
simCameraProp.setCalibration(resX, resY, diagFOV); | ||
|
||
return this; | ||
} | ||
|
||
public CameraParamBuilder withCalibError( | ||
float averageErrorPixels, float errorStdDevPixels) { | ||
simCameraProp.setCalibError(averageErrorPixels, errorStdDevPixels); | ||
|
||
return this; | ||
} | ||
|
||
public CameraParamBuilder withFPS(int fps) { | ||
simCameraProp.setFPS(fps); | ||
|
||
return this; | ||
} | ||
|
||
public CameraParamBuilder withLatency(double averageLatencyMs, double latencyStdDevMs) { | ||
simCameraProp.setAvgLatencyMs(averageLatencyMs); | ||
simCameraProp.setLatencyStdDevMs(latencyStdDevMs); | ||
|
||
return this; | ||
} | ||
|
||
public CameraParams build() { | ||
return new CameraParams(new PhotonCamera(cameraName), robotToCamera, simCameraProp); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package coppercore.vision; | ||
|
||
import edu.wpi.first.math.geometry.Pose3d; | ||
|
||
public interface VisionSimWrapper { | ||
public void addCamera(CameraParams cameraParams); | ||
|
||
public void update(Pose3d robotPoseMeters); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package coppercore.vision; | ||
|
||
import edu.wpi.first.math.geometry.Pose3d; | ||
|
||
public class VisionSimWrapperBlank implements VisionSimWrapper { | ||
@Override | ||
public void addCamera(CameraParams cameraParams) {} | ||
|
||
@Override | ||
public void update(Pose3d robotPoseMeters) {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package coppercore.vision; | ||
|
||
import edu.wpi.first.apriltag.AprilTagFieldLayout; | ||
import edu.wpi.first.math.geometry.Pose3d; | ||
import org.photonvision.simulation.PhotonCameraSim; | ||
import org.photonvision.simulation.VisionSystemSim; | ||
|
||
public class VisionSimWrapperSimulated implements VisionSimWrapper { | ||
VisionSystemSim visionSim; | ||
|
||
public VisionSimWrapperSimulated(String simName, AprilTagFieldLayout fieldLayout) { | ||
visionSim = new VisionSystemSim(simName); | ||
visionSim.addAprilTags(fieldLayout); | ||
} | ||
|
||
@Override | ||
public void addCamera(CameraParams cameraParams) { | ||
PhotonCameraSim cameraSim = | ||
new PhotonCameraSim(cameraParams.camera(), cameraParams.simCameraProp()); | ||
visionSim.addCamera(cameraSim, cameraParams.robotToCamera()); | ||
} | ||
|
||
@Override | ||
public void update(Pose3d robotPoseMeters) {} | ||
} |