Class PIDDrivetrain
- java.lang.Object
-
- ca.team3161.lib.robot.subsystem.AbstractSubsystem
-
- ca.team3161.lib.robot.subsystem.AbstractPooledSubsystem
-
- ca.team3161.lib.robot.subsystem.RepeatingPooledSubsystem
-
- ca.team3161.lib.robot.motion.drivetrains.AbstractDrivetrainBase
-
- ca.team3161.lib.robot.motion.drivetrains.PIDDrivetrain
-
- All Implemented Interfaces:
LifecycleListener
,Subsystem
,ComposedComponent<java.lang.Object>
public final class PIDDrivetrain extends AbstractDrivetrainBase implements ComposedComponent<java.lang.Object>
A drivetrain controller that uses PID objects and is able to accurately drive straight and turn by degrees. WARNING! This class is only intended and designed for autonomous usage!
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
PIDDrivetrain.Builder
A Builder to facilitate easy instantation of PIDDrivetrains.class
PIDDrivetrain.Task
An action this PIDDrivetrain may carry out.-
Nested classes/interfaces inherited from class ca.team3161.lib.robot.subsystem.AbstractSubsystem
AbstractSubsystem.RunTask
-
-
Field Summary
Fields Modifier and Type Field Description static long
SUBSYSTEM_TASK_PERIOD
-
Fields inherited from class ca.team3161.lib.robot.subsystem.AbstractSubsystem
job, resourceLocks, THREAD_PRIORITY
-
-
Constructor Summary
Constructors Constructor Description PIDDrivetrain(PIDDrivetrain.Builder builder)
Create a new PIDDrivetrain instance from a Builder.PIDDrivetrain(edu.wpi.first.wpilibj.SpeedController leftDrive, edu.wpi.first.wpilibj.SpeedController rightDrive, PID<? extends edu.wpi.first.wpilibj.pidwrappers.PIDEncoder,java.lang.Integer> leftEncoder, PID<? extends edu.wpi.first.wpilibj.pidwrappers.PIDEncoder,java.lang.Integer> rightEncoder, PID<? extends edu.wpi.first.wpilibj.interfaces.Gyro,java.lang.Float> turningPid, PID<? extends edu.wpi.first.wpilibj.interfaces.Gyro,java.lang.Float> bearingPid)
Create a new PIDDrivetrain instance.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
defineResources()
Require the SpeedControllers and PID objects.java.util.Collection<java.lang.Object>
getComposedComponents()
Get the composed components within this one.void
reset()
Reset the state of the drivetrain so that it can be cleanly reused.void
setTicksTarget(int ticks)
Drive forward a number of encoder ticks.void
stop()
Stop all movement by setting all motor target values to 0 and disabling them.void
task()
Iteratively PID loop.void
turnByDegrees(float degrees)
Turn in place.void
waitForTarget()
Suspends the calling thread until the target is reached, at which point it will be awoken again.-
Methods inherited from class ca.team3161.lib.robot.motion.drivetrains.AbstractDrivetrainBase
onLifecycleChange
-
Methods inherited from class ca.team3161.lib.robot.subsystem.RepeatingPooledSubsystem
isDone, start
-
Methods inherited from class ca.team3161.lib.robot.subsystem.AbstractPooledSubsystem
getExecutorService
-
Methods inherited from class ca.team3161.lib.robot.subsystem.AbstractSubsystem
acquireResources, cancel, getJob, isCancelled, isScheduled, isStarted, releaseResources, require
-
-
-
-
Field Detail
-
SUBSYSTEM_TASK_PERIOD
public static final long SUBSYSTEM_TASK_PERIOD
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
PIDDrivetrain
public PIDDrivetrain(edu.wpi.first.wpilibj.SpeedController leftDrive, edu.wpi.first.wpilibj.SpeedController rightDrive, PID<? extends edu.wpi.first.wpilibj.pidwrappers.PIDEncoder,java.lang.Integer> leftEncoder, PID<? extends edu.wpi.first.wpilibj.pidwrappers.PIDEncoder,java.lang.Integer> rightEncoder, PID<? extends edu.wpi.first.wpilibj.interfaces.Gyro,java.lang.Float> turningPid, PID<? extends edu.wpi.first.wpilibj.interfaces.Gyro,java.lang.Float> bearingPid)
Create a new PIDDrivetrain instance.- Parameters:
leftDrive
- the left side drivetrain SpeedControllerrightDrive
- the right side drivetrain SpeedControllerleftEncoder
- the left side drivetrain EncoderrightEncoder
- the right side drivetrain EncoderturningPid
- an AnglePidSrc (eg Gyro) to maintain a straight headingbearingPid
- an AnglePidSrc to orient to a vector while stationary
-
PIDDrivetrain
public PIDDrivetrain(PIDDrivetrain.Builder builder)
Create a new PIDDrivetrain instance from a Builder.- Parameters:
builder
- the PIDDrivetrain.Builder which contains all the parameters of this PIDDrivetrain.
-
-
Method Detail
-
defineResources
public void defineResources()
Require the SpeedControllers and PID objects.- Specified by:
defineResources
in interfaceSubsystem
- See Also:
AbstractSubsystem.require(Object)
-
turnByDegrees
public void turnByDegrees(float degrees)
Turn in place. Positive degrees may be either clockwise or anticlockwise, depending on the setup of your particular AnglePidSrc- Parameters:
degrees
- how many degrees to turn
-
setTicksTarget
public void setTicksTarget(int ticks)
Drive forward a number of encoder ticks.- Parameters:
ticks
- how many ticks to drive
-
reset
public void reset()
Reset the state of the drivetrain so that it can be cleanly reused.
-
stop
public void stop()
Stop all movement by setting all motor target values to 0 and disabling them.- Specified by:
stop
in classAbstractDrivetrainBase
-
waitForTarget
public void waitForTarget() throws java.lang.InterruptedException
Suspends the calling thread until the target is reached, at which point it will be awoken again.- Throws:
java.lang.InterruptedException
- if the calling thread is interrupted while waiting
-
getComposedComponents
public java.util.Collection<java.lang.Object> getComposedComponents()
Get the composed components within this one.- Specified by:
getComposedComponents
in interfaceComposedComponent<java.lang.Object>
- Returns:
- the composed components.
-
-