Add protobuf publish setting slider (#1075)

Allows logging software and live data view to see results. Also removes the requirement for AScope to keep up with the packet serde schema and instead just use the Protobuf descriptor.
This commit is contained in:
Sriman Achanta
2023-12-31 00:14:21 -05:00
committed by GitHub
parent e3eff8731f
commit 2ecd988628
41 changed files with 1630 additions and 41 deletions

View File

@@ -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);
}
}

View File

@@ -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);
}
}

View File

@@ -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);
}
}

View File

@@ -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);
}
}

View File

@@ -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);
}
}