Skip to content

Commit 4849f80

Browse files
authored
Merge pull request #72 from Manchester-Central/camera-inheritance-fix
Camera inheritance fix
2 parents 8bc9b7e + 525f22e commit 4849f80

File tree

4 files changed

+11
-12
lines changed

4 files changed

+11
-12
lines changed

src/main/java/com/chaos131/vision/AbstractChaosCamera.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public abstract class AbstractChaosCamera extends SubsystemBase {
6666
/**
6767
* A list of April Tags we care about. This is typically the list of all april tags on the field.
6868
*/
69-
protected ArrayList<Quad> m_localizationTags = new ArrayList<Quad>();
69+
protected ArrayList<? extends Quad> m_localizationTags = new ArrayList<Quad>();
7070

7171
/**
7272
* There are only 3 core modes for cameras in FRC: localization, tracking a game piece, mapping
@@ -177,7 +177,7 @@ public AbstractChaosCamera setRobotRotationSupplier(Supplier<Double> rotationSup
177177
* @param tags list of quads describing the april tags
178178
* @return the class itself for chaining
179179
*/
180-
public AbstractChaosCamera setTagsOfInterest(ArrayList<Quad> tags) {
180+
public AbstractChaosCamera setTagsOfInterest(ArrayList<? extends Quad> tags) {
181181
m_localizationTags = tags;
182182
return this;
183183
}

src/main/java/com/chaos131/vision/CameraTransforms.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ public static Matrix<N4, N4> FrustumProjectionMatrix(
127127
* @return a list of 4 element vectors that are in view of the camera
128128
*/
129129
public static ArrayList<Matrix<N4, N1>> CalculateVisibleCoordinates(
130-
Pose3d pose, Quad[] quads, double hfov, double vfov) {
130+
Pose3d pose, ArrayList<? extends Quad> quads, double hfov, double vfov) {
131131
return CalculateVisibleCoordinates(pose, quads, hfov, vfov, 0.05, 100);
132132
}
133133

@@ -143,7 +143,7 @@ public static ArrayList<Matrix<N4, N1>> CalculateVisibleCoordinates(
143143
* @return a list of 4 element vectors that are in view of the camera
144144
*/
145145
public static ArrayList<Matrix<N4, N1>> CalculateVisibleCoordinates(
146-
Pose3d pose, Quad[] quads, double hfov, double vfov, double n, double f) {
146+
Pose3d pose, ArrayList<? extends Quad> quads, double hfov, double vfov, double n, double f) {
147147
var view_projection_matrix = FrustumProjectionMatrix(hfov, vfov, n, f).times(ViewMatrix(pose));
148148
ArrayList<Matrix<N4, N1>> final_points = new ArrayList<>();
149149
for (Quad q : quads) {
@@ -174,7 +174,7 @@ public static ArrayList<Matrix<N4, N1>> CalculateVisibleCoordinates(
174174
* @return a list of 4 element vectors that are in view of the camera
175175
*/
176176
public static ArrayList<Matrix<N4, N1>> CalculateVisibleCoordinates(
177-
Pose3d pose, Quad[] quads, Matrix<N4, N4> view_proj) {
177+
Pose3d pose, ArrayList<? extends Quad> quads, Matrix<N4, N4> view_proj) {
178178
ArrayList<Matrix<N4, N1>> final_points = new ArrayList<>();
179179
for (Quad q : quads) {
180180
var points = q.getPoints();

src/main/java/com/chaos131/vision/LimelightCamera.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import static edu.wpi.first.units.Units.MetersPerSecond;
66
import static edu.wpi.first.units.Units.RotationsPerSecond;
77

8-
import com.chaos131.util.Quad;
98
import edu.wpi.first.math.geometry.Pose2d;
109
import edu.wpi.first.math.geometry.Pose3d;
1110
import edu.wpi.first.math.geometry.Rotation3d;
@@ -289,7 +288,7 @@ public void updateCropFromRobotpose(
289288
Pose3d robotPose, double horizontal_margin, double vertical_margin) {
290289
var visibletags =
291290
CameraTransforms.CalculateVisibleCoordinates(
292-
robotPose, (Quad[]) m_localizationTags.toArray(), EPSILON, EPSILON);
291+
robotPose, m_localizationTags, EPSILON, EPSILON);
293292
// returns in the order of [minX, minY, maxX, maxY]
294293
var bounds = CameraTransforms.FindBounds(visibletags, horizontal_margin, vertical_margin);
295294

src/test/java/com/chaos131/vision/CameraTransformsTests.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ public class CameraTransformsTests {
1818
@Test
1919
public void testCalculateVisibleCoordinates() {
2020
var source_tag = new Translation3d(-0.0381, 5.547868, 1.368552);
21-
var tag_coords = new Quad[] {new Quad(source_tag, source_tag, source_tag, source_tag)};
21+
var tag_coords = new ArrayList<Quad>();
22+
tag_coords.add(new Quad(source_tag, source_tag, source_tag, source_tag));
2223

2324
var camerapose =
2425
new Pose3d(new Translation3d(4.0, 5.547868, 1.368552), new Rotation3d(0, 0, Math.PI));
@@ -102,9 +103,7 @@ public void testAllTagsInView() {
102103
new Translation3d(22.0, field_up_meters / 2, 1.451102), // z is the speaker tag height
103104
new Rotation3d(0, 0, Math.PI));
104105
ArrayList<AprilTag> fmap_data = FieldData.LoadTagLocations(fmap.fmap2024);
105-
AprilTag[] tags = new AprilTag[fmap_data.size()];
106-
fmap_data.toArray(tags);
107-
var res = CameraTransforms.CalculateVisibleCoordinates(camerapose, tags, 80, 56, 0.2, 100);
106+
var res = CameraTransforms.CalculateVisibleCoordinates(camerapose, fmap_data, 80, 56, 0.2, 100);
108107
// String desmos = "";
109108
// for (var p : res) {
110109
// desmos += "(" + p.get(0, 0) + "," + p.get(1, 0) + "),";
@@ -116,7 +115,8 @@ public void testAllTagsInView() {
116115
@Test
117116
public void testCropSpace() {
118117
var speaker_tag = new Translation3d(-0.0381, 5.547868, 1.368552);
119-
var tag_coords = new Quad[] {new Quad(speaker_tag, speaker_tag, speaker_tag, speaker_tag)};
118+
var tag_coords = new ArrayList<Quad>();
119+
tag_coords.add(new Quad(speaker_tag, speaker_tag, speaker_tag, speaker_tag));
120120

121121
var camerapose =
122122
new Pose3d(new Translation3d(5.0, 5.547868, 1.368552), new Rotation3d(0, 0, Math.PI));

0 commit comments

Comments
 (0)