Package com.thunder.lib.auto
Class ThunderAutoProject
java.lang.Object
com.thunder.lib.auto.ThunderAutoProject
Represents a ThunderAuto project.
-
Constructor Summary
ConstructorsConstructorDescriptionDefault constructor.ThunderAutoProject(String projectPath) Loads a ThunderAuto project from the specified path. -
Method Summary
Modifier and TypeMethodDescriptionbooleanCheck if remote project updates from ThunderAuto are enabled (enabled by default).voidDisable remote project updates from ThunderAuto.booleanScans the deploy directory for a ThunderAuto project and loads the first one it finds.voidEnable remote project updates from ThunderAuto (enabled by default).getActionCommand(String actionName) Get an action command by name.getAutoMode(String autoModeName) Get an autonomous mode by name.Get the names of all autonomous modes in the project.getBooleanCondition(String conditionName) Get a registered boolean condition by name.Get the size of the configured field for the loaded project.Get the symmetry of the configured field for the loaded project.getName()Get the name of the loaded project.getSwitchCondition(String conditionName) Get a registered switch condition by name.getTrajectory(String trajectoryName) Get a trajectory by name.Get the names of all trajectories in the project.booleanCheck if an action with the given name exists in the project.booleanhasAutoMode(String autoModeName) Check if an autonomous mode with the given name exists.booleanhasTrajectory(String trajectoryName) Check if a trajectory with the given name exists.booleanisActionCommandRegistered(String actionName) Check if an action command with the given name is registered.booleanisBooleanConditionRegistered(String conditionName) Check if a boolean condition with the given name is registered.booleanisLoaded()Returns whether a project is successfully loaded.booleanisSwitchConditionRegistered(String conditionName) Check if a switch condition with the given name is registered.booleanLoads a ThunderAuto project from the specified path.voidregisterActionCommand(String actionName, Command command) Register an action command that is used in a trajectory or auto mode.voidregisterBooleanCondition(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.longregisterRemoteUpdateSubscriber(Runnable callback) Register a callback function to be called when the project is updated remotely from ThunderAuto.voidregisterSwitchCondition(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.voidsetRemoteUpdatesEnabled(boolean enabled) Set whether remote project updates from ThunderAuto are enabled (enabled by default).booleanunregisterRemoteUpdateSubscriber(long id) Unregister a previously registered remote update subscriber.
-
Constructor Details
-
ThunderAutoProject
public ThunderAutoProject()Default constructor. Creates an empty ThunderAuto project that is not loaded. -
ThunderAutoProject
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
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
Get the name of the loaded project.- Returns:
- The name of the loaded project, or an empty string if no project is loaded.
-
registerActionCommand
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
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
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
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
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
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
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
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
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
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
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
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
Get the names of all trajectories in the project.- Returns:
- A set of trajectory names.
-
getAutoMode
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
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
Get the names of all autonomous modes in the project.- Returns:
- A set of autonomous mode names.
-
getFieldSymmetry
Get the symmetry of the configured field for the loaded project.- Returns:
- The field symmetry.
-
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
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.
-