ThunderLib
Loading...
Searching...
No Matches
thunder::ThunderAutoProject Class Referencefinal

Public Types

using BooleanConditionFunc = std::function<bool()>
 
using SwitchConditionFunc = std::function<int()>
 
using RemoteUpdateCallbackFunc = std::function<void()>
 
using RemoteUpdateSubscriberID = size_t
 

Public Member Functions

 ThunderAutoProject () noexcept
 
 ThunderAutoProject (const std::filesystem::path &projectPath) noexcept
 
bool load (const std::filesystem::path &projectPath) noexcept
 
bool discoverAndLoadFromDeployDirectory () noexcept
 
bool isLoaded () const noexcept
 
 operator bool () const noexcept
 
std::string getName () const noexcept
 
void registerActionCommand (const std::string &actionName, frc2::CommandPtr command)
 
void registerActionCommand (const std::string &actionName, std::shared_ptr< frc2::Command > command)
 
bool isActionCommandRegistered (const std::string &actionName) const noexcept
 
bool hasAction (const std::string &actionName) const noexcept
 
frc2::CommandPtr getActionCommand (const std::string &actionName) const noexcept
 
void registerBooleanCondition (const std::string &conditionName, BooleanConditionFunc condition)
 
bool isBooleanConditionRegistered (const std::string &conditionName) const noexcept
 
BooleanConditionFunc getBooleanCondition (const std::string &conditionName) const noexcept
 
void registerSwitchCondition (const std::string &conditionName, SwitchConditionFunc condition)
 
bool isSwitchConditionRegistered (const std::string &conditionName) const noexcept
 
SwitchConditionFunc getSwitchCondition (const std::string &conditionName) const noexcept
 
std::unique_ptr< ThunderAutoTrajectorygetTrajectory (const std::string &trajectoryName) const noexcept
 
bool hasTrajectory (const std::string &trajectoryName) const noexcept
 
std::unordered_set< std::string > getTrajectoryNames () const noexcept
 
std::unique_ptr< ThunderAutoModegetAutoMode (const std::string &autoModeName) const noexcept
 
bool hasAutoMode (const std::string &autoModeName) const noexcept
 
std::unordered_set< std::string > getAutoModeNames () const noexcept
 
FieldSymmetry getFieldSymmetry () const noexcept
 
FieldDimensions getFieldDimensions () const noexcept
 
void setRemoteUpdatesEnabled (bool enabled) noexcept
 
void enableRemoteUpdates () noexcept
 
void disableRemoteUpdates () noexcept
 
bool areRemoteUpdatesEnabled () const noexcept
 
RemoteUpdateSubscriberID registerRemoteUpdateSubscriber (RemoteUpdateCallbackFunc callback) noexcept
 
bool unregisterRemoteUpdateSubscriber (RemoteUpdateSubscriberID id) noexcept
 
driver::ThunderAutoProject * getHandle () noexcept
 
const driver::ThunderAutoProject * getHandle () const noexcept
 

Constructor & Destructor Documentation

◆ ThunderAutoProject() [1/2]

thunder::ThunderAutoProject::ThunderAutoProject ( )
noexcept

Default constructor. Creates an empty ThunderAuto project that is not loaded.

◆ ThunderAutoProject() [2/2]

thunder::ThunderAutoProject::ThunderAutoProject ( const std::filesystem::path & projectPath)
explicitnoexcept

Loads a ThunderAuto project from the specified path.

Parameters
projectPathThe 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.

Member Function Documentation

◆ areRemoteUpdatesEnabled()

bool thunder::ThunderAutoProject::areRemoteUpdatesEnabled ( ) const
noexcept

Check if remote project updates from ThunderAuto are enabled (enabled by default).

Returns
True if remote updates are enabled, false otherwise.

◆ disableRemoteUpdates()

void thunder::ThunderAutoProject::disableRemoteUpdates ( )
noexcept

Disable remote project updates from ThunderAuto.

◆ discoverAndLoadFromDeployDirectory()

bool thunder::ThunderAutoProject::discoverAndLoadFromDeployDirectory ( )
noexcept

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.

◆ enableRemoteUpdates()

void thunder::ThunderAutoProject::enableRemoteUpdates ( )
noexcept

Enable remote project updates from ThunderAuto (enabled by default).

◆ getActionCommand()

frc2::CommandPtr thunder::ThunderAutoProject::getActionCommand ( const std::string & actionName) const
noexcept

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
actionNameThe name of the action to get.
Returns
A CommandPtr representing the action command, or a None command if not found.

◆ getAutoMode()

std::unique_ptr< ThunderAutoMode > thunder::ThunderAutoProject::getAutoMode ( const std::string & autoModeName) const
nodiscardnoexcept

Get an autonomous mode by name.

Parameters
autoModeNameThe name of the autonomous mode to get.
Returns
A unique pointer to the autonomous mode if it exists, or nullptr if it does not.

◆ getAutoModeNames()

std::unordered_set< std::string > thunder::ThunderAutoProject::getAutoModeNames ( ) const
noexcept

Get the names of all autonomous modes in the project.

Returns
An unordered set of autonomous mode names.

◆ getBooleanCondition()

ThunderAutoProject::BooleanConditionFunc thunder::ThunderAutoProject::getBooleanCondition ( const std::string & conditionName) const
noexcept

Get a registered boolean condition by name.

Parameters
conditionNameThe name of the condition to get.
Returns
The boolean condition function, or nullptr if not found.

◆ getFieldDimensions()

FieldDimensions thunder::ThunderAutoProject::getFieldDimensions ( ) const
noexcept

Get the size of the configured field for the loaded project.

Returns
The field size.

◆ getFieldSymmetry()

