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 void
addModule(DriveModule module)
Add a module to the drivetrain.void
arcade(double speed, double turn)
Drive in arcade mode.static ModularDrivetrain
from(edu.wpi.first.wpilibj.drive.DifferentialDrive differentialDrive)
Create a modular drivetrain from a differential drive<T> T
getInstalledModule(java.lang.Class<T> cls)
Gets the first installed module of the given typejava.util.List<DriveModule>
getInstalledModules()
Get all the installed modulesvoid
removeModule(DriveModule module)
Remove a module from the drivetrainvoid
setModules(DriveModule... modules)
Installs modules into the drivetrainvoid
stop()
Stop the mechanism from movingvoid
tank(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:Stoppable
Stop the mechanism from moving
-
arcade
public void arcade(double speed, double turn)
Description copied from interface:Drivetrain
Drive in arcade mode.- Specified by:
arcade
in 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:Drivetrain
Drive in tank mode.- Specified by:
tank
in 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
-
-