Class SmartMotorController

java.lang.Object
yams.core.motorcontrollers.SmartMotorController
Direct Known Subclasses:
NovaWrapper, SparkWrapper, TalonFXSWrapper, TalonFXWrapper

public abstract class SmartMotorController extends Object
Smart motor controller wrapper for motor controllers.

This abstract class is not instantiated directly. Instantiate the appropriate vendor wrapper: SparkWrapper for REV SPARK hardware, or yams.core.motorcontrollers.remote.TalonFXWrapper/yams.core.motorcontrollers.remote.TalonFXSWrapper for CTRE hardware. Configure all three via SmartMotorControllerConfig.

Example

SmartMotorControllerConfig config = new SmartMotorControllerConfig()
    .withClosedLoopController(0.1,0,0).withFeedforward(new
SimpleMotorFeedforward(0.05,0,0)).withStatorCurrentLimit(Amps.of(40)); SmartMotorController motor
= new SparkWrapper( new SparkMax(1, MotorType.kBrushless), DCMotor.getNEO(1), config);

// Use directly for duty-cycle or voltage control:
motor.setDutyCycle(0.5);
// Or attach to a mechanism:
Arm arm = new Arm(new ArmConfig(motor).withLength(Meters.of(0.5)));
  • Field Details

    • telemetry

      protected SmartMotorControllerTelemetry telemetry
      Telemetry.
    • m_config

      protected SmartMotorControllerConfig<?> m_config
    • m_slot

    • m_expoProfile

      protected Optional<org.wpilib.math.trajectory.ExponentialProfile> m_expoProfile
      Exponential profile for the closed loop controller.
    • m_expoState

      protected Optional<org.wpilib.math.trajectory.ExponentialProfile.State> m_expoState
      Exponential profile state for the closed loop controller.
    • m_trapezoidProfile

      protected Optional<org.wpilib.math.trajectory.TrapezoidProfile> m_trapezoidProfile
      Trapezoidal profile for the closed loop controller.
    • m_trapState

      protected Optional<org.wpilib.math.trajectory.TrapezoidProfile.State> m_trapState
      Trapezoidal profile state for the closed loop controller.
    • m_lastClosedLoopMechanismPosition

      protected Optional<org.wpilib.units.measure.Angle> m_lastClosedLoopMechanismPosition
      Mechanism position the closed loop controller last used, unwrapped across the continuous wrapping point.
    • m_pid

      protected Optional<org.wpilib.math.controller.PIDController> m_pid
      Simple PID controller for the motor controller.
    • m_lqr

      protected Optional<LQRController> m_lqr
      LQR controller for the motor controller.
    • setpointPosition

      protected Optional<org.wpilib.units.measure.Angle> setpointPosition
      Setpoint position
    • setpointVelocity

      protected Optional<org.wpilib.units.measure.AngularVelocity> setpointVelocity
      Setpoint velocity.
    • setpointFeedforwardForce

      protected Optional<org.wpilib.units.measure.Force> setpointFeedforwardForce
      Setpoint feedforward force, applied on top of the velocity setpoint, e.g. from a PathPlanner set-point generator.
    • m_closedLoopControllerThread

      protected org.wpilib.system.Notifier m_closedLoopControllerThread
      Thread of the closed loop controller.
    • m_closeHooks

      protected final List<Runnable> m_closeHooks
      Hooks run on close(). Lets command-layer helpers (e.g. live tuning) register their own cleanup without core depending on any command framework types.
    • parentTable

      protected Optional<org.wpilib.networktables.NetworkTable> parentTable
      Parent table for telemetry.
    • telemetryTable

      protected Optional<org.wpilib.networktables.NetworkTable> telemetryTable
      SmartMotorController telemetry table.
    • tuningTable

      protected Optional<org.wpilib.networktables.NetworkTable> tuningTable
      SmartMotorController tuning table.
    • telemetryConfig

      protected Optional<SmartMotorControllerTelemetryConfig> telemetryConfig
      Config for publishing specific telemetry.
    • m_simSupplier

      protected Optional<SimSupplier> m_simSupplier
      SimSupplier for the mechanism.
    • m_looseFollowers

      protected Optional<SmartMotorController[]> m_looseFollowers
      Loosely coupled followers.
    • m_systemCoreClosedLoopAlert

      protected Optional<org.wpilib.util.Alert> m_systemCoreClosedLoopAlert
      Alert shown when the closed loop controller is running on the SystemCore. Empty until constructed by the SmartMotorController implementation once its telemetry name (or a generated fallback identifier) is known.
    • m_batterySimUUID

      public final UUID m_batterySimUUID
      Battery simulation UUID used when standalone simulation.
  • Constructor Details

    • SmartMotorController

      protected SmartMotorController()
      Create the motor controller, subclasses wrap the vendor device.
  • Method Details

    • create

      public static SmartMotorController create(Object motorController, org.wpilib.math.system.DCMotor motorSim, SmartMotorControllerConfig<?> cfg)
      Create a SmartMotorController wrapper from the provided motor controller object.
      Parameters:
      motorController - Motor controller object.
      motorSim - DCMotor which the motor controller is connected too.
      cfg - SmartMotorControllerConfig for the SmartMotorController
      Returns:
      SmartMotorController.
    • isMotor

      public boolean isMotor(org.wpilib.math.system.DCMotor a, org.wpilib.math.system.DCMotor b)
      Compare DCMotors to identify the given motor.
      Parameters:
      a - DCMotor a
      b - DCMotor b
      Returns:
      True if same DC motor.
    • checkConfigSafety

      public void checkConfigSafety()
      Check config for safe values.
      Throws:
      SmartMotorControllerConfigurationException - if the motor is a single NEO 550 and the stator current limit is not defined.
      SmartMotorControllerConfigurationException - if the motor is a single NEO 550 and the stator current limit is above 40A.
    • getSimSupplier

      public Optional<SimSupplier> getSimSupplier()
      Get the sim supplier.
      Returns:
      Sim supplier.
    • setSimSupplier

      public void setSimSupplier(SimSupplier mechanismSupplier)
      Set the SimSupplier Mechanism.
      Parameters:
      mechanismSupplier - Mechanism sim supplier.
    • getTrapezoidalProfileState

      protected Optional<org.wpilib.math.trajectory.TrapezoidProfile.State> getTrapezoidalProfileState()
      Get the current encoder trapezoidal profile state for the closed loop controller.
      Returns:
      TrapezoidProfile.State from the encoders.
      Throws:
      SmartMotorControllerConfigurationException - if a trapezoidal profile and a linear closed loop controller are in use but the mechanism circumference is not configured.
    • getExponentialProfileState

      protected Optional<org.wpilib.math.trajectory.ExponentialProfile.State> getExponentialProfileState()
      Get the current encoder exponential profile state for the closed loop controller.
      Returns:
      ExponentialProfile.State from the encoders.
      Throws:
      SmartMotorControllerConfigurationException - if an exponential profile and a linear closed loop controller are in use but the mechanism circumference is not configured.
    • getVelocityMeasurementDelay

      public Optional<org.wpilib.units.measure.Time> getVelocityMeasurementDelay()
      Get how far behind the mechanism the measured velocity is, from how the motor controller filters it, as WPILib's SysId works it out for its presets. Feedback gains worked out for the closed loop depend on it. In simulation, the simulation period, since the simulated sensor is updated once a period.
      Returns:
      The delay, or empty if it is not known for this motor controller.
    • getClosedLoopControllerPeriod

      public org.wpilib.units.measure.Time getClosedLoopControllerPeriod()
      Get the period the closed loop controller runs at. A closed loop controller run on the SystemCore, such as an LQR or an exponential profile, runs at SmartMotorControllerConfig.withClosedLoopControlPeriod(Time), 20 ms by default. One run on the motor controller runs at 1 kHz.
      Returns:
      The closed loop controller's period.
    • stopClosedLoopController

      public void stopClosedLoopController()
      Stop the closed loop controller, and the loosely coupled followers' closed loop controllers. The followers are stopped too, as they are not sent the duty cycle or voltage the leader is driven at instead.
    • startClosedLoopController

      public void startClosedLoopController()
      Start the closed loop controller with the period, and the loosely coupled followers' closed loop controllers.
      Throws:
      SmartMotorControllerConfigurationException - if the control mode is closed loop, a linear closed loop controller is in use, and the mechanism circumference is not configured.
    • iterateClosedLoopController

      public void iterateClosedLoopController()
      Iterate the closed loop controller. Feedforward are only applied with profiled pid controllers.
      Throws:
      SmartMotorControllerConfigurationException - if the controller is running with a linear closed loop controller while the mechanism circumference is not configured.
      SmartMotorControllerConfigurationException - if the controller is running with a velocity setpoint that has a feedforward force while the mechanism circumference is not configured.
    • setupSimulation

      public abstract void setupSimulation()
      Setup the simulation for the wrapper.
    • seedRelativeEncoder

      public abstract void seedRelativeEncoder()
      Seed the relative encoder with the position from the absolute encoder.
    • synchronizeRelativeEncoder

      public abstract void synchronizeRelativeEncoder()
      Check if the relative encoder is out of sync with absolute encoder within defined tolerances.
    • simIterate

      public abstract void simIterate()
      Simulation iteration.
    • setZeroPower

      public abstract void setZeroPower(MotorMode mode)
      Set the motor zero power mode from COAST or BRAKE.
      Parameters:
      mode - MotorMode selected.
    • setEncoderVelocity

      public abstract void setEncoderVelocity(org.wpilib.units.measure.AngularVelocity velocity)
      Set the encoder velocity
      Parameters:
      velocity - AngularVelocity of the Mechanism.
      Throws:
      UnsupportedOperationException - if the motor controller does not support setting encoder velocity outside of simulation (e.g. REV Sparks).
    • setEncoderVelocity

      public abstract void setEncoderVelocity(org.wpilib.units.measure.LinearVelocity velocity)
      Set the encoder velocity.
      Parameters:
      velocity - Measurement LinearVelocity
      Throws:
      SmartMotorControllerConfigurationException - if the mechanism circumference is not configured.
      UnsupportedOperationException - if the motor controller does not support setting encoder velocity outside of simulation (e.g. REV Sparks).
    • setEncoderPosition

      public abstract void setEncoderPosition(org.wpilib.units.measure.Angle angle)
      Set the encoder position
      Parameters:
      angle - Current Mechanism Angle.
    • setEncoderPosition

      public abstract void setEncoderPosition(org.wpilib.units.measure.Distance distance)
      Set the encoder position.
      Parameters:
      distance - Current Measurement Distance.
      Throws:
      SmartMotorControllerConfigurationException - if the mechanism circumference is not configured.
    • setPosition

      public abstract void setPosition(org.wpilib.units.measure.Angle angle)
      Set the Mechanism Angle using the PID and feedforward from SmartMotorControllerConfig.
      Parameters:
      angle - Mechanism angle to set.
      Throws:
      SmartMotorControllerConfigurationException - if the configured vendor position control request is not supported by the motor controller.
    • setPosition

      public abstract void setPosition(org.wpilib.units.measure.Distance distance)
      Set the Mechanism Distance using the PID and feedforward from SmartMotorControllerConfig.
      Parameters:
      distance - Mechanism Distance to set.
      Throws:
      SmartMotorControllerConfigurationException - if the mechanism circumference is not configured.
      SmartMotorControllerConfigurationException - if the configured vendor position control request is not supported by the motor controller.
    • setVelocity

      public void setVelocity(org.wpilib.units.measure.LinearVelocity velocity)
      Set the Mechanism LinearVelocity using the PID and feedforward from SmartMotorControllerConfig.
      Parameters:
      velocity - Mechanism LinearVelocity to target.
      Throws:
      SmartMotorControllerConfigurationException - if the mechanism circumference is not configured.
      SmartMotorControllerConfigurationException - if the configured vendor velocity control request is not supported by the motor controller.
    • setVelocity

      public abstract void setVelocity(org.wpilib.units.measure.AngularVelocity angle)
      Set the Mechanism AngularVelocity using the PID and feedforward from SmartMotorControllerConfig.
      Parameters:
      angle - Mechanism AngularVelocity to target.
      Throws:
      SmartMotorControllerConfigurationException - if the configured vendor velocity control request is not supported by the motor controller.
    • setVelocity

      public void setVelocity(org.wpilib.units.measure.LinearVelocity velocity, org.wpilib.units.measure.Force feedforwardForce)
      Set the Mechanism LinearVelocity using the PID and feedforward from SmartMotorControllerConfig, with an additional feedforward Force applied on top, e.g. from a PathPlanner set-point generator. Applied whether the motor controller's native closed-loop velocity control or an LQR/software motion profile loop is driving the mechanism.
      Parameters:
      velocity - Mechanism LinearVelocity to target.
      feedforwardForce - Additional feedforward Force applied to the mechanism, or null for none.
      Throws:
      SmartMotorControllerConfigurationException - if the mechanism circumference is not configured.
      SmartMotorControllerConfigurationException - if the configured vendor velocity control request is not supported by the motor controller.
    • setVelocity

      public abstract void setVelocity(org.wpilib.units.measure.AngularVelocity angle, org.wpilib.units.measure.Force feedforwardForce)
      Set the Mechanism AngularVelocity using the PID and feedforward from SmartMotorControllerConfig, with an additional feedforward Force applied on top, e.g. from a PathPlanner set-point generator. Applied whether the motor controller's native closed-loop velocity control or an LQR/software motion profile loop is driving the mechanism.
      Parameters:
      angle - Mechanism AngularVelocity to target.
      feedforwardForce - Additional feedforward Force applied to the mechanism, or null for none.
      Throws:
      SmartMotorControllerConfigurationException - if a feedforward force is given and the mechanism circumference is not configured.
      SmartMotorControllerConfigurationException - if the configured vendor velocity control request is not supported by the motor controller.
    • applyConfig

      public abstract boolean applyConfig(SmartMotorControllerConfig<?> config)
      Parameters:
      config - SmartMotorControllerConfig to use.
      Returns:
      Successful Application of the configuration.
      Throws:
      SmartMotorControllerConfigurationException - if the config contains options that are invalid or unsupported for the motor controller.
      SmartMotorControllerConfigurationException - if a required config option is left unhandled during validation.
      IllegalArgumentException - if the config references an unsupported device or option for the motor controller (e.g. an unsupported external encoder or follower type).
    • getDutyCycle

      public abstract double getDutyCycle()
      Get the duty cycle output of the motor controller.
      Returns:
      DutyCycle of the motor controller.
    • setDutyCycle

      public abstract void setDutyCycle(double dutyCycle)
      Set the dutycycle output of the motor controller.
      Parameters:
      dutyCycle - Value between [-1,1]
    • getSupplyCurrent

      public abstract Optional<org.wpilib.units.measure.Current> getSupplyCurrent()
      Get the supply current of the motor controller.
      Returns:
      The supply current of the motor controller.
    • getStatorCurrent

      public abstract org.wpilib.units.measure.Current getStatorCurrent()
      Get the stator current of the motor controller.
      Returns:
      Stator current
    • getVoltage

      public abstract org.wpilib.units.measure.Voltage getVoltage()
      Get the voltage output of the motor.
      Returns:
      Voltage output of the motor.
    • setVoltage

      public abstract void setVoltage(org.wpilib.units.measure.Voltage voltage)
      Set the voltage output of the motor controller. Useful for Sysid.
      Parameters:
      voltage - Voltage to set the motor controller output to.
    • getDCMotor

      public abstract org.wpilib.math.system.DCMotor getDCMotor()
      Get the DCMotor modeling the motor controlled by the motor controller.
      Returns:
      DCMotor of the controlled motor.
    • getMeasurementVelocity

      public abstract org.wpilib.units.measure.LinearVelocity getMeasurementVelocity()
      Get the usable measurement of the motor for mechanisms operating under distance units converted with the SmartMotorControllerConfig.
      Returns:
      Measurement velocity of the mechanism post-gearing.
      Throws:
      SmartMotorControllerConfigurationException - if the mechanism circumference is not configured.
    • getMeasurementPosition

      public abstract org.wpilib.units.measure.Distance getMeasurementPosition()
      Get the usable measurement of the motor for mechanisms operating under distance units converted with the SmartMotorControllerConfig.
      Returns:
      Measurement velocity of the mechanism post-gearing.
      Throws:
      SmartMotorControllerConfigurationException - if the mechanism circumference is not configured.
    • getMeasurementAcceleration

      public abstract org.wpilib.units.measure.LinearAcceleration getMeasurementAcceleration()
      Get the usable measurement of the motor for mechanisms operating under distance units converted with the SmartMotorControllerConfig
      Returns:
      Measurement acceleration of the mechanism post-gearing.
      Throws:
      SmartMotorControllerConfigurationException - if the mechanism circumference is not configured.
    • getMechanismVelocity

      public abstract org.wpilib.units.measure.AngularVelocity getMechanismVelocity()
      Get the Mechanism AngularVelocity taking the configured MechanismGearing into the measurement applied via the SmartMotorControllerConfig. Uses getExternalEncoderMechanismVelocity() when the external (absolute) encoder is enabled with SmartMotorControllerConfig.withUseExternalFeedbackEncoder(boolean), otherwise getRelativeMechanismVelocity().
      Returns:
      Mechanism AngularVelocity
    • getMechanismAcceleration

      public abstract org.wpilib.units.measure.AngularAcceleration getMechanismAcceleration()
      Get the Mechanism AngularAcceleration, calculating it on the robot controller if necessary by taking the derivative of the velocity.
      Returns:
      Mechanism AngularAcceleration
    • getMechanismPosition

      public abstract org.wpilib.units.measure.Angle getMechanismPosition()
      Get the mechanism Angle taking the configured MechanismGearing from SmartMotorControllerConfig. Uses getExternalEncoderMechanismPosition() when the external (absolute) encoder is enabled with SmartMotorControllerConfig.withUseExternalFeedbackEncoder(boolean), otherwise getRelativeMechanismPosition().
      Returns:
      Mechanism Angle
    • getRelativeMechanismVelocity

      public abstract org.wpilib.units.measure.AngularVelocity getRelativeMechanismVelocity()
      Get the mechanism AngularVelocity from the relative encoder in the motor, scaled by the configured MechanismGearing. Never uses the external (absolute) encoder.
      Returns:
      Mechanism AngularVelocity from the relative encoder.
    • getRelativeMechanismPosition

      public abstract org.wpilib.units.measure.Angle getRelativeMechanismPosition()
      Get the mechanism Angle from the relative encoder in the motor, scaled by the configured MechanismGearing. Never uses the external (absolute) encoder.
      Returns:
      Mechanism Angle from the relative encoder.
    • getRotorVelocity

      public abstract org.wpilib.units.measure.AngularVelocity getRotorVelocity()
      Gets the angular velocity of the motor.
      Returns:
      AngularVelocity of the relative motor encoder.
    • getRotorPosition

      public abstract org.wpilib.units.measure.Angle getRotorPosition()
      Get the rotations of the motor with the relative encoder since the motor controller powered on scaled to the mechanism rotations.
      Returns:
      Angle of the relative encoder in the motor.
    • getExternalEncoderMechanismPosition

      public abstract Optional<org.wpilib.units.measure.Angle> getExternalEncoderMechanismPosition()
      Get the mechanism Angle from the external (absolute) encoder, scaled by the configured external encoder MechanismGearing. Available whether or not the external encoder is used for feedback.
      Returns:
      Mechanism Angle from the external encoder, or empty if none is attached.
    • getExternalEncoderMechanismVelocity

      public abstract Optional<org.wpilib.units.measure.AngularVelocity> getExternalEncoderMechanismVelocity()
      Get the mechanism AngularVelocity from the external (absolute) encoder, scaled by the configured external encoder MechanismGearing. Available whether or not the external encoder is used for feedback.
      Returns:
      Mechanism AngularVelocity from the external encoder, or empty if none is attached.
    • setupTelemetry

      public void setupTelemetry(org.wpilib.networktables.NetworkTable telemetry, org.wpilib.networktables.NetworkTable tuning)
      Update the telemetry under the motor name under the given NetworkTable
      Parameters:
      telemetry - NetworkTable to create the SmartMotorControllerTelemetry subtable under based off of SmartMotorControllerConfig.getTelemetryName().
      tuning - NetworkTable to create the tunable telemetry from SmartMotorControllerTelemetry subtable under. Based off of SmartMotorControllerConfig.getTelemetryName().
    • tuningEnabled

      public boolean tuningEnabled()
      Whether live tuning is enabled for this SmartMotorController, i.e. whether tuning values should be pulled from NetworkTables each loop via applyTuningValues().
      Returns:
      True if live tuning is enabled.
    • applyTuningValues

      public void applyTuningValues()
      Apply the live-tuned values (from the Tuning NetworkTable) to this SmartMotorController.
      Throws:
      SmartMotorControllerConfigurationException - if the control mode is not CLOSED_LOOP.
      SmartMotorControllerConfigurationException - if the motor controller implementation rejects a tuned value.
      IllegalArgumentException - if the tuned closed loop controller slot is not supported by the motor controller implementation.
    • stopLiveTuning

      public void stopLiveTuning()
      Stop live tuning, as when the "Live Tuning" command ends. A tuning voltage stops, it is turned off in the Tuning table, and the closed loop controller holds the setpoint again.
    • getLooselyCoupledFollowers

      public Optional<SmartMotorController[]> getLooselyCoupledFollowers()
      Get the loosely coupled followers, which are sent the leader's setpoints and run their own closed loop controllers.
      Returns:
      The loosely coupled followers, or empty if there are none.
    • addCloseHook

      public void addCloseHook(Runnable hook)
      Register a hook to run when close() is called, so command-layer helpers (e.g. live tuning) can clean up resources they registered elsewhere without core depending on any command framework types.
      Parameters:
      hook - Runnable to run on close().
    • setupTelemetry

      public void setupTelemetry()
      Setup Telemetry with default NT path
    • setupLiveTuning

      public void setupLiveTuning()
      Set up live tuning for this SmartMotorController when its telemetry verbosity is TelemetryVerbosity.HIGH, so the values under the Tuning table are applied while the "Live Tuning" command runs. Only sets it up once, however many times it is called.
    • updateTelemetry

      public void updateTelemetry()
      Update the telemetry under the motor name under the given NetworkTable
    • setMotorInverted

      public abstract void setMotorInverted(boolean inverted)
      Set the inversion state of the motor.
      Parameters:
      inverted - Inverted motor.
    • setEncoderInverted

      public abstract void setEncoderInverted(boolean inverted)
      Set the phase of the encoder attached to the brushless motor.
      Parameters:
      inverted - Phase of the encoder.
    • setMotionProfileMaxVelocity

      public abstract void setMotionProfileMaxVelocity(org.wpilib.units.measure.LinearVelocity maxVelocity)
      Set the maximum velocity of the trapezoidal profile for the feedback controller.
      Parameters:
      maxVelocity - Maximum velocity, will be translated to MetersPerSecond.
      Throws:
      SmartMotorControllerConfigurationException - if the mechanism circumference is not configured.
    • setMotionProfileMaxAcceleration

      public abstract void setMotionProfileMaxAcceleration(org.wpilib.units.measure.LinearAcceleration maxAcceleration)
      Set the maximum acceleration of the trapezoidal profile for the feedback controller.
      Parameters:
      maxAcceleration - Maximum acceleration, will be translated to MetersPerSecondPerSecond.
      Throws:
      SmartMotorControllerConfigurationException - if the mechanism circumference is not configured.
    • setMotionProfileMaxVelocity

      public abstract void setMotionProfileMaxVelocity(org.wpilib.units.measure.AngularVelocity maxVelocity)
      Set the maximum velocity for the trapezoidal profile for the feedback controller.
      Parameters:
      maxVelocity - Maximum velocity, will be translated to RotationsPerSecond.
    • setMotionProfileMaxAcceleration

      public abstract void setMotionProfileMaxAcceleration(org.wpilib.units.measure.AngularAcceleration maxAcceleration)
      Set the maximum acceleration for the trapezoidal profile for the feedback controller.
      Parameters:
      maxAcceleration - Maximum acceleration, will be translated to RotationsPerSecondPerSecond.
    • setMotionProfileMaxJerk

      public abstract void setMotionProfileMaxJerk(org.wpilib.units.measure.Velocity<org.wpilib.units.AngularAccelerationUnit> maxJerk)
      Set the maximum jerk for the trapezoidal profile for the feedback controller.
      Parameters:
      maxJerk - Maximum jerk, will be translated to RotationsPerSecondPerSecondPerSecond.
    • setExponentialProfile

      public abstract void setExponentialProfile(OptionalDouble kV, OptionalDouble kA, Optional<org.wpilib.units.measure.Voltage> maxInput)
      Set the exponential profile fields.
      Parameters:
      kV - kV for the exponential profile.
      kA - kA for the exponential profile.
      maxInput - Maximum input for the exponential profile.
    • setKp

      public abstract void setKp(double kP)
      Set kP for the feedback controller PID.
      Parameters:
      kP - kP
    • setKi

      public abstract void setKi(double kI)
      Set kI for the feedback controller PID.
      Parameters:
      kI - kI.
    • setKd

      public abstract void setKd(double kD)
      Set kD for the feedback controller PID.
      Parameters:
      kD - kD for the feedback controller PID.
    • setFeedback

      public abstract void setFeedback(double kP, double kI, double kD)
      Set the closed loop feedback controller PID.
      Parameters:
      kP - kP; Proportional scalar.
      kI - kI; Integral scalar.
      kD - kD; derivative scalar.
    • setKs

      public abstract void setKs(double kS)
      Static feedforward element.
      Parameters:
      kS - kS; Static feedforward.
    • setKv

      public abstract void setKv(double kV)
      Velocity feedforward element.
      Parameters:
      kV - kV; Velocity feedforward.
    • setKa

      public abstract void setKa(double kA)
      Acceleration feedforward element.
      Parameters:
      kA - kA; Acceleration feedforward.
    • setKg

      public abstract void setKg(double kG)
      kSin feedforward element.
      Parameters:
      kG - kG; Gravity feedforward.
    • setFeedforward

      public abstract void setFeedforward(double kS, double kV, double kA, double kG)
      Set the feedforward controller.
      Parameters:
      kS - kS; Static feedforward.
      kV - kV; Velocity feedforward.
      kA - kA; Acceleration feedforward.
      kG - kG; Gravity feedforward.
    • setStatorCurrentLimit

      public abstract void setStatorCurrentLimit(org.wpilib.units.measure.Current currentLimit)
      Set the stator current limit for the device.
      Parameters:
      currentLimit - Stator current limit.
    • setSupplyCurrentLimit

      public abstract void setSupplyCurrentLimit(org.wpilib.units.measure.Current currentLimit)
      Set the supply current limit.
      Parameters:
      currentLimit - Supply current limit.
    • setClosedLoopRampRate

      public abstract void setClosedLoopRampRate(org.wpilib.units.measure.Time rampRate)
      Set the closed loop ramp rate. The ramp rate is how fast the motor can go from 0-100, measured in seconds.
      Parameters:
      rampRate - Time from 0 to 100.
    • setOpenLoopRampRate

      public abstract void setOpenLoopRampRate(org.wpilib.units.measure.Time rampRate)
      Set the open loop ramp rate. The ramp rate is how fast the motor can go from 0 to 100, measured in Seconds.
      Parameters:
      rampRate - Time it takes to go from 0 to 100.
    • setMeasurementUpperLimit

      public abstract void setMeasurementUpperLimit(org.wpilib.units.measure.Distance upperLimit)
      Set the measurement upper limit, only works if mechanism circumference is defined.
      Parameters:
      upperLimit - Upper limit, will be translated to meters.
      Throws:
      SmartMotorControllerConfigurationException - if a lower limit is configured and it is greater than or equal to the new upper limit.
    • setMeasurementLowerLimit

      public abstract void setMeasurementLowerLimit(org.wpilib.units.measure.Distance lowerLimit)
      Set the measurement lower limit, only works if mechanism circumference is defined.
      Parameters:
      lowerLimit - Lower limit, will be translated to meters.
      Throws:
      SmartMotorControllerConfigurationException - if an upper limit is configured and the new lower limit is greater than or equal to it.
    • setMechanismUpperLimit

      public abstract void setMechanismUpperLimit(org.wpilib.units.measure.Angle upperLimit)
      Set the mechanism upper limit.
      Parameters:
      upperLimit - Upper limit, will be translated to rotations.
      Throws:
      SmartMotorControllerConfigurationException - if a lower limit is configured and it is greater than or equal to the new upper limit.
    • setMechanismLowerLimit

      public abstract void setMechanismLowerLimit(org.wpilib.units.measure.Angle lowerLimit)
      Set the mechanism lower limit.
      Parameters:
      lowerLimit - Lower limit, will be translated to rotations.
      Throws:
      SmartMotorControllerConfigurationException - if an upper limit is configured and the new lower limit is greater than or equal to it.
    • setMechanismLimits

      public abstract void setMechanismLimits(org.wpilib.units.measure.Angle lower, org.wpilib.units.measure.Angle upper)
      Set the Mechanism limits for the motor controller.
      Parameters:
      lower - Lower limit, will be translated to rotations.
      upper - Upper limit, will be translated to rotations.
      Throws:
      SmartMotorControllerConfigurationException - if both limits are non-null and the lower limit is greater than or equal to the upper limit.
    • setMechanismLimitsEnabled

      public abstract void setMechanismLimitsEnabled(boolean enabled)
      Enable or disable the mechanism/measurement limits in the motor controller.
      Parameters:
      enabled - Application of the limits
    • setMechanismGearing

      public abstract void setMechanismGearing(MechanismGearing gearing)
      Update the mechanism gearing used for position/velocity conversions.
      Parameters:
      gearing - New MechanismGearing to apply.
      Implementation Note:
      Forwards the gearing to all loosely coupled follower motors.
    • setMechanismCircumference

      public abstract void setMechanismCircumference(org.wpilib.units.measure.Distance circumference)
      Update the mechanism circumference used for linear position/velocity conversions.
      Parameters:
      circumference - New mechanism circumference.
    • setClosedLoopSlot

      public abstract void setClosedLoopSlot(SmartMotorController.ClosedLoopControllerSlot slot)
      Set the closed loop controller slot to use.
      Parameters:
      slot - Slot to use.
      Throws:
      IllegalArgumentException - if the slot is not supported by the motor controller (e.g. SLOT_3 on a TalonFX or TalonFXS).
    • getTemperature

      public abstract org.wpilib.units.measure.Temperature getTemperature()
      Get the SmartMotorController temperature.
      Returns:
      Temperature
    • getConfig

      public abstract SmartMotorControllerConfig<?> getConfig()
      Returns:
      SmartMotorControllerConfig used.
    • getMotorController

      public abstract Object getMotorController()
      Get the Motor Controller Object passed into the SmartMotorController.
      Returns:
      Motor Controller object.
    • getMotorControllerConfig

      public abstract Object getMotorControllerConfig()
      Get the motor controller object config generated by SmartMotorController based off the SmartMotorControllerConfig
      Returns:
      Motor controller config.
    • getMechanismPositionSetpoint

      public Optional<org.wpilib.units.measure.Angle> getMechanismPositionSetpoint()
      Get the Mechanism setpoint position.
      Returns:
      Mechanism Setpoint position.
    • getMeasurementPositionSetpoint

      public Optional<org.wpilib.units.measure.Distance> getMeasurementPositionSetpoint()
      Get the Mechanism setpoint position as a Distance.
      Returns:
      Measurement setpoint position, empty when there is no position setpoint or the mechanism circumference is not configured.
    • getMechanismSetpointVelocity

      public Optional<org.wpilib.units.measure.AngularVelocity> getMechanismSetpointVelocity()
      Get the Mechanism velocity setpoint.
      Returns:
      Mechanism velocity setpoint.
    • getSetpointFeedforwardForce

      public Optional<org.wpilib.units.measure.Force> getSetpointFeedforwardForce()
      Get the feedforward Force last supplied to setVelocity(AngularVelocity, Force) or setVelocity(LinearVelocity, Force).
      Returns:
      Setpoint feedforward Force.
    • getUnsupportedTelemetryFields

      Get a list of unsupported telemetry fields if any exist.
      Returns:
      Optional list of unsupported telemetry fields.
    • getName

      public String getName()
      Get the name of the SmartMotorController
      Returns:
      String name if present, else "SmartMotorController"
    • buildAlertId

      protected String buildAlertId(String motorControllerType, int deviceId, String alertType)
      Build a unique Alert identifier for this motor controller, for use once m_config has been assigned by the implementing constructor.

      The motor controller type and device ID are always included as a prefix, matching how SmartMotorControllerConfigurationException messages identify the device, e.g. "TalonFX(3)". If a telemetry name is configured, the identifier is motorControllerType(deviceId) + alertType + telemetryName. Otherwise a random UUID is used in place of the telemetry name so alerts from different motor controllers never collide: motorControllerType(deviceId) + UUID + alertType.

      Parameters:
      motorControllerType - Motor controller implementation type, e.g. "TalonFX".
      deviceId - CAN device ID of the motor controller.
      alertType - Alert type/qualifier, e.g. "ClosedLoop".
      Returns:
      Unique Alert identifier.
    • close

      public void close()
      Close the SMC for unit testing.
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • getClosedLoopControllerSlot

      public SmartMotorController.ClosedLoopControllerSlot getClosedLoopControllerSlot()
      Get the active closed loop controller slot.
      Returns:
      Active closed loop controller slot.