Class MotorWrapper

java.lang.Object
ca.team4308.absolutelib.wrapper.MotorWrapper

public class MotorWrapper extends Object
Unified motor controller wrapper, Doesnt matter the vendor.
  • Constructor Details

    • MotorWrapper

      public MotorWrapper(MotorWrapper.MotorType type, int id)
      Create a wrapper (SparkMax defaults to Brushless).
    • MotorWrapper

      public MotorWrapper(MotorWrapper.MotorType type, int id, com.revrobotics.spark.SparkLowLevel.MotorType sparkMotorType)
      Create a wrapper. Use this overload to specify SparkMax motor type. Sparkmax Motor type only needed for spark maxes.
  • Method Details

    • sparkMax

      public static MotorWrapper sparkMax(int id, com.revrobotics.spark.SparkLowLevel.MotorType sparkMotorType)
      Convenience factory for SparkMax with explicit motor type.
    • getType

      public MotorWrapper.MotorType getType()
    • getId

      public int getId()
    • set

      public void set(double output)
      Percent output [-1, 1].
    • setVoltage

      public void setVoltage(double volts)
      Approximate voltage control (converts volts to percent based on 12V nominal).
    • stop

      public void stop()
      Stop the motor (set output to 0).
    • setInverted

      public void setInverted(boolean inverted)
      Set inversion. of the motor With TalonFX and SparkMaxs it acesses the Configurator
    • getInverted

      public boolean getInverted()
    • follow

      public void follow(MotorWrapper leader, com.ctre.phoenix6.signals.MotorAlignmentValue MotorAligment)
      Make this motor follow a leader. Follows within the same vendor family. Cross-vendor follow is not supported.
      Parameters:
      MotorAligment - Only works on TalonFX
      leader - - Leader motor
    • follow

      public void follow(MotorWrapper leader)
      Make this motor follow a leader. Follows within the same vendor family. Cross-vendor follow is not supported.
    • asTalonFX

      public com.ctre.phoenix6.hardware.TalonFX asTalonFX()
    • asTalonSRX

      public com.ctre.phoenix.motorcontrol.can.TalonSRX asTalonSRX()
    • asVictorSPX

      public com.ctre.phoenix.motorcontrol.can.VictorSPX asVictorSPX()
    • asSparkMax

      public com.revrobotics.spark.SparkMax asSparkMax()
    • asCANSparkMax

      @Deprecated public com.revrobotics.spark.SparkMax asCANSparkMax()
      Deprecated.
    • isTalonFX

      public boolean isTalonFX()
    • isTalonSRX

      public boolean isTalonSRX()
    • isVictorSPX

      public boolean isVictorSPX()
    • isSparkMax

      public boolean isSparkMax()
    • get

      public Object get()
      Returns the motor controller instance (TalonFX, TalonSRX, VictorSPX, or SparkMax).
    • setBrakeMode

      public void setBrakeMode(boolean brake)
      Set brake/coast (neutral/idle) mode.
    • setOpenLoopRamp

      public void setOpenLoopRamp(double seconds)
      Set open-loop ramp (seconds from 0 to full). Note: TalonFX P6 implementation is not provided here; unwrap to TalonFX for advanced configs. DO NOT USE FOR SPARKMAX - SparkMax doesnt support Open-Loop-Ramp
    • getRawController

      public Object getRawController()
      Return the underlying vendor object (TalonFX, TalonSRX, VictorSPX, or SparkMax).
    • unwrap

      public <T> T unwrap(Class<T> clazz)
      Convenience unwrap to a requested vendor type. Returns null if the type does not match.
    • applyMotorConfig

      public void applyMotorConfig(MotorWrapper.MotorConfig config)
      Apply a unified MotorConfig.
    • addFollower

      public void addFollower(MotorWrapper follower)
      Add a follower that mirrors this motor's output using vendor follow.
    • configureMotionMagic

      public void configureMotionMagic(double cruiseVelocity, double acceleration, Double optionalJerk)
      Configure Motion Magic parameters (TalonFX Phoenix 6 or TalonSRX/VictorSPX Phoenix 5).
      Parameters:
      cruiseVelocity - Cruise velocity. Units: TalonFX: rotations/sec, TalonSRX/VictorSPX: native units per 100ms.
      acceleration - Acceleration. Units: TalonFX: rotations/sec^2, TalonSRX/VictorSPX: native units per 100ms/sec.
      optionalJerk - Jerk (optional). Units: TalonFX: rotations/sec^3. Ignored for Phoenix 5.
    • setMotionMagicPosition

      public void setMotionMagicPosition(double position, double arbFF)
      Set a Motion Magic position target.
      Parameters:
      position - Target position. Units: TalonFX: rotations, TalonSRX/VictorSPX: native sensor units.
      arbFF - Arbitrary feedforward. Units: Volts (Phoenix 6), Percent Output (Phoenix 5).
    • setMotionMagicPosition

      public void setMotionMagicPosition(double position)
    • configureMaxMotion

      public void configureMaxMotion(double cruiseVelocity, double acceleration)
      Configure REV MAXMotion (SparkMax).
      Parameters:
      cruiseVelocity - Max velocity. Units: rotations/sec.
      acceleration - Max acceleration. Units: rotations/sec^2.
    • setMaxMotionPosition

      public void setMaxMotionPosition(double position, double arbFF)
      Set MAXMotion position target.
      Parameters:
      position - Target position. Units: rotations.
      arbFF - Arbitrary feedforward. Units: Volts.
    • setMaxMotionPosition

      public void setMaxMotionPosition(double position)
    • setSmartPosition

      public void setSmartPosition(double position, double arbFF)
      Generic smart position setter choosing appropriate vendor motion mode. Falls back to percent output if unsupported.
      Parameters:
      position - Target position. Units: Rotations (TalonFX/SparkMax), Native Units (TalonSRX/VictorSPX).
      arbFF - Arbitrary feedforward. Units: Volts.
    • setSmartPosition

      public void setSmartPosition(double position)
    • getAppliedVoltage

      public double getAppliedVoltage()
    • getSimVoltage

      public double getSimVoltage()
      Get the applied voltage for simulation.
    • updateSimState

      public void updateSimState(double mechRotations, double mechVelRotPerSec)
      Update the vendor-specific simulation state from the physics simulation.
      Parameters:
      mechRotations - Mechanism position in rotations.
      mechVelRotPerSec - Mechanism velocity in rotations per second.
    • getOutputPercent

      public double getOutputPercent()
    • getCurrent

      public double getCurrent()
    • getTemperature

      public double getTemperature()
    • getPosition

      public double getPosition()
    • getVelocity

      public double getVelocity()
    • isConnected

      public boolean isConnected()
    • getMotorbyID

      public MotorWrapper getMotorbyID(int id)
    • isSmartMotionConfigured

      public boolean isSmartMotionConfigured()
    • getTalonFXSimState

      public com.ctre.phoenix6.sim.TalonFXSimState getTalonFXSimState()