Skip to content

Commit ad1f51b

Browse files
Gold856mcm001
authored andcommitted
Miscellanous clean up
1 parent 1b1f802 commit ad1f51b

12 files changed

Lines changed: 60 additions & 76 deletions

File tree

photon-core/src/main/java/org/photonvision/common/util/TestUtils.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public enum WPI2019Image {
5252
kRocketPanelAngleDark48in(1.2192),
5353
kRocketPanelAngleDark60in(1.524);
5454

55-
public static double FOV = 68.5;
55+
public static final double FOV = 68.5;
5656

5757
public final double distanceMeters;
5858
public final Path path;
@@ -90,7 +90,7 @@ public enum WPI2020Image {
9090
kRedLoading_084in(2.1336),
9191
kRedLoading_108in(2.7432);
9292

93-
public static double FOV = 68.5;
93+
public static final double FOV = 68.5;
9494

9595
public final double distanceMeters;
9696
public final Path path;
@@ -110,7 +110,7 @@ public enum WPI2024Images {
110110
kBackAmpZone_117in,
111111
kSpeakerCenter_143in;
112112

113-
public static double FOV = 68.5;
113+
public static final double FOV = 68.5;
114114

115115
public final Path path;
116116

@@ -129,7 +129,7 @@ public enum WPI2023Apriltags {
129129
k162_36_Straight,
130130
k383_60_Angle2;
131131

132-
public static double FOV = 68.5;
132+
public static final double FOV = 68.5;
133133

134134
public final Translation2d approxPose;
135135
public final Path path;
@@ -156,7 +156,7 @@ public enum WPI2022Image {
156156
kTerminal12ft6in(Units.feetToMeters(12.5)),
157157
kTerminal22ft6in(Units.feetToMeters(22.5));
158158

159-
public static double FOV = 68.5;
159+
public static final double FOV = 68.5;
160160

161161
public final double distanceMeters;
162162
public final Path path;

photon-core/src/main/java/org/photonvision/vision/calibration/JsonMatOfDouble.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ public <R extends Num, C extends Num> Matrix<R, C> getAsWpilibMat() {
110110
if (wpilibMat == null) {
111111
wpilibMat = new Matrix<R, C>(new SimpleMatrix(rows, cols, true, data));
112112
}
113-
return (Matrix<R, C>) wpilibMat;
113+
return wpilibMat;
114114
}
115115

116116
@Override

photon-core/src/main/java/org/photonvision/vision/camera/USBCameras/GenericUSBCameraSettables.java

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -100,12 +100,6 @@ protected void setUpExposureProperties() {
100100
// first.
101101
var autoExpProp = findProperty("exposure_auto", "auto_exposure");
102102

103-
if (expProp.isPresent()) {
104-
exposureAbsProp = expProp.get();
105-
this.minExposure = exposureAbsProp.getMin();
106-
this.maxExposure = exposureAbsProp.getMax();
107-
}
108-
109103
if (autoExpProp.isPresent()) {
110104
autoExposureProp = autoExpProp.get();
111105
}
@@ -278,10 +272,8 @@ private void cacheVideoModes() {
278272
continue;
279273
}
280274

281-
if (configuration.cameraQuirks.hasQuirk(CameraQuirk.FPSCap100)) {
282-
if (videoMode.fps > 100) {
283-
continue;
284-
}
275+
if (configuration.cameraQuirks.hasQuirk(CameraQuirk.FPSCap100) && videoMode.fps > 100) {
276+
continue;
285277
}
286278

287279
videoModesList.add(videoMode);

photon-core/src/main/java/org/photonvision/vision/pipe/impl/CornerDetectionPipe.java

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -62,19 +62,18 @@ private List<Point> findBoundingBoxCorners(TrackedTarget target) {
6262

6363
// find the bl/br/tr/tl corners
6464
// first, min by left/right
65-
var list_ = Arrays.asList(points);
66-
list_.sort(leftRightComparator);
65+
Arrays.sort(points, leftRightComparator);
6766
// of this, we now have left and right
6867
// sort to get top and bottom
69-
var left = new ArrayList<>(List.of(list_.get(0), list_.get(1)));
70-
left.sort(verticalComparator);
71-
var right = new ArrayList<>(List.of(list_.get(2), list_.get(3)));
72-
right.sort(verticalComparator);
68+
Point[] left = {points[0], points[1]};
69+
Arrays.sort(left, verticalComparator);
70+
Point[] right = {points[2], points[3]};
71+
Arrays.sort(right, verticalComparator);
7372

74-
var tl = left.get(0);
75-
var bl = left.get(1);
76-
var tr = right.get(0);
77-
var br = right.get(1);
73+
var tl = left[0];
74+
var bl = left[1];
75+
var tr = right[0];
76+
var br = right[1];
7877

7978
return List.of(bl, br, tr, tl);
8079
}
@@ -140,11 +139,9 @@ private List<Point> detectExtremeCornersByApproxPolyDp(TrackedTarget target, boo
140139

141140
// top left and top right are the poly corners closest to the bounding box tl and tr
142141
pointList.sort(compareDistToTl);
143-
var tl = pointList.get(0);
144-
pointList.remove(tl);
142+
var tl = pointList.remove(0);
145143
pointList.sort(compareDistToTr);
146-
var tr = pointList.get(0);
147-
pointList.remove(tr);
144+
var tr = pointList.remove(0);
148145

149146
// at this point we look for points on the left/right of the center of the remaining points
150147
// and maximize their distance from the center of the min area rectangle
@@ -160,12 +157,13 @@ private List<Point> detectExtremeCornersByApproxPolyDp(TrackedTarget target, boo
160157
for (var p : pointList) {
161158
if (p.y
162159
> target.m_mainContour.getBoundingRect().y
163-
+ target.m_mainContour.getBoundingRect().height / 2.0)
160+
+ target.m_mainContour.getBoundingRect().height / 2.0) {
164161
if (p.x < averageXCoordinate) {
165162
leftList.add(p);
166163
} else {
167164
rightList.add(p);
168165
}
166+
}
169167
}
170168
if (leftList.isEmpty() || rightList.isEmpty()) return null;
171169
leftList.sort(compareCenterDist);

photon-core/src/main/java/org/photonvision/vision/pipe/impl/FilterContoursPipe.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,7 @@ private void rejectOutliers(List<Contour> list, double xTol, double yTol) {
6767
double x = c.getCenterPoint().x;
6868
double y = c.getCenterPoint().y;
6969

70-
if (Math.abs(x - meanX) > stdDevX * xTol) {
71-
it.remove();
72-
} else if (Math.abs(y - meanY) > stdDevY * yTol) {
70+
if (Math.abs(x - meanX) > stdDevX * xTol || Math.abs(y - meanY) > stdDevY * yTol) {
7371
it.remove();
7472
}
7573
// Otherwise we're good! Keep it in

photon-core/src/main/java/org/photonvision/vision/pipe/impl/FindBoardCornersPipe.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public class FindBoardCornersPipe
5454
// Since we return results in real-time, we want to ensure it goes as fast as
5555
// possible
5656
// and fails as fast as possible.
57-
final int findChessboardFlags =
57+
static final int findChessboardFlags =
5858
Calib3d.CALIB_CB_NORMALIZE_IMAGE
5959
| Calib3d.CALIB_CB_ADAPTIVE_THRESH
6060
| Calib3d.CALIB_CB_FILTER_QUADS

photon-core/src/main/java/org/photonvision/vision/pipe/impl/GrayscalePipe.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,5 @@ protected Mat process(Mat in) {
3232
return outputMat;
3333
}
3434

35-
public static class GrayscaleParams {
36-
public GrayscaleParams() {}
37-
}
35+
public static class GrayscaleParams {}
3836
}

photon-core/src/main/java/org/photonvision/vision/processes/VisionModule.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -571,20 +571,20 @@ public UICameraConfiguration toUICameraConfig() {
571571
var temp = new HashMap<Integer, HashMap<String, Object>>();
572572
var videoModes = visionSource.getSettables().getAllVideoModes();
573573

574-
for (var k : videoModes.keySet()) {
574+
for (var k : videoModes.entrySet()) {
575575
var internalMap = new HashMap<String, Object>();
576576

577-
internalMap.put("width", videoModes.get(k).width);
578-
internalMap.put("height", videoModes.get(k).height);
579-
internalMap.put("fps", videoModes.get(k).fps);
577+
internalMap.put("width", k.getValue().width);
578+
internalMap.put("height", k.getValue().height);
579+
internalMap.put("fps", k.getValue().fps);
580580
internalMap.put(
581581
"pixelFormat",
582-
((videoModes.get(k) instanceof LibcameraGpuSource.FPSRatedVideoMode)
582+
((k.getValue() instanceof LibcameraGpuSource.FPSRatedVideoMode)
583583
? "kPicam"
584-
: videoModes.get(k).pixelFormat.toString())
584+
: k.getValue().pixelFormat.toString())
585585
.substring(1)); // Remove the k prefix
586586

587-
temp.put(k, internalMap);
587+
temp.put(k.getKey(), internalMap);
588588
}
589589

590590
if (videoModes.size() == 0) {

photon-core/src/main/java/org/photonvision/vision/processes/VisionModuleChangeSubscriber.java

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -55,23 +55,22 @@ public VisionModuleChangeSubscriber(VisionModule parentModule) {
5555

5656
@Override
5757
public void onDataChangeEvent(DataChangeEvent<?> event) {
58-
if (event instanceof IncomingWebSocketEvent wsEvent) {
59-
// Camera index -1 means a "multicast event" (i.e. the event is received by all cameras)
60-
if (wsEvent.cameraUniqueName != null
61-
&& wsEvent.cameraUniqueName.equals(parentModule.uniqueName())) {
62-
logger.trace("Got PSC event - propName: " + wsEvent.propertyName);
63-
changeListLock.lock();
64-
try {
65-
getSettingChanges()
66-
.add(
67-
new VisionModuleChange(
68-
wsEvent.propertyName,
69-
wsEvent.data,
70-
parentModule.pipelineManager.getCurrentPipeline().getSettings(),
71-
wsEvent.originContext));
72-
} finally {
73-
changeListLock.unlock();
74-
}
58+
// Camera index -1 means a "multicast event" (i.e. the event is received by all cameras)
59+
if (event instanceof IncomingWebSocketEvent wsEvent
60+
&& wsEvent.cameraUniqueName != null
61+
&& wsEvent.cameraUniqueName.equals(parentModule.uniqueName())) {
62+
logger.trace("Got PSC event - propName: " + wsEvent.propertyName);
63+
changeListLock.lock();
64+
try {
65+
getSettingChanges()
66+
.add(
67+
new VisionModuleChange(
68+
wsEvent.propertyName,
69+
wsEvent.data,
70+
parentModule.pipelineManager.getCurrentPipeline().getSettings(),
71+
wsEvent.originContext));
72+
} finally {
73+
changeListLock.unlock();
7574
}
7675
}
7776
}

photon-server/src/main/java/org/photonvision/server/DataSocketHandler.java

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -112,14 +112,13 @@ public void onBinaryMessage(WsBinaryMessageContext context) {
112112
var socketMessageType = DataSocketMessageType.fromEntryKey(entryKey);
113113

114114
logger.trace(
115-
() ->
116-
"Got WS message: ["
117-
+ socketMessageType
118-
+ "] ==> ["
119-
+ entryKey
120-
+ "], ["
121-
+ entryValue
122-
+ "]");
115+
"Got WS message: ["
116+
+ socketMessageType
117+
+ "] ==> ["
118+
+ entryKey
119+
+ "], ["
120+
+ entryValue
121+
+ "]");
123122

124123
if (socketMessageType == null) {
125124
logger.warn("Got unknown socket message type: " + entryKey);

0 commit comments

Comments
 (0)