mirror of
https://github.com/PhotonVision/photonvision
synced 2026-06-25 01:41:40 +00:00
Set default pipeline idx in PipelineManager constructor (#1286)
Addresses #1285
This commit is contained in:
@@ -13,11 +13,7 @@ defineProps<{
|
||||
|
||||
const driverMode = computed<boolean>({
|
||||
get: () => useCameraSettingsStore().isDriverMode,
|
||||
set: (v) =>
|
||||
useCameraSettingsStore().changeCurrentPipelineIndex(
|
||||
v ? -1 : useCameraSettingsStore().currentCameraSettings.lastPipelineIndex || 0,
|
||||
true
|
||||
)
|
||||
set: (v) => useCameraSettingsStore().setDriverMode(v)
|
||||
});
|
||||
|
||||
const fpsTooLow = computed<boolean>(() => {
|
||||
|
||||
@@ -236,6 +236,13 @@ export const useCameraSettingsStore = defineStore("cameraSettings", {
|
||||
}
|
||||
useStateStore().websocket?.send(payload, true);
|
||||
},
|
||||
setDriverMode(isDriverMode: boolean, cameraIndex: number = useStateStore().currentCameraIndex) {
|
||||
const payload = {
|
||||
driverMode: isDriverMode,
|
||||
cameraIndex: cameraIndex
|
||||
};
|
||||
useStateStore().websocket?.send(payload, true);
|
||||
},
|
||||
/**
|
||||
* Change the currently selected pipeline of the provided camera.
|
||||
*
|
||||
|
||||
@@ -61,7 +61,8 @@ public class PipelineManager {
|
||||
PipelineManager(
|
||||
DriverModePipelineSettings driverSettings,
|
||||
List<CVPipelineSettings> userPipelines,
|
||||
String uniqueName) {
|
||||
String uniqueName,
|
||||
int defaultIndex) {
|
||||
this.userPipelineSettings = new ArrayList<>(userPipelines);
|
||||
// This is to respect the default res idx for vendor cameras
|
||||
|
||||
@@ -70,10 +71,19 @@ public class PipelineManager {
|
||||
if (userPipelines.isEmpty()) addPipeline(PipelineType.Reflective);
|
||||
|
||||
calibration3dPipeline = new Calibrate3dPipeline(uniqueName);
|
||||
|
||||
// We know that at this stage, VisionRunner hasn't yet started so we're good to do this from
|
||||
// this thread
|
||||
this.setIndex(defaultIndex);
|
||||
updatePipelineFromRequested();
|
||||
}
|
||||
|
||||
public PipelineManager(CameraConfiguration config) {
|
||||
this(config.driveModeSettings, config.pipelineSettings, config.uniqueName);
|
||||
this(
|
||||
config.driveModeSettings,
|
||||
config.pipelineSettings,
|
||||
config.uniqueName,
|
||||
config.currentPipelineIndex);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -173,6 +183,14 @@ public class PipelineManager {
|
||||
|
||||
private volatile int requestedIndex = 0;
|
||||
|
||||
/**
|
||||
* Grab the currently requested pipeline index. The VisionRunner may not have changed over to this
|
||||
* pipeline yet.
|
||||
*/
|
||||
public int getRequestedIndex() {
|
||||
return requestedIndex;
|
||||
}
|
||||
|
||||
/**
|
||||
* Internal method for setting the active pipeline. <br>
|
||||
* <br>
|
||||
|
||||
@@ -143,7 +143,7 @@ public class VisionModule {
|
||||
ntConsumer =
|
||||
new NTDataPublisher(
|
||||
visionSource.getSettables().getConfiguration().nickname,
|
||||
pipelineManager::getCurrentPipelineIndex,
|
||||
pipelineManager::getRequestedIndex,
|
||||
this::setPipeline,
|
||||
pipelineManager::getDriverMode,
|
||||
this::setDriverMode);
|
||||
@@ -156,6 +156,7 @@ public class VisionModule {
|
||||
(result) ->
|
||||
lastPipelineResultBestTarget = result.hasTargets() ? result.targets.get(0) : null);
|
||||
|
||||
// Sync VisionModule state with the first pipeline index
|
||||
setPipeline(visionSource.getSettables().getConfiguration().currentPipelineIndex);
|
||||
|
||||
// Set vendor FOV
|
||||
@@ -321,7 +322,7 @@ public class VisionModule {
|
||||
|
||||
void changePipelineType(int newType) {
|
||||
pipelineManager.changePipelineType(newType);
|
||||
setPipeline(pipelineManager.getCurrentPipelineIndex());
|
||||
setPipeline(pipelineManager.getRequestedIndex());
|
||||
saveAndBroadcastAll();
|
||||
}
|
||||
|
||||
@@ -329,9 +330,7 @@ public class VisionModule {
|
||||
pipelineManager.setDriverMode(isDriverMode);
|
||||
setVisionLEDs(!isDriverMode);
|
||||
setPipeline(
|
||||
isDriverMode
|
||||
? PipelineManager.DRIVERMODE_INDEX
|
||||
: pipelineManager.getCurrentPipelineIndex());
|
||||
isDriverMode ? PipelineManager.DRIVERMODE_INDEX : pipelineManager.getRequestedIndex());
|
||||
saveAndBroadcastAll();
|
||||
}
|
||||
|
||||
@@ -385,7 +384,7 @@ public class VisionModule {
|
||||
var ret = pipelineManager.calibration3dPipeline.tryCalibration();
|
||||
pipelineManager.setCalibrationMode(false);
|
||||
|
||||
setPipeline(pipelineManager.getCurrentPipelineIndex());
|
||||
setPipeline(pipelineManager.getRequestedIndex());
|
||||
|
||||
if (ret != null) {
|
||||
logger.debug("Saving calibration...");
|
||||
@@ -447,7 +446,7 @@ public class VisionModule {
|
||||
setVisionLEDs(pipelineSettings.ledMode);
|
||||
|
||||
visionSource.getSettables().getConfiguration().currentPipelineIndex =
|
||||
pipelineManager.getCurrentPipelineIndex();
|
||||
pipelineManager.getRequestedIndex();
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -511,7 +510,7 @@ public class VisionModule {
|
||||
ret.uniqueName = visionSource.getSettables().getConfiguration().uniqueName;
|
||||
ret.currentPipelineSettings =
|
||||
SerializationUtils.objectToHashMap(pipelineManager.getCurrentPipelineSettings());
|
||||
ret.currentPipelineIndex = pipelineManager.getCurrentPipelineIndex();
|
||||
ret.currentPipelineIndex = pipelineManager.getRequestedIndex();
|
||||
ret.pipelineNicknames = pipelineManager.getPipelineNicknames();
|
||||
ret.cameraQuirks = visionSource.getSettables().getConfiguration().cameraQuirks;
|
||||
|
||||
@@ -553,7 +552,7 @@ public class VisionModule {
|
||||
var config = visionSource.getSettables().getConfiguration();
|
||||
config.setPipelineSettings(pipelineManager.userPipelineSettings);
|
||||
config.driveModeSettings = pipelineManager.driverModePipeline.getSettings();
|
||||
config.currentPipelineIndex = Math.max(pipelineManager.getCurrentPipelineIndex(), -1);
|
||||
config.currentPipelineIndex = Math.max(pipelineManager.getRequestedIndex(), -1);
|
||||
|
||||
return config;
|
||||
}
|
||||
|
||||
@@ -88,7 +88,7 @@ public class VisionModuleChangeSubscriber extends DataChangeSubscriber {
|
||||
parentModule.saveAndBroadcastAll();
|
||||
return;
|
||||
case "deleteCurrPipeline":
|
||||
var indexToDelete = parentModule.pipelineManager.getCurrentPipelineIndex();
|
||||
var indexToDelete = parentModule.pipelineManager.getRequestedIndex();
|
||||
logger.info("Deleting current pipe at index " + indexToDelete);
|
||||
int newIndex = parentModule.pipelineManager.removePipeline(indexToDelete);
|
||||
parentModule.setPipeline(newIndex);
|
||||
@@ -96,7 +96,7 @@ public class VisionModuleChangeSubscriber extends DataChangeSubscriber {
|
||||
return;
|
||||
case "changePipeline": // change active pipeline
|
||||
var index = (Integer) newPropValue;
|
||||
if (index == parentModule.pipelineManager.getCurrentPipelineIndex()) {
|
||||
if (index == parentModule.pipelineManager.getRequestedIndex()) {
|
||||
logger.debug("Skipping pipeline change, index " + index + " already active");
|
||||
return;
|
||||
}
|
||||
@@ -181,6 +181,9 @@ public class VisionModuleChangeSubscriber extends DataChangeSubscriber {
|
||||
parentModule.changePipelineType((Integer) newPropValue);
|
||||
parentModule.saveAndBroadcastAll();
|
||||
return;
|
||||
case "isDriverMode":
|
||||
parentModule.setDriverMode((Boolean) newPropValue);
|
||||
return;
|
||||
}
|
||||
|
||||
// special case for camera settables
|
||||
|
||||
@@ -30,7 +30,7 @@ public class PipelineManagerTest {
|
||||
public void testUniqueName() {
|
||||
TestUtils.loadLibraries();
|
||||
PipelineManager manager =
|
||||
new PipelineManager(new DriverModePipelineSettings(), List.of(), "meme_name");
|
||||
new PipelineManager(new DriverModePipelineSettings(), List.of(), "meme_name", -1);
|
||||
manager.addPipeline(PipelineType.Reflective, "Another");
|
||||
|
||||
// We now have ["New Pipeline", "Another"]
|
||||
|
||||
@@ -131,18 +131,16 @@ public class DataSocketHandler {
|
||||
case SMT_DRIVERMODE:
|
||||
{
|
||||
// TODO: what is this event?
|
||||
var data = (HashMap<String, Object>) entryValue;
|
||||
var dmExpEvent =
|
||||
new IncomingWebSocketEvent<Integer>(
|
||||
DataChangeDestination.DCD_ACTIVEMODULE, "driverExposure", data);
|
||||
var dmBrightEvent =
|
||||
new IncomingWebSocketEvent<Integer>(
|
||||
DataChangeDestination.DCD_ACTIVEMODULE, "driverBrightness", data);
|
||||
var data = (Boolean) entryValue;
|
||||
var dmIsDriverEvent =
|
||||
new IncomingWebSocketEvent<Boolean>(
|
||||
DataChangeDestination.DCD_ACTIVEMODULE, "isDriver", data);
|
||||
DataChangeDestination.DCD_ACTIVEMODULE,
|
||||
"isDriverMode",
|
||||
data,
|
||||
cameraIndex,
|
||||
context);
|
||||
|
||||
dcService.publishEvents(dmExpEvent, dmBrightEvent, dmIsDriverEvent);
|
||||
dcService.publishEvents(dmIsDriverEvent);
|
||||
break;
|
||||
}
|
||||
case SMT_CHANGECAMERANAME:
|
||||
|
||||
Reference in New Issue
Block a user