Class WsSparkMax
- java.lang.Object
-
- org.wildstang.framework.io.outputs.Output
-
- org.wildstang.framework.io.outputs.AnalogOutput
-
- org.wildstang.hardware.roborio.outputs.WsMotorController
-
- org.wildstang.hardware.roborio.outputs.WsSparkMax
-
public class WsSparkMax extends WsMotorController
Controls a Spark Max motor controller.
-
-
Constructor Summary
Constructors Constructor Description WsSparkMax(java.lang.String name, int channel, boolean brushless, double p_default)Constructs the motor controller from config.WsSparkMax(java.lang.String name, int channel, boolean brushless, double p_default, boolean invert)Constructs the motor controller from config.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddClosedLoop(int slotID, double P, double I, double D, double FF)voidaddFollower(int canConstant, boolean brushless, boolean oppose)Add a follower motor to the current motor.voidaddFollower(int canConstant, WsMotorControllers controller, boolean oppose)Add a follower motor to the current motor.voiddisableCurrentLimit()Does nothing, SparkMax has no current limit disable function.voidenableVoltageCompensation()Enables voltage compensation.com.revrobotics.CANSparkMaxgetController()Returns the raw motor controller Object.com.revrobotics.CANSparkMaxgetFollower()Returns the raw follower motor controller Object.doublegetOutput()Returns the current motor output percent.com.revrobotics.SparkMaxPIDControllergetPIDController()doublegetPosition()Returns the quadrature position from an encoder.doublegetTemperature()Returns the temperature of the motor.doublegetVelocity()Returns the quadrature velocity from an encoder.voidinitClosedLoop(double P, double I, double D, double FF)Sets up closed loop control for the motorvoidinitClosedLoop(double P, double I, double D, double FF, com.revrobotics.AbsoluteEncoder absEncoder)Sets up closed loop control for the motorvoidinitClosedLoop(double P, double I, double D, double FF, com.revrobotics.AbsoluteEncoder absEncoder, boolean isWrapped)Sets up closed loop control for the motorvoidnotifyConfigChange()Does nothing, config values only affects start state.voidresetEncoder()Resets the position of an encoder.voidsendDataToOutput()Sets motor controlvoidsetBrake()Sets the motor to brake mode, will not freely spin.voidsetCoast()Sets the motor to coast mode, will freely spin.voidsetCurrentLimit(int stallLimitAmps, int freeLimitAmps, int limitRPM)Sets the current limit of the motor controller.voidsetPosition(double target)Sets the motor to track the given positionvoidsetPosition(double target, int slotID)Sets the motor to track the given position with a specific PIDFF constantsvoidsetSpeed(double value)Wraps setValue().voidsetVelocity(double target)Sets the motor to track the given velocity-
Methods inherited from class org.wildstang.hardware.roborio.outputs.WsMotorController
stop
-
Methods inherited from class org.wildstang.framework.io.outputs.AnalogOutput
getValue, setValue
-
-
-
-
Constructor Detail
-
WsSparkMax
public WsSparkMax(java.lang.String name, int channel, boolean brushless, double p_default)Constructs the motor controller from config.- Parameters:
name- Descriptive name of the controller.channel- Motor controller CAN constant.brushless- True if the motor is brushless, false if brushed.p_default- Default output value.
-
WsSparkMax
public WsSparkMax(java.lang.String name, int channel, boolean brushless, double p_default, boolean invert)Constructs the motor controller from config.- Parameters:
name- Descriptive name of the controller.channel- Motor controller CAN constant.brushless- True if the motor is brushless, false if brushed.p_default- Default output value.invert- Invert the motor's direction.
-
-
Method Detail
-
addFollower
public void addFollower(int canConstant, boolean brushless, boolean oppose)Add a follower motor to the current motor.- Parameters:
canConstant- CAN constant of the new follower motor.brushless- True if the motor is brushless, false if brushed.oppose- True if the follow should oppose the direction of this motor.
-
addFollower
public void addFollower(int canConstant, WsMotorControllers controller, boolean oppose)Add a follower motor to the current motor.- Specified by:
addFollowerin classWsMotorController- Parameters:
canConstant- CAN constant of the new follower motor.controller- Enumeration representing type of controller.oppose- True if the follow should oppose the direction of this motor.
-
getController
public com.revrobotics.CANSparkMax getController()
Returns the raw motor controller Object.- Specified by:
getControllerin classWsMotorController- Returns:
- CANSparkMax Object.
-
getFollower
public com.revrobotics.CANSparkMax getFollower()
Returns the raw follower motor controller Object.- Specified by:
getFollowerin classWsMotorController- Returns:
- Follower motor controller object, null if no follower.
-
setBrake
public void setBrake()
Sets the motor to brake mode, will not freely spin.- Specified by:
setBrakein classWsMotorController
-
setCoast
public void setCoast()
Sets the motor to coast mode, will freely spin.- Specified by:
setCoastin classWsMotorController
-
setCurrentLimit
public void setCurrentLimit(int stallLimitAmps, int freeLimitAmps, int limitRPM)Sets the current limit of the motor controller.- Specified by:
setCurrentLimitin classWsMotorController- Parameters:
stallLimitAmps- The amount of amps drawn before limiting while less than limitRPM.freeLimitAmps- The amount of amps drawn before limiting while greater than limitRPM.limitRPM- Sets the line between stallLimitAmps and freeLimitAmps.
-
enableVoltageCompensation
public void enableVoltageCompensation()
Enables voltage compensation.
-
getVelocity
public double getVelocity()
Returns the quadrature velocity from an encoder.- Specified by:
getVelocityin classWsMotorController- Returns:
- Current velocity.
-
getPosition
public double getPosition()
Returns the quadrature position from an encoder.- Specified by:
getPositionin classWsMotorController- Returns:
- Current position.
-
resetEncoder
public void resetEncoder()
Resets the position of an encoder.- Specified by:
resetEncoderin classWsMotorController
-
getOutput
public double getOutput()
Returns the current motor output percent.- Specified by:
getOutputin classWsMotorController- Returns:
- Current motor output as a percent.
-
getTemperature
public double getTemperature()
Returns the temperature of the motor.- Specified by:
getTemperaturein classWsMotorController- Returns:
- Current temperature.
-
sendDataToOutput
public void sendDataToOutput()
Sets motor control- Specified by:
sendDataToOutputin classWsMotorController
-
setSpeed
public void setSpeed(double value)
Wraps setValue().- Overrides:
setSpeedin classWsMotorController- Parameters:
value- New motor percent speed, from -1.0 to 1.0.
-
initClosedLoop
public void initClosedLoop(double P, double I, double D, double FF)Sets up closed loop control for the motor- Parameters:
P- the P valueI- the I valueD- the D valueFF- the feed forward constant
-
initClosedLoop
public void initClosedLoop(double P, double I, double D, double FF, com.revrobotics.AbsoluteEncoder absEncoder)Sets up closed loop control for the motor- Parameters:
P- the P valueI- the I valueD- the D valueFF- the feed forward constantabsEncoder- absolute encoder used to provided PID feedback
-
initClosedLoop
public void initClosedLoop(double P, double I, double D, double FF, com.revrobotics.AbsoluteEncoder absEncoder, boolean isWrapped)Sets up closed loop control for the motor- Parameters:
P- the P valueI- the I valueD- the D valueFF- the feed forward constantabsEncoder- absolute encoder used to provided PID feedbackisWrapped- whether wrapping should be enabled
-
getPIDController
public com.revrobotics.SparkMaxPIDController getPIDController()
-
addClosedLoop
public void addClosedLoop(int slotID, double P, double I, double D, double FF)
-
setPosition
public void setPosition(double target)
Sets the motor to track the given position- Parameters:
target- the encoder target value to track to
-
setPosition
public void setPosition(double target, int slotID)Sets the motor to track the given position with a specific PIDFF constants- Parameters:
target- the encoder target to track toslotID- the ID slot of the sparkmax to use
-
setVelocity
public void setVelocity(double target)
Sets the motor to track the given velocity- Parameters:
target- the encoder target value velocity to track to
-
notifyConfigChange
public void notifyConfigChange()
Does nothing, config values only affects start state.
-
disableCurrentLimit
public void disableCurrentLimit()
Does nothing, SparkMax has no current limit disable function.- Specified by:
disableCurrentLimitin classWsMotorController
-
-