2021-01-16 20:41:47 -08:00
|
|
|
/*
|
2022-01-20 19:35:28 -08:00
|
|
|
* MIT License
|
2021-01-16 20:41:47 -08:00
|
|
|
*
|
2022-01-20 19:35:28 -08:00
|
|
|
* Copyright (c) 2022 PhotonVision
|
2021-01-16 20:41:47 -08:00
|
|
|
*
|
2022-01-20 19:35:28 -08:00
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
|
* of this software and associated documentation files (the "Software"), to deal
|
|
|
|
|
* in the Software without restriction, including without limitation the rights
|
|
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
|
* copies of the Software, and to permit persons to whom the Software is
|
|
|
|
|
* furnished to do so, subject to the following conditions:
|
2021-01-16 20:41:47 -08:00
|
|
|
*
|
2022-01-20 19:35:28 -08:00
|
|
|
* The above copyright notice and this permission notice shall be included in all
|
|
|
|
|
* copies or substantial portions of the Software.
|
|
|
|
|
*
|
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
|
|
|
* SOFTWARE.
|
2021-01-16 20:41:47 -08:00
|
|
|
*/
|
2022-01-20 19:35:28 -08:00
|
|
|
|
2021-01-16 20:41:47 -08:00
|
|
|
package org.photonvision;
|
|
|
|
|
|
2022-09-28 18:21:41 -07:00
|
|
|
import edu.wpi.first.math.geometry.*;
|
2021-01-16 20:41:47 -08:00
|
|
|
import java.util.ArrayList;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import org.junit.jupiter.api.Assertions;
|
|
|
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
|
import org.photonvision.common.dataflow.structures.Packet;
|
|
|
|
|
import org.photonvision.targeting.PhotonPipelineResult;
|
|
|
|
|
import org.photonvision.targeting.PhotonTrackedTarget;
|
2022-01-10 20:31:36 -08:00
|
|
|
import org.photonvision.targeting.TargetCorner;
|
2021-01-16 20:41:47 -08:00
|
|
|
|
|
|
|
|
class PacketTest {
|
|
|
|
|
@Test
|
|
|
|
|
void testSimpleTrackedTarget() {
|
|
|
|
|
var target =
|
|
|
|
|
new PhotonTrackedTarget(
|
2022-01-10 20:31:36 -08:00
|
|
|
3.0,
|
|
|
|
|
4.0,
|
|
|
|
|
9.0,
|
|
|
|
|
-5.0,
|
2022-09-28 18:21:41 -07:00
|
|
|
-1,
|
|
|
|
|
new Transform3d(new Translation3d(), new Rotation3d()),
|
2022-10-08 09:27:00 -04:00
|
|
|
0.25,
|
2022-01-10 20:31:36 -08:00
|
|
|
List.of(
|
|
|
|
|
new TargetCorner(1, 2),
|
|
|
|
|
new TargetCorner(3, 4),
|
|
|
|
|
new TargetCorner(5, 6),
|
|
|
|
|
new TargetCorner(7, 8)));
|
2021-01-16 20:41:47 -08:00
|
|
|
var p = new Packet(PhotonTrackedTarget.PACK_SIZE_BYTES);
|
|
|
|
|
target.populatePacket(p);
|
|
|
|
|
|
|
|
|
|
var b = new PhotonTrackedTarget();
|
|
|
|
|
b.createFromPacket(p);
|
|
|
|
|
|
|
|
|
|
Assertions.assertEquals(target, b);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
void testSimplePipelineResult() {
|
|
|
|
|
var result = new PhotonPipelineResult(1, new ArrayList<>());
|
|
|
|
|
var p = new Packet(result.getPacketSize());
|
|
|
|
|
result.populatePacket(p);
|
|
|
|
|
|
|
|
|
|
var b = new PhotonPipelineResult();
|
|
|
|
|
b.createFromPacket(p);
|
|
|
|
|
|
|
|
|
|
Assertions.assertEquals(result, b);
|
|
|
|
|
|
|
|
|
|
var result2 =
|
|
|
|
|
new PhotonPipelineResult(
|
|
|
|
|
2,
|
|
|
|
|
List.of(
|
|
|
|
|
new PhotonTrackedTarget(
|
|
|
|
|
3.0,
|
|
|
|
|
-4.0,
|
|
|
|
|
9.0,
|
|
|
|
|
4.0,
|
2022-09-28 18:21:41 -07:00
|
|
|
2,
|
|
|
|
|
new Transform3d(new Translation3d(1, 2, 3), new Rotation3d(1, 2, 3)),
|
2022-10-08 09:27:00 -04:00
|
|
|
0.25,
|
2022-01-10 20:31:36 -08:00
|
|
|
List.of(
|
|
|
|
|
new TargetCorner(1, 2),
|
|
|
|
|
new TargetCorner(3, 4),
|
|
|
|
|
new TargetCorner(5, 6),
|
|
|
|
|
new TargetCorner(7, 8))),
|
2021-01-16 20:41:47 -08:00
|
|
|
new PhotonTrackedTarget(
|
|
|
|
|
3.0,
|
|
|
|
|
-4.0,
|
|
|
|
|
9.1,
|
|
|
|
|
6.7,
|
2022-09-28 18:21:41 -07:00
|
|
|
3,
|
|
|
|
|
new Transform3d(new Translation3d(4, 2, 3), new Rotation3d(1, 5, 3)),
|
2022-10-08 09:27:00 -04:00
|
|
|
0.25,
|
2022-01-10 20:31:36 -08:00
|
|
|
List.of(
|
|
|
|
|
new TargetCorner(1, 2),
|
|
|
|
|
new TargetCorner(3, 4),
|
|
|
|
|
new TargetCorner(5, 6),
|
|
|
|
|
new TargetCorner(7, 8)))));
|
2021-01-16 20:41:47 -08:00
|
|
|
var p2 = new Packet(result2.getPacketSize());
|
|
|
|
|
result2.populatePacket(p2);
|
|
|
|
|
|
|
|
|
|
var b2 = new PhotonPipelineResult();
|
|
|
|
|
b2.createFromPacket(p2);
|
|
|
|
|
|
|
|
|
|
Assertions.assertEquals(result2, b2);
|
|
|
|
|
}
|
|
|
|
|
}
|