mirror of
https://github.com/PhotonVision/photonvision
synced 2026-07-05 03:21:40 +00:00
Remove camera index in ui (#1677)
With the new camera matching, this is SUPER BAD! Convert to using camera uuid. --------- Co-authored-by: Matt <matthew.morley.ca@gmail.com>
This commit is contained in:
@@ -23,7 +23,7 @@ import org.photonvision.common.dataflow.DataChangeDestination;
|
||||
import org.photonvision.common.dataflow.DataChangeSource;
|
||||
|
||||
public class IncomingWebSocketEvent<T> extends DataChangeEvent<T> {
|
||||
public final Integer cameraIndex;
|
||||
public final String cameraUniqueName;
|
||||
public final WsContext originContext;
|
||||
|
||||
public IncomingWebSocketEvent(DataChangeDestination destType, String propertyName, T newValue) {
|
||||
@@ -34,10 +34,10 @@ public class IncomingWebSocketEvent<T> extends DataChangeEvent<T> {
|
||||
DataChangeDestination destType,
|
||||
String propertyName,
|
||||
T newValue,
|
||||
Integer cameraIndex,
|
||||
String cameraUniqueName,
|
||||
WsContext originContext) {
|
||||
super(DataChangeSource.DCS_WEBSOCKET, destType, propertyName, newValue);
|
||||
this.cameraIndex = cameraIndex;
|
||||
this.cameraUniqueName = cameraUniqueName;
|
||||
this.originContext = originContext;
|
||||
}
|
||||
|
||||
@@ -50,8 +50,8 @@ public class IncomingWebSocketEvent<T> extends DataChangeEvent<T> {
|
||||
@Override
|
||||
public String toString() {
|
||||
return "IncomingWebSocketEvent{"
|
||||
+ "cameraIndex="
|
||||
+ cameraIndex
|
||||
+ "cameraUniqueName="
|
||||
+ cameraUniqueName
|
||||
+ ", sourceType="
|
||||
+ sourceType
|
||||
+ ", destType="
|
||||
|
||||
@@ -22,14 +22,14 @@ import org.photonvision.common.hardware.HardwareManager;
|
||||
import org.photonvision.vision.pipeline.result.CVPipelineResult;
|
||||
|
||||
public class StatusLEDConsumer implements CVPipelineResultConsumer {
|
||||
private final int index;
|
||||
private final String uniqueName;
|
||||
|
||||
public StatusLEDConsumer(int index) {
|
||||
this.index = index;
|
||||
public StatusLEDConsumer(String uniqueName) {
|
||||
this.uniqueName = uniqueName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void accept(CVPipelineResult t) {
|
||||
HardwareManager.getInstance().setTargetsVisibleStatus(this.index, t.hasTargets());
|
||||
HardwareManager.getInstance().setTargetsVisibleStatus(this.uniqueName, t.hasTargets());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,11 +31,11 @@ import org.photonvision.vision.pipeline.result.CalibrationPipelineResult;
|
||||
public class UIDataPublisher implements CVPipelineResultConsumer {
|
||||
private static final Logger logger = new Logger(UIDataPublisher.class, LogGroup.VisionModule);
|
||||
|
||||
private final int index;
|
||||
private final String uniqueName;
|
||||
private long lastUIResultUpdateTime = 0;
|
||||
|
||||
public UIDataPublisher(int index) {
|
||||
this.index = index;
|
||||
public UIDataPublisher(String uniqueName) {
|
||||
this.uniqueName = uniqueName;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -74,8 +74,8 @@ public class UIDataPublisher implements CVPipelineResultConsumer {
|
||||
dataMap.put("multitagResult", multitagData);
|
||||
}
|
||||
|
||||
var uiMap = new HashMap<Integer, HashMap<String, Object>>();
|
||||
uiMap.put(index, dataMap);
|
||||
var uiMap = new HashMap<String, HashMap<String, Object>>();
|
||||
uiMap.put(uniqueName, dataMap);
|
||||
|
||||
DataChangeService.getInstance()
|
||||
.publishEvent(OutgoingUIEvent.wrappedOf("updatePipelineResult", uiMap));
|
||||
|
||||
@@ -167,13 +167,13 @@ public class HardwareManager {
|
||||
|
||||
// API's supporting status LEDs
|
||||
|
||||
private Map<Integer, Boolean> pipelineTargets = new HashMap<Integer, Boolean>();
|
||||
private Map<String, Boolean> pipelineTargets = new HashMap<String, Boolean>();
|
||||
private boolean ntConnected = false;
|
||||
private boolean systemRunning = false;
|
||||
private int blinkCounter = 0;
|
||||
|
||||
public void setTargetsVisibleStatus(int pipelineIdx, boolean hasTargets) {
|
||||
pipelineTargets.put(pipelineIdx, hasTargets);
|
||||
public void setTargetsVisibleStatus(String uniqueName, boolean hasTargets) {
|
||||
pipelineTargets.put(uniqueName, hasTargets);
|
||||
}
|
||||
|
||||
public void setNTConnected(boolean isConnected) {
|
||||
|
||||
@@ -80,7 +80,6 @@ public class VisionModule {
|
||||
private final NTDataPublisher ntConsumer;
|
||||
private final UIDataPublisher uiDataConsumer;
|
||||
private final StatusLEDConsumer statusLEDsConsumer;
|
||||
protected final int moduleIndex;
|
||||
protected final QuirkyCamera cameraQuirks;
|
||||
|
||||
protected TrackedTarget lastPipelineResultBestTarget;
|
||||
@@ -94,7 +93,7 @@ public class VisionModule {
|
||||
MJPGFrameConsumer inputVideoStreamer;
|
||||
MJPGFrameConsumer outputVideoStreamer;
|
||||
|
||||
public VisionModule(PipelineManager pipelineManager, VisionSource visionSource, int index) {
|
||||
public VisionModule(PipelineManager pipelineManager, VisionSource visionSource) {
|
||||
logger =
|
||||
new Logger(
|
||||
VisionModule.class,
|
||||
@@ -133,8 +132,6 @@ public class VisionModule {
|
||||
this.cameraQuirks,
|
||||
getChangeSubscriber());
|
||||
this.streamRunnable = new StreamRunnable(new OutputStreamPipeline());
|
||||
this.moduleIndex = index;
|
||||
|
||||
changeSubscriberHandle = DataChangeService.getInstance().addSubscriber(changeSubscriber);
|
||||
|
||||
createStreams();
|
||||
@@ -148,8 +145,9 @@ public class VisionModule {
|
||||
this::setPipeline,
|
||||
pipelineManager::getDriverMode,
|
||||
this::setDriverMode);
|
||||
uiDataConsumer = new UIDataPublisher(index);
|
||||
statusLEDsConsumer = new StatusLEDConsumer(index);
|
||||
uiDataConsumer = new UIDataPublisher(visionSource.getSettables().getConfiguration().uniqueName);
|
||||
statusLEDsConsumer =
|
||||
new StatusLEDConsumer(visionSource.getSettables().getConfiguration().uniqueName);
|
||||
addResultConsumer(ntConsumer);
|
||||
addResultConsumer(uiDataConsumer);
|
||||
addResultConsumer(statusLEDsConsumer);
|
||||
@@ -531,7 +529,6 @@ public class VisionModule {
|
||||
HashMap<String, Object> map = new HashMap<>();
|
||||
HashMap<String, Object> subMap = new HashMap<>();
|
||||
subMap.put(propertyName, value);
|
||||
map.put("cameraIndex", this.moduleIndex);
|
||||
map.put("mutatePipelineSettings", subMap);
|
||||
|
||||
DataChangeService.getInstance()
|
||||
|
||||
@@ -57,8 +57,8 @@ public class VisionModuleChangeSubscriber extends DataChangeSubscriber {
|
||||
public void onDataChangeEvent(DataChangeEvent<?> event) {
|
||||
if (event instanceof IncomingWebSocketEvent wsEvent) {
|
||||
// Camera index -1 means a "multicast event" (i.e. the event is received by all cameras)
|
||||
if (wsEvent.cameraIndex != null
|
||||
&& (wsEvent.cameraIndex == parentModule.moduleIndex || wsEvent.cameraIndex == -1)) {
|
||||
if (wsEvent.cameraUniqueName != null
|
||||
&& wsEvent.cameraUniqueName.equals(parentModule.uniqueName())) {
|
||||
logger.trace("Got PSC event - propName: " + wsEvent.propertyName);
|
||||
changeListLock.lock();
|
||||
try {
|
||||
|
||||
@@ -35,24 +35,18 @@ public class VisionModuleManager {
|
||||
return visionModules;
|
||||
}
|
||||
|
||||
public VisionModule getModule(String nickname) {
|
||||
public VisionModule getModule(String uniqueName) {
|
||||
for (var module : visionModules) {
|
||||
if (module.getStateAsCameraConfig().nickname.equals(nickname)) return module;
|
||||
if (module.getStateAsCameraConfig().uniqueName.equals(uniqueName)) return module;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public VisionModule getModule(int i) {
|
||||
return visionModules.get(i);
|
||||
}
|
||||
|
||||
public synchronized VisionModule addSource(VisionSource visionSource) {
|
||||
visionSource.cameraConfiguration.streamIndex = newCameraIndex();
|
||||
|
||||
var pipelineManager = new PipelineManager(visionSource.getCameraConfiguration());
|
||||
var module =
|
||||
new VisionModule(
|
||||
pipelineManager, visionSource, visionSource.cameraConfiguration.streamIndex);
|
||||
var module = new VisionModule(pipelineManager, visionSource);
|
||||
visionModules.add(module);
|
||||
|
||||
return module;
|
||||
|
||||
Reference in New Issue
Block a user