Package com.revrobotics
Class SparkAnalogSensor
- java.lang.Object
-
- com.revrobotics.SparkAnalogSensor
-
- All Implemented Interfaces:
AnalogInput
,CANAnalog
,CANSensor
,MotorFeedbackSensor
,SparkMaxAnalogSensor
public class SparkAnalogSensor extends java.lang.Object implements AnalogInput, SparkMaxAnalogSensor
Get an instance of this class by usingCANSparkBase.getAnalog(Mode)
.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
SparkAnalogSensor.Mode
-
Nested classes/interfaces inherited from interface com.revrobotics.CANAnalog
CANAnalog.AnalogMode
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
getInverted()
Get the phase of the analog sensordouble
getPosition()
Get the position of the sensor.double
getPositionConversionFactor()
Get the current conversion factor for the position of the analog sensor.double
getVelocity()
Get the velocity of the sensor.double
getVelocityConversionFactor()
Get the current conversion factor for the velocity of the analog sensor.double
getVoltage()
Get the voltage of the analog sensor.REVLibError
setInverted(boolean inverted)
Set the phase of the anlog sensor so that it is set to be in phase with the motor itselfREVLibError
setPositionConversionFactor(double factor)
Set the conversion factor for the position of the analog sensor.REVLibError
setVelocityConversionFactor(double factor)
Set the conversion factor for the velocity of the analog sensor.
-
-
-
Method Detail
-
getVoltage
public double getVoltage()
Get the voltage of the analog sensor.- Specified by:
getVoltage
in interfaceAnalogInput
- Specified by:
getVoltage
in interfaceCANAnalog
- Specified by:
getVoltage
in interfaceSparkMaxAnalogSensor
- Returns:
- Voltage of the sensor.
-
getPosition
public double getPosition()
Get the position of the sensor. Returns value in the native unit of 'volt' by default, and can be changed by a scale factor using setPositionConversionFactor().- Specified by:
getPosition
in interfaceAnalogInput
- Specified by:
getPosition
in interfaceCANAnalog
- Specified by:
getPosition
in interfaceSparkMaxAnalogSensor
- Returns:
- Position of the sensor
-
getVelocity
public double getVelocity()
Get the velocity of the sensor. Returns value in the native units of 'volts per second' by default, and can be changed by a scale factor using setVelocityConversionFactor().- Specified by:
getVelocity
in interfaceCANAnalog
- Specified by:
getVelocity
in interfaceSparkMaxAnalogSensor
- Returns:
- Velocity of the sensor in volts per second
-
setPositionConversionFactor
public REVLibError 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.- Specified by:
setPositionConversionFactor
in interfaceAnalogInput
- Specified by:
setPositionConversionFactor
in interfaceCANAnalog
- Specified by:
setPositionConversionFactor
in interfaceSparkMaxAnalogSensor
- Parameters:
factor
- The conversion factor which will be multiplied by volts- Returns:
REVLibError.kOk
if successful
-
setVelocityConversionFactor
public REVLibError setVelocityConversionFactor(double factor)
Set the conversion factor for the velocity of the analog sensor. By default, revolutions per volt second is 1. Changing the velocity conversion factor will also change the velocity units.- Specified by:
setVelocityConversionFactor
in interfaceCANAnalog
- Specified by:
setVelocityConversionFactor
in interfaceSparkMaxAnalogSensor
- Parameters:
factor
- The conversion factor which will be multiplied by volts per second- Returns:
REVLibError.kOk
if successful
-
getPositionConversionFactor
public double getPositionConversionFactor()
Get the current conversion factor for the position of the analog sensor.- Specified by:
getPositionConversionFactor
in interfaceAnalogInput
- Specified by:
getPositionConversionFactor
in interfaceCANAnalog
- Specified by:
getPositionConversionFactor
in interfaceSparkMaxAnalogSensor
- Returns:
- Analog position conversion factor
-
getVelocityConversionFactor
public double getVelocityConversionFactor()
Get the current conversion factor for the velocity of the analog sensor.- Specified by:
getVelocityConversionFactor
in interfaceCANAnalog
- Specified by:
getVelocityConversionFactor
in interfaceSparkMaxAnalogSensor
- Returns:
- Analog velocity conversion factor
-
setInverted
public REVLibError setInverted(boolean inverted)
Set the phase of the anlog sensor so that it is set to be in phase with the motor itself- Specified by:
setInverted
in interfaceCANAnalog
- Specified by:
setInverted
in interfaceCANSensor
- Specified by:
setInverted
in interfaceMotorFeedbackSensor
- Specified by:
setInverted
in interfaceSparkMaxAnalogSensor
- Parameters:
inverted
- The phase of the sensor- Returns:
REVLibError.kOk
if successful
-
getInverted
public boolean getInverted()
Get the phase of the analog sensor- Specified by:
getInverted
in interfaceCANAnalog
- Specified by:
getInverted
in interfaceCANSensor
- Specified by:
getInverted
in interfaceMotorFeedbackSensor
- Specified by:
getInverted
in interfaceSparkMaxAnalogSensor
- Returns:
- The phase of the sensor
-
-