001/* 002 * Copyright (C) Photon Vision. 003 * 004 * This program is free software: you can redistribute it and/or modify 005 * it under the terms of the GNU General Public License as published by 006 * the Free Software Foundation, either version 3 of the License, or 007 * (at your option) any later version. 008 * 009 * This program is distributed in the hope that it will be useful, 010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 012 * GNU General Public License for more details. 013 * 014 * You should have received a copy of the GNU General Public License 015 * along with this program. If not, see <https://www.gnu.org/licenses/>. 016 */ 017 018package org.photonvision.common.configuration; 019 020import edu.wpi.first.apriltag.AprilTagFieldLayout; 021import java.util.Collection; 022import java.util.HashMap; 023import java.util.List; 024import org.photonvision.vision.processes.VisionSource; 025 026public class PhotonConfiguration { 027 private final HardwareConfig hardwareConfig; 028 private final HardwareSettings hardwareSettings; 029 private NetworkConfig networkConfig; 030 private AprilTagFieldLayout atfl; 031 private HashMap<String, CameraConfiguration> cameraConfigurations; 032 033 public PhotonConfiguration( 034 HardwareConfig hardwareConfig, 035 HardwareSettings hardwareSettings, 036 NetworkConfig networkConfig, 037 AprilTagFieldLayout atfl) { 038 this(hardwareConfig, hardwareSettings, networkConfig, atfl, new HashMap<>()); 039 } 040 041 public PhotonConfiguration( 042 HardwareConfig hardwareConfig, 043 HardwareSettings hardwareSettings, 044 NetworkConfig networkConfig, 045 AprilTagFieldLayout atfl, 046 HashMap<String, CameraConfiguration> cameraConfigurations) { 047 this.hardwareConfig = hardwareConfig; 048 this.hardwareSettings = hardwareSettings; 049 this.networkConfig = networkConfig; 050 this.cameraConfigurations = cameraConfigurations; 051 this.atfl = atfl; 052 } 053 054 public PhotonConfiguration() { 055 this( 056 new HardwareConfig(), 057 new HardwareSettings(), 058 new NetworkConfig(), 059 new AprilTagFieldLayout(List.of(), 0, 0)); 060 } 061 062 public HardwareConfig getHardwareConfig() { 063 return hardwareConfig; 064 } 065 066 public NetworkConfig getNetworkConfig() { 067 return networkConfig; 068 } 069 070 public HardwareSettings getHardwareSettings() { 071 return hardwareSettings; 072 } 073 074 public AprilTagFieldLayout getApriltagFieldLayout() { 075 return atfl; 076 } 077 078 public void setApriltagFieldLayout(AprilTagFieldLayout atfl) { 079 this.atfl = atfl; 080 } 081 082 public void setNetworkConfig(NetworkConfig networkConfig) { 083 this.networkConfig = networkConfig; 084 } 085 086 public HashMap<String, CameraConfiguration> getCameraConfigurations() { 087 return cameraConfigurations; 088 } 089 090 public void addCameraConfigs(Collection<VisionSource> sources) { 091 for (var s : sources) { 092 addCameraConfig(s.getCameraConfiguration()); 093 } 094 } 095 096 public void addCameraConfig(CameraConfiguration config) { 097 addCameraConfig(config.uniqueName, config); 098 } 099 100 public void addCameraConfig(String name, CameraConfiguration config) { 101 cameraConfigurations.put(name, config); 102 } 103 104 /** 105 * Delete a camera by its unique name 106 * 107 * @param name The camera name (usually unique name) 108 * @return True if the camera configuration was removed 109 */ 110 public boolean removeCameraConfig(String name) { 111 return cameraConfigurations.remove(name) != null; 112 } 113 114 @Override 115 public String toString() { 116 return "PhotonConfiguration [\n hardwareConfig=" 117 + hardwareConfig 118 + "\n hardwareSettings=" 119 + hardwareSettings 120 + "\n networkConfig=" 121 + networkConfig 122 + "\n atfl=" 123 + atfl 124 + "\n cameraConfigurations=" 125 + cameraConfigurations 126 + "\n]"; 127 } 128}