Class CANAnalog


  • public class CANAnalog
    extends java.lang.Object
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      static class  CANAnalog.AnalogMode  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      protected int getID()
      Get the ID of the sensor that is connected to the SparkMax through the encoder port on the front of the controller (not the top port).
      boolean getInverted()
      Get the phase of the CANSensor.
      double getPosition()
      Get the position of the motor.
      double getPositionConversionFactor()
      Get the current conversion factor for the position of the analog sensor.
      double getVelocity()
      Get the velocity of the motor.
      double getVelocityConversionFactor()
      Get the current conversion factor for the velocity of the analog sensor.
      double getVoltage()
      Get the voltage of the analog sensor.
      CANError setFeedbackSensorRange​(float minRange, float maxRange)
      The range of the feedback sensor can be specified if the sensor has a limited range, such as an absolute encoder or analog device.
      CANError setInverted​(boolean inverted)
      Set the phase of the CANSensor so that it is set to be in phase with the motor itself.
      CANError setPositionConversionFactor​(double factor)
      Set the conversion factor for the position of the analog sensor.
      CANError setVelocityConversionFactor​(double factor)
      Set the conversion factor for the veolocity of the analog sensor.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • CANAnalog

        public CANAnalog​(CANSparkMax device,
                         CANAnalog.AnalogMode mode)
        Constructs a CANAnalog.
        Parameters:
        device - The Spark Max to which the analog sensor is attached.
        mode - The mode of the analog sensor, either absolute or relative
    • Method Detail

      • getVoltage

        public double getVoltage()
        Get the voltage of the analog sensor.
        Returns:
        Voltage of the sensor.
      • getPosition

        public double getPosition()
        Get the position of the motor. Returns value in the native unit of 'volt' by default, and can be changed by a scale factor using setPositionConversionFactor().
        Returns:
        Position of the sensor in volts
      • getVelocity

        public double getVelocity()
        Get the velocity of the motor. Returns value in the native units of 'volts per second' by default, and can be changed by a scale factor using setVelocityConversionFactor().
        Returns:
        Velocity of the sensor in volts per second
      • setPositionConversionFactor

        public CANError setPositionConversionFactor​(double factor)
        Set the conversion factor for the position of the analog sensor. By default, revolutions per volt is 1. Changing the position conversion factor will also change the position units.
        Parameters:
        factor - The conversion factor which will be multiplied by volts
        Returns:
        CANError Set to CANError.kOK if successful
      • setVelocityConversionFactor

        public CANError setVelocityConversionFactor​(double factor)
        Set the conversion factor for the veolocity of the analog sensor. By default, revolutions per volt second is 1. Changing the velocity conversion factor will also change the velocity units.
        Parameters:
        factor - The conversion factor which will be multipled by volts per second
        Returns:
        CANError Set to CANError.kOK is successful
      • getPositionConversionFactor

        public double getPositionConversionFactor()
        Get the current conversion factor for the position of the analog sensor.
        Returns:
        Analog position conversion factor
      • getVelocityConversionFactor

        public double getVelocityConversionFactor()
        Get the current conversion factor for the velocity of the analog sensor.
        Returns:
        Analog velocity conversion factor
      • getID

        protected int getID()
        Get the ID of the sensor that is connected to the SparkMax through the encoder port on the front of the controller (not the top port).
        Returns:
        The ID of the sensor
      • setInverted

        public CANError setInverted​(boolean inverted)
        Set the phase of the CANSensor so that it is set to be in phase with the motor itself. This only works for quadrature encoders and analog sensors. This will throw an error if the user tries to set the inversion of the hall effect.
        Parameters:
        inverted - The phase of the sensor
        Returns:
        CANError.kOK if successful
      • getInverted

        public boolean getInverted()
        Get the phase of the CANSensor. This will just return false if the user tries to get the inversion of the hall effect.
        Returns:
        The phase of the sensor
      • setFeedbackSensorRange

        public CANError setFeedbackSensorRange​(float minRange,
                                               float maxRange)
        The range of the feedback sensor can be specified if the sensor has a limited range, such as an absolute encoder or analog device. The default range is -infinity to infinity. This is NOT the same as setting soft limits, as this will only check to ensure that setpoint commands for the controller fall within this range.
        Parameters:
        minRange - The lower bound on the range of the sensor
        maxRange - The upper bound on the range of the sensor
        Returns:
        CANError.kOK if successful