Files
YAGSL/swervelib/encoders/CanAndCoderSwerve.java

81 lines
1.6 KiB
Java
Raw Normal View History

package swervelib.encoders;
2023-08-09 15:05:33 -05:00
import com.reduxrobotics.sensors.canandcoder.CANandcoder;
/**
2023-08-09 15:05:33 -05:00
* HELIUM {@link CANandcoder} from ReduxRobotics absolute encoder, attached through the CAN bus.
*/
2023-08-09 15:05:33 -05:00
public class CanAndCoderSwerve extends SwerveAbsoluteEncoder
{
/**
2023-08-09 15:05:33 -05:00
* The {@link CANandcoder} representing the CANandCoder on the CAN bus.
*/
2023-08-09 15:05:33 -05:00
public CANandcoder encoder;
/**
* Inversion state of the encoder.
*/
private boolean inverted = false;
/**
2023-08-09 15:05:33 -05:00
* Create the {@link CANandcoder}
*
2023-08-09 15:05:33 -05:00
* @param canid The CAN ID whenever the CANandCoder is operating on the CANBus.
*/
2023-08-09 15:05:33 -05:00
public CanAndCoderSwerve(int canid)
{
encoder = new CANandcoder(canid);
}
/**
* Reset the encoder to factory defaults.
*/
@Override
2023-08-09 15:05:33 -05:00
public void factoryDefault()
{
encoder.resetFactoryDefaults(false);
}
/**
* Clear sticky faults on the encoder.
*/
@Override
2023-08-09 15:05:33 -05:00
public void clearStickyFaults()
{
encoder.clearStickyFaults();
}
/**
2023-08-09 15:05:33 -05:00
* Configure the CANandCoder to read from [0, 360) per second.
*
* @param inverted Whether the encoder is inverted.
*/
@Override
2023-08-09 15:05:33 -05:00
public void configure(boolean inverted)
{
this.inverted = inverted;
}
/**
* Get the absolute position of the encoder.
*
* @return Absolute position in degrees from [0, 360).
*/
@Override
2023-08-09 15:05:33 -05:00
public double getAbsolutePosition()
{
return (inverted ? -1.0 : 1.0) * encoder.getPosition() * 360;
}
/**
* Get the instantiated absolute encoder Object.
*
* @return Absolute encoder object.
*/
@Override
2023-08-09 15:05:33 -05:00
public Object getAbsoluteEncoder()
{
return encoder;
}
}