SmartPreference
SmartPreference
Section titled “SmartPreference”Wrapper for wpilib Preferences that improves it in a few ways:
- Previous values from NetworkTables are remembered if connection is lost instead of defaulting to the values set in code
- Everything is done dynamically so there is no need to specify type. However, because of NT limitations, the type must stay the same throughout the entirety of the code
- Including
low_bandwidth = Trueas a class attribute will stop theSmartPreferencefrom referencing NT and simply use defaults - Initializing, getting, and setting Preferences is made much easier and enables this class to be a drop-in replacement for normal values. For example:
class MyComponent:
# initialize a preference with NT key "foo" and default value True # SmartPreferences MUST be class attributes (ie. initialized under the header) # Values must be of type int, float, str, or bool foo = SmartPreference(True)
def execute(self):
# retrieve the preference from NT (defaults to previous value) foo = self.foo
# set the preference in NT self.foo = FalseMethods
Section titled “Methods”init()
Section titled “init()”set_name()
Section titled “set_name()”has_changed()
Section titled “has_changed()”Returns if any SmartPreference has changed since checked. Only works if called statically.