Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use protobufs for packed message data #974

Closed
wants to merge 93 commits into from
Closed
Show file tree
Hide file tree
Changes from 53 commits
Commits
Show all changes
93 commits
Select commit Hold shift + click to select a range
c95feb2
Bump to beta 2
mcm001 Oct 20, 2023
397d28d
Reduce copy paste spam going forwards
mcm001 Oct 20, 2023
2d5ccd6
Bump gradle
mcm001 Oct 20, 2023
acaefba
Maybe sorta half working
mcm001 Oct 21, 2023
0392f50
Merge branch 'master' into 2023-10-20_protobuf
srimanachanta Oct 22, 2023
a5f69e1
Remove optional
mcm001 Oct 25, 2023
20d7580
bump wpilib
mcm001 Oct 26, 2023
ebadcb7
Merge branch 'master' into 2023-10-20_protobuf
srimanachanta Oct 28, 2023
a6bd9f8
Merge branch 'master' into 2023-10-20_protobuf
srimanachanta Oct 31, 2023
95a0384
Merge remote-tracking branch 'upstream/master' into 2023-10-20_protobuf
mcm001 Nov 5, 2023
aebcfa0
Change targeting classes
srimanachanta Nov 6, 2023
5345b1b
Update OpenCVHelp.java
srimanachanta Nov 6, 2023
ce248c0
Merge branch '2023-10-20_protobuf' of https://github.com/mcm001/photo…
srimanachanta Nov 6, 2023
29e2df1
Merge branch 'master' into 2023-10-20_protobuf
srimanachanta Nov 6, 2023
42f1c4b
Update build.gradle
srimanachanta Nov 6, 2023
fd920fd
fix licence
srimanachanta Nov 6, 2023
bfb84d4
keep cleaning up
srimanachanta Nov 6, 2023
030f543
more formatting fixes
srimanachanta Nov 6, 2023
381e756
Update NTDataPublisher.java
srimanachanta Nov 6, 2023
c362730
Basic Protobuf Implementation
srimanachanta Nov 6, 2023
6f5b242
Update SimPhotonCamera.java
srimanachanta Nov 6, 2023
db6ad10
rename rawBytesEntry -> pipelineResults pub/sub
srimanachanta Nov 6, 2023
6d5759c
handle crap
srimanachanta Nov 6, 2023
fafe163
Formatting fixes
srimanachanta Nov 6, 2023
d9c32de
Add protobuf tests
srimanachanta Nov 6, 2023
7246a81
Fix bugs with packing and unpacking
srimanachanta Nov 6, 2023
5d100ce
Formatting fixes
srimanachanta Nov 6, 2023
2043802
prob wont fix but one can hope
srimanachanta Nov 8, 2023
6b9f0c9
add equality tests
srimanachanta Nov 8, 2023
4a5f145
fix assertion test
srimanachanta Nov 8, 2023
237b94d
revert to before CI crash
srimanachanta Nov 8, 2023
c9e04b8
Remove Packet stuff
srimanachanta Nov 8, 2023
c441321
general cleanup of photon-targetting
srimanachanta Nov 9, 2023
7412c18
todo, squash me
srimanachanta Nov 12, 2023
3eb4d40
add missing descriptor field
srimanachanta Nov 12, 2023
e5c15fa
add tests for Protobuf list pack and unpack
srimanachanta Nov 12, 2023
73eae67
Update PhotonPipelineResult.java
srimanachanta Nov 12, 2023
58fbe69
Make PhotonTrackedTarget final
srimanachanta Nov 12, 2023
a50e70e
Very broken gradle code lol
mcm001 Nov 13, 2023
c2a3c1e
Create unit test
mcm001 Nov 13, 2023
25e6b4b
Run lint
mcm001 Nov 13, 2023
07f7d49
bump wpilib version to fix gradle issue
srimanachanta Nov 14, 2023
48d1da5
add verifyVersion() call back
srimanachanta Nov 14, 2023
8bdb5b2
Revert "bump wpilib version to fix gradle issue"
srimanachanta Nov 14, 2023
c5c51e3
stupid shim
mcm001 Nov 14, 2023
067df21
Start on C++ things
mcm001 Nov 15, 2023
b4b71ac
Update PhotonCamera.cpp
mcm001 Nov 15, 2023
fa9b7c9
Merge branch 'master' into pr/974
srimanachanta Nov 15, 2023
82d2533
bump wpilib
srimanachanta Nov 16, 2023
465fe3b
Move geometry3d
mcm001 Nov 16, 2023
813f177
Merge branch '2023-10-20_protobuf' of github.com:mcm001/photonvision …
mcm001 Nov 16, 2023
aa8f0f5
wot
mcm001 Nov 16, 2023
fb192f5
Nuke packet
mcm001 Nov 16, 2023
22632b2
conform proto file to styleguide
srimanachanta Nov 16, 2023
932ee16
move sim stuff
srimanachanta Nov 16, 2023
f48ea8a
photon_types -> photon
srimanachanta Nov 17, 2023
99db4bf
Merge master
srimanachanta Nov 19, 2023
e7be5d0
stuff i missed
srimanachanta Nov 19, 2023
15a0eb6
move ctors to headers
srimanachanta Nov 20, 2023
6ec60a7
implement Protobuf into photon-targetting c++
srimanachanta Nov 20, 2023
ce3966c
Formatting fixes
srimanachanta Nov 20, 2023
69bafc1
update build for dependencies
srimanachanta Nov 20, 2023
31d2049
Update build.gradle
srimanachanta Nov 20, 2023
2a30b09
fix deprecation warning
srimanachanta Nov 20, 2023
e5cf987
Update OpenCVHelp.java
srimanachanta Nov 20, 2023
b3e8683
Merge branch 'master' into 2023-10-20_protobuf
srimanachanta Nov 20, 2023
b47eb45
Merge branch '2023-10-20_protobuf' of https://github.com/mcm001/photo…
srimanachanta Nov 20, 2023
68f9925
fix deprecations
srimanachanta Nov 20, 2023
defe690
Update setupBuild.gradle
srimanachanta Nov 20, 2023
57219e5
update build
srimanachanta Nov 20, 2023
3e7ed35
gib push
srimanachanta Nov 21, 2023
198d1f7
add comment
srimanachanta Nov 21, 2023
90620bd
Merge branch 'master' into 2023-10-20_protobuf
mcm001 Nov 21, 2023
479c6bf
json wpilib bump
srimanachanta Nov 21, 2023
b911394
fix PNPResult encoding bug
srimanachanta Nov 21, 2023
a6b669e
bump wpilib again
srimanachanta Nov 21, 2023
1a21927
fix gradle
srimanachanta Nov 21, 2023
5d931ff
look
srimanachanta Nov 22, 2023
558c1b4
Merge branch 'master' into 2023-10-20_protobuf
srimanachanta Nov 22, 2023
0ab58a7
remove modified files
srimanachanta Nov 22, 2023
3de2b6c
Merge branch '2023-10-20_protobuf' of https://github.com/mcm001/photo…
srimanachanta Nov 22, 2023
8ece13b
Manually initialize pnpresult
mcm001 Nov 23, 2023
d12eca5
Bump wpilib version in examples
mcm001 Nov 23, 2023
d18e3d1
Merge remote-tracking branch 'upstream/master' into 2023-10-20_protobuf
mcm001 Nov 23, 2023
9340e4f
Update javacommon.gradle
mcm001 Nov 23, 2023
1504f59
Update build.gradle
mcm001 Nov 23, 2023
f98ed57
Update build.gradle
mcm001 Nov 23, 2023
7e322e9
Merge branch 'master' into 2023-10-20_protobuf
srimanachanta Nov 23, 2023
98e0117
bump wpilib
srimanachanta Nov 23, 2023
a4d7617
Merge branch '2023-10-20_protobuf' of https://github.com/mcm001/photo…
srimanachanta Nov 24, 2023
cadbb09
Update build.gradle
mcm001 Nov 24, 2023
778cf3c
Merge branch 'master' into 2023-10-20_protobuf
srimanachanta Nov 25, 2023
5cea842
Merge branch 'master' into 2023-10-20_protobuf
srimanachanta Dec 1, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ allprojects {
apply from: "versioningHelper.gradle"

ext {
wpilibVersion = "2024.1.1-beta-3"
wpilibVersion = "2024.1.1-beta-3-29-g3985c03"
openCVversion = "4.8.0-2"
joglVersion = "2.4.0-rc-20200307"
javalinVersion = "5.6.2"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import java.util.function.Consumer;
import java.util.function.Supplier;
import org.photonvision.common.dataflow.CVPipelineResultConsumer;
import org.photonvision.common.dataflow.structures.Packet;
import org.photonvision.common.logging.LogGroup;
import org.photonvision.common.logging.Logger;
import org.photonvision.common.networktables.NTTopicSet;
Expand Down Expand Up @@ -129,15 +128,13 @@ public void updateCameraNickname(String newCameraNickname) {

@Override
public void accept(CVPipelineResult result) {
var simplified =
var res =
new PhotonPipelineResult(
result.getLatencyMillis(),
TrackedTarget.simpleFromTrackedTargets(result.targets),
result.multiTagResult);
Packet packet = new Packet(simplified.getPacketSize());
simplified.populatePacket(packet);

ts.rawBytesEntry.set(packet.getData());
ts.pipelineResultsPublisher.set(res);

ts.pipelineIndexPublisher.set(pipelineIndexSupplier.get());
ts.driverModePublisher.set(driverModeSupplier.getAsBoolean());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import org.opencv.core.CvType;
import org.opencv.core.Mat;
import org.opencv.core.MatOfDouble;
import org.photonvision.common.dataflow.structures.Packet;
import org.photonvision.vision.opencv.Releasable;

public class JsonMat implements Releasable {
Expand Down Expand Up @@ -121,9 +120,4 @@ public <R extends Num, C extends Num> Matrix<R, C> getAsWpilibMat() {
public void release() {
getAsMat().release();
}

public Packet populatePacket(Packet packet) {
packet.encode(this.data);
return packet;
}
}
11 changes: 10 additions & 1 deletion photon-lib/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -64,18 +64,27 @@ nativeUtils {
}
}


// Gradle complains about using outputs without an explicit dependency w/o this
tasks.named("compileJava") {
mustRunAfter ":photon-targeting:generateNativePhotonProtos"
}

model {
components {
Photon(NativeLibrarySpec) {
sources {
cpp {
source {
srcDirs "src/main/native/cpp"
include "**/*.cpp"
srcDirs project(":photon-targeting").tasks.named("generateNativePhotonProtos").get().outputs.files
include "**/*.cpp", "**/*.cc"
}
exportedHeaders {
srcDirs "src/main/native/include"
srcDirs "src/generate/native/include"
srcDirs project(":photon-targeting").tasks.named("generateNativePhotonProtos").get().outputs.files
include "**/*.h"
}
}
}
Expand Down
33 changes: 12 additions & 21 deletions photon-lib/src/main/java/org/photonvision/PhotonCamera.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,13 @@
import edu.wpi.first.networktables.MultiSubscriber;
import edu.wpi.first.networktables.NetworkTable;
import edu.wpi.first.networktables.NetworkTableInstance;
import edu.wpi.first.networktables.ProtobufSubscriber;
import edu.wpi.first.networktables.PubSubOption;
import edu.wpi.first.networktables.RawSubscriber;
import edu.wpi.first.networktables.StringSubscriber;
import edu.wpi.first.wpilibj.DriverStation;
import edu.wpi.first.wpilibj.Timer;
import java.util.Optional;
import java.util.Set;
import org.photonvision.common.dataflow.structures.Packet;
import org.photonvision.common.hardware.VisionLEDMode;
import org.photonvision.targeting.PhotonPipelineResult;

Expand All @@ -55,7 +54,7 @@ public class PhotonCamera implements AutoCloseable {
public static final String kTableName = "photonvision";

private final NetworkTable cameraTable;
RawSubscriber rawBytesEntry;
ProtobufSubscriber<PhotonPipelineResult> pipelineResultsSubscriber;
BooleanPublisher driverModePublisher;
BooleanSubscriber driverModeSubscriber;
DoublePublisher latencyMillisEntry;
Expand All @@ -75,7 +74,7 @@ public class PhotonCamera implements AutoCloseable {

@Override
public void close() {
rawBytesEntry.close();
pipelineResultsSubscriber.close();
driverModePublisher.close();
driverModeSubscriber.close();
latencyMillisEntry.close();
Expand Down Expand Up @@ -112,8 +111,6 @@ public static void setVersionCheckEnabled(boolean enabled) {
VERSION_CHECK_ENABLED = enabled;
}

Packet packet = new Packet(1);

/**
* Constructs a PhotonCamera from a root table.
*
Expand All @@ -127,11 +124,14 @@ public PhotonCamera(NetworkTableInstance instance, String cameraName) {
var photonvision_root_table = instance.getTable(kTableName);
this.cameraTable = photonvision_root_table.getSubTable(cameraName);
path = cameraTable.getPath();
rawBytesEntry =
pipelineResultsSubscriber =
cameraTable
.getRawTopic("rawBytes")
.getProtobufTopic("result_proto", PhotonPipelineResult.proto)
.subscribe(
"rawBytes", new byte[] {}, PubSubOption.periodic(0.01), PubSubOption.sendAll(true));
new PhotonPipelineResult(),
PubSubOption.periodic(0.01),
PubSubOption.sendAll(true));

driverModePublisher = cameraTable.getBooleanTopic("driverModeRequest").publish();
driverModeSubscriber = cameraTable.getBooleanTopic("driverMode").subscribe(false);
inputSaveImgEntry = cameraTable.getIntegerTopic("inputSaveImgCmd").getEntry(0);
Expand Down Expand Up @@ -171,21 +171,12 @@ public PhotonCamera(String cameraName) {
public PhotonPipelineResult getLatestResult() {
verifyVersion();

// Clear the packet.
packet.clear();

// Create latest result.
var ret = new PhotonPipelineResult();

// Populate packet and create result.
packet.setData(rawBytesEntry.get(new byte[] {}));

if (packet.getSize() < 1) return ret;
ret.createFromPacket(packet);
var ret = pipelineResultsSubscriber.get();

// Set the timestamp of the result.
// getLatestChange returns in microseconds, so we divide by 1e6 to convert to seconds.
ret.setTimestampSeconds((rawBytesEntry.getLastChange() / 1e6) - ret.getLatencyMillis() / 1e3);
ret.setTimestampSeconds(
(pipelineResultsSubscriber.getLastChange() / 1e6) - ret.getLatencyMillis() / 1e3);

// Return result.
return ret;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@
import org.opencv.imgproc.Imgproc;
import org.photonvision.PhotonCamera;
import org.photonvision.PhotonTargetSortMode;
import org.photonvision.common.dataflow.structures.Packet;
import org.photonvision.common.networktables.NTTopicSet;
import org.photonvision.estimation.CameraTargetRelation;
import org.photonvision.estimation.OpenCVHelp;
Expand Down Expand Up @@ -562,11 +561,9 @@ public void submitProcessedFrame(PhotonPipelineResult result) {
* @param receiveTimestamp The (sim) timestamp when this result was read by NT in microseconds
*/
public void submitProcessedFrame(PhotonPipelineResult result, long receiveTimestamp) {
ts.latencyMillisEntry.set(result.getLatencyMillis(), receiveTimestamp);
ts.pipelineResultsPublisher.set(result, receiveTimestamp);

var newPacket = new Packet(result.getPacketSize());
result.populatePacket(newPacket);
ts.rawBytesEntry.set(newPacket.getData(), receiveTimestamp);
ts.latencyMillisEntry.set(result.getLatencyMillis(), receiveTimestamp);

boolean hasTargets = result.hasTargets();
ts.hasTargetEntry.set(hasTargets, receiveTimestamp);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
import java.util.List;
import org.photonvision.PhotonCamera;
import org.photonvision.PhotonTargetSortMode;
import org.photonvision.common.dataflow.structures.Packet;
import org.photonvision.common.networktables.NTTopicSet;
import org.photonvision.targeting.MultiTargetPNPResult;
import org.photonvision.targeting.PhotonPipelineResult;
Expand Down Expand Up @@ -143,9 +142,7 @@ public void submitProcessedFrame(

PhotonPipelineResult newResult =
new PhotonPipelineResult(latencyMillis, targetList, new MultiTargetPNPResult());
var newPacket = new Packet(newResult.getPacketSize());
newResult.populatePacket(newPacket);
ts.rawBytesEntry.set(newPacket.getData());
ts.pipelineResultsPublisher.set(newResult);

boolean hasTargets = newResult.hasTargets();
ts.hasTargetEntry.set(hasTargets);
Expand Down
113 changes: 0 additions & 113 deletions photon-lib/src/main/native/cpp/photonlib/MultiTargetPNPResult.cpp

This file was deleted.

26 changes: 8 additions & 18 deletions photon-lib/src/main/native/cpp/photonlib/PhotonCamera.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
#include <opencv2/core/mat.hpp>

#include "PhotonVersion.h"
#include "photonlib/Packet.h"

namespace photonlib {

Expand All @@ -40,9 +39,10 @@ PhotonCamera::PhotonCamera(nt::NetworkTableInstance instance,
const std::string_view cameraName)
: mainTable(instance.GetTable("photonvision")),
rootTable(mainTable->GetSubTable(cameraName)),
rawBytesEntry(
rootTable->GetRawTopic("rawBytes")
.Subscribe("rawBytes", {}, {.periodic = 0.01, .sendAll = true})),
pipelineResultsSubscriber(
rootTable->GetProtobufTopic<PhotonPipelineResult>("result_proto")
.Subscribe(PhotonPipelineResult(),
{.periodic = 0.01, .sendAll = true})),
inputSaveImgEntry(
rootTable->GetIntegerTopic("inputSaveImgCmd").Publish()),
inputSaveImgSubscriber(
Expand Down Expand Up @@ -81,22 +81,12 @@ PhotonPipelineResult PhotonCamera::GetLatestResult() {
// Prints warning if not connected
VerifyVersion();

// Clear the current packet.
packet.Clear();

// Create the new result;
PhotonPipelineResult result;

// Fill the packet with latest data and populate result.
const auto value = rawBytesEntry.Get();
if (!value.size()) return result;

photonlib::Packet packet{value};

packet >> result;
PhotonPipelineResult result = pipelineResultsSubscriber.Get();

result.SetTimestamp(units::microsecond_t(rawBytesEntry.GetLastChange()) -
result.GetLatency());
result.SetTimestamp(
units::microsecond_t(pipelineResultsSubscriber.GetLastChange()) -
result.GetLatency());

return result;
}
Expand Down
Loading
Loading