Class 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.
    • 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 controller
        rightLeaderConfig - configuration for the right leader motor controller
        leftFollowerConfig - configuration for the left follower motor controller
        rightFollowerConfig - configuration for the right follower motor controller
    • Method Detail

      • setAccelerationRampRate

        public void setAccelerationRampRate​(double maxAccRate)
        Description copied from class: TankDrive
        Sets 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:
        setAccelerationRampRate in class TankDrive
        Parameters:
        maxAccRate - Time in seconds to go from 0 to full throttle.
      • setCurrentLimit

        public void setCurrentLimit​(int currentInAmps)
        Description copied from class: TankDrive
        Sets 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:
        setCurrentLimit in class TankDrive
        Parameters:
        currentInAmps - The current limit in Amps.
      • setSidePIDGains

        public void setSidePIDGains​(PIDGains gains)
        Description copied from class: TankDrive
        Set 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:
        setSidePIDGains in class TankDrive
        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: TankDrive
        Reset the encoders and gyroscope readings.
        Specified by:
        resetOdometry in class TankDrive