FieldSymmetry thunder::ThunderAutoProject::getFieldSymmetry ( ) const
noexcept

Get the symmetry of the configured field for the loaded project.

Returns
The field symmetry.

◆ getName()

std::string thunder::ThunderAutoProject::getName ( ) const
noexcept

Get the name of the loaded project.

Returns
The name of the loaded project, or an empty string if no project is loaded.

◆ getSwitchCondition()

ThunderAutoProject::SwitchConditionFunc thunder::ThunderAutoProject::getSwitchCondition ( const std::string & conditionName) const
noexcept

Get a registered switch condition by name.

Parameters
conditionNameThe name of the condition to get.
Returns
The switch condition function, or nullptr if not found.

◆ getTrajectory()

std::unique_ptr< ThunderAutoTrajectory > thunder::ThunderAutoProject::getTrajectory ( const std::string & trajectoryName) const
nodiscardnoexcept

Get a trajectory by name.

Parameters
trajectoryNameThe name of the trajectory to get.
Returns
A unique pointer to the trajectory if it exists, or nullptr if it does not.

◆ getTrajectoryNames()

std::unordered_set< std::string > thunder::ThunderAutoProject::getTrajectoryNames ( ) const
noexcept

Get the names of all trajectories in the project.

Returns
An unordered set of trajectory names.

◆ hasAction()

bool thunder::ThunderAutoProject::hasAction ( const std::string & actionName) const
noexcept

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
actionNameThe name of the action to check.
Returns
True if the action exists, false otherwise.

◆ hasAutoMode()

bool thunder::ThunderAutoProject::hasAutoMode ( const std::string & autoModeName) const
noexcept

Check if an autonomous mode with the given name exists.

Parameters
autoModeNameThe name of the autonomous mode to check.
Returns
True if the autonomous mode exists, false otherwise.

◆ hasTrajectory()

bool thunder::ThunderAutoProject::hasTrajectory ( const std::string & trajectoryName) const
noexcept

Check if a trajectory with the given name exists.

Parameters
trajectoryNameThe name of the trajectory to check.
Returns
True if the trajectory exists, false otherwise.

◆ isActionCommandRegistered()

bool thunder::ThunderAutoProject::isActionCommandRegistered ( const std::string & actionName) const
noexcept

Check if an action command with the given name is registered.

Parameters
actionNameThe name of the action to check.
Returns
True if the action command is registered, false otherwise.

◆ isBooleanConditionRegistered()

bool thunder::ThunderAutoProject::isBooleanConditionRegistered ( const std::string & conditionName) const
noexcept

Check if a boolean condition with the given name is registered.

Parameters
conditionNameThe name of the condition to check.
Returns
True if the boolean condition is registered, false otherwise.

◆ isLoaded()

bool thunder::ThunderAutoProject::isLoaded ( ) const
noexcept

Returns whether a project is successfully loaded.

Returns
True if a project is loaded, false otherwise.

◆ isSwitchConditionRegistered()

bool thunder::ThunderAutoProject::isSwitchConditionRegistered ( const std::string & conditionName) const
noexcept

Check if a switch condition with the given name is registered.

Parameters
conditionNameThe name of the condition to check.
Returns
True if the switch condition is registered, false otherwise.

◆ load()

bool thunder::ThunderAutoProject::load ( const std::filesystem::path & projectPath)
noexcept

Loads a ThunderAuto project from the specified path.

Parameters
projectPathThe 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.

◆ operator bool()

thunder::ThunderAutoProject::operator bool ( ) const
explicitnoexcept

Returns whether a project is successfully loaded.

Returns
True if a project is loaded, false otherwise.

◆ registerActionCommand() [1/2]

void thunder::ThunderAutoProject::registerActionCommand ( const std::string & actionName,
frc2::CommandPtr 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
actionNameThe name of the action.
commandThe command to be executed when the action is called.

◆ registerActionCommand() [2/2]

void thunder::ThunderAutoProject::registerActionCommand ( const std::string & actionName,
std::shared_ptr< frc2::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
actionNameameThe name of the action.
commandThe command to be executed when the action is called.

◆ registerBooleanCondition()

void thunder::ThunderAutoProject::registerBooleanCondition ( const std::string & conditionName,
BooleanConditionFunc 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
conditionNameThe name of the condition.
conditionThe function that returns a boolean indicating the next step to run.

◆ registerRemoteUpdateSubscriber()

ThunderAutoProject::RemoteUpdateSubscriberID thunder::ThunderAutoProject::registerRemoteUpdateSubscriber ( RemoteUpdateCallbackFunc callback)
noexcept

Register a callback function to be called when the project is updated remotely from ThunderAuto.

Parameters
callbackThe callback function to register.
Returns
A subscriber ID that can be used to unregister the callback, or 0 on failure.

◆ registerSwitchCondition()

void thunder::ThunderAutoProject::registerSwitchCondition ( const std::string & conditionName,
SwitchConditionFunc 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
conditionNameThe name of the condition.
conditionThe function that returns an integer indicating the next step to run.

◆ setRemoteUpdatesEnabled()

void thunder::ThunderAutoProject::setRemoteUpdatesEnabled ( bool enabled)
noexcept

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
enabledTrue to enable remote updates, false to disable them.

◆ unregisterRemoteUpdateSubscriber()

bool thunder::ThunderAutoProject::unregisterRemoteUpdateSubscriber ( RemoteUpdateSubscriberID id)
noexcept

Unregister a previously registered remote update subscriber.

Parameters
idThe subscriber ID returned by registerRemoteUpdateSubscriber().
Returns
True if the subscriber was successfully unregistered, false otherwise.

The documentation for this class was generated from the following files: