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
|
|
|
*
|
2023-04-18 18:49:40 -04:00
|
|
|
* Copyright (c) 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;
|
|
|
|
|
|
2023-02-13 17:57:01 -05:00
|
|
|
import edu.wpi.first.math.MatBuilder;
|
|
|
|
|
import edu.wpi.first.math.Matrix;
|
|
|
|
|
import edu.wpi.first.math.Nat;
|
|
|
|
|
import edu.wpi.first.math.numbers.*;
|
2022-12-16 17:05:23 -08:00
|
|
|
import edu.wpi.first.networktables.BooleanPublisher;
|
|
|
|
|
import edu.wpi.first.networktables.BooleanSubscriber;
|
|
|
|
|
import edu.wpi.first.networktables.DoubleArrayPublisher;
|
2023-02-13 17:57:01 -05:00
|
|
|
import edu.wpi.first.networktables.DoubleArraySubscriber;
|
2022-12-16 17:05:23 -08:00
|
|
|
import edu.wpi.first.networktables.DoublePublisher;
|
|
|
|
|
import edu.wpi.first.networktables.IntegerEntry;
|
2023-02-08 21:07:12 -05:00
|
|
|
import edu.wpi.first.networktables.IntegerPublisher;
|
2022-12-16 17:05:23 -08:00
|
|
|
import edu.wpi.first.networktables.IntegerSubscriber;
|
2023-01-05 19:28:32 -05:00
|
|
|
import edu.wpi.first.networktables.MultiSubscriber;
|
2021-01-16 20:41:47 -08:00
|
|
|
import edu.wpi.first.networktables.NetworkTable;
|
|
|
|
|
import edu.wpi.first.networktables.NetworkTableInstance;
|
2023-01-05 19:28:32 -05:00
|
|
|
import edu.wpi.first.networktables.PubSubOption;
|
2022-12-16 17:05:23 -08:00
|
|
|
import edu.wpi.first.networktables.RawSubscriber;
|
|
|
|
|
import edu.wpi.first.networktables.StringSubscriber;
|
2021-10-18 22:31:18 -04:00
|
|
|
import edu.wpi.first.wpilibj.DriverStation;
|
2022-10-21 20:53:28 -04:00
|
|
|
import edu.wpi.first.wpilibj.Timer;
|
2023-02-13 17:57:01 -05:00
|
|
|
import java.util.Optional;
|
2023-01-05 19:28:32 -05:00
|
|
|
import java.util.Set;
|
2021-01-16 20:41:47 -08:00
|
|
|
import org.photonvision.common.dataflow.structures.Packet;
|
|
|
|
|
import org.photonvision.common.hardware.VisionLEDMode;
|
|
|
|
|
import org.photonvision.targeting.PhotonPipelineResult;
|
|
|
|
|
|
|
|
|
|
/** Represents a camera that is connected to PhotonVision. */
|
|
|
|
|
public class PhotonCamera {
|
2023-01-05 19:28:32 -05:00
|
|
|
static final String kTableName = "photonvision";
|
|
|
|
|
|
2023-02-14 13:49:28 -05:00
|
|
|
protected final NetworkTable cameraTable;
|
2022-12-16 17:05:23 -08:00
|
|
|
RawSubscriber rawBytesEntry;
|
|
|
|
|
BooleanPublisher driverModePublisher;
|
|
|
|
|
BooleanSubscriber driverModeSubscriber;
|
|
|
|
|
DoublePublisher latencyMillisEntry;
|
|
|
|
|
BooleanPublisher hasTargetEntry;
|
|
|
|
|
DoublePublisher targetPitchEntry;
|
|
|
|
|
DoublePublisher targetYawEntry;
|
|
|
|
|
DoublePublisher targetAreaEntry;
|
|
|
|
|
DoubleArrayPublisher targetPoseEntry;
|
|
|
|
|
DoublePublisher targetSkewEntry;
|
|
|
|
|
StringSubscriber versionEntry;
|
2022-12-30 21:48:28 -06:00
|
|
|
IntegerEntry inputSaveImgEntry, outputSaveImgEntry;
|
2023-02-08 21:07:12 -05:00
|
|
|
IntegerPublisher pipelineIndexRequest, ledModeRequest;
|
|
|
|
|
IntegerSubscriber pipelineIndexState, ledModeState;
|
2022-12-16 17:05:23 -08:00
|
|
|
IntegerSubscriber heartbeatEntry;
|
2023-02-13 17:57:01 -05:00
|
|
|
private DoubleArraySubscriber cameraIntrinsicsSubscriber;
|
|
|
|
|
private DoubleArraySubscriber cameraDistortionSubscriber;
|
2022-12-16 17:05:23 -08:00
|
|
|
|
|
|
|
|
public void close() {
|
|
|
|
|
rawBytesEntry.close();
|
|
|
|
|
driverModePublisher.close();
|
|
|
|
|
driverModeSubscriber.close();
|
|
|
|
|
latencyMillisEntry.close();
|
|
|
|
|
hasTargetEntry.close();
|
|
|
|
|
targetPitchEntry.close();
|
|
|
|
|
targetYawEntry.close();
|
|
|
|
|
targetAreaEntry.close();
|
|
|
|
|
targetPoseEntry.close();
|
|
|
|
|
targetSkewEntry.close();
|
|
|
|
|
versionEntry.close();
|
|
|
|
|
inputSaveImgEntry.close();
|
|
|
|
|
outputSaveImgEntry.close();
|
2023-02-08 21:07:12 -05:00
|
|
|
pipelineIndexRequest.close();
|
|
|
|
|
pipelineIndexState.close();
|
|
|
|
|
ledModeRequest.close();
|
|
|
|
|
ledModeState.close();
|
|
|
|
|
pipelineIndexRequest.close();
|
2023-02-13 17:57:01 -05:00
|
|
|
cameraIntrinsicsSubscriber.close();
|
|
|
|
|
cameraDistortionSubscriber.close();
|
2022-12-16 17:05:23 -08:00
|
|
|
}
|
2021-01-16 20:41:47 -08:00
|
|
|
|
2021-10-18 22:31:18 -04:00
|
|
|
private final String path;
|
2022-12-25 07:01:57 +02:00
|
|
|
private final String name;
|
2021-01-16 20:41:47 -08:00
|
|
|
|
2022-02-28 07:37:52 -05:00
|
|
|
private static boolean VERSION_CHECK_ENABLED = true;
|
2022-12-16 17:05:23 -08:00
|
|
|
private static long VERSION_CHECK_INTERVAL = 5;
|
2022-10-21 20:53:28 -04:00
|
|
|
private double lastVersionCheckTime = 0;
|
2022-02-28 07:37:52 -05:00
|
|
|
|
2022-12-16 17:05:23 -08:00
|
|
|
private long prevHeartbeatValue = -1;
|
|
|
|
|
private double prevHeartbeatChangeTime = 0;
|
|
|
|
|
private static final double HEARBEAT_DEBOUNCE_SEC = 0.5;
|
|
|
|
|
|
2022-02-28 07:37:52 -05:00
|
|
|
public static void setVersionCheckEnabled(boolean enabled) {
|
|
|
|
|
VERSION_CHECK_ENABLED = enabled;
|
|
|
|
|
}
|
|
|
|
|
|
2021-01-16 20:41:47 -08:00
|
|
|
Packet packet = new Packet(1);
|
|
|
|
|
|
2023-01-05 19:28:32 -05:00
|
|
|
private final MultiSubscriber m_topicNameSubscriber;
|
|
|
|
|
|
2021-01-16 20:41:47 -08:00
|
|
|
/**
|
2022-01-10 11:56:45 -08:00
|
|
|
* Constructs a PhotonCamera from a root table.
|
|
|
|
|
*
|
2022-01-24 12:38:45 -05:00
|
|
|
* @param instance The NetworkTableInstance to pull data from. This can be a custom instance in
|
|
|
|
|
* simulation, but should *usually* be the default NTInstance from
|
|
|
|
|
* NetworkTableInstance::getDefault
|
|
|
|
|
* @param cameraName The name of the camera, as seen in the UI.
|
2022-01-10 11:56:45 -08:00
|
|
|
*/
|
2022-01-24 12:38:45 -05:00
|
|
|
public PhotonCamera(NetworkTableInstance instance, String cameraName) {
|
2022-12-25 07:01:57 +02:00
|
|
|
name = cameraName;
|
2023-02-14 13:49:28 -05:00
|
|
|
var photonvision_root_table = instance.getTable(kTableName);
|
|
|
|
|
this.cameraTable = photonvision_root_table.getSubTable(cameraName);
|
|
|
|
|
path = cameraTable.getPath();
|
2023-01-06 14:53:19 -08:00
|
|
|
rawBytesEntry =
|
2023-02-14 13:49:28 -05:00
|
|
|
cameraTable
|
2023-01-06 14:53:19 -08:00
|
|
|
.getRawTopic("rawBytes")
|
|
|
|
|
.subscribe(
|
|
|
|
|
"rawBytes", new byte[] {}, PubSubOption.periodic(0.01), PubSubOption.sendAll(true));
|
2023-02-17 06:21:10 -08:00
|
|
|
driverModePublisher = cameraTable.getBooleanTopic("driverModeRequest").publish();
|
|
|
|
|
driverModeSubscriber = cameraTable.getBooleanTopic("driverMode").subscribe(false);
|
2023-02-14 13:49:28 -05:00
|
|
|
inputSaveImgEntry = cameraTable.getIntegerTopic("inputSaveImgCmd").getEntry(0);
|
|
|
|
|
outputSaveImgEntry = cameraTable.getIntegerTopic("outputSaveImgCmd").getEntry(0);
|
|
|
|
|
pipelineIndexRequest = cameraTable.getIntegerTopic("pipelineIndexRequest").publish();
|
|
|
|
|
pipelineIndexState = cameraTable.getIntegerTopic("pipelineIndexState").subscribe(0);
|
|
|
|
|
heartbeatEntry = cameraTable.getIntegerTopic("heartbeat").subscribe(-1);
|
|
|
|
|
cameraIntrinsicsSubscriber =
|
|
|
|
|
cameraTable.getDoubleArrayTopic("cameraIntrinsics").subscribe(null);
|
|
|
|
|
cameraDistortionSubscriber =
|
|
|
|
|
cameraTable.getDoubleArrayTopic("cameraDistortion").subscribe(null);
|
|
|
|
|
|
|
|
|
|
ledModeRequest = photonvision_root_table.getIntegerTopic("ledModeRequest").publish();
|
|
|
|
|
ledModeState = photonvision_root_table.getIntegerTopic("ledModeState").subscribe(-1);
|
|
|
|
|
versionEntry = photonvision_root_table.getStringTopic("version").subscribe("");
|
2023-01-05 19:28:32 -05:00
|
|
|
|
|
|
|
|
m_topicNameSubscriber =
|
|
|
|
|
new MultiSubscriber(
|
|
|
|
|
instance,
|
|
|
|
|
new String[] {"/photonvision/"},
|
|
|
|
|
new PubSubOption[] {PubSubOption.topicsOnly(true)});
|
2021-01-16 20:41:47 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2022-01-10 11:56:45 -08:00
|
|
|
* Constructs a PhotonCamera from the name of the camera.
|
|
|
|
|
*
|
|
|
|
|
* @param cameraName The nickname of the camera (found in the PhotonVision UI).
|
|
|
|
|
*/
|
2021-01-16 20:41:47 -08:00
|
|
|
public PhotonCamera(String cameraName) {
|
2022-01-24 12:38:45 -05:00
|
|
|
this(NetworkTableInstance.getDefault(), cameraName);
|
2021-01-16 20:41:47 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2022-01-10 11:56:45 -08:00
|
|
|
* Returns the latest pipeline result.
|
|
|
|
|
*
|
|
|
|
|
* @return The latest pipeline result.
|
|
|
|
|
*/
|
2021-01-16 20:41:47 -08:00
|
|
|
public PhotonPipelineResult getLatestResult() {
|
2021-10-18 22:31:18 -04:00
|
|
|
verifyVersion();
|
|
|
|
|
|
2021-01-16 20:41:47 -08:00
|
|
|
// Clear the packet.
|
|
|
|
|
packet.clear();
|
|
|
|
|
|
|
|
|
|
// Create latest result.
|
|
|
|
|
var ret = new PhotonPipelineResult();
|
|
|
|
|
|
|
|
|
|
// Populate packet and create result.
|
2022-12-16 17:05:23 -08:00
|
|
|
packet.setData(rawBytesEntry.get(new byte[] {}));
|
2022-11-07 11:09:55 -07:00
|
|
|
|
2021-01-16 20:41:47 -08:00
|
|
|
if (packet.getSize() < 1) return ret;
|
|
|
|
|
ret.createFromPacket(packet);
|
|
|
|
|
|
2022-11-07 11:09:55 -07:00
|
|
|
// 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);
|
|
|
|
|
|
2021-01-16 20:41:47 -08:00
|
|
|
// Return result.
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2022-01-10 11:56:45 -08:00
|
|
|
* Returns whether the camera is in driver mode.
|
|
|
|
|
*
|
|
|
|
|
* @return Whether the camera is in driver mode.
|
|
|
|
|
*/
|
2021-01-16 20:41:47 -08:00
|
|
|
public boolean getDriverMode() {
|
2023-01-29 23:30:34 -05:00
|
|
|
return driverModeSubscriber.get();
|
2021-01-16 20:41:47 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2022-01-10 11:56:45 -08:00
|
|
|
* Toggles driver mode.
|
|
|
|
|
*
|
|
|
|
|
* @param driverMode Whether to set driver mode.
|
|
|
|
|
*/
|
2021-01-16 20:41:47 -08:00
|
|
|
public void setDriverMode(boolean driverMode) {
|
2023-01-29 23:30:34 -05:00
|
|
|
driverModePublisher.set(driverMode);
|
2021-01-16 20:41:47 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2022-01-10 11:56:45 -08:00
|
|
|
* Request the camera to save a new image file from the input camera stream with overlays. Images
|
|
|
|
|
* take up space in the filesystem of the PhotonCamera. Calling it frequently will fill up disk
|
|
|
|
|
* space and eventually cause the system to stop working. Clear out images in
|
|
|
|
|
* /opt/photonvision/photonvision_config/imgSaves frequently to prevent issues.
|
|
|
|
|
*/
|
2021-01-16 20:41:47 -08:00
|
|
|
public void takeInputSnapshot() {
|
2022-12-30 21:48:28 -06:00
|
|
|
inputSaveImgEntry.set(inputSaveImgEntry.get() + 1);
|
2021-01-16 20:41:47 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2022-01-10 11:56:45 -08:00
|
|
|
* Request the camera to save a new image file from the output stream with overlays. Images take
|
|
|
|
|
* up space in the filesystem of the PhotonCamera. Calling it frequently will fill up disk space
|
|
|
|
|
* and eventually cause the system to stop working. Clear out images in
|
|
|
|
|
* /opt/photonvision/photonvision_config/imgSaves frequently to prevent issues.
|
|
|
|
|
*/
|
2021-01-16 20:41:47 -08:00
|
|
|
public void takeOutputSnapshot() {
|
2022-12-30 21:48:28 -06:00
|
|
|
outputSaveImgEntry.set(outputSaveImgEntry.get() + 1);
|
2021-01-16 20:41:47 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2022-01-10 11:56:45 -08:00
|
|
|
* Returns the active pipeline index.
|
|
|
|
|
*
|
|
|
|
|
* @return The active pipeline index.
|
|
|
|
|
*/
|
2021-01-16 20:41:47 -08:00
|
|
|
public int getPipelineIndex() {
|
2023-02-08 21:07:12 -05:00
|
|
|
return (int) pipelineIndexState.get(0);
|
2021-01-16 20:41:47 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2022-01-10 11:56:45 -08:00
|
|
|
* Allows the user to select the active pipeline index.
|
|
|
|
|
*
|
|
|
|
|
* @param index The active pipeline index.
|
|
|
|
|
*/
|
2021-01-16 20:41:47 -08:00
|
|
|
public void setPipelineIndex(int index) {
|
2023-02-08 21:07:12 -05:00
|
|
|
pipelineIndexRequest.set(index);
|
2021-01-16 20:41:47 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2022-01-10 11:56:45 -08:00
|
|
|
* Returns the current LED mode.
|
|
|
|
|
*
|
|
|
|
|
* @return The current LED mode.
|
|
|
|
|
*/
|
2021-01-16 20:41:47 -08:00
|
|
|
public VisionLEDMode getLEDMode() {
|
2023-02-08 21:07:12 -05:00
|
|
|
int value = (int) ledModeState.get(-1);
|
2021-01-16 20:41:47 -08:00
|
|
|
switch (value) {
|
|
|
|
|
case 0:
|
2021-12-15 11:16:09 -06:00
|
|
|
return VisionLEDMode.kOff;
|
2021-01-16 20:41:47 -08:00
|
|
|
case 1:
|
2021-12-15 11:16:09 -06:00
|
|
|
return VisionLEDMode.kOn;
|
2021-01-16 20:41:47 -08:00
|
|
|
case 2:
|
2021-12-15 11:16:09 -06:00
|
|
|
return VisionLEDMode.kBlink;
|
2021-01-16 20:41:47 -08:00
|
|
|
case -1:
|
|
|
|
|
default:
|
2021-12-15 11:16:09 -06:00
|
|
|
return VisionLEDMode.kDefault;
|
2021-01-16 20:41:47 -08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2022-01-10 11:56:45 -08:00
|
|
|
* Sets the LED mode.
|
|
|
|
|
*
|
|
|
|
|
* @param led The mode to set to.
|
|
|
|
|
*/
|
2021-01-16 20:41:47 -08:00
|
|
|
public void setLED(VisionLEDMode led) {
|
2023-02-08 21:07:12 -05:00
|
|
|
ledModeRequest.set(led.value);
|
2021-01-16 20:41:47 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2022-01-10 11:56:45 -08:00
|
|
|
* Returns whether the latest target result has targets.
|
|
|
|
|
*
|
|
|
|
|
* <p>This method is deprecated; {@link PhotonPipelineResult#hasTargets()} should be used instead.
|
|
|
|
|
*
|
|
|
|
|
* @deprecated This method should be replaced with {@link PhotonPipelineResult#hasTargets()}
|
|
|
|
|
* @return Whether the latest target result has targets.
|
|
|
|
|
*/
|
2021-09-03 19:19:38 -07:00
|
|
|
@Deprecated
|
2021-01-16 20:41:47 -08:00
|
|
|
public boolean hasTargets() {
|
|
|
|
|
return getLatestResult().hasTargets();
|
|
|
|
|
}
|
2021-10-18 22:31:18 -04:00
|
|
|
|
2022-12-25 07:01:57 +02:00
|
|
|
/**
|
|
|
|
|
* Returns the name of the camera. This will return the same value that was given to the
|
|
|
|
|
* constructor as cameraName.
|
|
|
|
|
*
|
|
|
|
|
* @return The name of the camera.
|
|
|
|
|
*/
|
|
|
|
|
public String getName() {
|
|
|
|
|
return name;
|
|
|
|
|
}
|
|
|
|
|
|
2022-12-16 17:05:23 -08:00
|
|
|
/**
|
|
|
|
|
* Returns whether the camera is connected and actively returning new data. Connection status is
|
|
|
|
|
* debounced.
|
|
|
|
|
*
|
|
|
|
|
* @return True if the camera is actively sending frame data, false otherwise.
|
|
|
|
|
*/
|
|
|
|
|
public boolean isConnected() {
|
|
|
|
|
var curHeartbeat = heartbeatEntry.get();
|
|
|
|
|
var now = Timer.getFPGATimestamp();
|
|
|
|
|
|
|
|
|
|
if (curHeartbeat != prevHeartbeatValue) {
|
|
|
|
|
// New heartbeat value from the coprocessor
|
|
|
|
|
prevHeartbeatChangeTime = now;
|
|
|
|
|
prevHeartbeatValue = curHeartbeat;
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-05 19:28:32 -05:00
|
|
|
return (now - prevHeartbeatChangeTime) < HEARBEAT_DEBOUNCE_SEC;
|
2022-12-16 17:05:23 -08:00
|
|
|
}
|
|
|
|
|
|
2023-02-13 17:57:01 -05:00
|
|
|
public Optional<Matrix<N3, N3>> getCameraMatrix() {
|
|
|
|
|
var cameraMatrix = cameraIntrinsicsSubscriber.get();
|
|
|
|
|
if (cameraMatrix != null && cameraMatrix.length == 9) {
|
|
|
|
|
return Optional.of(new MatBuilder<>(Nat.N3(), Nat.N3()).fill(cameraMatrix));
|
|
|
|
|
} else return Optional.empty();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Optional<Matrix<N5, N1>> getDistCoeffs() {
|
|
|
|
|
var distCoeffs = cameraDistortionSubscriber.get();
|
|
|
|
|
if (distCoeffs != null && distCoeffs.length == 5) {
|
|
|
|
|
return Optional.of(new MatBuilder<>(Nat.N5(), Nat.N1()).fill(distCoeffs));
|
|
|
|
|
} else return Optional.empty();
|
|
|
|
|
}
|
|
|
|
|
|
2021-10-18 22:31:18 -04:00
|
|
|
private void verifyVersion() {
|
2022-02-28 07:37:52 -05:00
|
|
|
if (!VERSION_CHECK_ENABLED) return;
|
|
|
|
|
|
2022-10-21 20:53:28 -04:00
|
|
|
if ((Timer.getFPGATimestamp() - lastVersionCheckTime) < VERSION_CHECK_INTERVAL) return;
|
|
|
|
|
lastVersionCheckTime = Timer.getFPGATimestamp();
|
|
|
|
|
|
2022-12-16 17:05:23 -08:00
|
|
|
// Heartbeat entry is assumed to always be present. If it's not present, we
|
|
|
|
|
// assume that a camera with that name was never connected in the first place.
|
|
|
|
|
if (!heartbeatEntry.exists()) {
|
2023-02-14 13:49:28 -05:00
|
|
|
Set<String> cameraNames = cameraTable.getInstance().getTable(kTableName).getSubTables();
|
2023-01-05 19:28:32 -05:00
|
|
|
if (cameraNames.isEmpty()) {
|
|
|
|
|
DriverStation.reportError(
|
|
|
|
|
"Could not find any PhotonVision coprocessors on NetworkTables. Double check that PhotonVision is running, and that your camera is connected!",
|
|
|
|
|
false);
|
|
|
|
|
} else {
|
|
|
|
|
DriverStation.reportError(
|
|
|
|
|
"PhotonVision coprocessor at path "
|
|
|
|
|
+ path
|
|
|
|
|
+ " not found on NetworkTables. Double check that your camera names match!",
|
|
|
|
|
true);
|
|
|
|
|
DriverStation.reportError(
|
|
|
|
|
"Found the following PhotonVision cameras on NetworkTables:\n"
|
|
|
|
|
+ String.join("\n", cameraNames),
|
|
|
|
|
false);
|
|
|
|
|
}
|
2022-12-16 17:05:23 -08:00
|
|
|
}
|
|
|
|
|
// Check for connection status. Warn if disconnected.
|
2023-01-05 19:28:32 -05:00
|
|
|
else if (!isConnected()) {
|
2022-12-16 17:05:23 -08:00
|
|
|
DriverStation.reportWarning(
|
|
|
|
|
"PhotonVision coprocessor at path " + path + " is not sending new data.", true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Check for version. Warn if the versions aren't aligned.
|
|
|
|
|
String versionString = versionEntry.get("");
|
|
|
|
|
if (!versionString.equals("") && !PhotonVersion.versionMatches(versionString)) {
|
|
|
|
|
// Error on a verified version mismatch
|
|
|
|
|
// But stay silent otherwise
|
|
|
|
|
DriverStation.reportWarning(
|
2021-10-18 22:31:18 -04:00
|
|
|
"Photon version "
|
|
|
|
|
+ PhotonVersion.versionString
|
|
|
|
|
+ " does not match coprocessor version "
|
|
|
|
|
+ versionString
|
|
|
|
|
+ "!",
|
|
|
|
|
true);
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-01-16 20:41:47 -08:00
|
|
|
}
|