-
Notifications
You must be signed in to change notification settings - Fork 196
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9a7764f
commit bcb3e1c
Showing
9 changed files
with
620 additions
and
0 deletions.
There are no files selected for viewing
49 changes: 49 additions & 0 deletions
49
...rgeting/src/test/java/org/photonvision/targeting/proto/MultiTargetPNPResultProtoTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/* | ||
* Copyright (C) Photon Vision. | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package org.photonvision.targeting.proto; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
import edu.wpi.first.math.geometry.Rotation3d; | ||
import edu.wpi.first.math.geometry.Transform3d; | ||
import edu.wpi.first.math.geometry.Translation3d; | ||
import java.util.List; | ||
import org.junit.jupiter.api.Test; | ||
import org.photonvision.targeting.MultiTargetPNPResult; | ||
import org.photonvision.targeting.PNPResult; | ||
|
||
public class MultiTargetPNPResultProtoTest { | ||
@Test | ||
public void protobufTest() { | ||
var result = new MultiTargetPNPResult(); | ||
var serializedResult = MultiTargetPNPResult.proto.createMessage(); | ||
MultiTargetPNPResult.proto.pack(serializedResult, result); | ||
var unpackedResult = MultiTargetPNPResult.proto.unpack(serializedResult); | ||
assertEquals(result, unpackedResult); | ||
|
||
result = | ||
new MultiTargetPNPResult( | ||
new PNPResult( | ||
new Transform3d(new Translation3d(1, 2, 3), new Rotation3d(1, 2, 3)), 0.1), | ||
List.of(1, 2, 3)); | ||
serializedResult = MultiTargetPNPResult.proto.createMessage(); | ||
MultiTargetPNPResult.proto.pack(serializedResult, result); | ||
unpackedResult = MultiTargetPNPResult.proto.unpack(serializedResult); | ||
assertEquals(result, unpackedResult); | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
photon-targeting/src/test/java/org/photonvision/targeting/proto/PNPResultProtoTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/* | ||
* Copyright (C) Photon Vision. | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package org.photonvision.targeting.proto; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
import edu.wpi.first.math.geometry.Rotation3d; | ||
import edu.wpi.first.math.geometry.Transform3d; | ||
import org.junit.jupiter.api.Test; | ||
import org.photonvision.targeting.PNPResult; | ||
|
||
public class PNPResultProtoTest { | ||
@Test | ||
public void protobufTest() { | ||
var pnpRes = new PNPResult(); | ||
var serializedPNPRes = PNPResult.proto.createMessage(); | ||
PNPResult.proto.pack(serializedPNPRes, pnpRes); | ||
var unpackedPNPRes = PNPResult.proto.unpack(serializedPNPRes); | ||
assertEquals(pnpRes, unpackedPNPRes); | ||
|
||
pnpRes = new PNPResult(new Transform3d(1, 2, 3, new Rotation3d(1, 2, 3)), 0.1); | ||
serializedPNPRes = PNPResult.proto.createMessage(); | ||
PNPResult.proto.pack(serializedPNPRes, pnpRes); | ||
unpackedPNPRes = PNPResult.proto.unpack(serializedPNPRes); | ||
assertEquals(pnpRes, unpackedPNPRes); | ||
} | ||
} |
139 changes: 139 additions & 0 deletions
139
...rgeting/src/test/java/org/photonvision/targeting/proto/PhotonPipelineResultProtoTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,139 @@ | ||
/* | ||
* Copyright (C) Photon Vision. | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package org.photonvision.targeting.proto; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
import edu.wpi.first.math.geometry.Rotation3d; | ||
import edu.wpi.first.math.geometry.Transform3d; | ||
import edu.wpi.first.math.geometry.Translation3d; | ||
import java.util.List; | ||
import org.junit.jupiter.api.Test; | ||
import org.photonvision.targeting.*; | ||
|
||
public class PhotonPipelineResultProtoTest { | ||
@Test | ||
public void protobufTest() { | ||
// Empty Result | ||
var result = new PhotonPipelineResult(); | ||
var serializedResult = PhotonPipelineResult.proto.createMessage(); | ||
PhotonPipelineResult.proto.pack(serializedResult, result); | ||
var unpackedResult = PhotonPipelineResult.proto.unpack(serializedResult); | ||
assertEquals(result, unpackedResult); | ||
|
||
// non multitag result | ||
result = | ||
new PhotonPipelineResult( | ||
2, | ||
List.of( | ||
new PhotonTrackedTarget( | ||
3.0, | ||
-4.0, | ||
9.0, | ||
4.0, | ||
2, | ||
new Transform3d(new Translation3d(1, 2, 3), new Rotation3d(1, 2, 3)), | ||
new Transform3d(new Translation3d(1, 2, 3), new Rotation3d(1, 2, 3)), | ||
0.25, | ||
List.of( | ||
new TargetCorner(1, 2), | ||
new TargetCorner(3, 4), | ||
new TargetCorner(5, 6), | ||
new TargetCorner(7, 8)), | ||
List.of( | ||
new TargetCorner(1, 2), | ||
new TargetCorner(3, 4), | ||
new TargetCorner(5, 6), | ||
new TargetCorner(7, 8))), | ||
new PhotonTrackedTarget( | ||
3.0, | ||
-4.0, | ||
9.1, | ||
6.7, | ||
3, | ||
new Transform3d(new Translation3d(4, 2, 3), new Rotation3d(1, 5, 3)), | ||
new Transform3d(new Translation3d(4, 2, 3), new Rotation3d(1, 5, 3)), | ||
0.25, | ||
List.of( | ||
new TargetCorner(1, 2), | ||
new TargetCorner(3, 4), | ||
new TargetCorner(5, 6), | ||
new TargetCorner(7, 8)), | ||
List.of( | ||
new TargetCorner(1, 2), | ||
new TargetCorner(3, 4), | ||
new TargetCorner(5, 6), | ||
new TargetCorner(7, 8))))); | ||
serializedResult = PhotonPipelineResult.proto.createMessage(); | ||
PhotonPipelineResult.proto.pack(serializedResult, result); | ||
unpackedResult = PhotonPipelineResult.proto.unpack(serializedResult); | ||
assertEquals(result, unpackedResult); | ||
|
||
// multitag result | ||
result = | ||
new PhotonPipelineResult( | ||
2, | ||
List.of( | ||
new PhotonTrackedTarget( | ||
3.0, | ||
-4.0, | ||
9.0, | ||
4.0, | ||
2, | ||
new Transform3d(new Translation3d(1, 2, 3), new Rotation3d(1, 2, 3)), | ||
new Transform3d(new Translation3d(1, 2, 3), new Rotation3d(1, 2, 3)), | ||
0.25, | ||
List.of( | ||
new TargetCorner(1, 2), | ||
new TargetCorner(3, 4), | ||
new TargetCorner(5, 6), | ||
new TargetCorner(7, 8)), | ||
List.of( | ||
new TargetCorner(1, 2), | ||
new TargetCorner(3, 4), | ||
new TargetCorner(5, 6), | ||
new TargetCorner(7, 8))), | ||
new PhotonTrackedTarget( | ||
3.0, | ||
-4.0, | ||
9.1, | ||
6.7, | ||
3, | ||
new Transform3d(new Translation3d(4, 2, 3), new Rotation3d(1, 5, 3)), | ||
new Transform3d(new Translation3d(4, 2, 3), new Rotation3d(1, 5, 3)), | ||
0.25, | ||
List.of( | ||
new TargetCorner(1, 2), | ||
new TargetCorner(3, 4), | ||
new TargetCorner(5, 6), | ||
new TargetCorner(7, 8)), | ||
List.of( | ||
new TargetCorner(1, 2), | ||
new TargetCorner(3, 4), | ||
new TargetCorner(5, 6), | ||
new TargetCorner(7, 8)))), | ||
new MultiTargetPNPResult( | ||
new PNPResult( | ||
new Transform3d(new Translation3d(1, 2, 3), new Rotation3d(1, 2, 3)), 0.1), | ||
List.of(1, 2, 3))); | ||
serializedResult = PhotonPipelineResult.proto.createMessage(); | ||
PhotonPipelineResult.proto.pack(serializedResult, result); | ||
unpackedResult = PhotonPipelineResult.proto.unpack(serializedResult); | ||
assertEquals(result, unpackedResult); | ||
} | ||
} |
115 changes: 115 additions & 0 deletions
115
...argeting/src/test/java/org/photonvision/targeting/proto/PhotonTrackedTargetProtoTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
/* | ||
* Copyright (C) Photon Vision. | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package org.photonvision.targeting.proto; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
import edu.wpi.first.math.geometry.Rotation3d; | ||
import edu.wpi.first.math.geometry.Transform3d; | ||
import edu.wpi.first.math.geometry.Translation3d; | ||
import java.util.List; | ||
import org.junit.jupiter.api.Test; | ||
import org.photonvision.proto.Photon.ProtobufPhotonTrackedTarget; | ||
import org.photonvision.targeting.PhotonTrackedTarget; | ||
import org.photonvision.targeting.TargetCorner; | ||
import us.hebi.quickbuf.RepeatedMessage; | ||
|
||
public class PhotonTrackedTargetProtoTest { | ||
@Test | ||
public void protobufTest() { | ||
var target = | ||
new PhotonTrackedTarget( | ||
3.0, | ||
4.0, | ||
9.0, | ||
-5.0, | ||
-1, | ||
new Transform3d(new Translation3d(), new Rotation3d()), | ||
new Transform3d(new Translation3d(), new Rotation3d()), | ||
0.25, | ||
List.of( | ||
new TargetCorner(1, 2), | ||
new TargetCorner(3, 4), | ||
new TargetCorner(5, 6), | ||
new TargetCorner(7, 8)), | ||
List.of( | ||
new TargetCorner(1, 2), | ||
new TargetCorner(3, 4), | ||
new TargetCorner(5, 6), | ||
new TargetCorner(7, 8))); | ||
var serializedTarget = PhotonTrackedTarget.proto.createMessage(); | ||
PhotonTrackedTarget.proto.pack(serializedTarget, target); | ||
var unpackedTarget = PhotonTrackedTarget.proto.unpack(serializedTarget); | ||
assertEquals(target, unpackedTarget); | ||
} | ||
|
||
@Test | ||
public void protobufListTest() { | ||
List<PhotonTrackedTarget> targets = List.of(); | ||
var serializedTargets = | ||
RepeatedMessage.newEmptyInstance(ProtobufPhotonTrackedTarget.getFactory()); | ||
PhotonTrackedTarget.proto.pack(serializedTargets, targets); | ||
var unpackedTargets = PhotonTrackedTarget.proto.unpack(serializedTargets); | ||
assertEquals(targets, unpackedTargets); | ||
|
||
targets = | ||
List.of( | ||
new PhotonTrackedTarget( | ||
3.0, | ||
4.0, | ||
9.0, | ||
-5.0, | ||
-1, | ||
new Transform3d(new Translation3d(), new Rotation3d()), | ||
new Transform3d(new Translation3d(), new Rotation3d()), | ||
0.25, | ||
List.of( | ||
new TargetCorner(1, 2), | ||
new TargetCorner(3, 4), | ||
new TargetCorner(5, 6), | ||
new TargetCorner(7, 8)), | ||
List.of( | ||
new TargetCorner(1, 2), | ||
new TargetCorner(3, 4), | ||
new TargetCorner(5, 6), | ||
new TargetCorner(7, 8))), | ||
new PhotonTrackedTarget( | ||
7.0, | ||
2.0, | ||
1.0, | ||
-9.0, | ||
-1, | ||
new Transform3d(new Translation3d(), new Rotation3d()), | ||
new Transform3d(new Translation3d(), new Rotation3d()), | ||
0.25, | ||
List.of( | ||
new TargetCorner(1, 2), | ||
new TargetCorner(3, 4), | ||
new TargetCorner(5, 6), | ||
new TargetCorner(7, 8)), | ||
List.of( | ||
new TargetCorner(1, 2), | ||
new TargetCorner(3, 4), | ||
new TargetCorner(5, 6), | ||
new TargetCorner(7, 8)))); | ||
serializedTargets = RepeatedMessage.newEmptyInstance(ProtobufPhotonTrackedTarget.getFactory()); | ||
PhotonTrackedTarget.proto.pack(serializedTargets, targets); | ||
unpackedTargets = PhotonTrackedTarget.proto.unpack(serializedTargets); | ||
assertEquals(targets, unpackedTargets); | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
photon-targeting/src/test/java/org/photonvision/targeting/proto/TargetCornerProtoTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* | ||
* Copyright (C) Photon Vision. | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package org.photonvision.targeting.proto; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.photonvision.targeting.TargetCorner; | ||
|
||
public class TargetCornerProtoTest { | ||
@Test | ||
public void protobufTest() { | ||
var corner = new TargetCorner(0, 1); | ||
var serializedCorner = TargetCorner.proto.createMessage(); | ||
TargetCorner.proto.pack(serializedCorner, corner); | ||
var unpackedCorner = TargetCorner.proto.unpack(serializedCorner); | ||
assertEquals(corner, unpackedCorner); | ||
} | ||
} |
Oops, something went wrong.