Class WsSpark
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.WsSpark
Controls a Spark Max/Flex motor controller.
-
Constructor Summary
ConstructorsConstructorDescriptionWsSpark(String name, int channel, WsMotorControllers controller, double p_default) Constructs the motor controller from config.WsSpark(String name, int channel, WsMotorControllers controller, double p_default, boolean invert) Constructs the motor controller from config. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddClosedLoop(int slotID, double P, double I, double D, double FF) voidaddFollower(int canConstant, WsMotorControllers controller, boolean oppose) Add a follower motor to the current motor.voidvoidDoes nothing, Spark has no current limit disable function.voidEnables voltage compensation.com.revrobotics.spark.SparkBaseReturns the raw motor controller Object.com.revrobotics.spark.SparkBaseReturns the raw follower motor controller Object.doubleReturns the current motor output percent.doubleReturns the quadrature position from an encoder.doubleReturns the temperature of the motor.doubleReturns 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, boolean isEncoderFlipped) Sets up closed loop control for the motorvoidinitClosedLoop(double P, double I, double D, double FF, boolean isEncoderFlipped, boolean isWrapped) Sets up closed loop control for the motorvoidDoes nothing, config values only affects start state.voidResets the position of an encoder.voidSets 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 velocityvoidtempCurrentLimit(int limit) Sets the current limit, but does not burn flash.Methods inherited from class org.wildstang.hardware.roborio.outputs.WsMotorController
stopMethods inherited from class org.wildstang.framework.io.outputs.AnalogOutput
getValue, setValue
-
Constructor Details
-
WsSpark
Constructs the motor controller from config.- Parameters:
name- Descriptive name of the controller.channel- Motor controller CAN constant.controller- Enumeration representing type of controller.p_default- Default output value.
-
WsSpark
public WsSpark(String name, int channel, WsMotorControllers controller, double p_default, boolean invert) Constructs the motor controller from config.- Parameters:
name- Descriptive name of the controller.channel- Motor controller CAN constant.controller- Enumeration representing type of controller.p_default- Default output value.invert- Invert the motor's direction.
-
-
Method Details
-
addFollower
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.spark.SparkBase getController()Returns the raw motor controller Object.- Specified by:
getControllerin classWsMotorController- Returns:
- SparkBase Object.
-
getFollower
public com.revrobotics.spark.SparkBase 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.
-
configure
public void configure() -
tempCurrentLimit
public void tempCurrentLimit(int limit) Sets the current limit, but does not burn flash. Never use in init- Parameters:
limit- the amount of amps drawn before limiting
-
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, boolean isEncoderFlipped) Sets up closed loop control for the motor- Parameters:
P- the P valueI- the I valueD- the D valueFF- the feed forward constantisEncoderFlipped- whether to invert the encoder values
-
initClosedLoop
public void initClosedLoop(double P, double I, double D, double FF, boolean isEncoderFlipped, boolean isWrapped) Sets up closed loop control for the motor- Parameters:
P- the P valueI- the I valueD- the D valueFF- the feed forward constantisEncoderFlipped- whether to invert the encoder valuesisWrapped- whether wrapping should be enabled
-
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, Spark has no current limit disable function.- Specified by:
disableCurrentLimitin classWsMotorController
-