Class SparkMaxBrushlessTankDrive
- java.lang.Object
-
- edu.wpi.first.wpilibj2.command.SubsystemBase
-
- com.alumiboti5590.eop.subsystems.drivetrain.tank.TankDrive
-
- com.alumiboti5590.eop.subsystems.drivetrain.tank.SparkMaxBrushlessTankDrive
-
- All Implemented Interfaces:
edu.wpi.first.util.sendable.Sendable,edu.wpi.first.wpilibj2.command.Subsystem
public class SparkMaxBrushlessTankDrive extends TankDrive
A TankDrive implementation using Spark Max motor controllers to control brushless motors. Do not use this under any circumstances with brushed motors; this is designed for Neos, Neo 550s, and other brushless motors only.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class com.alumiboti5590.eop.subsystems.drivetrain.tank.TankDrive
TankDrive.TeleopDriveType
-
-
Field Summary
Fields Modifier and Type Field Description static intDEFAULT_CURRENT_LIMITLimit the motors to the following AMPS to prevent brownouts, trips, or too much power being drawn when it really isn't needed.static doubleDEFAULT_RAMP_RATEThe default ramp rate, meaning the motors will take this long (in seconds) to accelerate to full speed to prevent damage to the motor or subsystems.-
Fields inherited from class com.alumiboti5590.eop.subsystems.drivetrain.tank.TankDrive
DEFAULT_TELEOP_DRIVE_TYPE
-
-
Constructor Summary
Constructors Constructor Description SparkMaxBrushlessTankDrive(CANMotorConfig leftLeaderConfig, CANMotorConfig rightLeaderConfig, CANMotorConfig leftFollowerConfig, CANMotorConfig rightFollowerConfig)Creates a new drivetrain from the provided motor and optionally provided encoders
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidresetOdometry()Reset the encoders and gyroscope readings.voidsetAccelerationRampRate(double maxAccRate)Sets the ramp rate for open loop control modes.voidsetCurrentLimit(int currentInAmps)Sets the current limit in Amps.voidsetDrivetrainUsage(CANSparkMaxUtil.Usage desiredUsage)The following allows us to save precious time in our 20ms robot loop by not evaluating the Spark Max values any more than we really need to.voidsetSidePIDGains(PIDGains gains)Set the PID controller gains for both sides of the tank drive.-
Methods inherited from class com.alumiboti5590.eop.subsystems.drivetrain.tank.TankDrive
configureDifferentialDrive, curvatureDrive, getTeleopDriveTypeSendableChooser, setCurvatureQuickTurnSupplier, setCurvatureSpeedSupplier, setCurvatureSteeringSupplier, setInvertCurvatureSteering, setSquareTeleopInputs, setTankDriveLeftSpeedSupplier, setTankDriveRightSpeedSupplier, setTeleopDriveType, stop, tankDrive, teleopOpenDrive
-
Methods inherited from class edu.wpi.first.wpilibj2.command.SubsystemBase
addChild, getName, getSubsystem, initSendable, setName, setSubsystem
-
-
-
-
Field Detail
-
DEFAULT_RAMP_RATE
public static final double DEFAULT_RAMP_RATE
The default ramp rate, meaning the motors will take this long (in seconds) to accelerate to full speed to prevent damage to the motor or subsystems. In drivetrains, this also helps to prevent flip-overs from sudden acceleration.- See Also:
- Constant Field Values
-
DEFAULT_CURRENT_LIMIT
public static final int DEFAULT_CURRENT_LIMIT
Limit the motors to the following AMPS to prevent brownouts, trips, or too much power being drawn when it really isn't needed. This is a nice safety feature.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
SparkMaxBrushlessTankDrive
public SparkMaxBrushlessTankDrive(CANMotorConfig leftLeaderConfig, CANMotorConfig rightLeaderConfig, CANMotorConfig leftFollowerConfig, CANMotorConfig rightFollowerConfig)
Creates a new drivetrain from the provided motor and optionally provided encoders- Parameters:
leftLeaderConfig- configuration for the left leader motor controllerrightLeaderConfig- configuration for the right leader motor controllerleftFollowerConfig- configuration for the left follower motor controllerrightFollowerConfig- configuration for the right follower motor controller
-
-
Method Detail
-
setAccelerationRampRate
public void setAccelerationRampRate(double maxAccRate)
Description copied from class:TankDriveSets the ramp rate for open loop control modes.This is the maximum rate at which the motor controller's output is allowed to change.
- Specified by:
setAccelerationRampRatein classTankDrive- Parameters:
maxAccRate- Time in seconds to go from 0 to full throttle.
-
setCurrentLimit
public void setCurrentLimit(int currentInAmps)
Description copied from class:TankDriveSets the current limit in Amps.The motor controller will reduce the controller voltage output to avoid surpassing this limit. This limit is enabled by default and used for brushless only. This limit is highly recommended when brushless motors, but it also helps to avoid brownouts in any situation.
- Specified by:
setCurrentLimitin classTankDrive- Parameters:
currentInAmps- The current limit in Amps.
-
setSidePIDGains
public void setSidePIDGains(PIDGains gains)
Description copied from class:TankDriveSet the PID controller gains for both sides of the tank drive. Note that the actual effect will be determined by the motors used (Neos + Spark Max's have a lot more control because of their built-in encoder) but it tries to be fairly equal enough for a drivetrain to work.- Specified by:
setSidePIDGainsin classTankDrive- Parameters:
gains- desired PID gains
-
setDrivetrainUsage
public void setDrivetrainUsage(CANSparkMaxUtil.Usage desiredUsage)
The following allows us to save precious time in our 20ms robot loop by not evaluating the Spark Max values any more than we really need to. It's recommended to set this (although the code might do it automatically) before switching up the drive mode between position-based, velocity-based, or open.- Parameters:
desiredUsage- the short-term desired usage for the motor
-
resetOdometry
public void resetOdometry()
Description copied from class:TankDriveReset the encoders and gyroscope readings.- Specified by:
resetOdometryin classTankDrive
-
-