public class WsSpark extends WsMotorController
Controls a Spark Max/Flex motor controller.
  • Constructor Summary

    Constructors
    Constructor
    Description
    WsSpark(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 Type
    Method
    Description
    void
    addClosedLoop(int slotID, double P, double I, double D, double FF)
     
    void
    addFollower(int canConstant, WsMotorControllers controller, boolean oppose)
    Add a follower motor to the current motor.
    void
     
    void
    Does nothing, Spark has no current limit disable function.
    void
    Enables voltage compensation.
    com.revrobotics.spark.SparkBase
    Returns the raw motor controller Object.
    com.revrobotics.spark.SparkBase
    Returns the raw follower motor controller Object.
    double
    Returns the current motor output percent.
    double
    Returns the quadrature position from an encoder.
    double
    Returns the temperature of the motor.
    double
    Returns the quadrature velocity from an encoder.
    void
    initClosedLoop(double P, double I, double D, double FF)
    Sets up closed loop control for the motor
    void
    initClosedLoop(double P, double I, double D, double FF, boolean isEncoderFlipped)
    Sets up closed loop control for the motor
    void
    initClosedLoop(double P, double I, double D, double FF, boolean isEncoderFlipped, boolean isWrapped)
    Sets up closed loop control for the motor
    void
    Does nothing, config values only affects start state.
    void
    Resets the position of an encoder.
    void
    Sets motor control
    void
    Sets the motor to brake mode, will not freely spin.
    void
    Sets the motor to coast mode, will freely spin.
    void
    setCurrentLimit(int stallLimitAmps, int freeLimitAmps, int limitRPM)
    Sets the current limit of the motor controller.
    void
    setPosition(double target)
    Sets the motor to track the given position
    void
    setPosition(double target, int slotID)
    Sets the motor to track the given position with a specific PIDFF constants
    void
    setSpeed(double value)
    Wraps setValue().
    void
    setVelocity(double target)
    Sets the motor to track the given velocity
    void
    tempCurrentLimit(int limit)
    Sets the current limit, but does not burn flash.

    Methods inherited from class org.wildstang.hardware.roborio.outputs.WsMotorController

    stop

    Methods inherited from class org.wildstang.framework.io.outputs.AnalogOutput

    getValue, setValue

    Methods inherited from class org.wildstang.framework.io.outputs.Output

    disable, enable, getName, hashCode, isEnabled, update

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • WsSpark

      public WsSpark(String name, int channel, WsMotorControllers controller, double p_default)
      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

      public void addFollower(int canConstant, WsMotorControllers controller, boolean oppose)
      Add a follower motor to the current motor.
      Specified by:
      addFollower in class WsMotorController
      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:
      getController in class WsMotorController
      Returns:
      SparkBase Object.
    • getFollower

      public com.revrobotics.spark.SparkBase getFollower()
      Returns the raw follower motor controller Object.
      Specified by:
      getFollower in class WsMotorController
      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:
      setBrake in class WsMotorController
    • setCoast

      public void setCoast()
      Sets the motor to coast mode, will freely spin.
      Specified by:
      setCoast in class WsMotorController
    • setCurrentLimit

      public void setCurrentLimit(int stallLimitAmps, int freeLimitAmps, int limitRPM)
      Sets the current limit of the motor controller.
      Specified by:
      setCurrentLimit in class WsMotorController
      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:
      getVelocity in class WsMotorController
      Returns:
      Current velocity.
    • getPosition

      public double getPosition()
      Returns the quadrature position from an encoder.
      Specified by:
      getPosition in class WsMotorController
      Returns:
      Current position.
    • resetEncoder

      public void resetEncoder()
      Resets the position of an encoder.
      Specified by:
      resetEncoder in class WsMotorController
    • getOutput

      public double getOutput()
      Returns the current motor output percent.
      Specified by:
      getOutput in class WsMotorController
      Returns:
      Current motor output as a percent.
    • getTemperature

      public double getTemperature()
      Returns the temperature of the motor.
      Specified by:
      getTemperature in class WsMotorController
      Returns:
      Current temperature.
    • sendDataToOutput

      public void sendDataToOutput()
      Sets motor control
      Specified by:
      sendDataToOutput in class WsMotorController
    • setSpeed

      public void setSpeed(double value)
      Wraps setValue().
      Overrides:
      setSpeed in class WsMotorController
      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 value
      I - the I value
      D - the D value
      FF - 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 value
      I - the I value
      D - the D value
      FF - the feed forward constant
      isEncoderFlipped - 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 value
      I - the I value
      D - the D value
      FF - the feed forward constant
      isEncoderFlipped - whether to invert the encoder values
      isWrapped - 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 to
      slotID - 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:
      disableCurrentLimit in class WsMotorController