Package com.revrobotics
Class SparkMaxRelativeEncoder
java.lang.Object
com.revrobotics.SparkMaxRelativeEncoder
- All Implemented Interfaces:
CANEncoder,CANSensor,MotorFeedbackSensor,RelativeEncoder
Get an instance of this class by using
CANSparkMax.getEncoder() or CANSparkMax.getEncoder(Type, int).-
Nested Class Summary
Nested Classes -
Method Summary
Modifier and TypeMethodDescriptionintGet the average sampling depth for a quadrature encoder.intGet the counts per revolution of the quadrature encoder.booleanGet the phase of the MotorFeedbackSensor.intGet the number of samples for reading from a quadrature encoder.doubleGet the position of the motor.doubleGet the conversion factor for position of the encoder.doubleGet the velocity of the motor.doubleGet the conversion factor for velocity of the encoder.setAverageDepth(int depth) Set the average sampling depth for a quadrature encoder.setInverted(boolean inverted) Set the phase of the MotorFeedbackSensor so that it is set to be in phase with the motor itself.setMeasurementPeriod(int period_us) Set the measurement period for velocity measurements of a quadrature encoder.setPosition(double position) Set the position of the encoder.setPositionConversionFactor(double factor) Set the conversion factor for position of the encoder.setVelocityConversionFactor(double factor) Set the conversion factor for velocity of the encoder.
-
Method Details
-
getPosition
Description copied from interface:RelativeEncoderGet 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:
getPositionin interfaceCANEncoder- Specified by:
getPositionin interfaceRelativeEncoder- Returns:
- Number of rotations of the motor
-
getVelocity
Description copied from interface:RelativeEncoderGet 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:
getVelocityin interfaceCANEncoder- Specified by:
getVelocityin interfaceRelativeEncoder- Returns:
- Number the RPM of the motor
-
setPosition
Description copied from interface:RelativeEncoderSet the position of the encoder. By default the units are 'rotations' and can be changed by a scale factor using setPositionConversionFactor().- Specified by:
setPositionin interfaceCANEncoder- Specified by:
setPositionin interfaceRelativeEncoder- Parameters:
position- Number of rotations of the motor- Returns:
REVLibError.kOkif successful
-
setPositionConversionFactor
Description copied from interface:RelativeEncoderSet the conversion factor for position of the encoder. Multiplied by the native output units to give you position.- Specified by:
setPositionConversionFactorin interfaceCANEncoder- Specified by:
setPositionConversionFactorin interfaceRelativeEncoder- Parameters:
factor- The conversion factor to multiply the native units by- Returns:
REVLibError.kOkif successful
-
setVelocityConversionFactor
Description copied from interface:RelativeEncoderSet the conversion factor for velocity of the encoder. Multiplied by the native output units to give you velocity- Specified by:
setVelocityConversionFactorin interfaceCANEncoder- Specified by:
setVelocityConversionFactorin interfaceRelativeEncoder- Parameters:
factor- The conversion factor to multiply the native units by- Returns:
REVLibError.kOkif successful
-
getPositionConversionFactor
Description copied from interface:RelativeEncoderGet the conversion factor for position of the encoder. Multiplied by the native output units to give you position- Specified by:
getPositionConversionFactorin interfaceCANEncoder- Specified by:
getPositionConversionFactorin interfaceRelativeEncoder- Returns:
- The conversion factor for position
-
getVelocityConversionFactor
Description copied from interface:RelativeEncoderGet the conversion factor for velocity of the encoder. Multiplied by the native output units to give you velocity- Specified by:
getVelocityConversionFactorin interfaceCANEncoder- Specified by:
getVelocityConversionFactorin interfaceRelativeEncoder- Returns:
- The conversion factor for velocity
-
setAverageDepth
Description copied from interface:RelativeEncoderSet the average sampling depth for a quadrature encoder. This value sets the number of samples in the average for velocity readings. This can be any value from 1 to 64.When the SparkMax controller is in Brushless mode, this will not change any behavior.
- Specified by:
setAverageDepthin interfaceCANEncoder- Specified by:
setAverageDepthin interfaceRelativeEncoder- Parameters:
depth- The average sampling depth between 1 and 64 (default)- Returns:
REVLibError.kOkif successful
-
getAverageDepth
Description copied from interface:RelativeEncoderGet the average sampling depth for a quadrature encoder.- Specified by:
getAverageDepthin interfaceCANEncoder- Specified by:
getAverageDepthin interfaceRelativeEncoder- Returns:
- The average sampling depth
-
setMeasurementPeriod
Description copied from interface:RelativeEncoderSet the measurement period for velocity measurements of a quadrature encoder. When the SparkMax controller is in Brushless mode, this will not change any behavior.The basic formula to calculate velocity is change in position / change in time. This parameter sets the change in time for measurement.
- Specified by:
setMeasurementPeriodin interfaceCANEncoder- Specified by:
setMeasurementPeriodin interfaceRelativeEncoder- Parameters:
period_us- Measurement period in milliseconds. This number may be between 1 and 100 (default).- Returns:
REVLibError.kOkif successful
-
getMeasurementPeriod
Description copied from interface:RelativeEncoderGet the number of samples for reading from a quadrature encoder.- Specified by:
getMeasurementPeriodin interfaceCANEncoder- Specified by:
getMeasurementPeriodin interfaceRelativeEncoder- Returns:
- Number of samples
-
getCountsPerRevolution
Description copied from interface:RelativeEncoderGet 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:
getCountsPerRevolutionin interfaceCANEncoder- Specified by:
getCountsPerRevolutionin interfaceRelativeEncoder- Returns:
- Counts per revolution
-
setInverted
Description copied from interface:MotorFeedbackSensorSet 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:
setInvertedin interfaceCANEncoder- Specified by:
setInvertedin interfaceCANSensor- Specified by:
setInvertedin interfaceMotorFeedbackSensor- Specified by:
setInvertedin interfaceRelativeEncoder- Parameters:
inverted- The phase of the sensor- Returns:
REVLibError.kOkif successful
-
getInverted
Description copied from interface:MotorFeedbackSensorGet the phase of the MotorFeedbackSensor. This will just return false if the user tries to get the inversion of the hall sensor.- Specified by:
getInvertedin interfaceCANEncoder- Specified by:
getInvertedin interfaceCANSensor- Specified by:
getInvertedin interfaceMotorFeedbackSensor- Specified by:
getInvertedin interfaceRelativeEncoder- Returns:
- The phase of the sensor
-