mirror of
https://github.com/PhotonVision/photonvision
synced 2026-06-22 01:11:40 +00:00
Create timesync JNI for testing client (#1433)
This commit is contained in:
@@ -22,24 +22,30 @@ import org.photonvision.struct.PhotonPipelineMetadataSerde;
|
||||
import org.photonvision.targeting.serde.PhotonStructSerializable;
|
||||
|
||||
public class PhotonPipelineMetadata implements PhotonStructSerializable<PhotonPipelineMetadata> {
|
||||
// Mirror of the heartbeat entry -- monotonically increasing
|
||||
public long sequenceID;
|
||||
|
||||
// Image capture and NT publish timestamp, in microseconds and in the
|
||||
// coprocessor timebase. As
|
||||
// reported by WPIUtilJNI::now.
|
||||
// Image capture and NT publish timestamp, in microseconds
|
||||
// The timebase is nt::Now on the time sync server
|
||||
public long captureTimestampMicros;
|
||||
public long publishTimestampMicros;
|
||||
|
||||
// Mirror of the heartbeat entry -- monotonically increasing
|
||||
public long sequenceID;
|
||||
|
||||
// Time from last Time Sync Pong received and the construction of this metadata
|
||||
public long timeSinceLastPong;
|
||||
|
||||
public PhotonPipelineMetadata(
|
||||
long captureTimestampMicros, long publishTimestampMicros, long sequenceID) {
|
||||
long captureTimestampMicros,
|
||||
long publishTimestampMicros,
|
||||
long sequenceID,
|
||||
long timeSinceLastPong) {
|
||||
this.captureTimestampMicros = captureTimestampMicros;
|
||||
this.publishTimestampMicros = publishTimestampMicros;
|
||||
this.sequenceID = sequenceID;
|
||||
this.timeSinceLastPong = timeSinceLastPong;
|
||||
}
|
||||
|
||||
public PhotonPipelineMetadata() {
|
||||
this(-1, -1, -1);
|
||||
this(-1, -1, -1, Long.MAX_VALUE);
|
||||
}
|
||||
|
||||
/** Returns the time between image capture and publish to NT */
|
||||
|
||||
@@ -40,9 +40,6 @@ public class PhotonPipelineResult
|
||||
// Multi-tag result
|
||||
public Optional<MultiTargetPNPResult> multitagResult;
|
||||
|
||||
// HACK: Since we don't trust NT time sync, keep track of when we got this packet into robot code
|
||||
public long ntReceiveTimestampMicros = -1;
|
||||
|
||||
/** Constructs an empty pipeline result. */
|
||||
public PhotonPipelineResult() {
|
||||
this(new PhotonPipelineMetadata(), List.of(), Optional.empty());
|
||||
@@ -52,19 +49,21 @@ public class PhotonPipelineResult
|
||||
* Constructs a pipeline result.
|
||||
*
|
||||
* @param sequenceID The number of frames processed by this camera since boot
|
||||
* @param captureTimestamp The time, in uS in the coprocessor's timebase, that the coprocessor
|
||||
* captured the image this result contains the targeting info of
|
||||
* @param publishTimestamp The time, in uS in the coprocessor's timebase, that the coprocessor
|
||||
* published targeting info
|
||||
* @param captureTimestampMicros The time, in uS in the coprocessor's timebase, that the
|
||||
* coprocessor captured the image this result contains the targeting info of
|
||||
* @param publishTimestampMicros The time, in uS in the coprocessor's timebase, that the
|
||||
* coprocessor published targeting info
|
||||
* @param targets The list of targets identified by the pipeline.
|
||||
*/
|
||||
public PhotonPipelineResult(
|
||||
long sequenceID,
|
||||
long captureTimestamp,
|
||||
long publishTimestamp,
|
||||
long captureTimestampMicros,
|
||||
long publishTimestampMicros,
|
||||
long timeSinceLastPong,
|
||||
List<PhotonTrackedTarget> targets) {
|
||||
this(
|
||||
new PhotonPipelineMetadata(captureTimestamp, publishTimestamp, sequenceID),
|
||||
new PhotonPipelineMetadata(
|
||||
captureTimestampMicros, publishTimestampMicros, sequenceID, timeSinceLastPong),
|
||||
targets,
|
||||
Optional.empty());
|
||||
}
|
||||
@@ -84,10 +83,12 @@ public class PhotonPipelineResult
|
||||
long sequenceID,
|
||||
long captureTimestamp,
|
||||
long publishTimestamp,
|
||||
long timeSinceLastPong,
|
||||
List<PhotonTrackedTarget> targets,
|
||||
Optional<MultiTargetPNPResult> result) {
|
||||
this(
|
||||
new PhotonPipelineMetadata(captureTimestamp, publishTimestamp, sequenceID),
|
||||
new PhotonPipelineMetadata(
|
||||
captureTimestamp, publishTimestamp, sequenceID, timeSinceLastPong),
|
||||
targets,
|
||||
result);
|
||||
}
|
||||
@@ -162,26 +163,14 @@ public class PhotonPipelineResult
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the estimated time the frame was taken, in the Received system's time base. This is
|
||||
* calculated as (NT Receive time (robot base) - (publish timestamp, coproc timebase - capture
|
||||
* timestamp, coproc timebase))
|
||||
* Returns the estimated time the frame was taken, in the Time Sync Server's time base (nt::Now).
|
||||
* This is calculated using the estiamted offset between Time Sync Server time and local time. The
|
||||
* robot shall run a server, so the offset shall be 0.
|
||||
*
|
||||
* @return The timestamp in seconds
|
||||
*/
|
||||
public double getTimestampSeconds() {
|
||||
return (ntReceiveTimestampMicros
|
||||
- (metadata.publishTimestampMicros - metadata.captureTimestampMicros))
|
||||
/ 1e6;
|
||||
}
|
||||
|
||||
/** The time that the robot Received this result, in the FPGA timebase. */
|
||||
public long getNtReceiveTimestampMicros() {
|
||||
return ntReceiveTimestampMicros;
|
||||
}
|
||||
|
||||
/** Sets the FPGA timestamp this result was Received by robot code */
|
||||
public void setReceiveTimestampMicros(long timestampMicros) {
|
||||
this.ntReceiveTimestampMicros = timestampMicros;
|
||||
return metadata.captureTimestampMicros / 1e6;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -192,8 +181,6 @@ public class PhotonPipelineResult
|
||||
+ targets
|
||||
+ ", multitagResult="
|
||||
+ multitagResult
|
||||
+ ", ntReceiveTimestampMicros="
|
||||
+ ntReceiveTimestampMicros
|
||||
+ "]";
|
||||
}
|
||||
|
||||
@@ -204,7 +191,6 @@ public class PhotonPipelineResult
|
||||
result = prime * result + ((metadata == null) ? 0 : metadata.hashCode());
|
||||
result = prime * result + ((targets == null) ? 0 : targets.hashCode());
|
||||
result = prime * result + ((multitagResult == null) ? 0 : multitagResult.hashCode());
|
||||
result = prime * result + (int) (ntReceiveTimestampMicros ^ (ntReceiveTimestampMicros >>> 32));
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -223,7 +209,6 @@ public class PhotonPipelineResult
|
||||
if (multitagResult == null) {
|
||||
if (other.multitagResult != null) return false;
|
||||
} else if (!multitagResult.equals(other.multitagResult)) return false;
|
||||
if (ntReceiveTimestampMicros != other.ntReceiveTimestampMicros) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -48,6 +48,7 @@ public class PhotonPipelineResultProto
|
||||
msg.getSequenceId(),
|
||||
msg.getCaptureTimestampMicros(),
|
||||
msg.getNtPublishTimestampMicros(),
|
||||
msg.getTimeSinceLastPongMicros(),
|
||||
PhotonTrackedTarget.proto.unpack(msg.getTargets()),
|
||||
msg.hasMultiTargetResult()
|
||||
? Optional.of(MultiTargetPNPResult.proto.unpack(msg.getMultiTargetResult()))
|
||||
|
||||
Reference in New Issue
Block a user