Skip to content

Commit 3133608

Browse files
committed
remove option for multiple cameras on O.P.E
1 parent b25c298 commit 3133608

File tree

1 file changed

+20
-22
lines changed

1 file changed

+20
-22
lines changed

src/main/java/frc/trigon/robot/misc/objectdetectioncamera/ObjectPoseEstimator.java

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -14,30 +14,30 @@
1414

1515
public class ObjectPoseEstimator extends SubsystemBase {
1616
private final HashMap<Translation2d, Double> knownObjectPositions;
17-
private final ObjectDetectionCamera[] cameras;
17+
private final ObjectDetectionCamera camera;
1818
private final double deletionThresholdSeconds;
1919
private final SimulatedGamePieceConstants.GamePieceType gamePieceType;
2020
private final double rotationToTranslation;
2121

2222
/**
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.
2424
*
2525
* @param deletionThresholdSeconds the time in seconds after which an object is considered old and removed
2626
* @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
2828
*/
2929
public ObjectPoseEstimator(double deletionThresholdSeconds, DistanceCalculationMethod distanceCalculationMethod,
3030
SimulatedGamePieceConstants.GamePieceType gamePieceType,
31-
ObjectDetectionCamera... cameras) {
31+
ObjectDetectionCamera camera) {
3232
this.deletionThresholdSeconds = deletionThresholdSeconds;
3333
this.gamePieceType = gamePieceType;
34-
this.cameras = cameras;
34+
this.camera = camera;
3535
this.knownObjectPositions = new HashMap<>();
3636
this.rotationToTranslation = distanceCalculationMethod.rotationToTranslation;
3737
}
3838

3939
/**
40-
* Updates the object positions based on the cameras detected objects.
40+
* Updates the object positions based on the camera detected objects.
4141
* Removes objects that have not been detected for {@link ObjectPoseEstimator#deletionThresholdSeconds}.
4242
*/
4343
@Override
@@ -99,7 +99,7 @@ public void removeObject(Translation2d objectPosition) {
9999
}
100100

101101
/**
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.
103103
* This assumes the object is on the ground.
104104
* Once it is known that the object is on the ground,
105105
* 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
154154

155155
private void updateObjectPositions() {
156156
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;
168166
}
169-
170-
if (closestObjectToVisibleObjectDistanceMeters < ObjectDetectionCameraConstants.TRACKED_OBJECT_TOLERANCE_METERS && knownObjectPositions.get(closestObjectToVisibleObject) != currentTimestamp)
171-
removeObject(closestObjectToVisibleObject);
172-
knownObjectPositions.put(visibleObject, currentTimestamp);
173167
}
168+
169+
if (closestObjectToVisibleObjectDistanceMeters < ObjectDetectionCameraConstants.TRACKED_OBJECT_TOLERANCE_METERS && knownObjectPositions.get(closestObjectToVisibleObject) != currentTimestamp)
170+
removeObject(closestObjectToVisibleObject);
171+
knownObjectPositions.put(visibleObject, currentTimestamp);
174172
}
175173
}
176174

0 commit comments

Comments
 (0)