Package com.revrobotics
Class CANEncoder
- java.lang.Object
-
- com.revrobotics.CANEncoder
-
public class CANEncoder extends java.lang.Object
-
-
Field Summary
Fields Modifier and Type Field Description protected CANSparkMax
m_device
-
Constructor Summary
Constructors Constructor Description CANEncoder(CANSparkMax device)
Constructs a CANPIDController.CANEncoder(CANSparkMax device, EncoderType sensorType, int cpr)
Constructs a CANPIDController.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description int
getAverageDepth()
Get the averafe sampling depth for a quadrature encoder.int
getCPR()
Get the counts per revolution of the quadrature encoder.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.int
getMeasurementPeriod()
Get the number of samples for reading from a quadrature 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.CANError
setAverageDepth(int depth)
Set the average sampling depth for a quadrature encoder.CANError
setInverted(boolean inverted)
Set the phase of the CANSensor so that it is set to be in phase with the motor itself.CANError
setMeasurementPeriod(int period_us)
Set the measurement period for velocity measurements of a quadrature encoder.CANError
setPosition(double position)
Set the position of the encoder.CANError
setPositionConversionFactor(double factor)
Set the conversion factor for position of the encoder.CANError
setVelocityConversionFactor(double factor)
Set the conversion factor for velocity of the encoder.
-
-
-
Field Detail
-
m_device
protected final CANSparkMax m_device
-
-
Constructor Detail
-
CANEncoder
public CANEncoder(CANSparkMax device, EncoderType sensorType, int cpr)
Constructs a CANPIDController.- Parameters:
device
- The Spark Max to which the encoder is attached.sensorType
- The encoder type for the motor: kHallEffect or kQuadraturecpr
- The counts per revolution of the encoder
-
CANEncoder
public CANEncoder(CANSparkMax device)
Constructs a CANPIDController.- Parameters:
device
- The Spark Max to which the encoder is attached.
-
-
Method Detail
-
getPosition
public double getPosition()
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().- Returns:
- Number of rotations of the motor
-
getVelocity
public double getVelocity()
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().- Returns:
- Number the RPM of the motor
-
setPosition
public CANError setPosition(double position)
Set the position of the encoder. By default the units are 'rotations' and can be changed by a scale factor using setPositionConversionFactor().- Parameters:
position
- Number of rotations of the motor- Returns:
- CANError Set to CANError.kOK if successful
-
setPositionConversionFactor
public CANError setPositionConversionFactor(double factor)
Set the conversion factor for position of the encoder. Multiplied by the native output units to give you position.- Parameters:
factor
- The conversion factor to multiply the native units by- Returns:
- CANError Set to CANError.kOK if successful
-
setVelocityConversionFactor
public CANError setVelocityConversionFactor(double factor)
Set the conversion factor for velocity of the encoder. Multiplied by the native output units to give you velocity- Parameters:
factor
- The conversion factor to multiply the native units by- Returns:
- CANError Set to CANError.kOK if successful
-
getPositionConversionFactor
public double getPositionConversionFactor()
Get the conversion factor for position of the encoder. Multiplied by the native output units to give you position- Returns:
- The conversion factor for position
-
getVelocityConversionFactor
public double getVelocityConversionFactor()
Get the conversion factor for velocity of the encoder. Multiplied by the native output units to give you velocity- Returns:
- The conversion factor for velocity
-
setAverageDepth
public CANError setAverageDepth(int depth)
Set 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.- Parameters:
depth
- The average sampling depth between 1 and 64 (default)- Returns:
- CANError.kOK if successful
-
getAverageDepth
public int getAverageDepth()
Get the averafe sampling depth for a quadrature encoder.- Returns:
- The average sampling depth
-
setMeasurementPeriod
public CANError setMeasurementPeriod(int period_us)
Set 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 positon / change in time. This parameter sets the change in time for measurement.- Parameters:
period_us
- Measurement period in milliseconds. This number may be between 1 and 100 (default).- Returns:
- CANError.kOK if successful
-
getMeasurementPeriod
public int getMeasurementPeriod()
Get the number of samples for reading from a quadrature encoder.- Returns:
- Number of samples
-
getCPR
public int getCPR()
Get the counts per revolution of the quadrature encoder.- Returns:
- Counts per revolution
-
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
-
-