Package ca.team4308.absolutelib.wrapper
Class MotorWrapper
java.lang.Object
ca.team4308.absolutelib.wrapper.MotorWrapper
Unified motor controller wrapper, Doesnt matter the vendor.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfacestatic enumstatic classBuilder-style unified motor configuration supporting common options and optional motion parameters. -
Constructor Summary
ConstructorsConstructorDescriptionMotorWrapper(MotorWrapper.MotorType type, int id) Create a wrapper (SparkMax defaults to Brushless).MotorWrapper(MotorWrapper.MotorType type, int id, com.revrobotics.spark.SparkLowLevel.MotorType sparkMotorType) Create a wrapper. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddFollower(MotorWrapper follower) Add a follower that mirrors this motor's output using vendor follow.voidApply a unified MotorConfig.com.revrobotics.spark.SparkMaxDeprecated.com.revrobotics.spark.SparkMaxcom.ctre.phoenix6.hardware.TalonFXcom.ctre.phoenix.motorcontrol.can.TalonSRXcom.ctre.phoenix.motorcontrol.can.VictorSPXvoidconfigureMaxMotion(double cruiseVelocity, double acceleration) Configure REV MAXMotion (SparkMax).voidconfigureMotionMagic(double cruiseVelocity, double acceleration, Double optionalJerk) Configure Motion Magic parameters (TalonFX Phoenix 6 or TalonSRX/VictorSPX Phoenix 5).voidfollow(MotorWrapper leader) Make this motor follow a leader.voidfollow(MotorWrapper leader, com.ctre.phoenix6.signals.MotorAlignmentValue MotorAligment) Make this motor follow a leader.get()Returns the motor controller instance (TalonFX, TalonSRX, VictorSPX, or SparkMax).doubledoubleintgetId()booleangetMotorbyID(int id) doubledoubleReturn the underlying vendor object (TalonFX, TalonSRX, VictorSPX, or SparkMax).doubleGet the applied voltage for simulation.com.ctre.phoenix6.sim.TalonFXSimStatedoublegetType()doublebooleanbooleanbooleanbooleanbooleanbooleanvoidset(double output) Percent output [-1, 1].voidsetBrakeMode(boolean brake) Set brake/coast (neutral/idle) mode.voidsetInverted(boolean inverted) Set inversion.voidsetMaxMotionPosition(double position) voidsetMaxMotionPosition(double position, double arbFF) Set MAXMotion position target.voidsetMotionMagicPosition(double position) voidsetMotionMagicPosition(double position, double arbFF) Set a Motion Magic position target.voidsetOpenLoopRamp(double seconds) Set open-loop ramp (seconds from 0 to full).voidsetSmartPosition(double position) voidsetSmartPosition(double position, double arbFF) Generic smart position setter choosing appropriate vendor motion mode.voidsetVoltage(double volts) Approximate voltage control (converts volts to percent based on 12V nominal).static MotorWrappersparkMax(int id, com.revrobotics.spark.SparkLowLevel.MotorType sparkMotorType) Convenience factory for SparkMax with explicit motor type.voidstop()Stop the motor (set output to 0).<T> TConvenience unwrap to a requested vendor type.voidupdateSimState(double mechRotations, double mechVelRotPerSec) Update the vendor-specific simulation state from the physics simulation.
-
Constructor Details
-
MotorWrapper
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
-
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 TalonFXleader- - Leader motor
-
follow
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. -
isTalonFX
public boolean isTalonFX() -
isTalonSRX
public boolean isTalonSRX() -
isVictorSPX
public boolean isVictorSPX() -
isSparkMax
public boolean isSparkMax() -
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
Return the underlying vendor object (TalonFX, TalonSRX, VictorSPX, or SparkMax). -
unwrap
Convenience unwrap to a requested vendor type. Returns null if the type does not match. -
applyMotorConfig
Apply a unified MotorConfig. -
addFollower
Add a follower that mirrors this motor's output using vendor follow. -
configureMotionMagic
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
-
isSmartMotionConfigured
public boolean isSmartMotionConfigured() -
getTalonFXSimState
public com.ctre.phoenix6.sim.TalonFXSimState getTalonFXSimState()
-