Class ModularDrivetrain
- java.lang.Object
-
- com.thegongoliers.output.drivetrain.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 Summary
Constructors Constructor Description ModularDrivetrain(Drivetrain drivetrain)Default constructorModularDrivetrain(Drivetrain drivetrain, Clock clock)Constructor (for testing)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddModule(DriveModule module)Add a module to the drivetrain.voidarcade(double speed, double turn)Drive in arcade mode.static ModularDrivetrainfrom(edu.wpi.first.wpilibj.drive.DifferentialDrive differentialDrive)Create a modular drivetrain from a differential drive<T> TgetInstalledModule(java.lang.Class<T> cls)Gets the first installed module of the given typejava.util.List<DriveModule>getInstalledModules()Get all the installed modulesvoidremoveModule(DriveModule module)Remove a module from the drivetrainvoidsetModules(DriveModule... modules)Installs modules into the drivetrainvoidstop()Stop the mechanism from movingvoidtank(double leftSpeed, double rightSpeed)Drive in tank mode.
-
-
-
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 drivetrainclock- 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:StoppableStop the mechanism from moving
-
arcade
public void arcade(double speed, double turn)Description copied from interface:DrivetrainDrive in arcade mode.- Specified by:
arcadein interfaceDrivetrain- 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:DrivetrainDrive in tank mode.- Specified by:
tankin interfaceDrivetrain- 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
-
-