Package com.revrobotics
Class SparkMaxRelativeEncoder
- java.lang.Object
-
- com.revrobotics.SparkMaxRelativeEncoder
-
- All Implemented Interfaces:
CANEncoder
,CANSensor
,MotorFeedbackSensor
,RelativeEncoder
public class SparkMaxRelativeEncoder extends java.lang.Object implements RelativeEncoder
Get an instance of this class by usingCANSparkMax.getEncoder()
orCANSparkMax.getEncoder(Type, int)
.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
SparkMaxRelativeEncoder.Type
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description int
getAverageDepth()
Get the velocity calculation process's sampling depth for a quadrature or hall sensor encoder.int
getCountsPerRevolution()
Get the counts per revolution of the quadrature encoder.boolean
getInverted()
Get the phase of the MotorFeedbackSensor.int
getMeasurementPeriod()
Get the position measurement period used to calculate the velocity of a quadrature or hall sensor encoder.double
getPosition()
Get the position of the motor.double
getPositionConversionFactor()
Get the conversion factor for position of the encoder.double
getVelocity()
Get the velocity of the motor.double
getVelocityConversionFactor()
Get the conversion factor for velocity of the encoder.REVLibError
setAverageDepth(int depth)
Set the sampling depth of the velocity calculation process for a quadrature or hall sensor encoder.REVLibError
setInverted(boolean inverted)
Set the phase of the MotorFeedbackSensor so that it is set to be in phase with the motor itself.REVLibError
setMeasurementPeriod(int period_ms)
Set the position measurement period used to calculate the velocity of a quadrature or hall sensor encoder.REVLibError
setPosition(double position)
Set the position of the encoder.REVLibError
setPositionConversionFactor(double factor)
Set the conversion factor for position of the encoder.REVLibError
setVelocityConversionFactor(double factor)
Set the conversion factor for velocity of the encoder.
-
-
-
Method Detail
-
getPosition
public double getPosition()
Description copied from interface:RelativeEncoder
Get the position of the motor. This returns the native units of 'rotations' by default, and can be changed by a scale factor using setPositionConversionFactor().- Specified by:
getPosition
in interfaceCANEncoder
- Specified by:
getPosition
in interfaceRelativeEncoder
- Returns:
- Number of rotations of the motor
-
getVelocity
public double getVelocity()
Description copied from interface:RelativeEncoder
Get the velocity of the motor. This returns the native units of 'RPM' by default, and can be changed by a scale factor using setVelocityConversionFactor().- Specified by:
getVelocity
in interfaceCANEncoder
- Specified by:
getVelocity
in interfaceRelativeEncoder
- Returns:
- Number the RPM of the motor
-
setPosition
public REVLibError setPosition(double position)
Description copied from interface:RelativeEncoder
Set the position of the encoder. By default the units are 'rotations' and can be changed by a scale factor using setPositionConversionFactor().- Specified by:
setPosition
in interfaceCANEncoder
- Specified by:
setPosition
in interfaceRelativeEncoder
- Parameters:
position
- Number of rotations of the motor- Returns:
REVLibError.kOk
if successful
-
setPositionConversionFactor
public REVLibError setPositionConversionFactor(double factor)
Description copied from interface:RelativeEncoder
Set the conversion factor for position of the encoder. Multiplied by the native output units to give you position.- Specified by:
setPositionConversionFactor
in interfaceCANEncoder
- Specified by:
setPositionConversionFactor
in interfaceRelativeEncoder
- Parameters:
factor
- The conversion factor to multiply the native units by- Returns:
REVLibError.kOk
if successful
-
setVelocityConversionFactor
public REVLibError setVelocityConversionFactor(double factor)
Description copied from interface:RelativeEncoder
Set the conversion factor for velocity of the encoder. Multiplied by the native output units to give you velocity- Specified by:
setVelocityConversionFactor
in interfaceCANEncoder
- Specified by:
setVelocityConversionFactor
in interfaceRelativeEncoder
- Parameters:
factor
- The conversion factor to multiply the native units by- Returns:
REVLibError.kOk
if successful
-
getPositionConversionFactor
public double getPositionConversionFactor()
Description copied from interface:RelativeEncoder
Get the conversion factor for position of the encoder. Multiplied by the native output units to give you position- Specified by:
getPositionConversionFactor
in interfaceCANEncoder
- Specified by:
getPositionConversionFactor
in interfaceRelativeEncoder
- Returns:
- The conversion factor for position
-
getVelocityConversionFactor
public double getVelocityConversionFactor()
Description copied from interface:RelativeEncoder
Get the conversion factor for velocity of the encoder. Multiplied by the native output units to give you velocity- Specified by:
getVelocityConversionFactor
in interfaceCANEncoder
- Specified by:
getVelocityConversionFactor
in interfaceRelativeEncoder
- Returns:
- The conversion factor for velocity
-
setAverageDepth
public REVLibError setAverageDepth(int depth)
Description copied from interface:RelativeEncoder
Set the sampling depth of the velocity calculation process for a quadrature or hall sensor encoder. This value sets the number of samples in the average for velocity readings. For a quadrature encoder, this can be any value from 1 to 64 (default). For a hall sensor, it must be either 1, 2, 4, or 8 (default).- Specified by:
setAverageDepth
in interfaceCANEncoder
- Specified by:
setAverageDepth
in interfaceRelativeEncoder
- Parameters:
depth
- The velocity calculation process's sampling depth- Returns:
REVLibError.kOk
if successful
-
getAverageDepth
public int getAverageDepth()
Description copied from interface:RelativeEncoder
Get the velocity calculation process's sampling depth for a quadrature or hall sensor encoder.- Specified by:
getAverageDepth
in interfaceCANEncoder
- Specified by:
getAverageDepth
in interfaceRelativeEncoder
- Returns:
- The velocity calculation averaging process's sampling depth
-
setMeasurementPeriod
public REVLibError setMeasurementPeriod(int period_ms)
Description copied from interface:RelativeEncoder
Set the position measurement period used to calculate the velocity of a quadrature or hall sensor encoder. For a quadrature encoder, this number may be between 1 and 100 (default). For a hall sensor, this number may be between 8 and 64. The default for a hall sensor is 32ms.The basic formula to calculate velocity is change in position / change in time. This parameter sets the change in time for measurement.
- Specified by:
setMeasurementPeriod
in interfaceCANEncoder
- Specified by:
setMeasurementPeriod
in interfaceRelativeEncoder
- Parameters:
period_ms
- Measurement period in milliseconds- Returns:
REVLibError.kOk
if successful
-
getMeasurementPeriod
public int getMeasurementPeriod()
Description copied from interface:RelativeEncoder
Get the position measurement period used to calculate the velocity of a quadrature or hall sensor encoder.- Specified by:
getMeasurementPeriod
in interfaceCANEncoder
- Specified by:
getMeasurementPeriod
in interfaceRelativeEncoder
- Returns:
- The measurement period in milliseconds
-
getCountsPerRevolution
public int getCountsPerRevolution()
Description copied from interface:RelativeEncoder
Get the counts per revolution of the quadrature encoder.For a description on the difference between CPR, PPR, etc. go to https://www.cuidevices.com/blog/what-is-encoder-ppr-cpr-and-lpr
- Specified by:
getCountsPerRevolution
in interfaceCANEncoder
- Specified by:
getCountsPerRevolution
in interfaceRelativeEncoder
- Returns:
- Counts per revolution
-
setInverted
public REVLibError setInverted(boolean inverted)
Description copied from interface:MotorFeedbackSensor
Set the phase of the MotorFeedbackSensor 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 sensor.- Specified by:
setInverted
in interfaceCANEncoder
- Specified by:
setInverted
in interfaceCANSensor
- Specified by:
setInverted
in interfaceMotorFeedbackSensor
- Specified by:
setInverted
in interfaceRelativeEncoder
- Parameters:
inverted
- The phase of the sensor- Returns:
REVLibError.kOk
if successful
-
getInverted
public boolean getInverted()
Description copied from interface:MotorFeedbackSensor
Get the phase of the MotorFeedbackSensor. This will just return false if the user tries to get the inversion of the hall sensor.- Specified by:
getInverted
in interfaceCANEncoder
- Specified by:
getInverted
in interfaceCANSensor
- Specified by:
getInverted
in interfaceMotorFeedbackSensor
- Specified by:
getInverted
in interfaceRelativeEncoder
- Returns:
- The phase of the sensor
-
-