diff --git a/rio/src/main/java/org/teamtators/common/config/ConfigCommandStore.java b/rio/src/main/java/org/teamtators/common/config/ConfigCommandStore.java index 76437edb..d8be9aa3 100644 --- a/rio/src/main/java/org/teamtators/common/config/ConfigCommandStore.java +++ b/rio/src/main/java/org/teamtators/common/config/ConfigCommandStore.java @@ -102,12 +102,14 @@ public void createCommandsFromConfig(ObjectNode json) throws ConfigException { JsonNode config = json.get(command.getName()); configureCommand(command, config); } - for (int i = 0; i < 10; i++) { + boolean wasUpdated; + do { + wasUpdated = false; for (Map.Entry commandEntry : commandsMapCopy.entrySet()) { Command command = commandEntry.getValue(); - command.updateRequirements(); + wasUpdated = wasUpdated || command.updateRequirements(); } - } + } while (wasUpdated); } public void configureCommand(Command command, JsonNode config) throws ConfigException { diff --git a/rio/src/main/java/org/teamtators/common/scheduler/Command.java b/rio/src/main/java/org/teamtators/common/scheduler/Command.java index 02cc2b5d..f41674b9 100644 --- a/rio/src/main/java/org/teamtators/common/scheduler/Command.java +++ b/rio/src/main/java/org/teamtators/common/scheduler/Command.java @@ -105,8 +105,12 @@ public boolean doesRequire(Subsystem subsystem) { return requirements != null && requirements.contains(subsystem); } - public void updateRequirements() { - + /** + * Updates any requirements on this command to require all child commands + * @return If any requirements had to be added + */ + public boolean updateRequirements() { + return false; } private boolean isRequiring(Subsystem subsystem, CommandRunContext context) { diff --git a/rio/src/main/java/org/teamtators/common/scheduler/SequentialCommand.java b/rio/src/main/java/org/teamtators/common/scheduler/SequentialCommand.java index 2e9013b6..578098fb 100644 --- a/rio/src/main/java/org/teamtators/common/scheduler/SequentialCommand.java +++ b/rio/src/main/java/org/teamtators/common/scheduler/SequentialCommand.java @@ -76,13 +76,17 @@ private void updateValidStates() { } @Override - public void updateRequirements() { + public boolean updateRequirements() { // A sequential command requires all subsystems required by all child commands - sequence.forEach(run -> { - run.command.updateRequirements(); - if (run.command.getRequirements() != null) + boolean wasUpdated = false; + for (SequentialCommandRun run : sequence) { + wasUpdated = wasUpdated || run.command.updateRequirements(); + int lengthBefore = getRequirements().size(); + if (run.command.getRequirements() != null && !run.parallel) requiresAll(run.command.getRequirements()); - }); + wasUpdated = wasUpdated || (lengthBefore != getRequirements().size()); + } + return wasUpdated; } @Override diff --git a/rio/src/main/java/org/teamtators/levitator/commands/AutoSelector.java b/rio/src/main/java/org/teamtators/levitator/commands/AutoSelector.java index bf892113..594ce657 100644 --- a/rio/src/main/java/org/teamtators/levitator/commands/AutoSelector.java +++ b/rio/src/main/java/org/teamtators/levitator/commands/AutoSelector.java @@ -141,9 +141,9 @@ public void configure(Config config) { } @Override - public void updateRequirements() { + public boolean updateRequirements() { if (config == null) { - return; + return false; } List commandNames = new ArrayList<>(); if (config.type == SelectorType.FIELD_CONFIGURATION) { @@ -156,6 +156,7 @@ public void updateRequirements() { } else { logger.error("Invalid selector type: " + config.type); } + boolean wasUpdated = false; for (String commandName : commandNames) { Command command; try { @@ -163,8 +164,11 @@ public void updateRequirements() { } catch (IllegalArgumentException e) { continue; } + int lengthBefore = getRequirements().size(); requiresAll(command.getRequirements()); + wasUpdated = wasUpdated || (lengthBefore != getRequirements().size()); } + return wasUpdated; } public enum SelectorType {