Class ThunderAutoProject

java.lang.Object
com.thunder.lib.auto.ThunderAutoProject

public class ThunderAutoProject extends Object
Represents a ThunderAuto project.
  • Constructor Details

    • ThunderAutoProject

      public ThunderAutoProject()
      Default constructor. Creates an empty ThunderAuto project that is not loaded.
    • ThunderAutoProject

      public ThunderAutoProject(String projectPath)
      Loads a ThunderAuto project from the specified path.
      Parameters:
      projectPath - The path to the ThunderAuto project. If an absolute path is provided, it will be used as-is. If a relative path is provided, it will be considered relative to the deploy directory.
  • Method Details

    • load

      public boolean load(String projectPath)
      Loads a ThunderAuto project from the specified path.
      Parameters:
      projectPath - The path to the ThunderAuto project. If an absolute path is provided, it will be used as-is. If a relative path is provided, it will be considered relative to the deploy directory.
      Returns:
      True if the project was successfully loaded, false otherwise.
    • discoverAndLoadFromDeployDirectory

      public boolean discoverAndLoadFromDeployDirectory()
      Scans the deploy directory for a ThunderAuto project and loads the first one it finds.
      Returns:
      True if a project was found and loaded, false otherwise.
    • isLoaded

      public boolean isLoaded()
      Returns whether a project is successfully loaded.
      Returns:
      True if a project is loaded, false otherwise.
    • getName

      public String getName()
      Get the name of the loaded project.
      Returns:
      The name of the loaded project, or an empty string if no project is loaded.
    • registerActionCommand

      public void registerActionCommand(String actionName, Command command)
      Register an action command that is used in a trajectory or auto mode. If an action is already registered with the same name, it will be replaced. If an action referenced during the execution of a trajectory or auto mode is not found, nothing will be executed.
      Parameters:
      actionName - The name of the action.
      command - The command to be executed when the action is called.
    • isActionCommandRegistered

      public boolean isActionCommandRegistered(String actionName)
      Check if an action command with the given name is registered.
      Parameters:
      actionName - The name of the action to check.
      Returns:
      True if the action command is registered, false otherwise.
    • hasAction

      public boolean hasAction(String actionName)
      Check if an action with the given name exists in the project. Note: This function has nothing to do with registered action commands, it is simply checking the existence of an action in the project.
      Parameters:
      actionName - The name of the action to check.
      Returns:
      True if the action exists, false otherwise.
    • getActionCommand

      public Command getActionCommand(String actionName)
      Get an action command by name. If the action name references an action group defined in the project, the corresponding command group will be constructed and returned. If the action name references an action command that has been registered via registerActionCommand(), the registered command will be returned. If the action name does not reference a valid action group in the project or a registered command, a None command will be returned.
      Parameters:
      actionName - The name of the action to get.
      Returns:
      A CommandPtr representing the action command, or a none command if not found.
    • registerBooleanCondition

      public void registerBooleanCondition(String conditionName, BooleanSupplier condition)
      Register a boolean condition that is used during a branch step in an auto mode to determine the next step to run. If a condition is already registered with the same name, it will be replaced. If a condition that is referenced during the execution of an auto mode is not found, the auto mode will stop executing and an error will be logged.
      Parameters:
      conditionName - The name of the condition.
      condition - The function that returns a boolean indicating the next step to run.
    • isBooleanConditionRegistered

      public boolean isBooleanConditionRegistered(String conditionName)
      Check if a boolean condition with the given name is registered.
      Parameters:
      conditionName - The name of the condition to check.
      Returns:
      True if the boolean condition is registered, false otherwise.
    • getBooleanCondition

      public Optional<BooleanSupplier> getBooleanCondition(String conditionName)
      Get a registered boolean condition by name.
      Parameters:
      conditionName - The name of the condition to get.
      Returns:
      The boolean condition function, or an empty optional if not found.
    • registerSwitchCondition

      public void registerSwitchCondition(String conditionName, IntSupplier condition)
      Register a switch condition that is used during a branch step in an auto mode to determine the next step to run. If a condition is already registered with the same name, it will be replaced. If a condition that is referenced during the execution of an auto mode is not found, the auto mode will stop executing and an error will be logged.
      Parameters:
      conditionName - The name of the condition.
      condition - The function that returns an integer indicating the next step to run.
    • isSwitchConditionRegistered

      public boolean isSwitchConditionRegistered(String conditionName)
      Check if a switch condition with the given name is registered.
      Parameters:
      conditionName - The name of the condition to check.
      Returns:
      True if the switch condition is registered, false otherwise.
    • getSwitchCondition

      public Optional<IntSupplier> getSwitchCondition(String conditionName)
      Get a registered switch condition by name.
      Parameters:
      conditionName - The name of the condition to get.
      Returns:
      The switch condition function, or an empty optional if not found.
    • getTrajectory

      public Optional<ThunderAutoTrajectory> getTrajectory(String trajectoryName)
      Get a trajectory by name.
      Parameters:
      trajectoryName - The name of the trajectory to get.
      Returns:
      The trajectory if it exists, or an empty optional if it does not.
    • hasTrajectory

      public boolean hasTrajectory(String trajectoryName)
      Check if a trajectory with the given name exists.
      Parameters:
      trajectoryName - The name of the trajectory to check.
      Returns:
      True if the trajectory exists, false otherwise.
    • getTrajectoryNames

      public HashSet<String> getTrajectoryNames()
      Get the names of all trajectories in the project.
      Returns:
      A set of trajectory names.
    • getAutoMode

      public Optional<ThunderAutoMode> getAutoMode(String autoModeName)
      Get an autonomous mode by name.
      Parameters:
      autoModeName - The name of the autonomous mode to get.
      Returns:
      A ThunderAutoMode if it exists, or an empty optional if it does not.
    • hasAutoMode

      public boolean hasAutoMode(String autoModeName)
      Check if an autonomous mode with the given name exists.
      Parameters:
      autoModeName - The name of the autonomous mode to check.
      Returns:
      True if the autonomous mode exists, false otherwise.
    • getAutoModeNames

      public HashSet<String> getAutoModeNames()
      Get the names of all autonomous modes in the project.
      Returns:
      A set of autonomous mode names.
    • getFieldSymmetry

      public FieldSymmetry getFieldSymmetry()
      Get the symmetry of the configured field for the loaded project.
      Returns:
      The field symmetry.
    • getFieldDimensions

      public FieldDimensions getFieldDimensions()
      Get the size of the configured field for the loaded project.
      Returns:
      The field size.
    • setRemoteUpdatesEnabled

      public void setRemoteUpdatesEnabled(boolean enabled)
      Set whether remote project updates from ThunderAuto are enabled (enabled by default). Remote updates will only occur only when the robot is in Disabled mode and FMS is not connected.
      Parameters:
      enabled - True to enable remote updates, false to disable them.
    • enableRemoteUpdates

      public void enableRemoteUpdates()
      Enable remote project updates from ThunderAuto (enabled by default).
    • disableRemoteUpdates

      public void disableRemoteUpdates()
      Disable remote project updates from ThunderAuto.
    • areRemoteUpdatesEnabled

      public boolean areRemoteUpdatesEnabled()
      Check if remote project updates from ThunderAuto are enabled (enabled by default).
      Returns:
      True if remote updates are enabled, false otherwise.
    • registerRemoteUpdateSubscriber

      public long registerRemoteUpdateSubscriber(Runnable callback)
      Register a callback function to be called when the project is updated remotely from ThunderAuto.
      Parameters:
      callback - The callback runnable to register.
      Returns:
      A subscriber ID that can be used to unregister the callback, or 0 on failure.
    • unregisterRemoteUpdateSubscriber

      public boolean unregisterRemoteUpdateSubscriber(long id)
      Unregister a previously registered remote update subscriber.
      Parameters:
      id - The subscriber ID returned by registerRemoteUpdateSubscriber().
      Returns:
      True if the subscriber was successfully unregistered, false otherwise.