|
14 | 14 |
|
15 | 15 | public class ObjectPoseEstimator extends SubsystemBase { |
16 | 16 | private final HashMap<Translation2d, Double> knownObjectPositions; |
17 | | - private final ObjectDetectionCamera[] cameras; |
| 17 | + private final ObjectDetectionCamera camera; |
18 | 18 | private final double deletionThresholdSeconds; |
19 | 19 | private final SimulatedGamePieceConstants.GamePieceType gamePieceType; |
20 | 20 | private final double rotationToTranslation; |
21 | 21 |
|
22 | 22 | /** |
23 | | - * Constructs an ObjectPoseEstimator for estimating the positions of objects detected by cameras. |
| 23 | + * Constructs an ObjectPoseEstimator for estimating the positions of objects detected by camera. |
24 | 24 | * |
25 | 25 | * @param deletionThresholdSeconds the time in seconds after which an object is considered old and removed |
26 | 26 | * @param gamePieceType the type of game piece to track |
27 | | - * @param cameras the cameras used for detecting objects |
| 27 | + * @param camera the camera used for detecting objects |
28 | 28 | */ |
29 | 29 | public ObjectPoseEstimator(double deletionThresholdSeconds, DistanceCalculationMethod distanceCalculationMethod, |
30 | 30 | SimulatedGamePieceConstants.GamePieceType gamePieceType, |
31 | | - ObjectDetectionCamera... cameras) { |
| 31 | + ObjectDetectionCamera camera) { |
32 | 32 | this.deletionThresholdSeconds = deletionThresholdSeconds; |
33 | 33 | this.gamePieceType = gamePieceType; |
34 | | - this.cameras = cameras; |
| 34 | + this.camera = camera; |
35 | 35 | this.knownObjectPositions = new HashMap<>(); |
36 | 36 | this.rotationToTranslation = distanceCalculationMethod.rotationToTranslation; |
37 | 37 | } |
38 | 38 |
|
39 | 39 | /** |
40 | | - * Updates the object positions based on the cameras detected objects. |
| 40 | + * Updates the object positions based on the camera detected objects. |
41 | 41 | * Removes objects that have not been detected for {@link ObjectPoseEstimator#deletionThresholdSeconds}. |
42 | 42 | */ |
43 | 43 | @Override |
@@ -99,7 +99,7 @@ public void removeObject(Translation2d objectPosition) { |
99 | 99 | } |
100 | 100 |
|
101 | 101 | /** |
102 | | - * Gets the position of the closest object on the field from the 3D rotation of the object relative to the cameras. |
| 102 | + * Gets the position of the closest object on the field from the 3D rotation of the object relative to the camera. |
103 | 103 | * This assumes the object is on the ground. |
104 | 104 | * Once it is known that the object is on the ground, |
105 | 105 | * one can simply find the transform from the camera to the ground and apply it to the object's rotation. |
@@ -154,23 +154,21 @@ private double calculateObjectDistanceRating(Translation2d objectTranslation, Po |
154 | 154 |
|
155 | 155 | private void updateObjectPositions() { |
156 | 156 | final double currentTimestamp = Timer.getTimestamp(); |
157 | | - for (ObjectDetectionCamera camera : this.cameras) { |
158 | | - for (Translation2d visibleObject : camera.getObjectPositionsOnField(gamePieceType)) { |
159 | | - Translation2d closestObjectToVisibleObject = new Translation2d(); |
160 | | - double closestObjectToVisibleObjectDistanceMeters = Double.POSITIVE_INFINITY; |
161 | | - |
162 | | - for (Translation2d knownObject : knownObjectPositions.keySet()) { |
163 | | - final double currentObjectDistanceMeters = visibleObject.getDistance(knownObject); |
164 | | - if (currentObjectDistanceMeters < closestObjectToVisibleObjectDistanceMeters) { |
165 | | - closestObjectToVisibleObjectDistanceMeters = currentObjectDistanceMeters; |
166 | | - closestObjectToVisibleObject = knownObject; |
167 | | - } |
| 157 | + for (Translation2d visibleObject : camera.getObjectPositionsOnField(gamePieceType)) { |
| 158 | + Translation2d closestObjectToVisibleObject = new Translation2d(); |
| 159 | + double closestObjectToVisibleObjectDistanceMeters = Double.POSITIVE_INFINITY; |
| 160 | + |
| 161 | + for (Translation2d knownObject : knownObjectPositions.keySet()) { |
| 162 | + final double currentObjectDistanceMeters = visibleObject.getDistance(knownObject); |
| 163 | + if (currentObjectDistanceMeters < closestObjectToVisibleObjectDistanceMeters) { |
| 164 | + closestObjectToVisibleObjectDistanceMeters = currentObjectDistanceMeters; |
| 165 | + closestObjectToVisibleObject = knownObject; |
168 | 166 | } |
169 | | - |
170 | | - if (closestObjectToVisibleObjectDistanceMeters < ObjectDetectionCameraConstants.TRACKED_OBJECT_TOLERANCE_METERS && knownObjectPositions.get(closestObjectToVisibleObject) != currentTimestamp) |
171 | | - removeObject(closestObjectToVisibleObject); |
172 | | - knownObjectPositions.put(visibleObject, currentTimestamp); |
173 | 167 | } |
| 168 | + |
| 169 | + if (closestObjectToVisibleObjectDistanceMeters < ObjectDetectionCameraConstants.TRACKED_OBJECT_TOLERANCE_METERS && knownObjectPositions.get(closestObjectToVisibleObject) != currentTimestamp) |
| 170 | + removeObject(closestObjectToVisibleObject); |
| 171 | + knownObjectPositions.put(visibleObject, currentTimestamp); |
174 | 172 | } |
175 | 173 | } |
176 | 174 |
|
|
0 commit comments