Package org.texastorque.torquelib.motors
Class TorqueNEO
java.lang.Object
org.texastorque.torquelib.motors.TorqueNEO
Designed to be the one and only motor wrapper for 2023.
This is a loose wrapper, designed only to:
- organize the REVLib objects.
- provide more distinct and consise get and set methods.
- handle REVLib errors.
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic final class
Collected representation of the SmartMotionProfile parameters. -
Field Summary
Modifier and TypeFieldDescriptionfinal com.revrobotics.SparkMaxPIDController
final com.revrobotics.RelativeEncoder
final ArrayList<com.revrobotics.CANSparkMax>
final com.revrobotics.CANSparkMax
The internal components to the motor wrapper. -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
addFollower
(int id, boolean invert) Add a follower motor ID.void
void
configurePID
(TorquePID pid) Configure the PID parameters.void
Configure the SmartMotionProfile parameters.double
double
double
Default unit is rotations, changed with setConversionFactors method.double
Default unit is RPM, changed with setConversionFactors method.double
getVolts()
void
setBreakMode
(boolean isBreak) void
setConversionFactors
(double posFactor, double veloFactor) void
setCurrent
(double current) Set the motor to a amperage output.void
setCurrentLimit
(int amps) Set the maximum current the motor can draw.void
setPercent
(double percent) Set the motor to a percent output from a decimal.void
setPosition
(double pos) Default unit is rotations, changed with setConversionFactors method.void
setPositionConversionFactor
(double factor) void
setSmartPosition
(double pos) Default unit is rotations, changed with setConversionFactors method.void
setSmartVelocity
(double velo) Default unit is RPM, changed with setConversionFactors method.void
setVelocity
(double velo) Default unit is RPM, changed with setConversionFactors method.void
setVelocityConversionFactor
(double factor) void
setVoltageCompensation
(double volts) Set the voltage compensation for the motor.void
setVolts
(double volts) Set the motor to a voltage output.
-
Field Details
-
motor
public final com.revrobotics.CANSparkMax motorThe internal components to the motor wrapper. These are marked public for a reason. Since they are marked final their reference cannot be set from outside, but they can be accessed and mutated from outside just like a get method. -
encoder
public final com.revrobotics.RelativeEncoder encoder -
controller
public final com.revrobotics.SparkMaxPIDController controller -
followers
-
-
Constructor Details
-
TorqueNEO
public TorqueNEO(int id) Build a new TorqueNEO.- Parameters:
id
- The CAN ID of the motor.encoderType
- The type of encoder to use.inverted
- Whether or not the motor is inverted.followers
- The CAN IDs of the followers.
-
-
Method Details
-
setBreakMode
public void setBreakMode(boolean isBreak) -
setPositionConversionFactor
public void setPositionConversionFactor(double factor) -
setVelocityConversionFactor
public void setVelocityConversionFactor(double factor) -
setConversionFactors
public void setConversionFactors(double posFactor, double veloFactor) -
addFollower
public void addFollower(int id, boolean invert) Add a follower motor ID.- Parameters:
id
- The CAN ID of the follower.invert
- Is the follower inverted relative to the leader?
-
burnFlash
public void burnFlash() -
setPercent
public void setPercent(double percent) Set the motor to a percent output from a decimal. Domain is [-1, 1] where 0 is off and negative values are reversed.- Parameters:
percent
- The percent output as a decimal.
-
getPercent
public double getPercent() -
setVolts
public void setVolts(double volts) Set the motor to a voltage output. Domain is [-12, 12] where 0 is off and negative values are reversed assuming max volts of 12.- Parameters:
percent
- The voltage output.
-
getVolts
public double getVolts() -
setVoltageCompensation
public void setVoltageCompensation(double volts) Set the voltage compensation for the motor.- Parameters:
volts
- Voltage compensation.
-
setCurrent
public void setCurrent(double current) Set the motor to a amperage output. Domain is [-40, 40] where 0 is off and negative values are reversed assuming max amperage of 40.- Parameters:
percent
- The amperage output.
-
getCurrent
public double getCurrent() -
setCurrentLimit
public void setCurrentLimit(int amps) Set the maximum current the motor can draw.- Parameters:
amps
- Maximum amperage.
-
configurePID
Configure the PID parameters. Necessary to use position and velocity control.- Parameters:
pid
- The TorquePID object.
-
setPosition
public void setPosition(double pos) Default unit is rotations, changed with setConversionFactors method.- Parameters:
pos
- The position to set.
-
getPosition
public double getPosition()Default unit is rotations, changed with setConversionFactors method.- Returns:
- The position.
-
setVelocity
public void setVelocity(double velo) Default unit is RPM, changed with setConversionFactors method.- Parameters:
velo
- The velocity to set.
-
getVelocity
public double getVelocity()Default unit is RPM, changed with setConversionFactors method.- Returns:
- The velocity.
-
configureSmartMotion
Configure the SmartMotionProfile parameters. Necessary to use the smart motion control.- Parameters:
profile
- The SmartMotionProfile object.
-
setSmartPosition
public void setSmartPosition(double pos) Default unit is rotations, changed with setConversionFactors method.- Parameters:
pos
- The position to set.
-
setSmartVelocity
public void setSmartVelocity(double velo) Default unit is RPM, changed with setConversionFactors method.- Parameters:
velo
- The velocity to set.
-