Package com.revrobotics
Class CANAnalog
- java.lang.Object
-
- com.revrobotics.CANSensor
-
- com.revrobotics.CANAnalog
-
public class CANAnalog extends CANSensor
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
CANAnalog.AnalogMode
-
Nested classes/interfaces inherited from class com.revrobotics.CANSensor
CANSensor.FeedbackSensorType
-
-
Constructor Summary
Constructors Constructor Description CANAnalog(CANSparkMax device, CANAnalog.AnalogMode mode)
Constructs a CANAnalog.
-
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
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.
-
-
-
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()
Description copied from class:CANSensor
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).
-
setInverted
public CANError setInverted(boolean inverted)
Description copied from class:CANSensor
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.- Specified by:
setInverted
in classCANSensor
- Parameters:
inverted
- The phase of the sensor- Returns:
- CANError.kOK if successful
-
getInverted
public boolean getInverted()
Description copied from class:CANSensor
Get the phase of the CANSensor. This will just return false if the user tries to get the inversion of the hall effect.- Specified by:
getInverted
in classCANSensor
- Returns:
- The phase of the sensor
-
-