Files
YAGSL/swervelib/encoders/CanAndCoderSwerve.java

102 lines
2.1 KiB
Java
Raw Normal View History

package swervelib.encoders;
2024-01-15 14:37:13 -06:00
import com.reduxrobotics.sensors.canandcoder.Canandcoder;
/**
2024-01-15 14:37:13 -06: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
{
/**
2024-01-15 14:37:13 -06:00
* The {@link Canandcoder} representing the CANandCoder on the CAN bus.
*/
2024-01-16 16:53:07 -06:00
public Canandcoder encoder;
/**
2024-01-15 14:37:13 -06: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)
{
2024-01-15 14:37:13 -06:00
encoder = new Canandcoder(canid);
}
/**
* Reset the encoder to factory defaults.
2024-01-16 16:53:07 -06:00
*
* This will not clear the stored zero offset.
*/
@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();
}
/**
2024-01-16 16:53:07 -06: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)
{
2024-01-16 16:53:07 -06:00
encoder.setSettings(new Canandcoder.Settings().setInvertDirection(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()
{
2024-01-16 16:53:07 -06:00
return encoder.getAbsPosition() * 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;
}
/**
2024-01-16 16:53:07 -06:00
* Cannot set the offset of the Canandcoder.
*
* @param offset the offset the Absolute Encoder uses as the zero point.
2024-01-16 16:53:07 -06:00
* @return true if setting the zero point succeeded, false otherwise
*/
@Override
public boolean setAbsoluteEncoderOffset(double offset)
{
2024-01-16 16:53:07 -06:00
return encoder.setSettings(new Canandcoder.Settings().setZeroOffset(offset));
}
/**
* Get the velocity in degrees/sec.
*
* @return velocity in degrees/sec.
*/
@Override
public double getVelocity()
{
2024-01-16 16:53:07 -06:00
return encoder.getVelocity() * 360;
}
}