ImprovedAbstractDrive
This class provides an improved abstract implementation of the Drive interface. It simplifies the process of creating a custom drive system by requiring only the implementation of the abstractSetTranslation(Translation) method. This class handles the management of the current translation and the application of any DriveModifier functions.
Key Concepts
- Simplified Implementation: Developers only need to focus on how a given
Translationis applied to the robot's motors. - Drive Modifiers: Supports the use of
Function<Translation, Translation>objects to modify the translation before it is applied to the robot. This allows for dynamic adjustments to drive behavior (e.g., inversion, scaling).
Methods
abstractGetTranslation()
Returns the last Translation that was set to the drive. This method is intended for internal use by the ImprovedAbstractDrive class and its subclasses.
abstractSetTranslation(Translation translation)
An abstract method that must be implemented by subclasses. This method is where the logic for physically setting the motor powers based on the provided translation should reside.
getTranslation()
Overrides the Drive interface method. Returns the current Translation of the drive, which is the last translation that was processed and applied.
setTranslation(Translation translation)
Overrides the Drive interface method. This is the primary method for commanding the drive. It first applies any configured modifier to the input translation, then updates the internal translation state, and finally calls abstractSetTranslation() to apply the modified translation to the robot's motors.
getDriveModifier()
Returns the currently configured Function<Translation, Translation> that modifies the drive's translation. By default, this is an identity function (no modification).
setDriveModifier(Function<Translation, Translation> modifier)
Sets a new Function<Translation, Translation> to be used as the drive modifier. This allows for custom logic to be applied to translations before they are sent to the abstractSetTranslation() method.