Package frc.team88.swerve.configuration
Class Configuration
- java.lang.Object
-
- frc.team88.swerve.configuration.Configuration
-
- All Implemented Interfaces:
NetworkTablePopulator
public class Configuration extends java.lang.Object implements NetworkTablePopulator
Parses a swerve configuration file, generates objects from it, and provides access to all of its contents.
-
-
Constructor Summary
Constructors Constructor Description Configuration(java.lang.String configPath)
Loads the base config and user config from the filesystem.Configuration(java.lang.String configPath, SwerveGyro gyro)
Loads the base config and user config from the filesystem.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static <T> T
configCheckAndGet(com.electronwill.nightconfig.core.Config config, java.lang.String key, java.lang.Class<T> type)
Checks the existence and type of the given config field, then returns the value.static double
configCheckAndGetDouble(com.electronwill.nightconfig.core.Config config, java.lang.String key)
Checks that the given field exists and is a number, then returns it as a double.static double
configCheckAndGetDoubleOrElse(com.electronwill.nightconfig.core.Config config, java.lang.String key, double defaultValue)
If the given field exists, check that it's a number then return it as a double.static <T extends java.lang.Enum<T>>
TconfigCheckAndGetEnum(com.electronwill.nightconfig.core.Config config, java.lang.String key, java.lang.Class<T> enumType)
Checks that the given field exists and is an enum, then returns the value.static <T> T
configCheckAndGetOrElse(com.electronwill.nightconfig.core.Config config, java.lang.String key, java.lang.Class<T> type, T defaultValue)
If the given field exists, check it's type then return it's value.java.util.Map<java.lang.Integer,com.ctre.phoenix.CANifier>
getCanifiers()
Gets a mapping from can IDs to canifiers instantiated by this configuration.SwerveGyro
getGyro()
Gets the gyro object specified by this config.SwerveModule[]
getModules()
Gets the swerve modules specified by this config.void
populateNetworkTable(edu.wpi.first.networktables.NetworkTable table)
Populates the given network table with data from this class.
-
-
-
Constructor Detail
-
Configuration
public Configuration(java.lang.String configPath, SwerveGyro gyro)
Loads the base config and user config from the filesystem.- Parameters:
configPath
- The file path of the toml config. It can be a relative path inside of the deploy directory or an absolute path.gyro
- The gyro to use. Will instantiate from config if null.- Throws:
SwerveConfigException
- If the user provided config is incorrect.
-
Configuration
public Configuration(java.lang.String configPath)
Loads the base config and user config from the filesystem. Instantiates the gyro from the config.- Parameters:
configPath
- The file path of the toml config. It can be a relative path inside of the deploy directory or an absolute path.- Throws:
SwerveConfigException
- If the user provided config is incorrect.
-
-
Method Detail
-
getGyro
public SwerveGyro getGyro()
Gets the gyro object specified by this config.- Returns:
- The gyro object.
-
getModules
public SwerveModule[] getModules()
Gets the swerve modules specified by this config.- Returns:
- The modules array.
-
getCanifiers
public java.util.Map<java.lang.Integer,com.ctre.phoenix.CANifier> getCanifiers()
Gets a mapping from can IDs to canifiers instantiated by this configuration.- Returns:
- The mapping from can IDs to CANifiers.
-
populateNetworkTable
public void populateNetworkTable(edu.wpi.first.networktables.NetworkTable table)
Description copied from interface:NetworkTablePopulator
Populates the given network table with data from this class. May also read in values.- Specified by:
populateNetworkTable
in interfaceNetworkTablePopulator
- Parameters:
table
- The table to populate, and possibly read from.
-
configCheckAndGet
public static <T> T configCheckAndGet(com.electronwill.nightconfig.core.Config config, java.lang.String key, java.lang.Class<T> type)
Checks the existence and type of the given config field, then returns the value.- Type Parameters:
T
- The type of the field.- Parameters:
config
- The config to get the field from.key
- The key of the field to get.type
- The expected type of the field.- Returns:
- The value of the field.
- Throws:
SwerveConfigException
- If the key does not exist or is not the right type.
-
configCheckAndGetDouble
public static double configCheckAndGetDouble(com.electronwill.nightconfig.core.Config config, java.lang.String key)
Checks that the given field exists and is a number, then returns it as a double.- Parameters:
config
- The config to get the field from.key
- The key of the field to get.- Returns:
- The value of the field.
- Throws:
SwerveConfigException
- If the key does not exist or is not a number.
-
configCheckAndGetEnum
public static <T extends java.lang.Enum<T>> T configCheckAndGetEnum(com.electronwill.nightconfig.core.Config config, java.lang.String key, java.lang.Class<T> enumType)
Checks that the given field exists and is an enum, then returns the value.- Type Parameters:
T
- The type of the field.- Parameters:
config
- The config to get the field from.key
- The key of the field to get.enumType
- The expected enum type of the field.- Returns:
- The value of the field.
- Throws:
SwerveConfigException
- If the key does not exist, is not a string, or is not in the enum.
-
configCheckAndGetOrElse
public static <T> T configCheckAndGetOrElse(com.electronwill.nightconfig.core.Config config, java.lang.String key, java.lang.Class<T> type, T defaultValue)
If the given field exists, check it's type then return it's value. Otherwise, return the default.- Type Parameters:
T
- The type of the field.- Parameters:
config
- The config to get the field from.key
- The key of the field to get.type
- The expected type of the field.defaultValue
- The value to return if the field doesn't exist.- Returns:
- The value of the field.
- Throws:
SwerveConfigException
- If the key is not the right type.
-
configCheckAndGetDoubleOrElse
public static double configCheckAndGetDoubleOrElse(com.electronwill.nightconfig.core.Config config, java.lang.String key, double defaultValue)
If the given field exists, check that it's a number then return it as a double. Otherwise, return the default.- Parameters:
config
- The config to get the field from.key
- The key of the field to get.defaultValue
- The value to return if the field doesn't exist.- Returns:
- The value of the field.
- Throws:
SwerveConfigException
- If the key is not a number.
-
-