Class ModularDrivetrain

  • All Implemented Interfaces:
    Drivetrain, Stoppable

    public class ModularDrivetrain
    extends java.lang.Object
    implements Drivetrain
    A wrapper class for a drivetrain which adds support for drive modules. Does not apply drive modules during tank driving.
    • Constructor Detail

      • ModularDrivetrain

        public ModularDrivetrain​(Drivetrain drivetrain)
        Default constructor
        Parameters:
        drivetrain - the drivetrain
      • ModularDrivetrain

        public ModularDrivetrain​(Drivetrain drivetrain,
                                 Clock clock)
        Constructor (for testing)
        Parameters:
        drivetrain - the drivetrain
        clock - the clock to use to calculate delta time
    • Method Detail

      • from

        public static ModularDrivetrain from​(edu.wpi.first.wpilibj.drive.DifferentialDrive differentialDrive)
        Create a modular drivetrain from a differential drive
        Parameters:
        differentialDrive - the differential drive
        Returns:
        the drivetrain
      • stop

        public void stop()
        Description copied from interface: Stoppable
        Stop the mechanism from moving
        Specified by:
        stop in interface Stoppable
      • arcade

        public void arcade​(double speed,
                           double turn)
        Description copied from interface: Drivetrain
        Drive in arcade mode.
        Specified by:
        arcade in interface Drivetrain
        Parameters:
        speed - A percent speed for forward/backward motion between -1 and 1, inclusive. 1 is forward and -1 is reverse.
        turn - A percent speed for turning between -1 and 1, inclusive. 1 is clockwise and -1 is counter clockwise.
      • tank

        public void tank​(double leftSpeed,
                         double rightSpeed)
        Description copied from interface: Drivetrain
        Drive in tank mode.
        Specified by:
        tank in interface Drivetrain
        Parameters:
        leftSpeed - A percent speed for the left side between -1 and 1, inclusive. 1 is forward and -1 is reverse.
        rightSpeed - A percent speed for the right side between -1 and 1, inclusive. 1 is forward and -1 is reverse.
      • setModules

        public void setModules​(DriveModule... modules)
        Installs modules into the drivetrain
        Parameters:
        modules - the modules
      • addModule

        public void addModule​(DriveModule module)
        Add a module to the drivetrain. Note: you can add a module more than once, though this may produce undesired behavior
        Parameters:
        module - the module to add
      • removeModule

        public void removeModule​(DriveModule module)
        Remove a module from the drivetrain
        Parameters:
        module - the module to remove
      • getInstalledModules

        public java.util.List<DriveModule> getInstalledModules()
        Get all the installed modules
        Returns:
        the modules
      • getInstalledModule

        public <T> T getInstalledModule​(java.lang.Class<T> cls)
        Gets the first installed module of the given type
        Parameters:
        cls - the class of the module to find
        Returns:
        the first module of the given type, or null if it was not found