Package com.marswars.vision
Class MwVisionSim
java.lang.Object
com.marswars.vision.MwVisionSim
Handles PhotonVision simulation for generating vision data in simulation mode.
Creates a simulated vision system with cameras and AprilTag field layout,
and generates vision target data that can be integrated with the proxy server.
The vision system label is hard-coded to "proxy-vision-sim" for NetworkTables. The field layout must be specified at construction time and cannot be changed.
Usage Example:
// Load the field layout
AprilTagFieldLayout fieldLayout = AprilTagFieldLayout.loadField(
AprilTagFields.k2025Reefscape
);
// Create vision simulation with the field layout
VisionSimulation visionSim = new VisionSimulation(fieldLayout);
// Or use the convenience constructor
VisionSimulation visionSim = new VisionSimulation(AprilTagFields.k2025Reefscape);
// Add default cameras (front, left, right, back)
visionSim.addDefaultCameras();
// Or add custom cameras
Transform3d robotToCamera = new Transform3d(
new Translation3d(0.5, 0, 0.3),
new Rotation3d(0, Math.toRadians(-15), 0)
);
visionSim.addCamera("frontCamera", robotToCamera);
// In periodic, update with robot pose
visionSim.update(robotPose);
// Get vision solutions
List<TagSolutionData> solutions = visionSim.getTagSolutions(robotPose);
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classRepresents a single simulated camera with its properties and transform. -
Constructor Summary
ConstructorsConstructorDescriptionMwVisionSim(AprilTagFieldLayout field_layout) Creates a new VisionSimulation with the specified field layout.MwVisionSim(AprilTagFields field) Creates a new VisionSimulation with a predefined field layout. -
Method Summary
Modifier and TypeMethodDescriptionaddCamera(String camera_name, Transform3d robot_to_camera) Adds a simulated camera to the vision system.addCamera(String camera_name, org.photonvision.simulation.SimCameraProperties properties, Transform3d robot_to_camera, double max_sight_range) Adds a simulated camera with custom properties to the vision system.voidAdds a default set of four cameras positioned around the robot.voidadjustCamera(MwVisionSim.CameraSimulation camera_sim, Transform3d new_robot_to_camera) Adjusts a camera's transform relative to the robot.static org.photonvision.simulation.SimCameraPropertiesCreates default camera properties typical for FRC vision systems.voidenableProcessedStream(boolean enable) Enables or disables the processed camera stream for all cameras.voidenableRawStream(boolean enable) Enables or disables the raw camera stream for all cameras.Gets all cameras in the simulation.Gets the AprilTag field layout being used.getTagSolutions(Pose2d robot_pose) Extracts vision data from all cameras and converts to TagSolutionData format.org.photonvision.simulation.VisionSystemSimGets the vision system simulator.voidUpdates the vision simulation with the current robot pose.
-
Constructor Details
-
MwVisionSim
Creates a new VisionSimulation with the specified field layout. The vision system will be labeled "proxy-vision-sim" in NetworkTables.- Parameters:
field_layout- the AprilTag field layout to use for the simulation
-
MwVisionSim
Creates a new VisionSimulation with a predefined field layout. This is a convenience constructor that loads the field layout automatically. The vision system will be labeled "proxy-vision-sim" in NetworkTables.- Parameters:
field- the predefined AprilTag field (e.g., AprilTagFields.k2025Reefscape)
-
-
Method Details
-
addDefaultCameras
public void addDefaultCameras()Adds a default set of four cameras positioned around the robot. Creates front, left, right, and back cameras at standard positions: - Front: 0.3m forward, 0.3m up, angled 20° down - Left: 0.3m left, 0.3m up, angled 20° down, facing 90° left - Right: 0.3m right, 0.3m up, angled 20° down, facing 90° right - Back: 0.3m back, 0.3m up, angled 20° down, facing 180° back All cameras use default camera properties. -
addCamera
Adds a simulated camera to the vision system.- Parameters:
camera_name- the name of the camerarobot_to_camera- transform from robot center to camera- Returns:
- the created CameraSimulation object
-
addCamera
public MwVisionSim.CameraSimulation addCamera(String camera_name, org.photonvision.simulation.SimCameraProperties properties, Transform3d robot_to_camera, double max_sight_range) Adds a simulated camera with custom properties to the vision system.- Parameters:
camera_name- the name of the cameraproperties- the camera properties (resolution, FOV, noise, etc.)robot_to_camera- transform from robot center to cameramax_sight_range- maximum sight range of the camera in meters- Returns:
- the created CameraSimulation object
-
createDefaultCameraProperties
public static org.photonvision.simulation.SimCameraProperties createDefaultCameraProperties()Creates default camera properties typical for FRC vision systems. - 960x720 resolution - 70 degree diagonal FOV - Minimal noise and latency for simulation - 30 FPS- Returns:
- SimCameraProperties with default settings
-
update
Updates the vision simulation with the current robot pose. This should be called periodically (every robot loop) with the simulated robot pose.- Parameters:
robot_pose- the current simulated robot pose on the field
-
getCameras
Gets all cameras in the simulation.- Returns:
- list of all CameraSimulation objects
-
getVisionSim
public org.photonvision.simulation.VisionSystemSim getVisionSim()Gets the vision system simulator.- Returns:
- the VisionSystemSim instance
-
getFieldLayout
Gets the AprilTag field layout being used.- Returns:
- the AprilTagFieldLayout
-
getTagSolutions
Extracts vision data from all cameras and converts to TagSolutionData format. This method processes the latest results from all simulated cameras and generates tag solution data compatible with the proxy server format.- Parameters:
robot_pose- the current robot pose (used for timestamp synchronization)- Returns:
- list of TagSolutionData from all cameras with valid targets
-
adjustCamera
Adjusts a camera's transform relative to the robot. Useful for simulating moving mechanisms like turrets.- Parameters:
camera_sim- the camera simulation to adjustnew_robot_to_camera- the new transform from robot to camera
-
enableRawStream
public void enableRawStream(boolean enable) Enables or disables the raw camera stream for all cameras. The raw stream shows the original camera feed without any processing overlay. Disabled by default to reduce overhead.- Parameters:
enable- true to enable the raw stream, false to disable
-
enableProcessedStream
public void enableProcessedStream(boolean enable) Enables or disables the processed camera stream for all cameras. The processed stream shows the camera feed with vision processing overlays (e.g., detected targets). Disabled by default to reduce overhead.- Parameters:
enable- true to enable the processed stream, false to disable
-