Send corners of min area rectangles (#382)

Adds a new corners entry to targets. Breaks byte-packed backwards compatibility. 

Co-authored-by: Tyler Veness <calcmogul@gmail.com>
This commit is contained in:
Matt
2022-01-10 20:31:36 -08:00
committed by GitHub
parent e6d8e05b91
commit 3ad476bc28
12 changed files with 215 additions and 99 deletions

View File

@@ -26,13 +26,23 @@ import org.junit.jupiter.api.Test;
import org.photonvision.common.dataflow.structures.Packet;
import org.photonvision.targeting.PhotonPipelineResult;
import org.photonvision.targeting.PhotonTrackedTarget;
import org.photonvision.targeting.TargetCorner;
class PacketTest {
@Test
void testSimpleTrackedTarget() {
var target =
new PhotonTrackedTarget(
3.0, 4.0, 9.0, -5.0, new Transform2d(new Translation2d(1, 2), new Rotation2d(1.5)));
3.0,
4.0,
9.0,
-5.0,
new Transform2d(new Translation2d(1, 2), new Rotation2d(1.5)),
List.of(
new TargetCorner(1, 2),
new TargetCorner(3, 4),
new TargetCorner(5, 6),
new TargetCorner(7, 8)));
var p = new Packet(PhotonTrackedTarget.PACK_SIZE_BYTES);
target.populatePacket(p);
@@ -62,13 +72,23 @@ class PacketTest {
-4.0,
9.0,
4.0,
new Transform2d(new Translation2d(1, 2), new Rotation2d(1.5))),
new Transform2d(new Translation2d(1, 2), new Rotation2d(1.5)),
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,
new Transform2d(new Translation2d(1, 5), new Rotation2d(1.5)))));
new Transform2d(new Translation2d(1, 5), new Rotation2d(1.5)),
List.of(
new TargetCorner(1, 2),
new TargetCorner(3, 4),
new TargetCorner(5, 6),
new TargetCorner(7, 8)))));
var p2 = new Packet(result2.getPacketSize());
result2.populatePacket(p2);
@@ -77,46 +97,4 @@ class PacketTest {
Assertions.assertEquals(result2, b2);
}
@Test
void testBytePackFromCpp() {
byte[] bytePack = {
64, 8, 0, 0, 0, 0, 0, 0, 64, 16, 0, 0, 0, 0, 0, 0, 64, 34, 0, 0, 0, 0, 0, 0, -64, 20, 0, 0, 0,
0, 0, 0, 63, -16, 0, 0, 0, 0, 0, 0, 64, 0, 0, 0, 0, 0, 0, 0, 64, 85, 124, 101, 19, -54, -47,
122
};
var t = new PhotonTrackedTarget();
t.createFromPacket(new Packet(bytePack));
var target =
new PhotonTrackedTarget(
3.0, 4.0, 9.0, -5.0, new Transform2d(new Translation2d(1, 2), new Rotation2d(1.5)));
Assertions.assertEquals(t, target);
}
@Test
void testPacketv2021_1_6() {
// From v2021.1.6
var simplified =
new PhotonPipelineResult(
12.34,
List.of(
new PhotonTrackedTarget(
-23, -10, 6, 1, new Transform2d(new Translation2d(1, 2), new Rotation2d(3)))));
byte[] bytes = {
64, 40, -82, 20, 122, -31, 71, -82, 1, -64, 55, 0, 0, 0, 0, 0, 0, -64, 36, 0, 0, 0, 0, 0, 0,
64, 24, 0, 0, 0, 0, 0, 0, 63, -16, 0, 0, 0, 0, 0, 0, 63, -16, 0, 0, 0, 0, 0, 0, 64, 0, 0, 0,
0, 0, 0, 0, 64, 101, 124, 101, 19, -54, -47, 122, 0
};
// Let's check that those bytes still mean the same thing
Packet packet = new Packet(1);
packet.clear();
packet.setData(bytes);
var ret = new PhotonPipelineResult();
ret.createFromPacket(packet);
System.out.println(ret);
Assertions.assertEquals(simplified, ret);
}
}

View File

@@ -25,8 +25,13 @@
TEST(PacketTest, PhotonTrackedTarget) {
photonlib::PhotonTrackedTarget target{
3.0, 4.0, 9.0, -5.0,
frc::Transform2d(frc::Translation2d(1_m, 2_m), 1.5_rad)};
3.0,
4.0,
9.0,
-5.0,
frc::Transform2d(frc::Translation2d(1_m, 2_m), 1.5_rad),
{std::pair{1, 2}, std::pair{3, 4}, std::pair{5, 6}, std::pair{7, 8}}};
photonlib::Packet p;
p << target;
@@ -52,11 +57,20 @@ TEST(PacketTest, PhotonPipelineResult) {
wpi::SmallVector<photonlib::PhotonTrackedTarget, 2> targets{
photonlib::PhotonTrackedTarget{
3.0, -4.0, 9.0, 4.0,
frc::Transform2d(frc::Translation2d(1_m, 2_m), 1.5_rad)},
3.0,
-4.0,
9.0,
4.0,
frc::Transform2d(frc::Translation2d(1_m, 2_m), 1.5_rad),
{std::pair{1, 2}, std::pair{3, 4}, std::pair{5, 6}, std::pair{7, 8}}},
photonlib::PhotonTrackedTarget{
3.0, -4.0, 9.1, 6.7,
frc::Transform2d(frc::Translation2d(1_m, 5_m), 1.5_rad)}};
3.0,
-4.0,
9.1,
6.7,
frc::Transform2d(frc::Translation2d(1_m, 5_m), 1.5_rad),
{std::pair{1, 2}, std::pair{3, 4}, std::pair{5, 6},
std::pair{7, 8}}}};
photonlib::PhotonPipelineResult result2{2_s, targets};
photonlib::Packet p2;
@@ -67,25 +81,3 @@ TEST(PacketTest, PhotonPipelineResult) {
EXPECT_EQ(result2, b2);
}
TEST(PacketTest, BytePackFromJava) {
std::vector<signed char> bytePack{
64, 8, 0, 0, 0, 0, 0, 0, 64, 16, 0, 0, 0, 0,
0, 0, 64, 34, 0, 0, 0, 0, 0, 0, -64, 20, 0, 0,
0, 0, 0, 0, 63, -16, 0, 0, 0, 0, 0, 0, 64, 0,
0, 0, 0, 0, 0, 0, 64, 85, 124, 101, 19, -54, -47, 122};
std::vector<char> bytes;
for (auto a : bytePack) bytes.emplace_back(static_cast<char>(a));
photonlib::Packet packet{bytes};
photonlib::PhotonTrackedTarget res;
packet >> res;
photonlib::PhotonTrackedTarget target{
3.0, 4.0, 9.0, -5.0,
frc::Transform2d(frc::Translation2d(1_m, 2_m), 1.5_rad)};
EXPECT_EQ(res, target);
}